Example #1
0
        internal static void LoadConfig_impl(string trinity_config_file)
        {
            lock (config_load_lock)
            {
                if (!File.Exists(trinity_config_file))
                {
                    //TODO log warning
                    return;
                }

                var config = XmlConfiguration.Load(trinity_config_file);

                s_clusterConfigurations.Clear();
                s_localConfigurationSection.Clear();

                if (config.RootConfigVersion == ConfigurationConstants.Values.LEGACYVER)
                {
                    LoadConfigLegacy(trinity_config_file);
                }
                else if (config.RootConfigVersion == ConfigurationConstants.Values.CURRENTVER)
                {
                    LoadConfigCurrentVer(config);
                }
                else
                {
                    throw new TrinityConfigException("Unrecognized " + ConfigurationConstants.Attrs.CONFIG_VERSION);
                }

                is_config_loaded = true;

                ApplyConfigurationSettings(GetLocalConfiguration());
            }
        }
        internal static void LoadTrinityConfig(string trinity_config_file, bool forceLoad = false)
        {
            lock (config_load_lock)
            {
                if (is_config_loaded && !forceLoad)
                {
                    return;
                }
                if (!File.Exists(trinity_config_file))
                {
                    return;
                }

                var config = XmlConfiguration.Load(trinity_config_file);

                s_clusterConfigurations.Clear();
                s_localConfigurationSection.Clear();

                if (config.RootConfigVersion == ConfigurationConstants.Tags.LEGACYVER)
                {
                    LoadConfigLegacy(trinity_config_file);
                }
                else if (config.RootConfigVersion == ConfigurationConstants.Tags.CURRENTVER)
                {
                    s_localConfigurationSection = new ConfigurationSection(config.LocalSection);
                    var clusterSections = config.ClusterSections;
                    foreach (var clusterSection in clusterSections)
                    {
                        if (clusterSection.Attribute(ConfigurationConstants.Attrs.ID) != null)
                        {
                            s_clusterConfigurations.Add(clusterSection.Attribute(ConfigurationConstants.Attrs.ID).Value, new ClusterConfig(clusterSection));
                        }
                    }

                    s_current_cluster_config = new ClusterConfig(clusterSections.FirstOrDefault(
                                                                     _ => _.Attribute(ConfigurationConstants.Attrs.ID) == null) ??
                                                                 new XElement(ConfigurationConstants.Tags.CLUSTER));

                    s_clusterConfigurations.Add(ConfigurationConstants.Tags.DEFAULT_CLUSTER, s_current_cluster_config);
                }
                else
                {
                    throw new TrinityConfigException("Unrecognized " + ConfigurationConstants.Attrs.CONFIG_VERSION);
                }
                //LOCAL override CLUSTER
                var entries        = new Network.ServerInfo();
                var server_entries = s_current_cluster_config.GetMyServerInfo();
                var proxy_entries  = s_current_cluster_config.GetMyProxyInfo();
                if (proxy_entries != null)
                {
                    entries.Merge(proxy_entries);
                }
                if (server_entries != null)
                {
                    entries.Merge(server_entries);
                }

                foreach (var entry in s_localConfigurationSection)
                {
                    entries[entry.Key] = entry.Value;
                }

                ApplyConfigurationSettings(entries);

                is_config_loaded = true;
            }
        }