Example #1
0
        public async Task <List <ConfigurationItemListDTO> > GetConfigurationItemListAsync(QueryConfigurationItemFilterModel filterModel)
        {
            Expression <Func <ConfigurationItem, bool> > searchExpression = filterModel.GetSearchExpression <ConfigurationItem>();

            if (filterModel.NamespaceNames != null && filterModel.NamespaceNames.Length > 0)
            {
                Expression <Func <ConfigurationItem, bool> > temp = null;
                foreach (string namespaceName in filterModel.NamespaceNames)
                {
                    temp = temp == null ? m => m.NamespaceName.Equals(namespaceName) : temp.Or(m => m.NamespaceName.Equals(namespaceName));
                }
                searchExpression = searchExpression.And(temp);
            }
            ConfigCenterEnvironmentConsoleHelper.WriteLine("拼接条件完毕", "Debug", ConsoleColor.DarkGreen);
            List <ConfigurationItem> allConfigurationItems = await _configurationItemRepository.GetAllInfoFromCacheAsync();

            ConfigCenterEnvironmentConsoleHelper.WriteLine(allConfigurationItems == null ? "以从环境获取数据,但为空" : $"以从环境获取数据,数量:{allConfigurationItems.Count}", "Debug",
                                                           ConsoleColor.DarkGreen);
            if (allConfigurationItems == null)
            {
                return(null);
            }
            List <ConfigurationItem> configurationItemsFromDb = allConfigurationItems.Where(searchExpression.Compile()).OrderBy(m => m.Key).ToList();

            ConfigCenterEnvironmentConsoleHelper.WriteLine($"已通过条件筛选完毕,数量:{configurationItemsFromDb.Count}", "Debug", ConsoleColor.DarkGreen);
            var result = _mapper.Map <List <ConfigurationItemListDTO> >(configurationItemsFromDb);

            return(result);
        }
Example #2
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 #3
0
 /// <summary>
 /// 入口
 /// </summary>
 /// <param name="args"></param>
 /// <returns></returns>
 public static async Task Main(string[] args)
 {
     Console.Title = $"{ConfigCenterEnvironmentConfig.ServerInfo.Name} 版本:[{ApplicationConfig.GetProgramVersion()}]";
     string[] inputArgs = MateralAPPHelper.HandlerArgs(args, ConfigCenterEnvironmentConfig.ServerInfo);
     ConfigCenterEnvironmentConsoleHelper.WriteLine($"本服务地址:{ApplicationConfig.Url}");
     ConfigCenterEnvironmentConsoleHelper.WriteLine($"本服务公开地址:{ApplicationConfig.PublicUrl}");
     await CreateHostBuilder(inputArgs).Build().RunAsync();
 }
 public Task RegisterResult(bool isSuccess, string message)
 {
     if (isSuccess)
     {
         ConfigCenterEnvironmentConsoleHelper.WriteLine("注册成功");
     }
     else
     {
         ConfigCenterEnvironmentConsoleHelper.WriteLine(message, "注册失败", ConsoleColor.Red);
     }
     return(Task.CompletedTask);
 }