Example #1
0
        private X509Certificate2 GetCertificate(IConfigurationRoot configuration)
        {
            if (IsLocalConnection(configuration))
            {
                return(null); // localhost, no TLS
            }

            X509Certificate2 certificate = null;
            var certName = _securityOptions.X509CertificateName ?? Invariant($"CN={Environment.MachineName}");

            certificate = Certificates.GetCertificateForEncryption(certName);
            if (certificate == null)
            {
#if DEBUG
                return(null);
#else
                CommonStartup.Exit((int)BrokerExitCodes.NoCertificate, Resources.Critical_NoTlsCertificate, certName);
#endif
            }

            _logger.LogInformation(Resources.Trace_CertificateIssuer, certificate.Issuer);
            _logger.LogInformation(Resources.Trace_CertificateSubject, certificate.Subject);

            return(certificate);
        }
Example #2
0
 protected override void OnStart(string[] args)
 {
     Task.Run(() => {
         CommonStartup.CreateAndRunWebHostForService(_configuration);
         Stop();
     }).DoNotWait();
 }
Example #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            var commonStartup = new CommonStartup();

            commonStartup.ConfigureServices(services);
        }
        public void ConfigureServices(IServiceCollection services)
        {
            CommonStartup.ConfigureServices(services, Configuration);

            services.AddWebAssemblyPrerenderingNoopAuthentication();

            services.AddControllersWithViews();
            services.AddRazorPages();
        }
Example #5
0
        private void PingTimeout(object state)
        {
            var cts = (CancellationTokenSource)state;

            if (_cts == cts)
            {
                _logger.LogCritical(Resources.Critical_PingTimeOut);
                CommonStartup.Exit();
            }
        }
Example #6
0
        public static async Task Main(string[] args)
        {
            // Need to force assembly loading (https://github.com/dotnet/aspnetcore/issues/26601)
            typeof(App).ToString();

            var builder = WebAssemblyHostBuilder.CreateDefault(args);

            builder.RootComponents.Add <App>("app");

            builder.Services.AddAuth0Authentication(options =>
            {
                builder.Configuration.Bind("Oidc", options.ProviderOptions);
            });

            CommonStartup.ConfigureServices(builder.Services, builder.Configuration);

            await builder.Build().RunAsync();
        }
Example #7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            IApplicationSettings appSettings = new ApplicationSettings();

            Configuration.Bind(appSettings);

            services.AddSingleton(appSettings);
            services.AddSingleton <IAppMongoClient, AppMongoClient>();

            ILanguage languageProvider = new TextCache();

            languageProvider.Initialise(_env.IsDevelopment());

            services.AddSingleton(languageProvider);

            services.AddIdentity <ApplicationUserMongo, ApplicationRoleMongo>()
            .AddMongoDbStores <ApplicationUserMongo, ApplicationRoleMongo, Guid>
            (
                appSettings.ConnectionString, appSettings.DatabaseName
            )
            .AddDefaultTokenProviders();

            // Add application services.
            services.AddScoped <INotification, EmailSender>();
            CommonStartup.AddCommonServices(services);

            services.AddScoped <IAuthService, AuthService <ApplicationUserMongo, ApplicationRoleMongo> >();

            services.AddScoped <IExpensesData, ExpensesDataMongo>();

            services.AddScoped <ISessionInfo, SessionInfo>();

            services.AddSession(options =>
            {
                // Set a short timeout for easy testing.
                //options.IdleTimeout = TimeSpan.FromSeconds(10);
                options.Cookie.HttpOnly = true;
                // Make the session cookie essential
                options.Cookie.IsEssential = true;
            });

            services.AddAutoMapper();
            services.AddMvc();
        }
Example #8
0
        public async static Task Main(string[] args)
        {
            // Startups
            common   = new CommonStartup();
            accounts = new AccountsStartup();
            entries  = new EntriesStartup();
            sharing  = new SharingStartup();

            // Configure.
            WebAssemblyHostBuilder builder = WebAssemblyHostBuilder.CreateDefault();

            ConfigureServices(builder.Services);
            ConfigureComponents(builder.RootComponents);

            // Startup.
            WebAssemblyHost host = builder.Build();

            StartupServices(host.Services);

            // Run.
            await host.RunAsync();
        }
Example #9
0
        public void Initialize()
        {
            if (_options.ParentProcessID != null)
            {
                int     pid = _options.ParentProcessID.Value;
                Process process;
                try {
                    process = Process.GetProcessById(pid);
                    process.EnableRaisingEvents = true;
                } catch (ArgumentException) {
                    _logger.LogCritical(Resources.Critical_ParentProcessNotFound, pid);
                    CommonStartup.Exit();
                    return;
                }

                _logger.LogInformation(Resources.Info_MonitoringParentProcess, pid);
                process.Exited += delegate {
                    _logger.LogInformation(Resources.Info_ParentProcessExited, pid);
                    CommonStartup.Exit();
                };
            }

            Ping();
        }
Example #10
0
 private void Application_Startup(object sender, StartupEventArgs e)
 {
     StockDataImportStartup.RegisterServices();
     DatabaseStartup.RegisterServices();
     CommonStartup.RegisterServices();
 }
Example #11
0
 public void ConfigureServices(IServiceCollection services)
 {
     CommonStartup.ConfigureServices(services, Configuration);
 }
Example #12
0
 protected override void OnStop()
 {
     CommonStartup.Exit();
 }
Example #13
0
 protected override void OnStart(string[] args)
 {
     Task.Run(() => CommonStartup.CreateAndRunWebHostForService()).DoNotWait();
 }