private async Task ExecuteAndUnloadAsync(string assemblyPath, HashSet <string> tests, CancellationToken token) { // Create the unloadable HostAssemblyLoadContext var alc = new CustomAssemblyLoadContext(assemblyPath); // Create a weak reference to the AssemblyLoadContext that will allow us to detect // when the unload completes. var alcWeakRef = new WeakReference(alc); try { // Load the plugin assembly into the HostAssemblyLoadContext. // NOTE: the assemblyPath must be an absolute path. var assembly = alc.LoadFromAssemblyPath(assemblyPath); using var runner = CreateRunner(tests, assembly.Location); runner.Start(); TestSessionFinished.WaitOne(); TestSessionFinished.Reset(); await WaitRunnerExitAsync(runner, token); } catch (Exception e) { Console.WriteLine(e); } // This initiates the unload of the HostAssemblyLoadContext. The actual unloading doesn't happen // right away, GC has to kick in later to collect all the stuff. alc.Unload(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <MoInvoiceContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DevConnection")).UseLazyLoadingProxies()); services.AddAutoMapper(typeof(Mappings.MappingProfile).Assembly); services.AddScoped <IInvoiceService, InvoiceService>(); services.AddScoped <ICustomerService, CustomerService>(); services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); var processSuffix = "32bit"; if (Environment.Is64BitProcess && IntPtr.Size == 8) { processSuffix = "64bit"; } var context = new CustomAssemblyLoadContext(); context.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), $"PDFNative\\{processSuffix}\\libwkhtmltox.dll")); services.AddScoped <IPDFService, PDFService>(); services.AddControllersWithViews(); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddScoped <IRazorLightEngine>(sp => { var engine = new RazorLightEngineBuilder() .UseFilesystemProject(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)) .UseMemoryCachingProvider() .Build(); return(engine); }); var processSufix = "32bit"; if (Environment.Is64BitProcess && IntPtr.Size == 8) { processSufix = "64bit"; } var context = new CustomAssemblyLoadContext(); context.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), $"PDFNative\\{processSufix}\\libwkhtmltox.dll")); services.AddScoped <IPDFService, PDFService>(); }
private static void LoadAssembly(string nums) { var context = new CustomAssemblyLoadContext(); context.Unloading += ContextUnloading; Assembly assembly = context.LoadFromAssemblyPath(@"C:\Users\толеутайб\source\repos\DynamicFactorial\DynamicFactorial\DynamicFactorial\bin\Debug\netcoreapp3.0\ToCountFactorial\ToCountFactorial\bin\Debug\netcoreapp3.0\ToCountFactorial.dll"); var type = assembly.GetType("ToCountFactorial.Program"); var greetMethod = type.GetMethod("ToFactorial"); string numFactorials = String.Empty; string[] tokens = nums.Split(','); for (int i = 0; i < tokens.Length; i++) { if (int.TryParse(tokens[i], out var number)) { var instance = Activator.CreateInstance(type); int result = (int)greetMethod.Invoke(instance, new object[] { number }); numFactorials += result.ToString(); numFactorials += '\n'; } } MessageBox.Show(numFactorials); context.Unload(); }
public void Decompile(CompilationStreamPair streams, TextWriter codeWriter) { Argument.NotNull(nameof(streams), streams); Argument.NotNull(nameof(codeWriter), codeWriter); using (var loadContext = new CustomAssemblyLoadContext(shouldShareAssembly: _ => true)) { var assembly = loadContext.LoadFromStream(streams.AssemblyStream); ValidateStaticConstructors(assembly); using var runtimeLease = _runtimePool.GetOrCreate(); var runtime = runtimeLease.Object; runtime.Flush(); var context = new JitWriteContext(codeWriter, runtime); context.Translator = new IntelTranslator { SymbolResolver = (Instruction instruction, long addr, ref long offset) => ResolveSymbol(runtime, instruction, addr, context.CurrentMethodAddress) }; WriteJitInfo(runtime.ClrInfo, codeWriter); WriteProfilerState(codeWriter); var architecture = MapArchitecture(runtime.ClrInfo.DacInfo.TargetArchitecture); foreach (var type in assembly.DefinedTypes) { if (type.IsNested) { continue; // it's easier to handle nested generic types recursively, so we suppress all nested for consistency } DisassembleAndWriteMembers(context, type); } } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //PDF var context = new CustomAssemblyLoadContext(); context.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll")); services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); //>>>Cors Origin services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => builder .WithOrigins("http://localhost:4200") .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials()); }); //>>>END Cors Origin services.AddTransient <IAccountService, AccountService>(); //DI services.AddTransient <IUserDetailDAL, UserDetailDAL>(); //DI services.AddTransient <IReportDSL, ReportDSL>(); //DI services.AddSignalR(); //To Allow SignalR services.AddControllers(); services.AddDbContext <AppDbContext>(contextOptions => { contextOptions.UseSqlServer(Configuration.GetValue <string>(key: "ConnectionString")); }); services.AddDirectoryBrowser(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton <IFileProvider>( new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"))); services.AddDistributedMemoryCache(); services.AddControllersWithViews() .AddJsonOptions(options => { options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); options.JsonSerializerOptions.PropertyNamingPolicy = null; }); services.AddSession(options => { options.IdleTimeout = TimeSpan.FromMinutes(240);//You can set Time }); services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddControllersWithViews(); services.AddDbContext <DBContext>(options => options.UseMySql(Configuration.GetConnectionString("DefaultConnection"))); services.AddAutoMapper(typeof(Startup)); services.Configure <Appsettings>(Configuration.GetSection("AppSettings")); services.Configure <EmailSettings>(Configuration.GetSection("EmailSettings")); var context = new CustomAssemblyLoadContext(); var path = Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll"); context.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll")); services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); }
public void Decompile(CompilationStreamPair streams, TextWriter codeWriter) { Argument.NotNull(nameof(streams), streams); Argument.NotNull(nameof(codeWriter), codeWriter); using (var loadContext = new CustomAssemblyLoadContext(shouldShareAssembly: _ => true)) { var assembly = loadContext.LoadFromStream(streams.AssemblyStream); ValidateStaticConstructors(assembly); using var runtimeLease = _runtimePool.GetOrCreate(); var runtime = runtimeLease.Object; runtime.Flush(); var context = new JitWriteContext(codeWriter, runtime); WriteJitInfo(runtime.ClrInfo, codeWriter); WriteProfilerState(codeWriter); foreach (var type in assembly.DefinedTypes) { if (type.IsNested) { continue; // it's easier to handle nested generic types recursively, so we suppress all nested for consistency } DisassembleAndWriteMembers(context, type); } } }
public static CompilerResponse Compile(string code) { string assemblyName = "UserCode"; SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(code); var refPaths = new[] { typeof(Object).GetTypeInfo().Assembly.Location, typeof(Console).GetTypeInfo().Assembly.Location, Path.Combine(Path.GetDirectoryName(typeof(OutputHandler).GetTypeInfo().Assembly.Location), "SandboxHelpers.dll"), Path.Combine(Path.GetDirectoryName(typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly.Location), "System.Runtime.dll") }; MetadataReference[] references = refPaths.Select(r => MetadataReference.CreateFromFile(r)).ToArray(); CSharpCompilation compilation = CSharpCompilation.Create( assemblyName, syntaxTrees: new[] { syntaxTree }, references: references, options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); using (var ms = new MemoryStream()) { EmitResult result = compilation.Emit(ms); if (!result.Success) { List <string> failures = result.Diagnostics.Where(diagnostic => diagnostic.IsWarningAsError || diagnostic.Severity == DiagnosticSeverity.Error).Select(x => x.ToString()).ToList(); return(new CompilerResponse() { Status = "Error", Errors = failures }); } else { ms.Seek(0, SeekOrigin.Begin); var loader = new CustomAssemblyLoadContext(); Assembly assembly = loader.LoadFromStream(ms); var type = assembly.GetType("CodeEnv.SandBox"); var instance = assembly.CreateInstance("CodeEnv.SandBox"); var prop = type.GetProperty("Output"); var meth = type.GetMember("Run").First() as MethodInfo; meth.Invoke(instance, null); var outputs = prop.GetValue(instance, null); assembly = null; loader.Unload(); return(new CompilerResponse() { Status = "Success", ConsoleLogs = (outputs as OutputHandler).GetLines() }); } } }
public override void Configure(IFunctionsHostBuilder builder) { var wkHtmlToPdfFileName = "libwkhtmltox"; if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { wkHtmlToPdfFileName += ".so"; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { wkHtmlToPdfFileName += ".dylib"; } CustomAssemblyLoadContext context = new CustomAssemblyLoadContext(); context.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), wkHtmlToPdfFileName)); builder.Services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); var configuration = builder.GetContext().Configuration; var storageSettings = new StorageSettings { ConnectionString = configuration["ConnectionString"] }; builder.Services.AddSingleton(storageSettings); builder.Services.AddSingleton <IStorageService, StorageService>(); }
public static void ConfigurePDF(this IServiceCollection services) { services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); var context = new CustomAssemblyLoadContext(); context.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll")); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var thisContext = new CustomAssemblyLoadContext(); thisContext.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll")); services.AddSingleton <Models.UserService>(); services.AddSingleton <Models.ProductService>(); services.AddSingleton <Models.CartService>(); services.AddSingleton <Models.AddressService>(); services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); services.AddMvc(); services.AddDistributedMemoryCache(); // Adds a default in-memory implementation of IDistributedCache services.AddSession(); services.AddHttpContextAccessor(); services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => false; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddSession(options => { // Set session timeout value options.IdleTimeout = TimeSpan.FromHours(24); options.Cookie.HttpOnly = true; }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
public async Task <IActionResult> GenerateSomeDocumentAsync() { var path = "C:\\Dev\\VSCode\\MailRoomSolution\\MailRoom.Api\\Utils\\v0.12.4\\64 bit\\libwkhtmltox.dll"; CustomAssemblyLoadContext context = new CustomAssemblyLoadContext(); context.LoadUnmanagedLibrary(path); var converter = new SynchronizedConverter(new PdfTools()); var doc = converter.Convert(new HtmlToPdfDocument() { GlobalSettings = { ColorMode = ColorMode.Color, Orientation = Orientation.Landscape, PaperSize = PaperKind.A4Plus, }, Objects = { new ObjectSettings() { PagesCount = true, HtmlContent = "This is my Test PDF...", WebSettings = { DefaultEncoding = "utf-8" }, HeaderSettings ={ FontSize =9, Right = "Page [page] of [toPage]", Line = true, Spacing = 2.812 } } } }); return(File(doc, "application/pdf")); }
/// <summary> /// Method that receives a html document and /// converts it in a bytes array document /// </summary> /// <param name="htmlDocumentContent">Document content in HTML format</param> /// <param name="showHeader"></param> /// <returns>Document converted into PDF in the form of a bytes array</returns> public byte[] GetPdfFromHtlm(string htmlDocumentContent, bool showHeader = true) { var doc = new HtmlToPdfDocument() { GlobalSettings = { PaperSize = PaperKind.Letter, Orientation = Orientation.Portrait, Margins = showHeader ? new MarginSettings(20, 20, 20, 10) : new MarginSettings(10, 10, 10, 10), }, Objects = { new ObjectSettings() { HtmlContent = htmlDocumentContent, } } }; CustomAssemblyLoadContext context = new CustomAssemblyLoadContext(); context.LoadUnmanagedLibrary(System.IO.Directory.GetCurrentDirectory() + "\\libwkhtmltox.dll"); var converter = new SynchronizedConverter(new PdfTools()); return(_converter.Convert(doc)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); var connection = Configuration.GetConnectionString("Dev"); services.AddDbContext <FacturacionDbContext>(options => options.UseSqlServer(connection).UseLazyLoadingProxies()); services.AddScoped <IWarehouseRepository, WarehouseRepository>(); services.AddScoped <IProductRepository, ProductRepository>(); services.AddScoped <IPersonRepository, PersonRepository>(); services.AddScoped <IOrderRepository, OrderRepository>(); services.AddScoped <IOrderDetailRepository, OrderDetailRepository>(); services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); var architectureFolder = (IntPtr.Size == 8) ? "64 bit" : "32 bit"; var wkHtmlToPdfPath = Path.Combine(_hostingEnvironment.ContentRootPath, $"wkhtmltox\\v0.12.4\\{architectureFolder}\\libwkhtmltox"); CustomAssemblyLoadContext context = new CustomAssemblyLoadContext(); context.LoadUnmanagedLibrary(wkHtmlToPdfPath); services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); // Add Cors services.AddCors(o => o.AddPolicy("MyPolicy", builder => { builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); })); }
/// <summary> /// This method gets called by the runtime. Use this method to add services to the container. /// </summary> public void ConfigureServices(IServiceCollection services) { services.AddServices(); var context = new CustomAssemblyLoadContext(); context.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), "Utilities/DinkToPdfFiles/libwkhtmltox.dll")); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connection = @"Server=localhost\SQLEXPRESS;Database=AstmaDB;Trusted_Connection=True;"; services.AddDbContext <MainContext>(options => options.UseSqlServer(connection)); services.AddMvc(); services.AddCors(o => o.AddPolicy("MyPolicy", builder => { builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); })); services.Configure <MvcOptions>(options => { options.Filters.Add(new CorsAuthorizationFilterFactory("MyPolicy")); }); string rootPath = Directory.GetCurrentDirectory(); var architectureFolder = (IntPtr.Size == 8) ? "64 bit" : "32 bit"; var wkHtmlToPdfPath = Path.Combine(rootPath, $"wkhtmltox\\{architectureFolder}\\libwkhtmltox.dll"); var context = new CustomAssemblyLoadContext(); context.LoadUnmanagedLibrary(wkHtmlToPdfPath); services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); }
private void ConfigurePdfService(IServiceCollection services) { CustomAssemblyLoadContext context = new CustomAssemblyLoadContext(); string path = @"C:\" + "libwkhtmltox.dll"; context.LoadUnmanagedLibrary(path); services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); }
private static Type[] GetTypesFromCompiledAssembly(Stream peStream) { peStream.Seek(0, SeekOrigin.Begin); var assemblyLoadContext = new CustomAssemblyLoadContext(); var assembly = assemblyLoadContext.LoadFromStream(peStream); var types = assembly.GetTypes(); return(types); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => false; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.Configure <IdentityOptions>(options => { // Password settings options.Password.RequireDigit = true; options.Password.RequiredLength = 8; options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = true; options.Password.RequireLowercase = false; }); //After adding users services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer( Configuration.GetConnectionString("DefaultConnection"))); services.AddIdentity <IdentityUser, IdentityRole>() .AddEntityFrameworkStores <ApplicationDbContext>().AddDefaultUI().AddDefaultTokenProviders(); services.AddScoped <IDbInitializer, DbInitializer>(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>(); //pdf var contextt = new CustomAssemblyLoadContext(); contextt.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll")); services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); //Before adding users //services.AddDbContext<ApplicationDbContext>(options => // options.UseSqlServer( // Configuration.GetConnectionString("DefaultConnection"))); //services.AddDefaultIdentity<IdentityUser>() // .AddEntityFrameworkStores<ApplicationDbContext>(); //services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); //for the shopping bag services.AddSession(options => { options.IdleTimeout = TimeSpan.FromMinutes(30); options.Cookie.HttpOnly = false; }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); var context = new CustomAssemblyLoadContext(); context.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), "lib", "libwkhtmltox.dll")); services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); }
public static void AddFilesApi(this IServiceCollection services) { services.AddSingleton <IConverter>(x => new SynchronizedConverter(new PdfTools())); services.AddSingleton <IImagesRepository, ImagesRepository>(); var wkHtmlToPdfContext = new CustomAssemblyLoadContext(); var architectureFolder = (IntPtr.Size == 8) ? "64 bit" : "32 bit"; var wkHtmlToPdfPath = Path.Combine(AppContext.BaseDirectory, $"libs\\wkhtmltox\\{architectureFolder}\\libwkhtmltox"); wkHtmlToPdfContext.LoadUnmanagedLibrary(wkHtmlToPdfPath); }
public ExperimentsController(ScientificStudiesRecordDbContext context, IMapper mapper) { _context = context; _unitOfWork = new UnitOfWork(context); _mapper = mapper; CustomAssemblyLoadContext assemblyContext = new CustomAssemblyLoadContext(); assemblyContext.LoadUnmanagedLibrary("/home/teo/Projects/Master_rad/ScientificStudyRecords/ScientificStudyWeb/bin/Debug/netcoreapp3.1/libwkhtmltox.so"); _converter = new SynchronizedConverter(new PdfTools()); ; }
public override void Initialize(IServiceCollection serviceCollection, IConfiguration configuration) { var context = new CustomAssemblyLoadContext(); var buildDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); context.LoadUnmanagedLibrary(Path.Combine(buildDir, "libwkhtmltox.dll")); serviceCollection.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); serviceCollection.AddTransient <IPdfConverterService, PdfConverterService>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews(); services.AddDbContext <ApplicationContext>(options => options.UseSqlServer(Configuration.GetConnectionString("ApplicationContext"))); services.AddScoped <IProductServices, ProductServiceImpls>(); services.AddSession(); // Create pdf dotnetcore var context = new CustomAssemblyLoadContext(); context.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll")); services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var context = new CustomAssemblyLoadContext(); var architectureFolder = (IntPtr.Size == 8) ? "64bit" : "32bit"; var wkHtmlToPdfPath = Path.Combine(Directory.GetCurrentDirectory(), architectureFolder, $"libwkhtmltox.dll"); context.LoadUnmanagedLibrary(wkHtmlToPdfPath); services.AddMvc() .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver()) .SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); //services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
private static void HandlerScenario(string methodName) { var context = new CustomAssemblyLoadContext(); var assembly = context.LoadFromAssemblyPath(Path.GetFullPath(loaderPath)); var scannerType = assembly.GetTypes().Single(t => t.Name == "AssemblyScanner"); var instance = Activator.CreateInstance(scannerType); var method = scannerType.GetMethod(methodName); method.Invoke(instance, null); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var context = new CustomAssemblyLoadContext(); context.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll")); services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); services.AddControllersWithViews(); services.AddScoped <HomeStation, HomeStation>(); services.AddDbContext <DataContext>(options => options.UseSqlServer("Server=DESKTOP-E7O9U9N; Database=HTMLtoPDF; Trusted_Connection=True; MultipleActiveResultSets=True;")); }
/// <summary> /// Generate custom assembly load context to make it available to get libwkhtmltox.dll AND .dylib AND .so files from /simpleFakeRent/. /// // Will probably be DELETED /// </summary> public static void ConfigureCustomAssembly(this IServiceCollection services) { var context = new CustomAssemblyLoadContext(); context.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll")); /* #if DEBUG * context.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll")); #else * context.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.so")); #endif */ }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // configure strongly typed settings objects var appSettingsSection = Configuration.GetSection("AppSettings"); services.Configure <AppSettings>(appSettingsSection); //Add Cors for Cross Domain services.AddCors(options => { options.AddPolicy("AllowAll", builder1 => { builder1.AllowAnyOrigin(); builder1.AllowAnyHeader(); builder1.AllowAnyMethod(); }); }); // configure jwt authentication var appSettings = appSettingsSection.Get <AppSettings>(); var key = Encoding.ASCII.GetBytes(appSettings.Secret); services.AddAuthentication(x => { x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(x => { x.RequireHttpsMetadata = false; x.SaveToken = true; x.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(key), ValidateLifetime = true, ValidateIssuer = false, ValidateAudience = false, ClockSkew = TimeSpan.Zero }; }); // configure DI for application services services.AddScoped <IUserService, UserService>(); services.AddMvc(); var context = new CustomAssemblyLoadContext(); context.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll")); services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); }