Example #1
0
        private void InitCluster()
        {
            //Load data center from app.config
            cluster = ApolloConfigSettingHelper.GetApolloConfigSettings().Cluster;// GetAppConfig("Apollo.Cluster");

            string env = Foundation.Foundation.Server.EnvType;

            //LPT and DEV will be treated as a cluster(lower case)
            if (string.IsNullOrWhiteSpace(cluster) &&
                (Env.DEV.ToString().Equals(env, StringComparison.CurrentCultureIgnoreCase) ||
                 Env.LPT.ToString().Equals(env, StringComparison.CurrentCultureIgnoreCase))
                )
            {
                cluster = env.ToLower();
            }

            //Use data center as cluster
            if (string.IsNullOrWhiteSpace(cluster))
            {
                cluster = DataCenter;
            }

            //Use sub env as cluster
            if (string.IsNullOrWhiteSpace(cluster))
            {
                cluster = SubEnv;
            }

            //Use default cluster
            if (string.IsNullOrWhiteSpace(cluster))
            {
                cluster = ConfigConsts.CLUSTER_NAME_DEFAULT;
            }
        }
Example #2
0
        protected void Application_Start()
        {
            ApolloConfigSettingHelper.SetBaseDir(AppDomain.CurrentDomain.BaseDirectory);

            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
        public ApolloConfigDemo()
        {
            ApolloConfigSettingHelper.SetBaseDir(@"E:\Src\apollo-net\ApolloDemo\bin\Debug");

            config        = ConfigService.GetAppConfig();
            anotherConfig = ConfigService.GetConfig("zipkin");
            var propNames = anotherConfig.GetPropertyNames();
            //config.ConfigChanged += new ConfigChangeEvent(OnChanged);
            //anotherConfig.ConfigChanged += new ConfigChangeEvent(OnChanged);
        }
        private static string GetAppSetting(string key, string defaultValue)
        {
            string value = ApolloConfigSettingHelper.GetMetas()?.FirstOrDefault(m => key.Equals(m.Key)).Value; //ConfigurationManager.AppSettings[key];

            if (!string.IsNullOrWhiteSpace(value))
            {
                return(value);
            }

            return(defaultValue);
        }
Example #5
0
        private void InitRefreshInterval()
        {
            string customizedRefreshInterval = ApolloConfigSettingHelper.GetApolloConfigSettings().RefreshInterval; // GetAppConfig("Apollo.RefreshInterval");

            if (customizedRefreshInterval != null)
            {
                if (int.TryParse(customizedRefreshInterval, out int cusTimeout))
                {
                    refreshInterval = cusTimeout;
                }
                else
                {
                    logger.Warn(
                        string.Format("Config for Apollo.RefreshInterval is invalid: {0}", customizedRefreshInterval));
                }
            }
        }
Example #6
0
        private void InitReadTimeout()
        {
            string customizedReadTimeout = ApolloConfigSettingHelper.GetApolloConfigSettings().ReadTimeout; // GetAppConfig("Apollo.ReadTimeout");

            if (customizedReadTimeout != null)
            {
                if (int.TryParse(customizedReadTimeout, out int cusTimeout))
                {
                    readTimeout = cusTimeout;
                }
                else
                {
                    logger.Warn(
                        string.Format("Config for Apollo.ReadTimeout is invalid: {0}", customizedReadTimeout));
                }
            }
        }
        //public string Property(string name, string defaultValue)
        //{
        //    if (null == name) return defaultValue;
        //    if ("app.id" == name)
        //    {
        //        return AppId ?? defaultValue;
        //    }
        //    else
        //    {
        //        return System.Configuration.ConfigurationManager.AppSettings[name] ?? defaultValue;
        //    }
        //}

        public void Initialize()
        {
            try
            {
                appId = ApolloConfigSettingHelper.GetApolloConfigSettings().AppId; //System.Configuration.ConfigurationManager.AppSettings[APP_ID_ITEM];

                if (!String.IsNullOrWhiteSpace(appId))
                {
                    appId = appId.Trim();
                    sb.Append("App Id is set to [" + appId + "] from System.Configuration.ConfigurationManager.AppSettings[" + APP_ID_ITEM + "]." + Environment.NewLine);
                }
                else
                {
                    sb.Append("App Id is set to null from System.Configuration.ConfigurationManager.AppSettings[" + APP_ID_ITEM + "]." + Environment.NewLine);
                };
            }
            catch (Exception ex)
            {
                sb.Append("Exception happened when getting App Id from AppSettings: " + ex + Environment.NewLine);
                sb.Append("App Id is set to " + appId + " with this exception happened.");
            }
        }