Esempio n. 1
0
        public async Task Hand(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            var config = _configProvider.Get <AuthConfig>();

            if (!config.Auditing)
            {
                await next();

                return;
            }

            var auditInfo = CreateAuditInfo(context);

            var sw = new Stopwatch();

            sw.Start();

            var resultContext = await next();

            sw.Stop();

            if (auditInfo != null)
            {
                try
                {
                    //执行结果
                    if (resultContext.Result is ObjectResult result)
                    {
                        auditInfo.Result = JsonSerializer.Serialize(result.Value);
                    }

                    //用时
                    auditInfo.ExecutionDuration = sw.ElapsedMilliseconds;

                    await _auditInfoService.Add(auditInfo);
                }
                catch (Exception ex)
                {
                    _logger.LogError("审计日志插入异常:{@ex}", ex);
                }
            }
        }
        public async Task DoAsync(CancellationToken cancellationToken)
        {
            var config = _configProvider.Get <AggregateQueryConfig>();

            foreach (var accountId in NumberRange.ToInts(config.AccountIds))
            {
                var results = await _client.GetLatestActivities(accountId);

                var tubeStops = results.Aggregates.Count();
                if (tubeStops == 0 && config.IgnoreNotFound)
                {
                    continue;
                }

                var activitiesCount = results.Aggregates.Sum(a => a.Count);

                Console.WriteLine($"Account id {accountId} found {tubeStops} tube stops covering {activitiesCount} activities");

                await _resultSaver.Save(results);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Query the API for all scheduled messages.
        /// </summary>
        /// <returns>The list of scheduled messages.</returns>
        private async Task <IList <ScheduledMessage> > GetMessages()
        {
            var configResult = await configProvider.Get();

            if (!configResult.IsSuccess)
            {
                return(null);
            }
            var config = configResult.Value;

            var result = await httpClient.GetAsync($"{config.ApiUrl}/scheduled-messages");

            if (!result.IsSuccessStatusCode)
            {
                return(null);
            }

            var returnedMessages =
                JsonConvert.DeserializeObject <IList <ScheduledMessage> >(await result.Content.ReadAsStringAsync());

            return(returnedMessages);
        }
        public ExcelExportResultModel Export <T>(ExportModel model, IList <T> entities) where T : class, new()
        {
            if (model == null)
            {
                throw new NullReferenceException("Excel导出信息不存在");
            }

            //设置列对应的属性类型
            SetColumnPropertyType <T>(model);

            if (_config.TempPath.IsNull())
            {
                var sysConfig = _configProvider.Get <PathConfig>();
                _config.TempPath = Path.Combine(sysConfig.TempPath, "Excel");
            }

            var saveName = Guid.NewGuid() + model.Format.ToDescription();

            var saveDir = Path.Combine(_config.TempPath, "Export", DateTime.Now.Format("yyyyMMdd"));

            if (!Directory.Exists(saveDir))
            {
                Directory.CreateDirectory(saveDir);
            }

            var result = new ExcelExportResultModel
            {
                SaveName = saveName,
                FileName = model.FileName,
                Path     = Path.Combine(saveDir, saveName)
            };

            using var fs = new FileStream(result.Path, FileMode.Create, FileAccess.Write);

            //创建文件
            _exportHandler.CreateExcel(model, entities, fs);

            return(result);
        }
Esempio n. 5
0
        /// <summary>
        /// 设置说明
        /// </summary>
        private void SetDescription(ExcelWorksheet sheet, ExportModel model, ref int index)
        {
            var subSb = new StringBuilder();

            if (model.ShowExportPeople && _loginInfo != null)
            {
                subSb.AppendFormat("导出人:{0}    ", _loginInfo.AccountName);
            }

            if (model.ShowExportDate)
            {
                subSb.AppendFormat("导出时间:{0}    ", DateTime.Now.Format());
            }

            if (model.ShowCopyright)
            {
                var config = _configProvider.Get <SystemConfig>();
                subSb.AppendFormat("{0}", config.Copyright);
            }

            if (subSb.Length < 1)
            {
                return;
            }

            sheet.Row(index).Height = 20;
            var cell = sheet.Cells[2, 1, 2, model.Columns.Count];

            cell.Value           = subSb.ToString();
            cell.Merge           = true;
            cell.Style.Font.Size = 10;
            cell.Style.Font.Color.SetColor(Color.Black);
            cell.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
            cell.Style.VerticalAlignment   = ExcelVerticalAlignment.Center;
            cell.Style.Fill.PatternType    = ExcelFillStyle.Solid;
            cell.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(198, 224, 180));
            index++;
        }
Esempio n. 6
0
 public Task <RunDetails> DoAsync(CancellationToken cancellationToken)
 {
     _config = _configProvider.Get <AggregateActivitiesParameters>();
     return(_storeRepository.RunForEachEnabledStore(this, cancellationToken));
 }
Esempio n. 7
0
        public async Task <IResultModel <ModuleBuildCodeResultModel> > BuildCode(Guid moduleId, IList <ClassEntity> classList = null)
        {
            var result = new ResultModel <ModuleBuildCodeResultModel>();

            var module = await _repository.GetAsync(moduleId);

            if (module == null)
            {
                return(result.Failed("模块不存在"));
            }

            //创建模块生成对象
            var moduleBuildModel = _mapper.Map <ModuleBuildModel>(module);

            var config = _configProvider.Get <CodeGeneratorConfig>();

            moduleBuildModel.Prefix   = config.Prefix;
            moduleBuildModel.UiPrefix = config.UiPrefix;

            var id       = Guid.NewGuid().ToString();
            var rootPath = config.BuildCodePath;

            if (rootPath.IsNull())
            {
                var pathConfig = _configProvider.Get <PathConfig>();
                rootPath = Path.Combine(pathConfig.TempPath, "CodeGenerator/BuildCode");
            }

            var moduleFullName = $"{config.Prefix}.Module.{module.Code}";
            var buildModel     = new TemplateBuildModel
            {
                RootPath             = Path.Combine(rootPath, id, moduleFullName),
                NuGetPackageVersions = _nugetHelper.GetVersions()
            };

            if (classList == null)
            {
                //如果classList参数为null,表示生成整个解决方案
                buildModel.GenerateSln = true;
                classList = await _classRepository.QueryAllByModule(module.Id);
            }

            foreach (var classEntity in classList)
            {
                var classBuildModel = _mapper.Map <ClassBuildModel>(classEntity);
                var propertyList    = await _propertyRepository.QueryByClass(classEntity.Id);

                if (propertyList.Any())
                {
                    //查询属性
                    foreach (var propertyEntity in propertyList)
                    {
                        var propertyBuildModel = _mapper.Map <PropertyBuildModel>(propertyEntity);

                        //如果属性类型是枚举,查询枚举信息
                        if (propertyEntity.Type == PropertyType.Enum && propertyEntity.EnumId.NotEmpty())
                        {
                            var enumEntity = await _enumRepository.GetAsync(propertyEntity.EnumId);

                            propertyBuildModel.Enum = new EnumBuildModel
                            {
                                Name    = enumEntity.Name,
                                Remarks = enumEntity.Remarks
                            };

                            var enumItemList = await _enumItemRepository.QueryByEnum(propertyEntity.EnumId);

                            propertyBuildModel.Enum.ItemList = enumItemList.Select(m => new EnumItemBuildModel
                            {
                                Name    = m.Name,
                                Remarks = m.Remarks,
                                Value   = m.Value
                            }).ToList();
                        }

                        classBuildModel.PropertyList.Add(propertyBuildModel);
                    }
                }

                var modelPropertyList = await _modelPropertyRepository.QueryByClass(classEntity.Id);

                if (modelPropertyList.Any())
                {
                    foreach (var propertyEntity in modelPropertyList)
                    {
                        var modelPropertyBuildModel = _mapper.Map <ModelPropertyBuildModel>(propertyEntity);
                        //如果属性类型是枚举,查询枚举信息
                        if (propertyEntity.Type == PropertyType.Enum && propertyEntity.EnumId.NotEmpty())
                        {
                            var enumEntity = await _enumRepository.GetAsync(propertyEntity.EnumId);

                            modelPropertyBuildModel.Enum = new EnumBuildModel
                            {
                                Name    = enumEntity.Name,
                                Remarks = enumEntity.Remarks
                            };

                            var enumItemList = await _enumItemRepository.QueryByEnum(propertyEntity.EnumId);

                            modelPropertyBuildModel.Enum.ItemList = enumItemList.Select(m => new EnumItemBuildModel
                            {
                                Name    = m.Name,
                                Remarks = m.Remarks,
                                Value   = m.Value
                            }).ToList();
                        }

                        classBuildModel.ModelPropertyList.Add(modelPropertyBuildModel);
                    }
                }

                classBuildModel.Method = await _classMethodRepository.GetByClass(classEntity.Id);

                moduleBuildModel.ClassList.Add(classBuildModel);
            }

            buildModel.Module = moduleBuildModel;

            var builder = new DefaultTemplateBuilder();

            builder.Build(buildModel);

            var sourceDir  = Path.Combine(rootPath, id);
            var outputFile = Path.Combine(rootPath, id + ".zip");

            ZipFile.CreateFromDirectory(sourceDir, outputFile);

            //删除临时文件
            Directory.Delete(sourceDir, true);

            var resultModel = new ModuleBuildCodeResultModel
            {
                Id      = id,
                Name    = moduleBuildModel.Name + ".zip",
                ZipPath = outputFile
            };

            return(result.Success(resultModel));
        }
Esempio n. 8
0
        public async Task <IResultModel> GetTree()
        {
            //先取缓存
            if (_cacheHandler.TryGetValue(CacheKeys.PERMISSION_TREE, out TreeResultModel <int, PermissionTreeResultModel> root))
            {
                return(ResultModel.Success(root));
            }

            var config = _configProvider.Get <SystemConfig>();
            var id     = 0;

            root = new TreeResultModel <int, PermissionTreeResultModel>
            {
                Id    = id,
                Label = config.Title,
                Item  = new PermissionTreeResultModel()
            };
            root.Path.Add(root.Label);

            var modules     = _moduleRepository.GetAllAsync();
            var permissions = await _repository.GetAllAsync();

            //模块
            foreach (var module in await modules)
            {
                var moduleNode = new TreeResultModel <int, PermissionTreeResultModel>
                {
                    Id    = ++id,
                    Label = module.Name,
                    Item  = new PermissionTreeResultModel
                    {
                        Label = module.Name,
                        Code  = module.Code
                    }
                };

                moduleNode.Path.AddRange(root.Path);
                moduleNode.Path.Add(module.Name);

                var controllers = permissions.Where(m => m.ModuleCode.EqualsIgnoreCase(module.Code)).DistinctBy(m => m.Controller);
                //控制器
                foreach (var controller in controllers)
                {
                    var controllerName = controller.Name.Split('_')[0];
                    var controllerNode = new TreeResultModel <int, PermissionTreeResultModel>
                    {
                        Id    = ++id,
                        Label = controllerName,
                        Item  = new PermissionTreeResultModel
                        {
                            Label = controllerName,
                            Code  = controller.Controller
                        }
                    };

                    controllerNode.Path.AddRange(moduleNode.Path);
                    controllerNode.Path.Add(controllerName);

                    var permissionList = permissions.Where(m => m.ModuleCode.EqualsIgnoreCase(module.Code) && m.Controller.EqualsIgnoreCase(controller.Controller));
                    //权限
                    foreach (var permission in permissionList)
                    {
                        var permissionName = permission.Name.Contains("_") ? permission.Name.Split('_')[1] : permission.Name;
                        var permissionNode = new TreeResultModel <int, PermissionTreeResultModel>
                        {
                            Id    = ++id,
                            Label = permissionName,
                            Item  = new PermissionTreeResultModel
                            {
                                Label        = permissionName,
                                Code         = permission.Code,
                                IsPermission = true
                            }
                        };

                        permissionNode.Path.AddRange(controllerNode.Path);
                        permissionNode.Path.Add(permissionName);

                        controllerNode.Children.Add(permissionNode);
                    }

                    moduleNode.Children.Add(controllerNode);
                }
                root.Children.Add(moduleNode);
            }

            await _cacheHandler.SetAsync(CacheKeys.PERMISSION_TREE, root);

            return(ResultModel.Success(root));
        }
        public CosmosDbStore(IConfigProvider configProvider)
        {
            CosmosDbStore cosmosDbStore = this;

            this._client       = new Lazy <DocumentClient>((Func <DocumentClient>)(() => cosmosDbStore.InitialiseClient(configProvider)));
            this._cosmosConfig = new Lazy <CosmosConfig>((Func <CosmosConfig>)(() => (CosmosConfig)configProvider.Get <CosmosConfig>()));
        }
 public ServiceCredentialsProvider(IConfigProvider configProvider)
 {
     m_app = configProvider.Get <AzureApplication>();
 }
Esempio n. 11
0
 public ProductService(IConfigProvider configProvider)
 {
     this.stripeConfiguration = configProvider.Get <IStripeConfiguration>();
 }
Esempio n. 12
0
 public static string Get(this IConfigProvider config, string key) => config.Get <string>(key);
Esempio n. 13
0
 public Task <RunDetails> DoAsync(CancellationToken cancellationToken)
 {
     _activities = _activityFactory.CreateActivities(_configProvider.Get <PopulateActivitiesParameters>()).ToArray();
     return(_storeRepository.RunForEachEnabledStore(this, cancellationToken));
 }
Esempio n. 14
0
        public async Task <ResultModel <LoginResultModel> > Login(LoginModel model)
        {
            var result = new ResultModel <LoginResultModel>();

            //检测验证码
            if (!await CheckVerifyCode(result, model))
            {
                return(result);
            }

            //检测账户
            var account = await _accountRepository.GetByUserName(model.UserName, model.AccountType);

            var checkAccountResult = CheckAccount(account);

            if (!checkAccountResult.Successful)
            {
                return(result.Failed(checkAccountResult.Msg));
            }

            //检测密码
            if (!CheckPassword(result, model, account))
            {
                return(result);
            }

            using var uow = _dbContext.NewUnitOfWork();

            //判断是否激活,如果未激活需要修改为已激活状态
            if (account.Status == AccountStatus.Inactive)
            {
                if (!await _accountRepository.UpdateAccountStatus(account.Id, AccountStatus.Enabled, uow))
                {
                    return(result.Failed());
                }
            }

            //更新登录信息
            var loginInfo = await UpdateLoginInfo(account, model, uow);

            if (loginInfo != null)
            {
                uow.Commit();

                var config = _configProvider.Get <ComponentConfig>();
                if (config.Login.VerifyCode)
                {
                    //删除验证码缓存
                    await _cacheHandler.RemoveAsync($"{CacheKeys.AUTH_VERIFY_CODE}:{model.VerifyCode.Id}");
                }

                //清除账户的认证信息缓存
                await _cacheHandler.RemoveAsync($"{CacheKeys.ACCOUNT_AUTH_INFO}:{account.Id}:{model.Platform.ToInt()}");

                return(result.Success(new LoginResultModel
                {
                    Account = account,
                    AuthInfo = loginInfo
                }));
            }

            return(result.Failed());
        }
        /// <summary>
        /// 加载权限树
        /// </summary>
        /// <returns></returns>
        private void LoadTree()
        {
            var config = _configProvider.Get <SystemConfig>();

            _tree = new TreeResultModel <string, PermissionTreeModel>
            {
                Id    = "",
                Label = config.Title,
                Item  = new PermissionTreeModel()
            };
            _tree.Path.Add(_tree.Label);

            var controllers = _mvcHelper.GetAllController();

            //模块
            foreach (var module in _moduleCollection)
            {
                var moduleNode = new TreeResultModel <string, PermissionTreeModel>
                {
                    Id    = module.Code,
                    Label = module.Name,
                    Item  = new PermissionTreeModel
                    {
                        Label = module.Name,
                        Code  = module.Code
                    }
                };

                moduleNode.Path.AddRange(_tree.Path);
                moduleNode.Path.Add(module.Name);

                //控制器
                foreach (var controller in controllers.Where(m => m.Area.EqualsIgnoreCase(module.Code)))
                {
                    var controllerName = controller.Description ?? controller.Name;
                    var controllerNode = new TreeResultModel <string, PermissionTreeModel>
                    {
                        Id    = $"{module.Code}_{controller.Name}".ToLower(),
                        Label = controllerName,
                        Item  = new PermissionTreeModel
                        {
                            Label = controllerName
                        }
                    };

                    controllerNode.Item.Code = controllerNode.Id;

                    controllerNode.Path.AddRange(moduleNode.Path);
                    controllerNode.Path.Add(controllerName);

                    var permissions = Query(module.Code, controller.Name);
                    //权限
                    foreach (var permission in permissions)
                    {
                        var permissionName = permission.Name.Contains("_") ? permission.Name.Split('_')[1] : permission.Name;
                        var permissionNode = new TreeResultModel <string, PermissionTreeModel>
                        {
                            Id    = permission.Code,
                            Label = permissionName,
                            Item  = new PermissionTreeModel
                            {
                                Label        = permissionName,
                                Code         = permission.Code,
                                IsPermission = true
                            }
                        };

                        permissionNode.Path.AddRange(controllerNode.Path);
                        permissionNode.Path.Add(permissionName);

                        controllerNode.Children.Add(permissionNode);
                    }

                    moduleNode.Children.Add(controllerNode);
                }
                _tree.Children.Add(moduleNode);
            }
        }
Esempio n. 16
0
 /// <summary>
 /// 取得 Redis 連線字串
 /// </summary>
 /// <param name="config"></param>
 /// <returns></returns>
 public static string RedisConnection(this IConfigProvider config)
 {
     return(config.Get("Redis:Connection", "localhost"));
 }
Esempio n. 17
0
 /// <summary>
 /// 取得 Redis 預設資料庫
 /// </summary>
 /// <param name="config"></param>
 /// <returns></returns>
 public static int RedisDefaultDatabase(this IConfigProvider config)
 {
     return(config.Get("Redis:DefaultDatabase", 2));
 }
Esempio n. 18
0
 public TeslaMateRepository(IConfigProvider configProvider)
 {
     _config = configProvider.Get <DatabaseConfig>();
 }
Esempio n. 19
0
        public async Task <IResultModel <Guid> > Add(AccountAddModel model, IUnitOfWork uow = null)
        {
            var result = new ResultModel <Guid>();

            var account = _mapper.Map <AccountEntity>(model);

            var exists = await Exists(account);

            if (!exists.Successful)
            {
                return(exists);
            }

            //默认未激活状态,用户首次登录激活
            account.Status = AccountStatus.Inactive;

            //设置默认密码
            if (account.Password.IsNull())
            {
                var config = _configProvider.Get <AdminConfig>();
                account.Password = config.DefaultPassword.NotNull() ? config.DefaultPassword : "******";
            }

            account.Password = _passwordHandler.Encrypt(account.UserName, account.Password);

            //如果uow参数为空,需要自动处理工作单元
            var noUow = uow == null;

            if (noUow)
            {
                uow = _dbContext.NewUnitOfWork();
            }

            if (await _accountRepository.AddAsync(account, uow))
            {
                if (model.Roles != null && model.Roles.Any())
                {
                    var accountRoleList = model.Roles.Select(m => new AccountRoleEntity {
                        AccountId = account.Id, RoleId = m
                    }).ToList();
                    if (await _accountRoleRepository.AddAsync(accountRoleList, uow))
                    {
                        if (noUow)
                        {
                            uow.Commit();
                        }

                        return(result.Success(account.Id));
                    }
                }
                else
                {
                    if (noUow)
                    {
                        uow.Commit();
                    }

                    return(result.Success(account.Id));
                }
            }

            return(result.Failed());
        }