Beispiel #1
0
        private static string ReadFromConfig(Func <string, DomainSwitchNodeType, string, string> func, string nodeName,
                                             DomainSwitchNodeType nodeType = DomainSwitchNodeType.Unknown, string defaultValue = "",
                                             bool isThrow = false)
        {
            if (string.IsNullOrEmpty(nodeName) || nodeType == DomainSwitchNodeType.Unknown)
            {
                return(defaultValue);
            }
            var configValue = string.Empty;

            try
            {
                configValue = func.Invoke(nodeName, nodeType, defaultValue);
            }
            catch (Exception ex)
            {
                LogHelper.Warn($"Read DomainConfig({nodeName}) handler error {ex.Message}", ex);
                if (isThrow)
                {
                    throw;
                }
            }

            if (string.IsNullOrEmpty(configValue) && !string.IsNullOrEmpty(defaultValue))
            {
                configValue = defaultValue;
            }

            return(configValue);
        }
Beispiel #2
0
        /// <summary>
        ///     读取配置中心中配置列表的值
        /// </summary>
        /// <param name="nodeName"></param>
        /// <param name="nodeType"></param>
        /// <param name="defaultValue"></param>
        public static string GetDomainSwitchConfig(string nodeName,
                                                   DomainSwitchNodeType nodeType = DomainSwitchNodeType.Unknown, string defaultValue = "")
        {
            if (string.IsNullOrEmpty(nodeName) || nodeType == DomainSwitchNodeType.Unknown)
            {
                return(defaultValue);
            }
            var key         = FixDictKey(ConfigType.DomainSwitch, $"{nodeType}:{nodeName}");
            var configValue = GetFromConfigurationDict(key, defaultValue);

            if (!string.IsNullOrEmpty(configValue))
            {
                return(configValue);
            }
            var loadRlt = ConfigProvider.Instance.LoadDomainSwitch(configValue, nodeType);

            configValue = loadRlt.Item1 == 0 ? loadRlt.Item3 : defaultValue;
            return(configValue);
        }
Beispiel #3
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}", ""));
                }
            }
        }