Пример #1
0
        public async Task <object> GetAsync()
        {
            //Get a value as string.
            string host = await _settingProvider.GetOrNullAsync("Smtp.Host");

            //string host2 = await SettingProvider.GetOrNullAsync("Smtp.Host");

            //Get a bool value and fallback to the default value (false) if not set.
            bool enableSsl1 = await _settingProvider.GetAsync <bool>("Smtp.EnableSsl");

            //Get a bool value and fallback to the provided default value (true) if not set.
            bool enableSsl2 = await _settingProvider.GetAsync("Smtp.EnableSsl", defaultValue : true);

            //Get a bool value with the IsTrueAsync shortcut extension method
            bool enableSsl3 = await _settingProvider.IsTrueAsync("Smtp.EnableSsl");

            //Get an int value or the default value (0) if not set
            int port1 = await _settingProvider.GetAsync <int>("Smtp.Port");

            //Get an int value or null if not provided
            int?port2 = (await _settingProvider.GetOrNullAsync("Smtp.Port"))?.To <int>();

            string setting1 = await _settingProvider.GetOrNullAsync("Example.Setting1");

            string setting2 = await _settingProvider.GetOrNullAsync("Example.Setting2");

            string setting3 = await _settingProvider.GetOrNullAsync("Example.Setting3");

            return(new { host, enableSsl1, enableSsl2, enableSsl3, port1, port2, setting1, setting2, setting3 });
        }
        protected virtual async Task <FileValidation> GetBySettingAsync()
        {
            var fileSizeLimited = await _settingProvider
                                  .GetAsync(
                AbpOssManagementSettingNames.FileLimitLength,
                AbpOssManagementSettingNames.DefaultFileLimitLength);

            var fileAllowExtension = await _settingProvider
                                     .GetOrDefaultAsync(AbpOssManagementSettingNames.AllowFileExtensions, _serviceProvider);

            return(new FileValidation(fileSizeLimited, fileAllowExtension.Split(',')));
        }
Пример #3
0
        public async Task FooAsync()
        {
            //Get a value as string.
            string userName = await _settingProvider.GetOrNullAsync("Smtp.UserName");

            //Get a bool value and fallback to the default value (false) if not set.
            bool enableSsl = await _settingProvider.GetAsync <bool>("Smtp.EnableSsl");

            //Get a bool value and fallback to the provided default value (true) if not set.
            bool enableSsl2 = await _settingProvider.GetAsync <bool>(
                "Smtp.EnableSsl", defaultValue : true);

            //Get a bool value with the IsTrueAsync shortcut extension method
            bool enableSsl3 = await _settingProvider.IsTrueAsync("Smtp.EnableSsl");

            //Get an int value or the default value (0) if not set
            int port = (await _settingProvider.GetAsync <int>("Smtp.Port"));

            //Get an int value or null if not provided
            int?port2 = (await _settingProvider.GetOrNullAsync("Smtp.Port"))?.To <int>();
        }
Пример #4
0
        private async Task <bool> ValidateFile(IFormFile file)
        {
            var maxLength = await _settingProvider.GetAsync <long>("App.UploadFiles.MaxLength");

            //为空检查
            if (file == null || file.Length == 0)
            {
                throw new UserFriendlyException("文件不能为空");
            }

            //大小检查
            if (file.Length > maxLength)
            {
                var KB = Math.Floor((double)(maxLength / 1024));
                var MB = Math.Floor((double)(maxLength / 1024 / 1024));

                string size;
                if (MB > 0)
                {
                    size = MB + "MB";
                }
                else
                {
                    size = KB + "KB";
                }

                throw new UserFriendlyException("上传的文件的不应该大于" + size);
            }

            //文件格式检查
            var allowTypes = await _settingProvider.GetOrNullAsync("App.UploadFiles.AllowType");

            var allowTypeList = allowTypes.Split(",");

            if (Array.IndexOf(allowTypeList, Path.GetExtension(file.FileName)) == -1)
            {
                throw new UserFriendlyException("请上传正确的文件格式");
            }

            return(true);
        }
Пример #5
0
 public static T Get <T>([NotNull] this ISettingProvider settingProvider, [NotNull] string name, T defaultValue = default)
     where T : struct
 {
     return(AsyncHelper.RunSync(() => settingProvider.GetAsync(name, defaultValue)));
 }
        protected virtual async Task OverrideOptionsAsync(IdentityOptions options)
        {
            options.Password.RequiredLength = await _settingProvider.GetAsync(IdentitySettingNames.Password.RequiredLength, options.Password.RequiredLength);

            options.Password.RequiredUniqueChars = await _settingProvider.GetAsync(IdentitySettingNames.Password.RequiredUniqueChars, options.Password.RequiredUniqueChars);

            options.Password.RequireNonAlphanumeric = await _settingProvider.GetAsync(IdentitySettingNames.Password.RequireNonAlphanumeric, options.Password.RequireNonAlphanumeric);

            options.Password.RequireLowercase = await _settingProvider.GetAsync(IdentitySettingNames.Password.RequireLowercase, options.Password.RequireLowercase);

            options.Password.RequireUppercase = await _settingProvider.GetAsync(IdentitySettingNames.Password.RequireUppercase, options.Password.RequireUppercase);

            options.Password.RequireDigit = await _settingProvider.GetAsync(IdentitySettingNames.Password.RequireDigit, options.Password.RequireDigit);

            options.Lockout.AllowedForNewUsers = await _settingProvider.GetAsync(IdentitySettingNames.Lockout.AllowedForNewUsers, options.Lockout.AllowedForNewUsers);

            options.Lockout.DefaultLockoutTimeSpan  = TimeSpan.FromSeconds(await _settingProvider.GetAsync(IdentitySettingNames.Lockout.LockoutDuration, options.Lockout.DefaultLockoutTimeSpan.TotalSeconds.To <int>()));
            options.Lockout.MaxFailedAccessAttempts = await _settingProvider.GetAsync(IdentitySettingNames.Lockout.MaxFailedAccessAttempts, options.Lockout.MaxFailedAccessAttempts);

            options.SignIn.RequireConfirmedEmail = await _settingProvider.GetAsync(IdentitySettingNames.SignIn.RequireConfirmedEmail, options.SignIn.RequireConfirmedEmail);

            options.SignIn.RequireConfirmedPhoneNumber = await _settingProvider.GetAsync(IdentitySettingNames.SignIn.RequireConfirmedPhoneNumber, options.SignIn.RequireConfirmedPhoneNumber);
        }