public static IApplicationBuilder UseWebClientStaticFiles(this IApplicationBuilder app, IConfiguration DirectoryConfiguration, IWebHostEnvironment env) { bool useStatic = DirectoryConfiguration.ReadBoolProperty(UseStaticFilesPropertyName); if (useStatic) { var path = env.WebRootPath; if (env.IsDevelopment() || string.IsNullOrWhiteSpace(path)) { path = BuildWebRootPath(); env.WebRootPath = path; } var options = new SharedOptions() { FileProvider = new PhysicalFileProvider(path) }; var fileOptions = new DefaultFilesOptions(options); fileOptions.DefaultFileNames.Add("Login.html"); fileOptions.DefaultFileNames.Add("Chat.html"); app.UseDefaultFiles(fileOptions); app.UseStaticFiles(new StaticFileOptions(options)); } return(app); }
public static HttpClient CreateHttpClient(SharedOptions options) { if (options.UseIntegratedSecurity) { var username = System.Security.Principal.WindowsIdentity.GetCurrent().Name; Console.WriteLine($"Using integrated security with user {username} to access the Augurk API's."); var handler = new HttpClientHandler { UseDefaultCredentials = true, PreAuthenticate = true, }; var secureClient = new HttpClient(handler); return(secureClient); } var client = new HttpClient(); if (options.UseBasicAuthentication) { if (string.IsNullOrEmpty(options.BasicAuthenticationUsername) || string.IsNullOrEmpty(options.BasicAuthenticationPassword)) { Console.Error.WriteLine("When using basic HTTP authentication, you must specify a username and password)"); System.Environment.Exit(-1); } var byteArray = Encoding.ASCII.GetBytes($"{options.BasicAuthenticationUsername}:{options.BasicAuthenticationPassword}"); client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); } return(client); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseDefaultFiles(); app.UseStaticFiles(); var shared = new SharedOptions { FileProvider = new PhysicalFileProvider( Path.Combine(Directory.GetCurrentDirectory(), "var", "data")), RequestPath = "/files" }; app.UseDirectoryBrowser(new DirectoryBrowserOptions(shared)); app.UseStaticFiles(new StaticFileOptions(shared) { ServeUnknownFileTypes = true }); app.UseAuthorization(); app.UseOpenApi(); app.UseSwaggerUi3(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapHub <RaceHub>("/_ws/race"); }); }
private static StaticFileOptions GetStaticFilesOptions() { var paths = new List <string> { Path.Combine(Path.GetDirectoryName(typeof(Startup).Assembly.Location), "wwwroot") }; var providers = paths.Where(Directory.Exists).Select(p => new PhysicalFileProvider(p)).ToArray(); StaticFileOptions options = null; if (providers.Length > 0) { var combinedProvider = new CompositeFileProvider(providers); var sharedOptions = new SharedOptions { FileProvider = combinedProvider }; options = new StaticFileOptions(sharedOptions); } return(options); }
public DependencyModule( ILogger <DependencyModule> logger, SharedOptions sharedOptions) { _logger = logger; _sharedOptions = sharedOptions; }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) { app.UseAbp(); if (env.IsDevelopment()) { app.UseDevException(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Error"); } app.JTUseCors(); app.JTUseMvc(); app.JTUseSwagger(_config["SwaggerBasePath"]); var root = Path.Combine(Directory.GetCurrentDirectory(), WebFileSystemCoreConsts.FilePathBase); if (!Directory.Exists(root)) { Directory.CreateDirectory(root); } var shareOption = new SharedOptions { FileProvider = new PhysicalFileProvider(root), RequestPath = new PathString($"/{WebFileSystemCoreConsts.FilePathBase}") }; app.JTUseStaticFiles(new JTStaticFileOptions(shareOption) { UseDefault = false }); app.JTUseDirectoryBrowser(new DirectoryBrowserOptions(shareOption)); }
private void Startup(IAppBuilder app) { var config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional }); // use JSON by default. var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml"); config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType); // automatically convert JSON attribute names to camelCase. var json = config.Formatters.JsonFormatter; json.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); app.UseWebApi(config); var staticFilesSharedOptions = new SharedOptions { FileSystem = new PhysicalFileSystem(GetStaticFilesPath()) }; app.UseDefaultFiles(new DefaultFilesOptions(staticFilesSharedOptions) { DefaultFileNames = new[] { "index.html" } }); app.UseStaticFiles(new StaticFileOptions(staticFilesSharedOptions)); }
public DraftFileBusinessLogic(SharedOptions sharedOptions, IFileRepository fileRepository) { SharedOptions = sharedOptions; _fileRepository = fileRepository; RootDraftPath = Path.Combine(sharedOptions.DataPath, sharedOptions.SaveDraftPath); }
public override async Task <SendEmailResult> SendEmailAsync <TTemplate>(string emailAddress, string templateId, TTemplate parameters, bool test) { // convert the model's public properties to a dictionary var mergeParameters = parameters.GetPropertiesDictionary(); // prefix subject with environment name mergeParameters["Environment"] = SharedOptions.IsProduction() ? "" : $"[{SharedOptions.Environment}] "; // determine which client to use var client = test ? TestClient : ProductionClient; // send email var response = await client.SendEmailAsync( emailAddress, templateId, mergeParameters, Options.ClientReference); // get result var notification = await client.GetNotificationByIdAsync(response.id); return(new SendEmailResult { Status = notification.status, Server = "Gov Notify", ServerUsername = Options.ClientReference, EmailAddress = emailAddress, EmailSubject = notification.subject }); }
public ChangeEmailViewService(SharedOptions sharedOptions, IUserRepository userRepo, IUrlHelper urlHelper, ISendEmailService sendEmailService) { SharedOptions = sharedOptions ?? throw new ArgumentNullException(nameof(sharedOptions)); UserRepository = userRepo ?? throw new ArgumentNullException(nameof(userRepo)); UrlHelper = urlHelper ?? throw new ArgumentNullException(nameof(urlHelper)); SendEmailService = sendEmailService; }
public SendEmailService(SharedOptions sharedOptions, EmailOptions emailOptions, ILogger <SendEmailService> logger, [KeyFilter(QueueNames.SendEmail)] IQueue sendEmailQueue) { SharedOptions = sharedOptions ?? throw new ArgumentNullException(nameof(sharedOptions)); EmailOptions = emailOptions ?? throw new ArgumentNullException(nameof(emailOptions)); Logger = logger ?? throw new ArgumentNullException(nameof(logger)); SendEmailQueue = sendEmailQueue ?? throw new ArgumentNullException(nameof(sendEmailQueue)); }
/// <summary> /// Defaults to all request paths in the current physical directory /// </summary> /// <param name="sharedOptions"></param> public StaticFileOptions(SharedOptions sharedOptions) : base(sharedOptions) { ContentTypeProvider = new FileExtensionContentTypeProvider(); OnPrepareResponse = _ => { }; GetCustomETag = _ => Task.FromResult(""); }
/// <summary> /// Defaults to all request paths in the current physical directory /// </summary> /// <param name="sharedOptions"></param> public StaticFileOptions(SharedOptions sharedOptions) : base(sharedOptions) { ContentTypeProvider = new FileExtensionContentTypeProvider(); OnPrepareResponse = _ => { //_.OwinContext.Response.Headers.Add("Cache-Control", new[] { "public", "max-age=1000" }); }; }
/// <summary> /// Creates an new instance of the SharedOptionsBase. /// </summary> /// <param name="sharedOptions"></param> protected SharedOptionsBase(SharedOptions sharedOptions) { if (sharedOptions == null) { throw new ArgumentNullException(nameof(sharedOptions)); } SharedOptions = sharedOptions; }
private void ConfigureStaticFiles(IAppBuilder app) { SharedOptions sharedOptions = new SharedOptions(); sharedOptions.FileSystem = new PhysicalFileSystem(new RootPathProvider().GetRootPath()); StaticFileOptions staticFileOptions = new StaticFileOptions(sharedOptions); app.UseStaticFiles(staticFileOptions); }
public EpsgTransformGraph(EpsgArea fromArea, EpsgArea toArea, SharedOptions options) { Contract.Requires(fromArea != null); Contract.Requires(toArea != null); Contract.Requires(options != null); _options = options; _crsValidator = _options.CreateCrsValidator(fromArea, toArea); _opValidator = _options.CreateOperationValidator(fromArea, toArea); }
public CompaniesHouseAPI(CompaniesHouseOptions options, SharedOptions sharedOptions) { Options = options ?? throw new ArgumentNullException("You must provide the companies house options", nameof(CompaniesHouseOptions)); SharedOptions = sharedOptions ?? throw new ArgumentNullException(nameof(sharedOptions)); BaseUri = new Uri(Options.ApiServer); _apiKey = Options.ApiKey; MaxRecords = Options.MaxRecords; }
public UserRepository(DatabaseOptions databaseOptions, SharedOptions sharedOptions, IDataRepository dataRepository, IUserLogger userAuditLog, IMapper autoMapper) { DatabaseOptions = databaseOptions ?? throw new ArgumentNullException(nameof(databaseOptions)); SharedOptions = sharedOptions ?? throw new ArgumentNullException(nameof(sharedOptions)); DataRepository = dataRepository ?? throw new ArgumentNullException(nameof(dataRepository)); UserAuditLog = userAuditLog ?? throw new ArgumentNullException(nameof(userAuditLog)); AutoMapper = autoMapper ?? throw new ArgumentNullException(nameof(autoMapper)); }
public PinInThePostService( SharedOptions sharedOptions, IEventLogger customLogger, IGovNotifyAPI govNotifyApi) { SharedOptions = sharedOptions; CustomLogger = customLogger; this.govNotifyApi = govNotifyApi; }
public PublicSectorRepository(IDataRepository dataRepository, ICompaniesHouseAPI companiesHouseAPI, SharedOptions sharedOptions, IOrganisationBusinessLogic organisationBusinessLogic) { _DataRepository = dataRepository; _CompaniesHouseAPI = companiesHouseAPI; _sharedOptions = sharedOptions; _organisationBusinessLogic = organisationBusinessLogic; }
public DependencyModule( ILogger <DependencyModule> logger, SharedOptions sharedOptions, ResponseCachingOptions responseCachingOptions) { _logger = logger; _sharedOptions = sharedOptions; _responseCachingOptions = responseCachingOptions; }
void IStartup.Configure(IApplicationBuilder app) { app.UseResponseCompression(); #if DEBUG app.Use((context, next) => { Console.WriteLine(new System.Text.StringBuilder() .Append(new System.Net.IPEndPoint(context.Connection.RemoteIpAddress, context.Connection.RemotePort)) .Append(" ") .Append(context.Request.PathBase) .Append(context.Request.Path) .Append(context.Request.QueryString) .ToString()); return(next()); }); #endif app.Use((context, next) => { context.SmuggleRestApiSuffix("/rest"); return(next()); }); app.Map("/rest", a => { a.UseStatusCodePages(); a.UseExceptionHandler(HandleException); #if DEBUG a.UseDeveloperExceptionPage(); #endif a.UsePathBase("/rest"); a.Run(RestApi.HandleRestApiRequestAsync); }); app.UseStatusCodePages(); string uiPath = Path.Join(AppContext.BaseDirectory, "ui"); if (Directory.Exists(uiPath)) { var sharedOptions = new SharedOptions() { FileProvider = new PhysicalFileProvider(uiPath), }; app.UseDefaultFiles(new DefaultFilesOptions(sharedOptions) { DefaultFileNames = new[] { "index.html" }, }); app.UseStaticFiles(new StaticFileOptions(sharedOptions)); } }
public NotificationService(SharedOptions sharedOptions, ILogger <NotificationService> logger, IEventLogger customLogger, [KeyFilter(QueueNames.SendNotifyEmail)] IQueue sendNotifyEmailQueue) { SharedOptions = sharedOptions ?? throw new ArgumentNullException(nameof(sharedOptions)); Logger = logger ?? throw new ArgumentNullException(nameof(logger)); CustomLogger = customLogger ?? throw new ArgumentNullException(nameof(customLogger)); SendNotifyEmailQueue = sendNotifyEmailQueue ?? throw new ArgumentNullException(nameof(sendNotifyEmailQueue)); }
public SmtpEmailProvider(IEmailTemplateRepository emailTemplateRepo, SmtpEmailOptions smtpEmailOptions, SharedOptions sharedOptions, ILogger <SmtpEmailProvider> logger, [KeyFilter(Filenames.EmailSendLog)] IAuditLogger emailSendLog) : base(sharedOptions, emailTemplateRepo, logger, emailSendLog) { Options = smtpEmailOptions ?? throw new ArgumentNullException(nameof(smtpEmailOptions)); //TODO ensure smtp config is present (when enabled) }
public BaseEmailProvider( SharedOptions sharedOptions, IEmailTemplateRepository emailTemplateRepo, ILogger logger, [KeyFilter(Filenames.EmailSendLog)] IAuditLogger emailSendLog) { EmailTemplateRepo = emailTemplateRepo ?? throw new ArgumentNullException(nameof(emailTemplateRepo)); Logger = logger ?? throw new ArgumentNullException(nameof(logger)); EmailSendLog = emailSendLog ?? throw new ArgumentNullException(nameof(emailSendLog)); SharedOptions = sharedOptions ?? throw new ArgumentNullException(nameof(sharedOptions)); }
public DependencyModule(ILogger <DependencyModule> logger, SharedOptions sharedOptions, StorageOptions storageOptions, DistributedCacheOptions distributedCacheOptions, DataProtectionOptions dataProtectionOptions, ResponseCachingOptions responseCachingOptions) { _logger = logger; _sharedOptions = sharedOptions; _storageOptions = storageOptions; _distributedCacheOptions = distributedCacheOptions; _dataProtectionOptions = dataProtectionOptions; _responseCachingOptions = responseCachingOptions; }
/// <summary> /// Configuration for the DefaultFilesMiddleware. /// </summary> /// <param name="sharedOptions"></param> public DefaultFilesOptions(SharedOptions sharedOptions) : base(sharedOptions) { // Prioritized list DefaultFileNames = new List <string>() { "default.htm", "default.html", "index.htm", "index.html", }; }
public FacebookJob(ILoggerFactory loggerFactory, IFacebookHelper facebookHelper, IAccountService accountService, ICampaignAccountStatisticRepository campaignAccountStatisticRepository, ICampaignService campaignService, IOptionsMonitor <SharedOptions> optionsAccessor) { _logger = loggerFactory.CreateLogger <FacebookJob>(); _accountService = accountService; _facebookHelper = facebookHelper; _options = optionsAccessor.CurrentValue; _campaignService = campaignService; _campaignAccountStatisticRepository = campaignAccountStatisticRepository; }
public DependencyModule( ILogger <DependencyModule> logger, SharedOptions sharedOptions, CompaniesHouseOptions coHoOptions, ResponseCachingOptions responseCachingOptions, DistributedCacheOptions distributedCacheOptions, DataProtectionOptions dataProtectionOptions) { _logger = logger; _sharedOptions = sharedOptions; _coHoOptions = coHoOptions; _responseCachingOptions = responseCachingOptions; _distributedCacheOptions = distributedCacheOptions; _dataProtectionOptions = dataProtectionOptions; }
public DatabaseContext(SharedOptions sharedOptions, DatabaseOptions databaseOptions) { SharedOptions = sharedOptions; DatabaseOptions = databaseOptions; if (!string.IsNullOrWhiteSpace(DatabaseOptions.ConnectionString)) { ConnectionString = DatabaseOptions.ConnectionString; } if (databaseOptions.UseMigrations) { EnsureMigrated(); } }