/// <summary> /// 读取配置文件 /// </summary> /// <param name="dllName"></param> /// <param name="sectionName"></param> /// <returns></returns> public static RedisSetting GetSetting(string dllName = StaticString.DefaultRedisConfigDll, string sectionName = StaticString.DefautlRedisConfigSection) { if (!AppConfig.IsExists(dllName)) { throw new NotFoundException("未找到对应的配置文件"); } dllName = Assembly.GetCallingAssembly().GetName().Name; if (!AppConfig.DllConfigs[dllName].IsExists(sectionName)) { throw new NotFoundException("未找到对应的配置文件下的配置节点"); } var Setting = new RedisSetting(); try { Setting.ClientName = StringUtil.FormatKey(dllName, sectionName); Setting.LocalCacheEnable = CoralConvert.Convert <bool>(AppConfig.DllConfigs[dllName][sectionName]["LocalCacheEnable"]); Setting.LocalCacheTimeout = CoralConvert.Convert <int>(AppConfig.DllConfigs[dllName][sectionName]["LocalCacheTimeout"]); Setting.ServerList = AppConfig.DllConfigs[dllName][sectionName]["ServerList"]; Setting.Version = AppConfig.DllConfigs[dllName][sectionName]["Version"]; Setting.DefaultDb = Convert.ToInt32(AppConfig.DllConfigs[dllName][sectionName]["DefaultDb"] ?? "0"); Setting.Password = AppConfig.DllConfigs[dllName][sectionName]["Password"]; return(Setting); } catch (Exception ex) { throw CoralException.ThrowException(item => item.ConfigError, innerException: ex, param: Setting); } }
public ResultErrorMessage(CoralException excetion) : base(ResultState.Fail, excetion.Message) { //如果出现错误则数据里面也包含错误编码 //Data = excetion.HResult; ErrorCode = excetion.HResult; }
public void ProvideFault(System.Exception error, MessageVersion version, ref Message fault) { var errorMessage = new ResultErrorMessage(CoralException.ThrowException <CoralErrorCode>(item => item.SystemError, innerException: error)); fault = Message.CreateMessage(version, error.Source, new RawBodyWriter(errorMessage)); fault.Properties.Add(WebBodyFormatMessageProperty.Name, new WebBodyFormatMessageProperty(WebContentFormat.Raw)); HttpRequestMessageProperty reqProp = new HttpRequestMessageProperty(); reqProp.Headers[HttpRequestHeader.ContentType] = "application/json"; fault.Properties.Add(HttpRequestMessageProperty.Name, reqProp); }
public static ICache GetRedisCache(RedisSetting setting) { try { return(new RedisCache(setting)); } catch (NullReferenceException) { throw CoralException.ThrowException(item => item.ConfigError); } }
public void InstallModules() { try { _modules = MetaDataManager.Type.Find(CoralModule.IsCoralModule) .SortByDependencies(item => { //所有的模块都默认依赖于CoralModule if (item == typeof(CoreModule)) { return(new List <Type>()); } var dependencies = DependencyAttribute.GetDependencies(item).Where(type => !type.IsAbstract).ToList(); dependencies.Add(typeof(CoreModule)); return(dependencies); }) .Select(item => UnityService.Resolve(item) as CoralModule) .Where(item => item != null) .ToList(); _coralModules = new Dictionary <string, CoralModule>(); _typeModules = new Dictionary <Type, CoralModule>(); //构建名字和模块的字典 foreach (var module in _modules) { if (_coralModules.ContainsKey(module.Name)) { throw CoralException.ThrowException(item => item.ModuleExisted, module.Name); } _coralModules.Add(module.Name, module); } //构建类型 foreach (var module in _modules) { foreach (var type in module.Types) { if (!_typeModules.ContainsKey(type)) { _typeModules.Add(type, module); } } } _modules.ForEach(item => item.Prepare()); _modules.ForEach(item => item.Install()); _modules.ForEach(item => item.Installed()); } catch (ReflectionTypeLoadException ex) { throw new CoralModuleException(ex); } }
/// <summary> /// 创建数据库上下文 /// </summary> /// <param name="context"></param> /// <returns></returns> public virtual CoralDbContext Create(DbInitContext context) { if (context == null) { throw CoralException.ThrowException <DbErrorCode>(item => item.InvalideDbCoden, "上下文为空"); } if (context.Config == null) { throw CoralException.ThrowException <DbErrorCode>(item => item.InvalideDbCoden, "上下文配置为空"); } if (string.IsNullOrEmpty(context.Config.NameOrConnectionString)) { throw CoralException.ThrowException <DbErrorCode>(item => item.InvalideDbCoden, "连接字符串为空"); } return(_contexts.GetOrAdd(context.GetIdentity(), item => _creator(item, context))); }