Exemple #1
0
 private void LoadAllDomainSwitch()
 {
     try
     {
         var dict = DomainSwitch.GetAllDomainDict();
         if (dict != null && dict.Any())
         {
             var configMd5 = dict.ToJsonStr().Md5Encrypt();
             if (_updateFlagDict.TryGetValue(nameof(ConfigType.DomainSwitch), out var lastMd5) &&
                 string.Equals(configMd5, lastMd5, StringComparison.OrdinalIgnoreCase))
             {
                 return;
             }
             ConfigCenterContext.SetDomainSwitch(dict);
             _updateFlagDict.TryAdd(nameof(ConfigType.DomainSwitch), configMd5);
             configUpdateTime[nameof(ConfigType.DomainSwitch)] = DateTime.Now;
         }
     }
     catch (Exception ex)
     {
         LogHelper.Warn($"LoadAllDomainSwitch handler error ,{ex.Message}", ex);
     }
 }
Exemple #2
0
        /// <summary>
        ///     加载配置
        /// </summary>
        public Tuple <int, string, string> LoadDomainSwitch(string nodeName = "",
                                                            DomainSwitchNodeType nodeType = DomainSwitchNodeType.Unknown)
        {
            lock (LockDW)
            {
                try
                {
                    var configValue = string.Empty;
                    if (!string.IsNullOrEmpty(nodeName) && nodeType != DomainSwitchNodeType.Unknown)
                    {
                        if (nodeType == DomainSwitchNodeType.ServiceUrl)
                        {
                            configValue = DomainSwitch.GetServiceUrl(nodeName);
                        }
                        if (nodeType == DomainSwitchNodeType.SiteHost)
                        {
                            configValue = DomainSwitch.GetSiteHost(nodeName);
                        }

                        var nodePath = $"{nodeType}:{nodeName}";
                        if (!string.IsNullOrEmpty(configValue))
                        {
                            ConfigCenterContext.SetDomainSwitch(nodePath, configValue);
                        }
                        return(new Tuple <int, string, string>(0, "刷新成功", configValue));
                    }

                    LoadAllDomainSwitch();
                    return(new Tuple <int, string, string>(0, "刷新成功", ""));
                }
                catch (Exception ex)
                {
                    LogHelper.Warn($"LoadDomainSwitch({nodeName},{nodeType}) handler error ,{ex.Message}", ex);
                    return(new Tuple <int, string, string>(1, $"LoadDomainSwitch Failed {ex.Message}", ""));
                }
            }
        }