Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static Settings LoadSettings(IConfiguration configuration)
        {
            var settings = new Settings();
            var size     = Environment.GetEnvironmentVariable("MAX_UPLOAD_SIZE");

            if (string.IsNullOrEmpty(size))
            {
                size = configuration["MaxUploadSize"];
            }
            if (!string.IsNullOrEmpty(size))
            {
                if (Utils.TryParseByteNumber(size, out long value))
                {
                    settings.MaxUploadSize = value;
                }
                else
                {
                    throw new ConfigurationException("MaxUploadSize Variable Error");
                }
            }

            try {
                var useLog = Environment.GetEnvironmentVariable("USE_LOG");
                if (!string.IsNullOrEmpty(useLog))
                {
                    settings.UseLog = bool.Parse(useLog);
                }
                else
                {
                    settings.UseLog = configuration.GetValue <bool>("UseLog");
                }
            }
            catch (Exception ex) {
                throw new ConfigurationException("UseLog Variable Error", ex);
            }

            try {
                var useSwagger = Environment.GetEnvironmentVariable("USE_SWAGGER");
                if (!string.IsNullOrEmpty(useSwagger))
                {
                    settings.UseSwagger = bool.Parse(useSwagger);
                }
                else
                {
                    settings.UseSwagger = configuration.GetValue <bool>("UseSwagger");
                }
            }
            catch (Exception ex) {
                throw new ConfigurationException("UseSwagger Variable Error", ex);
            }
            settings.AuthSetting      = AuthSetting.LoadSettings(configuration);
            settings.FileSetting      = FileSetting.LoadSettings(configuration);
            settings.ThumbnailSetting = ThumbnailSetting.LoadSettings(configuration);
            settings.MimeSetting      = MimeSetting.LoadSettings(configuration);
            settings.CacheSetting     = CacheSetting.LoadSettings(configuration);
            return(settings);
        }
Example #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="cacheSetting"></param>
 public CacheModule(CacheSetting cacheSetting)
 {
     uploadCache = new MemoryCache(new MemoryCacheOptions());
     fileCache   = new MemoryCache(new MemoryCacheOptions());
     if (cacheSetting.UploadCacheTime > 0)
     {
         uploadTimespan = new TimeSpan(0, 0, cacheSetting.UploadCacheTime);
     }
     else
     {
         uploadTimespan = new TimeSpan(0, 0, 60);
     }
     if (cacheSetting.MaxCacheTime > 0)
     {
         maxCacheTimespan = new TimeSpan(0, cacheSetting.MaxCacheTime, 0);
     }
     else
     {
         maxCacheTimespan = new TimeSpan(0, 30, 0);
     }
     if (cacheSetting.MaxCacheCount > 0)
     {
         maxCacheCount = cacheSetting.MaxCacheCount;
     }
     else
     {
         maxCacheCount = 10000;
     }
     if (cacheSetting.MaxCacheCount > 0)
     {
         maxCacheEntitySize = cacheSetting.MaxCacheEntitySize;
     }
     else
     {
         maxCacheEntitySize = 5 * 1024 * 1024;
     }
 }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static CacheSetting LoadSettings(IConfiguration configuration)
        {
            var cacheSetting = new CacheSetting();

            try {
                var uploadCacheTime = Environment.GetEnvironmentVariable("UPLOAD_CACHE_TIME");
                if (!string.IsNullOrEmpty(uploadCacheTime))
                {
                    cacheSetting.UploadCacheTime = int.Parse(uploadCacheTime);
                }
                else
                {
                    cacheSetting.UploadCacheTime = configuration.GetValue <int>("UploadCacheTime");
                }
            }
            catch (Exception ex) {
                throw new ConfigurationException("UploadCacheTime Variable Error", ex);
            }

            try {
                var maxCacheCount = Environment.GetEnvironmentVariable("MAX_CACHE_COUNT");
                if (!string.IsNullOrEmpty(maxCacheCount))
                {
                    cacheSetting.MaxCacheCount = int.Parse(maxCacheCount);
                }
                else
                {
                    cacheSetting.MaxCacheCount = configuration.GetValue <int>("MaxCacheCount");
                }
            }
            catch (Exception ex) {
                throw new ConfigurationException("MaxCacheCount Variable Error", ex);
            }

            try {
                var maxCacheTime = Environment.GetEnvironmentVariable("MAX_CACHE_TIME");
                if (!string.IsNullOrEmpty(maxCacheTime))
                {
                    cacheSetting.MaxCacheTime = int.Parse(maxCacheTime);
                }
                else
                {
                    cacheSetting.MaxCacheTime = configuration.GetValue <int>("MaxCacheTime");
                }
            }
            catch (Exception ex) {
                throw new ConfigurationException("MaxCacheTime Variable Error", ex);
            }

            var maxCacheEntitySize = Environment.GetEnvironmentVariable("MAX_CACHE_ENTITY_SIZE");

            if (string.IsNullOrEmpty(maxCacheEntitySize))
            {
                maxCacheEntitySize = configuration["MaxCacheEntitySize"];
            }
            if (!string.IsNullOrEmpty(maxCacheEntitySize))
            {
                if (Utils.TryParseByteNumber(maxCacheEntitySize, out long value))
                {
                    cacheSetting.MaxCacheEntitySize = value;
                }
                else
                {
                    throw new ConfigurationException("MaxCacheEntitySize Variable Error");
                }
            }

            return(cacheSetting);
        }