示例#1
0
        /// <summary>
        /// Local的配置
        /// 系统的所有的基础性配置都会在这里初始化
        /// </summary>
        /// <param name="configuration">本地配置json</param>
        private static void UpdateLocal(Configuration configuration)
        {
            // ServerSetting的初始化依赖配置驱动的,只有配置了才会被初始化,如果某个微服务未使用到某个配置,不配置即可,这样可以做到按需初始化
            try
            {
                if (configuration.DataBase != null)
                {
                    var dbstr = string.Format(dbXMl, configuration.DataBase.RefFile, configuration.DataBase.DbFile);
                    if (!string.IsNullOrEmpty(dbstr))
                    {
                        XElement xml = XElement.Parse(dbstr);
                        DbModelContextManager.Initlize(xml); // 初始化数据库配置和sql脚本
                    }
                }

                ConfigManager.Initlize(configuration.ConstKeyValue);  // 初始化常量

                CacheManager.Initlize(configuration.RedisConfig);     // 初始化redis
                MQHostConfigManager.Initlize(configuration.RabbitMQ); // 是时候MQ
                FileServerManager.Initlize(configuration.FileServer); // 初始化文件服务器
            }
            catch (Exception ex)
            {
                logger.LogError(ex, $"ServerSetting.UpdateLocal.Error");
                throw ex;
            }
        }
示例#2
0
        private static Dictionary <string, string> getStandConfig()
        {
            Dictionary <string, string> standConfig = new Dictionary <string, string>();

            try
            {
                var jsonSerializerSettings = new JsonSerializerSettings()
                {
                    NullValueHandling = NullValueHandling.Ignore,
                    Formatting        = Formatting.Indented
                };
                standConfig.Add(SuperGMS.HttpProxy.SuperHttpProxy.HttpProxy, config.HttpProxy == null ? string.Empty : Newtonsoft.Json.JsonConvert.SerializeObject(new Configuration()
                {
                    HttpProxy = config.HttpProxy
                }, jsonSerializerSettings));
                string dbStr = string.Empty;
                if (config.DataBase != null && !string.IsNullOrEmpty(config.DataBase.DbFile))
                {
                    var db  = DbModelContextManager.GetDataBase(config.DataBase.DbFile);
                    var map = DbModelContextManager.GetSqlMap();
                    dbStr = $"<DataBase>\r\n{db?.ToString()}\r\n{map?.ToString()}\r\n</DataBase>";
                }

                standConfig.Add(DbModelContextManager.DATABASE, dbStr);
                standConfig.Add(ConfigManager.CONSTKEYVALUE, config.ConstKeyValue == null ? string.Empty : Newtonsoft.Json.JsonConvert.SerializeObject(new Configuration()
                {
                    ConstKeyValue = config.ConstKeyValue
                }, jsonSerializerSettings));
                standConfig.Add(CacheManager.RedisConfig, config.RedisConfig == null ? string.Empty : Newtonsoft.Json.JsonConvert.SerializeObject(new Configuration()
                {
                    RedisConfig = config.RedisConfig
                }, jsonSerializerSettings));
                standConfig.Add(MQHostConfigManager.RabbitMQ, config.RabbitMQ == null ? string.Empty : Newtonsoft.Json.JsonConvert.SerializeObject(new Configuration()
                {
                    RabbitMQ = config.RabbitMQ
                }, jsonSerializerSettings));
                standConfig.Add(FileServerManager.FileServerName, config.FileServer == null ? string.Empty : Newtonsoft.Json.JsonConvert.SerializeObject(new Configuration()
                {
                    FileServer = config.FileServer
                }, jsonSerializerSettings));
            }
            catch (Exception e)
            {
                logger.LogCritical(e, "初始化标准配置失败");
            }
            return(standConfig);
        }
示例#3
0
 /// <summary>
 /// 根据dbContextName 获取对应得物理数据库的信息
 /// </summary>
 /// <param name="dbContextName">dbContextName</param>
 /// <returns>DbModelContext</returns>
 internal static DbModelContext GetDbModelContext(string dbContextName)
 {
     return(DbModelContextManager.GetDbModelContext(dbContextName));
 }
示例#4
0
        /// <summary>
        /// 按推送节点更新
        /// </summary>
        /// <param name="path">变更路径</param>
        private static void UpdateZookeeper(string path, string configData)
        {
            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            if (string.IsNullOrEmpty(configData))
            {
                return;
            }

            logger.LogDebug($"更新路径:{path},更新内容:{configData}");

            try
            {
                lock (_objLock)
                {
                    string[] ps = path.Split("/", StringSplitOptions.RemoveEmptyEntries);
                    switch (ps[ps.Length - 1])
                    {
                    case DbModelContextManager.DATABASE:     // 数据库,从zookeeper推过来的直接就是数据库和脚本的xml内容,这个跟文件有区别,文件是通过 ref引到外部文件的
                                                             // DataBase db = Newtonsoft.Json.JsonConvert.DeserializeObject<DataBase>(configData);
                        var xmlStr = XElement.Parse(configData);
                        DbModelContextManager.Initlize(xmlStr);

                        // Config.DataBase = db; // 把本地的完整配置更新,数据库配置不需要更新全局
                        break;

                    case ConfigManager.CONSTKEYVALUE:     // 常量
                        var keyValue =
                            Newtonsoft.Json.JsonConvert.DeserializeObject <Configuration>(configData);
                        ConfigManager.Initlize(keyValue.ConstKeyValue);
                        Config.ConstKeyValue = keyValue.ConstKeyValue;
                        break;

                    case CacheManager.RedisConfig:     // redis
                        var redisConfig =
                            Newtonsoft.Json.JsonConvert.DeserializeObject <Configuration>(configData);
                        CacheManager.Initlize(redisConfig.RedisConfig);
                        Config.RedisConfig = redisConfig.RedisConfig;
                        break;

                    case MQHostConfigManager.RabbitMQ:     // rabbitMQ
                        var mq = Newtonsoft.Json.JsonConvert.DeserializeObject <Configuration>(configData);
                        MQHostConfigManager.Initlize(mq.RabbitMQ);
                        Config.RabbitMQ = mq.RabbitMQ;
                        break;

                    case FileServerManager.FileServerName:     // fileserver
                        var fs = Newtonsoft.Json.JsonConvert.DeserializeObject <Configuration>(configData);
                        FileServerManager.Initlize(fs.FileServer);
                        Config.FileServer = fs.FileServer;
                        break;

                    case SuperGMS.HttpProxy.SuperHttpProxy.HttpProxy:     //HttpProxy
                        var pxyName = Newtonsoft.Json.JsonConvert.DeserializeObject <Configuration>(configData);
                        Config.HttpProxy = pxyName.HttpProxy;
                        break;
                    }

                    updateConfigurationAction?.Invoke(ps[ps.Length - 1], Config); // 执行用户自定义的回调,目前只有log在用,其他不用
                }
            }
            catch (Exception ex)
            {
                logger.LogCritical(ex, $"ServerSetting.UpdateZookeeper.Error.path={path},configData={configData}");
            }
        }