Exemplo n.º 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);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static ThumbnailSetting LoadSettings(IConfiguration configuration)
        {
            var thumbnailSetting   = new ThumbnailSetting();
            var thumbnailDirectory = Environment.GetEnvironmentVariable("THUMBNAIL_DIRECTORY");

            if (thumbnailDirectory == null)
            {
                thumbnailDirectory = configuration["ThumbnailDirectory"];
            }
            if (thumbnailDirectory != null)
            {
                thumbnailSetting.ThumbnailDirectory = thumbnailDirectory;
            }

            var thumbnailExts = Environment.GetEnvironmentVariable("THUMBNAIL_EXTS");

            if (thumbnailExts == null)
            {
                thumbnailExts = configuration["ThumbnailExts"];
            }
            if (thumbnailExts != null)
            {
                thumbnailSetting.ThumbnailExts = thumbnailExts.Split(',', StringSplitOptions.RemoveEmptyEntries);
            }
            else
            {
                thumbnailSetting.ThumbnailExts = new string[0];
            }

            try {
                var thumbnailTypes = configuration.GetSection("ThumbnailTypes").Get <ThumbnailType[]>();
                thumbnailSetting.Types = thumbnailTypes ?? new ThumbnailType[0];
            }
            catch (Exception ex) {
                throw new ConfigurationException("ThumbnailTypes Variable Error", ex);
            }
            return(thumbnailSetting);
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="thumbnailSetting"></param>
        public ThumbnailModule(ThumbnailSetting thumbnailSetting)
        {
            if (!string.IsNullOrEmpty(thumbnailSetting.ThumbnailDirectory))
            {
                fileDirectory = thumbnailSetting.ThumbnailDirectory;
            }
            else
            {
                var basePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
                fileDirectory = Path.Combine(basePath, "thumbnail");
            }
            var dir = new DirectoryInfo(fileDirectory);

            if (!dir.Exists)
            {
                dir.Create();
            }

            var codecInfos = ImageCodecInfo.GetImageEncoders();//获取图像编码器的信息

            codecDict = new Dictionary <string, ImageCodecInfo>();
            if (thumbnailSetting.ThumbnailExts != null)
            {
                foreach (var item in thumbnailSetting.ThumbnailExts)
                {
                    var ext = item.Trim().ToLower();
                    foreach (var info in codecInfos)
                    {
                        var arr = info.FilenameExtension.Split(';');
                        var fe  = "*" + ext.ToUpper();
                        if (arr.Contains(fe))
                        {
                            codecDict[ext] = info;
                            break;
                        }
                    }
                }
            }
            var op = new Options {
                Ext    = "_s",
                Width  = 320,
                Height = 240,
                Mode   = "HW",
                Flag   = 100
            };

            optionsDict = new Dictionary <string, Options>()
            {
                { "S", op }
            };
            if (thumbnailSetting.Types != null)
            {
                foreach (var item in thumbnailSetting.Types)
                {
                    var option = new Options();
                    if (string.IsNullOrWhiteSpace(item.Type))
                    {
                        continue;
                    }
                    var type = item.Type.ToUpper();
                    option.Ext = "_" + type;
                    if (item.Width != null && item.Width > 0)
                    {
                        option.Width = item.Width.Value;
                    }
                    if (item.Height != null && item.Height > 0)
                    {
                        option.Height = item.Height.Value;
                    }
                    if (option.Width <= 0 && option.Height <= 0)
                    {
                        option.Width = 320;
                    }
                    if (string.IsNullOrEmpty(option.Mode))
                    {
                        option.Mode = "F";
                    }
                    if (item.Flag != null && item.Flag > 0 && item.Flag <= 100)
                    {
                        option.Flag = item.Flag.Value;
                    }
                    else
                    {
                        option.Flag = 100;
                    }
                    optionsDict[type] = option;
                }
            }
        }