Esempio n. 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // set up our EF data context
            var connection = Configuration.GetConnectionString(ConnectionStrings.SqlServer);

            services.AddDbContext <EmailServiceContext>(options =>
            {
                options.UseMemoryCache(null);
                options.UseSqlServer(connection, sqlOptions =>
                {
                    sqlOptions.MigrationsAssembly("EmailService.Web");
                    sqlOptions.EnableRetryOnFailure();
                });
            });

            // add custom services
            services.AddTransient <IApplicationKeyStore, DbApplicationKeyStore>();
            services.AddSingleton <ICryptoServices>(RsaCryptoServices.Instance);
            services.AddSingleton <IEmailTransportFactory>(EmailTransportFactory.Instance);
            services.AddAzureStorageServices(options =>
            {
                options.ConnectionString = Configuration.GetConnectionString(ConnectionStrings.Storage);
            });

            services.Configure <KestrelServerOptions>(options =>
            {
                if (HostingEnv.IsDevelopment())
                {
                    options.UseHttps("localhost.pfx", "0dinpa55");
                }
            });

            // set up AI telemetry
            services.AddApplicationInsightsTelemetry(Configuration);

            // Add framework services.
            services.AddMvc(options =>
            {
                if (HostingEnv.IsDevelopment())
                {
                    options.SslPort = 44320;
                }

                options.Filters.Add(new RequireHttpsAttribute());
            });

            services.AddAuthentication(sharedOptions =>
            {
                sharedOptions.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            });
        }
Esempio n. 2
0
        public OfflineTool()
        {
            if (Environment.GetEnvironmentVariable("MUTATION") == "CHD")
            {
                mut = Mutation.CHD;
            }
            else if (Environment.GetEnvironmentVariable("MUTATION") == "HDD")
            {
                mut = Mutation.HDD;
            }
            else
            {
                throw new Exception("Environment variable MUTATION missing value invalid. Supported: CHD, HDD.");
            }
            Console.WriteLine("Mutation: " + mut);

            if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Production")
            {
                henv = HostingEnv.Production;
            }
            else if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Staging")
            {
                henv = HostingEnv.Staging;
            }
            else
            {
                henv = HostingEnv.Development;
            }
            Console.WriteLine("Environment: " + henv);

            var    builder               = new ConfigurationBuilder().AddEnvironmentVariables();
            string appSettingsFile       = Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json");
            string appSettingsDevenvFile = Path.Combine(Directory.GetCurrentDirectory(), "appsettings.devenv.json");

            if (File.Exists(appSettingsFile))
            {
                builder.AddJsonFile(appSettingsFile, optional: true);
            }
            if (File.Exists(appSettingsDevenvFile))
            {
                builder.AddJsonFile(appSettingsDevenvFile, optional: true);
            }

            // Config specific to mutation and hosting environment
            string cfgFileName = null;

            if (henv == HostingEnv.Production && mut == Mutation.HDD)
            {
                cfgFileName = "/etc/zdo/zdo-hdd-live/appsettings.json";
            }
            if (henv == HostingEnv.Staging && mut == Mutation.HDD)
            {
                cfgFileName = "/etc/zdo/zdo-hdd-stage/appsettings.json";
            }
            if (henv == HostingEnv.Production && mut == Mutation.CHD)
            {
                cfgFileName = "/etc/zdo/zdo-chd-live/appsettings.json";
            }
            if (henv == HostingEnv.Staging && mut == Mutation.CHD)
            {
                cfgFileName = "/etc/zdo/zdo-chd-stage/appsettings.json";
            }
            if (henv != HostingEnv.Development)
            {
                builder.AddJsonFile(cfgFileName, optional: false);
            }
            config = builder.Build();
        }
Esempio n. 3
0
        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
        {
            if (HostingEnv.IsDevelopment())
            {
                loggerFactory.AddConsole(Startup.Configuration.GetSection("Logging"));
                loggerFactory.AddDebug();
            }
            else
            {
                loggerFactory.AddMailServiceDatabase(options => {
                    options.ConnectionString   = Configuration.GetConnectionString("ErrorLogMailServiceConnectionString");
                    options.CurrentHttpContext = () => app.ApplicationServices.GetRequiredService <IHttpContextAccessor>();
                });
            }

            if (this._startupExceptions.Any(ex => ex.Value.Count > 0))
            {
                var logger = loggerFactory.CreateLogger(ApplicationName);

                app.Run(async context => {
                    context.Response.StatusCode  = (int)HttpStatusCode.InternalServerError;
                    context.Response.ContentType = "text/plain";

                    foreach (var ex in this._startupExceptions)
                    {
                        foreach (var val in ex.Value)
                        {
                            logger.LogError($"{ex.Key}:::{val.Message}");
                            await context.Response.WriteAsync($"Error on {ex.Key}: {val.Message}").ConfigureAwait(false);
                        }
                    }
                });
                return;
            }

            //app.UseCustomisedCsp();

            //app.UseCustomisedHeadersMiddleware();

            app.AddDevMiddlewares();

            app.UseStaticFiles();

            if (HostingEnv.IsProduction())
            {
                app.UseResponseCompression();
            }

            app.AddCustomLocalization();
            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                // http://stackoverflow.com/questions/25982095/using-googleoauth2authenticationoptions-got-a-redirect-uri-mismatch-error
                // routes.MapRoute(name: "signin-google", template: "signin-google", defaults: new { controller = "Account", action = "ExternalLoginCallback" });

                // Route for: /setLangugage/?culture=en-GB
                routes.MapRoute(name: "set-language", template: "setlanguage", defaults: new { controller = "Home", action = "SetLanguage" });

                routes.MapSpaFallbackRoute(name: "spa-fallback", defaults: new { controller = "Home", action = "Index" });
            });
        }