/// <summary> /// 获取系统的所有storages /// </summary> /// <returns></returns> private static List <StorageDAO> GetStorages() { var cacheFilter = new CacheFilter(_storageCacheKey); var cacheClient = new RedisClientCache(); List <StorageDAO> storages = cacheClient.Query <List <StorageDAO> >(cacheFilter); if (storages == null || storages.Count == 0) { string sql = "select * from t_sys_storage where misdelete=0 order by mitemid"; string connectionString = ConfigurationManager.AppSetting("ConnectionString"); IORM _orm = new SugarORM(connectionString); var client = _orm.GetSqlClient <SqlSugarClient>(); storages = client.SqlQueryable <StorageDAO>(sql).ToList(); CacheModel storageCache = new CacheModel() { Key = _storageCacheKey, Data = storages }; if (cacheClient.IsExistCacheKey(cacheFilter)) { cacheClient.Delete(cacheFilter); } cacheClient.Add(storageCache); } return(storages); }
private async void SendExceptionLog(HttpContext httpContext, Exception exception) { var loggerFactory = BaseLoggerFactory.Instance(); var request = httpContext.Request; LogDTO log = new LogDTO() { AppName = ConfigurationManager.AppSetting("AppName"), Level = LogLevelType.Error, Type = LogType.Exception, Content = new { RequestURL = request.Host + request.Path, RequestMethod = request.Method, RequestData = GetRequestData(request), RequestToken = GetRequestToken(request), UserId = TokenContext.CurrentContext != null?TokenContext.CurrentContext.GetUserId() : null, OrganizationId = TokenContext.CurrentContext != null?TokenContext.CurrentContext.GetOrganizationId() : null, Message = GetExceptionMessage(exception) } }; loggerFactory.Add(log); }
public static void AddDbContextPool(this IServiceCollection services) { services.AddDbContextPool <MysqlDbContext>(options => { options.UseMySQL(ConfigurationManager.AppSetting("ConnectionString")); } ); }
public EmailClient() { _host = ConfigurationManager.AppSetting("EmailHost"); _port = Convert.ToInt32(ConfigurationManager.AppSetting("EmailPort")); _fromEamil = ConfigurationManager.AppSetting("FromEmail"); _fromName = ConfigurationManager.AppSetting("FromName"); _password = ConfigurationManager.AppSetting("EmailPassword"); }
private BaseLoggerFactory() { _host = ConfigurationManager.AppSetting("LogFactoryHost"); if (string.IsNullOrWhiteSpace(_host)) { throw new ArgumentNullException("LogFactoryHost 没有配置"); } }
public RabbitMQEventBus(IEventHandlerExecutionContext eventHandlerExecutionContext) { _mqHost = ConfigurationManager.AppSetting("RabbitMQHost"); _mqUser = ConfigurationManager.AppSetting("RabbitMQUser"); _mqPassword = ConfigurationManager.AppSetting("RabbitMQPassword"); _eventQueue = new RabbitQueue(_mqHost, _mqUser, _mqPassword); _eventHandlerExecutionContext = eventHandlerExecutionContext; }
/// <summary> /// 创建超级管理员用户 /// </summary> /// <param name="userDTO"></param> /// <returns></returns> public OperationResult CreateUser(UserDTO userDTO) { OperationResult result = new OperationResult(); var user = _mapper.Map <User.Domain.AggregateUser.Entity.User>(userDTO); var emailTemplateUrl = ConfigurationManager.AppSetting("GatewayHost") + "/emailtemplates?type=1"; EmailTemplateDTO emailTemplate = new EmailTemplateDTO(); try { emailTemplate = new HttpClientUtility().Get <EmailTemplateDTO>(emailTemplateUrl); if (emailTemplate != null && emailTemplate.Contents != null) { var content = emailTemplate.Contents.FirstOrDefault(x => x.LangId == userDTO.LangId); emailTemplate.Content = content != null ? content.Value : null; } } catch (Exception ex) { string message = "无法激活邮件模板:" + emailTemplateUrl + "错误详情:" + ex.Message; throw new RequestDataExcepiton(message); } if (emailTemplate == null || string.IsNullOrWhiteSpace(emailTemplate.Content)) { result.Success = false; result.Messages.Add("无法找到激活邮件模板,无法完成注册"); return(result); } var emailTemplateDO = _mapper.Map <EmailTemplate>(emailTemplate); result = _userDomainService.CreateUser(user, emailTemplateDO); if (result.Success) { string activeUrl = ConfigurationManager.AppSetting("ActiveUrl") + "?id=" + user.UserActiveInfo.Id; string supportEamil = ConfigurationManager.AppSetting("FromEmail"); _eventBus.PublishAsync <UserWaitActiveEvent>(new UserWaitActiveEvent() { UserId = user.Id, EmailAddress = user.EmailAddress, EmailContent = string.Format(emailTemplate.Content, user.GetUserName(), activeUrl, supportEamil) }); } return(result); }
/// <summary> /// 应用服务, 领域服务注入 /// </summary> /// <param name="services"></param> public static void AddGloabalIoc(this IServiceCollection services) { var assemblyNames = GetAssemblyFromConfiguration(ConfigurationManager.AppSetting("IocAssemblys")); if (assemblyNames == null || assemblyNames.Count == 0) { return; } foreach (var assemblyName in assemblyNames) { services.AddAssembly(assemblyName, ServiceLifetime.Transient); } }
/// <summary> /// 设置组织的数据库 /// </summary> /// <param name="organizationId"></param> public static void SetOrganizationStorageRelation(string organizationId) { var storageMaxOrganiztonCount = ConfigurationManager.AppSetting("StorageMaxOrganiztonCount"); if (string.IsNullOrWhiteSpace(storageMaxOrganiztonCount)) { throw new Exception("没有找到配置项StorageMaxOrganiztonCount"); } int maxConfiguration = 0; if (!int.TryParse(storageMaxOrganiztonCount, out maxConfiguration)) { throw new Exception("配置项StorageMaxOrganiztonCount只能是整形数字"); } var storages = GetStorages(); if (storages == null || storages.Count == 0) { throw new Exception("没有找到任何的storeage"); } var storage = storages.FirstOrDefault(x => x.MOrgCount < maxConfiguration); if (storage == null) { throw new Exception("没有找到合适的数据库,请确认数据库是否已满"); } OrganizaitonStoreRelationDAO organizaitonStore = new OrganizaitonStoreRelationDAO() { MItemID = GuidUtility.GetGuid(), MOrgID = organizationId, MStorageID = storage.MItemID, MIsActive = true, MIsDelete = false }; string connectionString = ConfigurationManager.AppSetting("ConnectionString"); IORM _orm = new SugarORM(connectionString); var client = _orm.GetSqlClient <SqlSugarClient>(); client.Insertable <OrganizaitonStoreRelationDAO>(organizaitonStore).ExecuteCommand(); }
public RedisClientCache() { _redisHost = ConfigurationManager.AppSetting("RedisHost"); _redisPort = ConfigurationManager.AppSetting("RedisPort"); _redisPassword = ConfigurationManager.AppSetting("RedisPassword"); _redisDataBaseName = ConfigurationManager.AppSetting("RedisDateBase"); _redisDataBaseName = string.IsNullOrWhiteSpace(_redisDataBaseName) ? "1" : _redisDataBaseName; var csredis = new CSRedis.CSRedisClient($"{_redisHost}:{_redisPort},password={_redisPassword},defaultDatabase={_redisDataBaseName},poolsize=50,ssl=false,writeBuffer=10240"); //初始化 RedisHelper RedisHelper.Initialization(csredis); }
/// <summary> /// automapper注册,包括profile配置文件 /// </summary> /// <param name="services"></param> public static void AddAutoMappers(this IServiceCollection services) { var assemblyNames = GetAssemblyFromConfiguration(ConfigurationManager.AppSetting("AutoMapperIocAssemblys")); if (assemblyNames == null || assemblyNames.Count == 0) { return; } var assemblys = new List <Assembly>(); foreach (var assemblyName in assemblyNames) { assemblys.Add(GetAssemblyByName(assemblyName)); } services.AddAutoMapper(assemblys); }
/// <summary> /// 获取token /// </summary> /// <param name="token"></param> /// <returns></returns> private TokenDTO GetToken(string token) { TokenDTO result = null; HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add("token", token); string url = ConfigurationManager.AppSetting("SessionValidateHost") + $"?token={token}"; ResponseResult checkTokenResult = GetOriginalResponse <ResponseResult>(url, httpClient); if (checkTokenResult.Success) { result = JsonConvert.DeserializeObject <TokenDTO>(checkTokenResult.Data.ToString()); } return(result); }
/// <summary> /// 根据组织获取连接字符串 /// </summary> /// <param name="organizationId"></param> /// <returns></returns> public static string GetConnectionString(string organizationId) { string connectionString = ConfigurationManager.AppSetting("ConnectionString"); IORM _orm = new SugarORM(connectionString); var client = _orm.GetSqlClient <SqlSugarClient>(); string sql = GetQuerySql(organizationId); OrganizaitonStoreRelationDAO dbStore = client.SqlQueryable <OrganizaitonStoreRelationDAO>(sql).First(); if (dbStore == null) { throw new Exception($"找不到组织{organizationId}对应的业务数据库"); } return(GetConnectionString(dbStore)); }
/// <summary> /// 向EFCore 上下文中注入实体关系 /// </summary> /// <param name="modelBuilder"></param> private void RegisterEntityRelationship(ModelBuilder modelBuilder) { var assemblyNames = GetAssemblyFromConfiguration(ConfigurationManager.AppSetting("ORMIocAssemblys")); if (assemblyNames == null || assemblyNames.Count == 0) { return; } List <Type> entitys = new List <Type>(); foreach (var assemblyName in assemblyNames) { var assembly = GetAssemblyByName(assemblyName); var tempEntitys = assembly.DefinedTypes.Select(t => t.AsType()).ToList(); if (tempEntitys == null || tempEntitys.Count == 0) { return; } tempEntitys = tempEntitys.Where(x => typeof(ICustomModelBuilder).IsAssignableFrom(x)).ToList(); entitys.AddRange(tempEntitys); } if (entitys == null || entitys.Count == 0) { return; } foreach (var entity in entitys) { if (entity != null && entity != typeof(ICustomModelBuilder)) { var builder = (ICustomModelBuilder)Activator.CreateInstance(entity); builder.Builder(modelBuilder); } } }
/// <summary> /// 向EFCore 上下文中注入实体 /// </summary> /// <param name="modelBuilder"></param> private void RegisterEntity(ModelBuilder modelBuilder) { var assemblyNames = GetAssemblyFromConfiguration(ConfigurationManager.AppSetting("ORMIocAssemblys")); if (assemblyNames == null || assemblyNames.Count == 0) { return; } List <Type> entitys = new List <Type>(); foreach (var assemblyName in assemblyNames) { var assembly = GetAssemblyByName(assemblyName); var tempEntitys = assembly.DefinedTypes.Select(t => t.AsType()).ToList(); if (tempEntitys == null || tempEntitys.Count == 0) { return; } tempEntitys = tempEntitys.Where(x => (x.GetTypeInfo().IsSubclassOf(typeof(BasePO)) || x.GetTypeInfo().IsSubclassOf(typeof(BaseLanguagePO))) && !x.GetTypeInfo().IsAbstract).ToList(); entitys.AddRange(tempEntitys); } if (entitys == null || entitys.Count == 0) { return; } foreach (var entity in entitys) { modelBuilder.Entity(entity); } }
protected virtual void SetConnectionString() { _connectionString = ConfigurationManager.AppSetting("ConnectionString"); }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { var connectionString = ConfigurationManager.AppSetting("ConnectionString"); optionsBuilder.UseMySQL(connectionString); }