/// <summary> /// /// </summary> /// <param name="configuration"></param> /// <returns></returns> public static MimeSetting LoadSettings(IConfiguration configuration) { var mimeSetting = new MimeSetting(); var defaultMime = Environment.GetEnvironmentVariable("DEFAULT_MIME"); if (string.IsNullOrEmpty(defaultMime)) { defaultMime = configuration["DefaultMime"]; } if (!string.IsNullOrEmpty(defaultMime)) { mimeSetting.DefaultMime = defaultMime; } try { var mimeInfos = configuration.GetSection("MimeInfos").Get <MimeInfo[]>(); mimeSetting.MimeInfos = mimeInfos ?? new MimeInfo[0]; } catch (Exception ex) { throw new ConfigurationException("MimeInfos Variable Error", ex); } return(mimeSetting); }
/// <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); }
/// <summary> /// /// </summary> /// <param name="mimeSetting"></param> public MimeModule(MimeSetting mimeSetting) { this.contentTypeProvider = new FileExtensionContentTypeProvider(); if (mimeSetting.MimeInfos != null) { foreach (var item in mimeSetting.MimeInfos) { contentTypeProvider.Mappings[item.Ext] = item.Mime; } } if (!string.IsNullOrEmpty(mimeSetting.DefaultMime)) { defaultMime = mimeSetting.DefaultMime; } else { defaultMime = "application/octet-stream"; } }