コード例 #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
        protected BlobContainerClient GetContainerClient()
        {
            // Uses the IApplicationSecrets interface to retrieve all the data related to the secret "BlobStorage"  
            IApplicationSecretsConnectionStrings secret = _applicationSecrets.Secret("BlobStorage");
            string blobConnectionString = secret.Value;
            string containerName = secret[ContainerName];

            // Create a BlobServiceClient object which will be used to get a container 
            BlobServiceClient blobServiceClient = new BlobServiceClient(blobConnectionString);

            // Get the container containing the blob
            BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);
            return (containerClient);
        }
コード例 #3
0
        /// <summary>
        /// This is the application entry point.
        /// </summary>
        /// <returns></returns>
        internal async Task Run()
        {
            $"Application Started at {DateTime.Now.ToLongTimeString()}".TraceInformation();

            _InitialConfiguration.TraceInformation("Dumping InitialConfiguration");
            _ApplicationSecrets.TraceInformation("Dumping ApplicationSecrets");

            // Demonstrate how to get at any connection string
            string FileLoggerConnectionString = _ApplicationSecrets.ConnectionString("FileLogger");

            if (!string.IsNullOrEmpty(FileLoggerConnectionString))
            {
                FileLoggerConnectionString.TraceInformation("FileLogger connection string value");

                // Demonstrate how to get ENTIRE secret, including description and metadata
                IApplicationSecretsConnectionStrings FileLoggerSecret = _ApplicationSecrets.Secret("FileLogger");
                if (FileLoggerSecret != null)
                {
                    FileLoggerSecret.TraceInformation("FileLogger ENTIRE secret");

                    if (FileLoggerSecret.MetaDataProperties != null)
                    {
                        foreach (SecretMetaData metaData in FileLoggerSecret.MetaDataProperties)
                        {
                            metaData.TraceInformation("MetaData");
                        }
                    }
                }
            }

            // Display the JWT token that was read from Redis Cache
            string JWT = _Configuration["ONIT_JWT"];

            if (!string.IsNullOrEmpty(JWT))
            {
                JWT.TraceInformation("JWT token from cache");
            }
            else
            {
                "No JWT token was found".TraceInformation();
            }


            $"Application Ended at {DateTime.Now.ToLongTimeString()}".TraceInformation();

            Console.WriteLine("PRESS <ENTER> TO EXIT");
            Console.ReadKey();
        }