/// <summary> /// Consturktur of the file hosting service /// </summary> /// <param name="options">File hosting options</param> public FileHostingService(FileHostingOptions options) { Options = options; }
/// <summary> /// This method gets called by the runtime. Use this method to add services to the container. /// </summary> /// <param name="services">Service Parameter</param> public void ConfigureServices(IServiceCollection services) { try { // Check for corupted xml key files from asp.net core var aspKeyRingFolder = Environment.ExpandEnvironmentVariables(@"%LocalAppData%\ASP.net\DataProtection-Keys"); if (Directory.Exists(aspKeyRingFolder)) { var xmlKeyRingFiles = Directory.GetFiles(aspKeyRingFolder, "*.xml", SearchOption.TopDirectoryOnly); foreach (var xmlKeyRingFile in xmlKeyRingFiles) { var byteCount = File.ReadAllBytes(xmlKeyRingFile)?.Length ?? 0; if (byteCount <= 3) { logger.Info("Broken key ring file found. This has been removed."); File.Delete(xmlKeyRingFile); } } } var tempFolder = Configuration.GetValue <string>(WebHostDefaults.ContentRootKey); if (tempFolder.TrimEnd('/', '\\') == AppContext.BaseDirectory.TrimEnd('/', '\\')) { tempFolder = Path.Combine(Path.GetTempPath(), "RestService"); if (Directory.Exists(tempFolder)) { SoftCleanup(tempFolder); } } Directory.CreateDirectory(tempFolder); var reportingOptions = new ReportingServiceOptions() { TempFolder = tempFolder }; services.AddSingleton <IReportingService, ReportingService>(s => new ReportingService(reportingOptions)); var fileHostingOptions = new FileHostingOptions() { TempFolder = tempFolder }; services.AddSingleton <IFileHostingService, FileHostingService>(s => new FileHostingService(fileHostingOptions)); services.AddControllers(); var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "AGReportingService", Version = "v1" }); c.IncludeXmlComments(xmlPath, true); c.CustomOperationIds(apiDesc => apiDesc.TryGetMethodInfo(out MethodInfo methodInfo) ? methodInfo.Name : null); }); } catch (Exception ex) { logger.Error(ex, "The config services section failed."); } }