fix locator to prevent fileload exception in reflection only context for referenced dlls of plugins.

added probing path to app.config to include dlls in the plugins dir.
updated pdf exporter code to the working code. still doesnt work on stream code though.
This commit is contained in:
chris.watts90@outlook.com 2017-07-06 16:19:39 +01:00
parent 568f399a3f
commit cf2f5a72ae
6 changed files with 60 additions and 12 deletions

View File

@ -44,6 +44,7 @@
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />

View File

@ -3,6 +3,7 @@ using System.Threading;
using Interfaces; using Interfaces;
using Syncfusion.HtmlConverter; using Syncfusion.HtmlConverter;
using Syncfusion.Pdf; using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
namespace PDFExporter namespace PDFExporter
{ {
@ -28,11 +29,44 @@ namespace PDFExporter
void DoExport(string fileContent, string baseUrl) void DoExport(string fileContent, string baseUrl)
{ {
var pdfExporter = new HtmlToPdfConverter(); //var pdfExporter = new HtmlToPdfConverter();
//var settings2 = new IEConverterSettings();
//settings2.AdditionalDelay = 2000;
//pdfExporter.ConverterSettings = settings2;
//PdfDocument doc = pdfExporter.Convert(fileContent, baseUrl);
var conv = new HtmlToPdfConverter();
PdfDocument document = new PdfDocument();
//Set page margins and dimensions.
PdfUnitConvertor convertor = new PdfUnitConvertor();
float width = convertor.ConvertToPixels(document.PageSettings.Width, PdfGraphicsUnit.Point);
float height = convertor.ConvertToPixels(document.PageSettings.Height, PdfGraphicsUnit.Point);
var settings = new IEConverterSettings(); var settings = new IEConverterSettings();
settings.AdditionalDelay = 2000;
pdfExporter.ConverterSettings = settings; settings.EnableHyperLink = true;
PdfDocument doc = pdfExporter.Convert(fileContent, baseUrl); settings.EnableJavaScript = true;
settings.SplitImages = false;
settings.SplitTextLines = false;
settings.Margin.All = 20.0f;
settings.PdfPageSize = PdfPageSize.A4;
conv.ConverterSettings = settings;
//Convert the URL/HTML string by providing the required width and height.
var doc = conv.Convert(@"http://www.bbc.co.uk", width, height, AspectRatio.KeepWidth);
doc.PageSettings.Size = PdfPageSize.A4;
doc.PageSettings.SetMargins((float)20.0f);
doc.Save("c:\\zzz\\test3.pdf");
//doc.Close(true);
MemoryStream ms = new MemoryStream(); MemoryStream ms = new MemoryStream();
doc.Save(ms); doc.Save(ms);
doc.Close(true); doc.Close(true);

View File

@ -58,7 +58,7 @@ namespace RaceLapTimer
// id.Close(); // id.Close();
// id.Dispose(); // id.Dispose();
// fs.Flush(true); // fs.Flush(true);
// fs.Close(); // fs.Close(); //this still isnt saving the file.. :(
//} //}
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
@ -40,9 +41,18 @@ namespace RaceLapTimer.Extensions
if (!IsAssembly(ext)) continue; if (!IsAssembly(ext)) continue;
var assembly = Assembly.ReflectionOnlyLoadFrom(file); var assembly = Assembly.ReflectionOnlyLoadFrom(file);
var pluginTypes = (from t in assembly.GetExportedTypes() var pluginTypes = new List<Type>();
where t.GetInterfaces().Any(x => x.Name == typeof(T).Name) try
select t).ToList(); {
pluginTypes.AddRange((from t in assembly.GetExportedTypes()
where t.GetInterfaces().Any(x => x.Name == typeof(T).Name)
select t).ToList());
}
catch (FileLoadException flex)
{
_logger.Error(flex);
}
if (pluginTypes.Any()) if (pluginTypes.Any())
{ {
discoveryList.Add(new DiscoveredPlugin discoveryList.Add(new DiscoveredPlugin

View File

@ -32,6 +32,9 @@
<assemblyIdentity name="Ninject.Extensions.ChildKernel" publicKeyToken="c7192dc5380945e7" culture="neutral" /> <assemblyIdentity name="Ninject.Extensions.ChildKernel" publicKeyToken="c7192dc5380945e7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.2.0.0" newVersion="3.2.0.0" /> <bindingRedirect oldVersion="0.0.0.0-3.2.0.0" newVersion="3.2.0.0" />
</dependentAssembly> </dependentAssembly>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="plugins"/>
</assemblyBinding>
</assemblyBinding> </assemblyBinding>
</runtime> </runtime>
</configuration> </configuration>

View File

@ -96,10 +96,10 @@ copy /B /Y "$(TargetDir)NLogConfig.xml" "$(TargetDir)Configs\NLogConfig.xml"
copy /B /Y "$(SolutionDir)RaceLapTimer\$(OutDir)Ninject.Extensions.Xml.dll" "$(TargetDir)Ninject.Extensions.Xml.dll" copy /B /Y "$(SolutionDir)RaceLapTimer\$(OutDir)Ninject.Extensions.Xml.dll" "$(TargetDir)Ninject.Extensions.Xml.dll"
copy /B /Y "$(SolutionDir)PDFExporter\$(OutDir)PDFExporter.dll" "$(TargetDir)Plugins\PDFExporter.dll" copy /B /Y "$(SolutionDir)PDFExporter\$(OutDir)PDFExporter.dll" "$(TargetDir)Plugins\PDFExporter.dll"
copy /B /Y "$(SolutionDir)PDFExporter\$(OutDir).dll" "$(TargetDir)Plugins\PDFExporter.dll" copy /B /Y "$(SolutionDir)PDFExporter\$(OutDir).dll" "$(TargetDir)Plugins\PDFExporter.dll"
copy /B /Y "$(SolutionDir)PDFExporter\$(OutDir)Syncfusion.HtmlConverter.Base.dll" "$(TargetDir)Syncfusion.HtmlConverter.Base.dll" copy /B /Y "$(SolutionDir)PDFExporter\$(OutDir)Syncfusion.HtmlConverter.Base.dll" "$(TargetDir)Plugins\Syncfusion.HtmlConverter.Base.dll"
copy /B /Y "$(SolutionDir)PDFExporter\$(OutDir)Syncfusion.Pdf.Base.dll" "$(TargetDir)Syncfusion.Pdf.Base.dll" copy /B /Y "$(SolutionDir)PDFExporter\$(OutDir)Syncfusion.Pdf.Base.dll" "$(TargetDir)Plugins\Syncfusion.Pdf.Base.dll"
copy /B /Y "$(SolutionDir)PDFExporter\$(OutDir)Syncfusion.Compression.Base.dll" "$(TargetDir)Syncfusion.Compression.Base.dll" copy /B /Y "$(SolutionDir)PDFExporter\$(OutDir)Syncfusion.Compression.Base.dll" "$(TargetDir)Plugins\Syncfusion.Compression.Base.dll"
copy /B /Y "$(SolutionDir)PDFExporter\$(OutDir)Microsoft.mshtml.dll" "$(TargetDir)Microsoft.mshtml.dll"</PostBuildEvent> copy /B /Y "$(SolutionDir)PDFExporter\$(OutDir)Microsoft.mshtml.dll" "$(TargetDir)Plugins\Microsoft.mshtml.dll"</PostBuildEvent>
</PropertyGroup> </PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.