Example #1
0
        /// <summary>
        /// 连接配置中心
        /// </summary>
        /// <returns></returns>
        private async Task ConnectConfigCenterAsync()
        {
            try
            {
                var serverManage = ApplicationData.GetService <IServerManage>();
                ResultModel <List <ServerListDTO> > resultModel = await serverManage.GetServerListAsync();

                if (resultModel.ResultType == ResultTypeEnum.Success)
                {
                    ServerListDTO server = resultModel.Data.FirstOrDefault(m => m.ServerCategory == ServerCategoryEnum.ConfigCenter);
                    if (server == null)
                    {
                        throw new ConfigCenterEnvironmentException("获取配置中心服务失败");
                    }
                    ConfigCenterEnvironmentConfig.ConfigCenterUrl = server.Url;
                    ConfigCenterEnvironmentConsoleHelper.WriteLine($"已获取配置中心地址:{ConfigCenterEnvironmentConfig.ConfigCenterUrl}");
                    var configCenterHub = ApplicationData.GetService <IConfigCenterHub>();
                    var registerModel   = new RegisterEnvironmentRequestModel
                    {
                        Name = ConfigCenterEnvironmentConfig.ServerInfo.Name,
                        Url  = ApplicationConfig.PublicUrl,
                        Key  = ConfigCenterEnvironmentConfig.ServerInfo.Key
                    };
                    await configCenterHub.RegisterEnvironment(registerModel);
                }
                else
                {
                    throw new ConfigCenterEnvironmentException("获取配置中心服务失败");
                }
            }
            catch (Exception exception)
            {
                throw new ConfigCenterEnvironmentException("获取配置中心服务失败", exception);
            }
        }
Example #2
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="serverList"></param>
        public static void Init(List <ServerListDTO> serverList)
        {
            ServerListDTO server = serverList.FirstOrDefault(m => m.ServerCategory == ServerCategoryEnum.Authority);

            if (server != null)
            {
                AuthorityUrl = server.Url;
            }
            server = serverList.FirstOrDefault(m => m.ServerCategory == ServerCategoryEnum.ConfigCenter);
            if (server != null)
            {
                ConfigCenterUrl = server.Url;
            }
            DeployUrls = serverList.Where(m => m.ServerCategory == ServerCategoryEnum.Deploy).Select(m => new KeyValueModel(m.Url, $"{m.Name}[{m.Url}]")).OrderBy(m => m.Value).ToArray();
            if (DeployUrls.Count > 0)
            {
                DeployUrl = DeployUrls.First();
            }
        }