コード例 #1
0
        public static bool RefreshConfigurationFromCache(this IRedisCache cache, IApplicationSecrets secrets, IConfigurationRoot configuration)
        {
            if (!Initialized)
            {
                // Get the information about what cache values we need refreshed into configuration
                IApplicationSecretsConnectionStrings TimedCacheRefresh = secrets.Secret("TimedCacheRefresh");
                if (TimedCacheRefresh != null)
                {
                    // Use the "TimedCacheRefresh" secret to get the list of cache keys that need to be auto-refreshed
                    // and placed into the contiguration. This allows the application to read cache values just like
                    // regular configuration settings in "appsettings.json". The "Value" for this secret contains
                    // an array of cache keys that must be refreshed periodically.
                    string[] keys = TimedCacheRefresh.Value.Split(',');

                    // The MetadataProperties "RefreshPeriodMinutes" contains the refresh period for the cache keys
                    string RefreshPeriodMinutes = TimedCacheRefresh["RefreshPeriodMinutes"];
                    if (!string.IsNullOrWhiteSpace(RefreshPeriodMinutes))
                    {
                        int minutes = int.Parse(RefreshPeriodMinutes);

                        // Start the thread that will read the cache every N minutes
                        Task task = new Task(() => LaunchTimedRefresh(cache, keys, minutes, configuration));
                        task.Start();

                        // Wait for the thread to read all cache keys for the first time before continuing
                        waitForCompletion.WaitOne();
                        Initialized = true;
                    }
                }
            }

            return(Initialized);
        }
コード例 #2
0
 /// <summary>
 /// We use constructor dependency injection to the interfaces we need at runtime
 /// </summary>
 /// <param name="InitialConfiguration"></param>
 /// <param name="ApplicationSecrets"></param>
 /// <param name="Configuration"></param>
 public MyApplication(IApplicationSetupConfiguration InitialConfiguration,
                      IApplicationSecrets ApplicationSecrets,
                      IConfiguration Configuration)
 {
     _InitialConfiguration = InitialConfiguration;
     _ApplicationSecrets   = ApplicationSecrets;
     _Configuration        = Configuration;
 }
コード例 #3
0
        public ApplicationRequirements(ILogger <T> applicationLogger, IApplicationSecrets applicationSecrets, IConfiguration applicationConfiguration, IApplicationSetupConfiguration applicationSetupConfiguration, IHostEnvironment hostEnvironment)
        {
            try
            {
                this.applicationSecrets            = applicationSecrets;
                this.ApplicationLogger             = applicationLogger;
                this.ApplicationConfiguration      = applicationConfiguration;
                this.ApplicationSetupConfiguration = applicationSetupConfiguration;
                this.HostEnvironment = hostEnvironment;

                TraceLoggerExtension._HostEnvironment     = hostEnvironment;
                TraceLoggerExtension._environmentName     = applicationSetupConfiguration.RTE;
                TraceLoggerExtension._Logger              = applicationLogger;
                TraceLoggerExtension._SerializationFormat = applicationSetupConfiguration.SerializationFormat;
            }
            catch
            {
            }
        }
        /// <summary>
        /// This method will create an initialize a generic Host Builder
        /// </summary>
        /// <typeparam name="TApp">Main application type. Used to access user secrets</typeparam>
        /// <param name="args">Application arguments</param>
        /// <param name="localServiceConfiguration">Delegate to be executed to add any non-standard configuration needs</param>
        /// <returns>Configured IHostBuilder</returns>
        public static IHostBuilder CreateHostBuilder <TApp>(string[] args, ConfigureLocalServices <TApp> localServiceConfiguration = null) where TApp : class
        {
            IApplicationSecrets            appSecrets      = null;
            IApplicationSetupConfiguration appIntialConfig = null;
            IAppConfigSections             sections        = null;

            IHostBuilder hostBuilder = Host.CreateDefaultBuilder(args)
                                       .ConfigureAppConfiguration((hostingContext, builder) =>
            {
                sections        = ConfigFactory.Initialize <TApp>(hostingContext, builder);
                appSecrets      = sections.appSecrets;
                appIntialConfig = sections.appIntialConfig;
            })
                                       .ConfigureServices((hostingContext, services) =>
            {
                localServiceConfiguration?.Invoke(hostingContext, services, sections);

                services
                .AddTransient <TApp>()
                .AddSingleton <IApplicationSetupConfiguration>(sp =>
                {
                    return(appIntialConfig);
                })
                .AddSingleton <IApplicationSecrets>(sp =>
                {
                    return(appSecrets);
                })
                .AddSingleton <IHostEnvironment>(sp =>
                {
                    return(hostingContext.HostingEnvironment);
                })
                .AddSingleton <IApplicationRequirements <TApp>, ApplicationRequirements <TApp> >();

                services.BuildServiceProvider();
            })
                                       .ConfigureLogging((hostingContext, logging) =>
            {
                ConfigureCustomLogging(hostingContext, logging, appSecrets, appIntialConfig);
            });

            return(hostBuilder);
        }
コード例 #5
0
 public LocalServiceBus(IApplicationSecrets applicationSecrets) : base(applicationSecrets)
 {
 }
コード例 #6
0
 public ServiceBusBase(IApplicationSecrets applicationSecrets)
 {
     _applicationSecrets = applicationSecrets;
 }
コード例 #7
0
 public AzureServiceBus(IApplicationSecrets applicationSecrets) : base(applicationSecrets)
 {
 }
コード例 #8
0
 public BlobFileStorage(IApplicationSecrets applicationSecrets)
 {
     _applicationSecrets = applicationSecrets;
 }
コード例 #9
0
 public LocalMemoryCache(IApplicationSecrets applicationSecrets, IMemoryCache memoryCache) : base(applicationSecrets)
 {
     Cache = memoryCache;
 }
コード例 #10
0
        /// <summary>
        /// Different types of logging are enabled based on the MyProjectSettings:EnabledLoggers: [ "File", "Console", "Debug" ]
        /// </summary>
        /// <param name="hostingContext">Generic host builder context used to configure the application</param>
        /// <param name="logging">Interface used to configure logging providers</param>
        /// <param name="applicationSecrets">Interface used to access all properties in the "ApplicationSecrets" property of the appsettings.json file</param>
        /// <param name="applicationSetupConfiguration">Interface used to access all properties in the "InitialConfiguration" property of the appsettings.json file</param>
        public static void ConfigureCustomLogging(HostBuilderContext hostingContext, ILoggingBuilder logging, IApplicationSecrets applicationSecrets, IApplicationSetupConfiguration applicationSetupConfiguration)
        {
            TraceLoggerExtension._HostEnvironment     = hostingContext.HostingEnvironment;
            TraceLoggerExtension._SerializationFormat = applicationSetupConfiguration.SerializationFormat;

            logging.ClearProviders();

            if (applicationSetupConfiguration.IsLoggingEnabled)
            {
                logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));

                if (applicationSetupConfiguration.IsLoggerEnabled(EnabledLoggersEnum.Debug))
                {
                    logging.AddDebug();
                }

                if (applicationSetupConfiguration.IsLoggerEnabled(EnabledLoggersEnum.Console))
                {
                    logging.AddConsole();
                }

                if (applicationSetupConfiguration.IsLoggerEnabled(EnabledLoggersEnum.File))
                {
                    // The FileLogger will be configured for log4Net local logging during development.
                    string logConnectionString = applicationSecrets.ConnectionString("FileLogger");

                    // Must set the log name prior to adding Log4Net because it must know this value
                    // before it loads the config file. It does pattern matching and substitution on the filename.
                    string logPath = null;
                    string logName = null;
                    if (!string.IsNullOrEmpty(logConnectionString))
                    {
                        string[] logParts = logConnectionString.Split(";");
                        logPath = logParts[0]?.Replace("LogPath=", "");
                        logName = logParts[1]?.Replace("LogName=", "");
                    }

                    if (!string.IsNullOrEmpty(logPath))
                    {
                        if (!Directory.Exists(logPath))
                        {
                            Directory.CreateDirectory(logPath);
                        }

                        logName = $"{logPath}\\{logName}";
                    }

                    log4net.GlobalContext.Properties["LogName"] = logName;
                    logging.AddLog4Net("log4net.config");
                }
            }
        }
コード例 #11
0
 public HmacAuthenticationHeaderGenerator(IClock clock, IAuthenticatedUserLookup userLookup, IApplicationSecrets applicationSecrets)
 {
     this.Clock              = clock;
     this.UserLookup         = userLookup;
     this.ApplicationSecrets = applicationSecrets;
 }
コード例 #12
0
        public static IRedisCache InitializeRedisCache(this IConfigurationRoot configuration, IApplicationSecrets secrets)
        {
            IRedisCache cache = null;

            // Connect to the redis cache using the secret "ApplicationCache"
            string RedisConnectionString = secrets.ConnectionString("ApplicationCache");

            if (!string.IsNullOrEmpty(RedisConnectionString))
            {
                cache = new RedisCache(RedisConnectionString);
            }

            return(cache);
        }
        /// <summary>
        /// Different types of logging are enabled based on the MyProjectSettings:EnabledLoggers: [ "File", "Console", "Debug" ]
        /// </summary>
        /// <param name="hostingContext">Generic host builder context used to configure the application</param>
        /// <param name="logging">Interface used to configure logging providers</param>
        /// <param name="applicationSecrets">Interface used to access all properties in the "ApplicationSecrets" property of the appsettings.json file</param>
        /// <param name="applicationSetupConfiguration">Interface used to access all properties in the "InitialConfiguration" property of the appsettings.json file</param>
        public static void ConfigureCustomLogging(HostBuilderContext hostingContext, ILoggingBuilder logging, IApplicationSecrets applicationSecrets, IApplicationSetupConfiguration applicationSetupConfiguration)
        {
            logging.ClearProviders();

            if (applicationSetupConfiguration.IsLoggingEnabled)
            {
                logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));

                if (applicationSetupConfiguration.IsLoggerEnabled(EnabledLoggersEnum.Debug))
                {
                    logging.AddDebug();
                }

                if (applicationSetupConfiguration.IsLoggerEnabled(EnabledLoggersEnum.Console))
                {
                    logging.AddConsole();
                }

                if (applicationSetupConfiguration.IsLoggerEnabled(EnabledLoggersEnum.File))
                {
                    // The FileLogger will be configured for log4Net local logging during development.
                    // It will contain the instrumentation key for Azure Application Insights when
                    // the connection information is coming from KeyVault
                    string logConnectionString = applicationSecrets.ConnectionString("FileLogger");
                    Guid   gKey;
                    if (!string.IsNullOrEmpty(applicationSetupConfiguration.KeyVaultKey) && Guid.TryParse(logConnectionString, out gKey))
                    {
                        string instrumentationKey = logConnectionString;
                        logging.AddApplicationInsights(instrumentationKey);

                        // Adding the filter below to ensure logs of all severities
                        // is sent to ApplicationInsights.
                        logging.AddFilter <Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider>
                            ("RemoteLogging", LogLevel.Debug);
                    }
                    else  // No local KeyVaultKey or environment setting for InitialConfiguration_KeyVaultKey found, so use local Log4Net logging
                    {
                        // Must set the log name prior to adding Log4Net because it must know this value
                        // before it loads the config file. It does pattern matching and substitution on the filename.
                        string logPath = null;
                        string logName = null;
                        if (!string.IsNullOrEmpty(logConnectionString))
                        {
                            string[] logParts = logConnectionString.Split(";");
                            logPath = logParts[0]?.Replace("LogPath=", "");
                            logName = logParts[1]?.Replace("LogName=", "");
                        }

                        if (!string.IsNullOrEmpty(logPath))
                        {
                            if (!Directory.Exists(logPath))
                            {
                                Directory.CreateDirectory(logPath);
                            }

                            logName = $"{logPath}\\{logName}";
                        }

                        log4net.GlobalContext.Properties["LogName"] = logName;
                        logging.AddLog4Net("log4net.config");
                    }
                }
            }
        }
コード例 #14
0
 public RedisCache(IApplicationSecrets applicationSecrets) : base(applicationSecrets)
 {
 }
コード例 #15
0
 public CacheBase(IApplicationSecrets applicationSecrets)
 {
     _applicationSecrets   = applicationSecrets;
     CacheConnectionString = _applicationSecrets.ConnectionString(CacheBase.ConfigSectionName);
 }
コード例 #16
0
 public LocalFileStorage(IApplicationSecrets applicationSecrets)
 {
     _applicationSecrets = applicationSecrets;
 }