Ejemplo n.º 1
0
        private static void LoadConfigCurrrentVer(XmlConfiguration config)
        {
            s_localConfigurationSection = new ConfigurationSection(config.LocalSection);
            var clusterSections = config.ClusterSections;

            foreach (var clusterSection in clusterSections)
            {
                if (!IsDefaultClusterConfiguration(clusterSection))
                {
                    s_clusterConfigurations.Add(clusterSection.Attribute(ConfigurationConstants.Attrs.ID).Value, new ClusterConfig(clusterSection));
                }
            }

            // The default cluster config is the one without an Id.
            s_current_cluster_config =
                new ClusterConfig(
                    clusterSections.FirstOrDefault(IsDefaultClusterConfiguration) ??
                    new XElement(ConfigurationConstants.Tags.CLUSTER));

            s_clusterConfigurations.Add(ConfigurationConstants.Values.DEFAULT_CLUSTER, s_current_cluster_config);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// !Caller holds config_load_lock
        /// </summary>
        /// <param name="trinity_config_file"></param>
        private static void LoadConfigLegacy(string trinity_config_file)
        {
            XMLConfig xml_config = new XMLConfig(trinity_config_file);

            //construct local configuration section
            XElement localSection = new XElement(ConfigurationConstants.Tags.LOCAL);
            XElement loggingEntry = new XElement(ConfigurationConstants.Tags.LOGGING);
            XElement storageEntry = new XElement(ConfigurationConstants.Tags.STORAGE);
            XElement networkEntry = new XElement(ConfigurationConstants.Tags.NETWORK);

            loggingEntry.SetAttributeValue(ConfigurationConstants.Attrs.LOGGING_DIRECTORY, xml_config.GetEntryValue(ConfigurationConstants.Tags.LOGGING.LocalName, ConfigurationConstants.Attrs.LOGGING_DIRECTORY));
            loggingEntry.SetAttributeValue(ConfigurationConstants.Attrs.LOGGING_LEVEL, xml_config.GetEntryValue(ConfigurationConstants.Tags.LOGGING.LocalName, ConfigurationConstants.Attrs.LOGGING_LEVEL));
            storageEntry.SetAttributeValue(ConfigurationConstants.Attrs.STORAGE_ROOT, xml_config.GetEntryValue(ConfigurationConstants.Tags.STORAGE.LocalName, ConfigurationConstants.Attrs.STORAGE_ROOT));
            networkEntry.SetAttributeValue(ConfigurationConstants.Attrs.HTTP_PORT, xml_config.GetEntryValue(ConfigurationConstants.Tags.NETWORK.LocalName, ConfigurationConstants.Attrs.HTTP_PORT));
            networkEntry.SetAttributeValue(ConfigurationConstants.Attrs.CLIENT_MAX_CONN, xml_config.GetEntryValue(ConfigurationConstants.Tags.NETWORK.LocalName, ConfigurationConstants.Attrs.CLIENT_MAX_CONN));
            if (loggingEntry.Attributes().Count() > 0)
            {
                localSection.Add(loggingEntry);
            }
            if (storageEntry.Attributes().Count() > 0)
            {
                localSection.Add(storageEntry);
            }
            if (networkEntry.Attributes().Count() > 0)
            {
                localSection.Add(networkEntry);
            }

            //construct local ConfigurationSection
            s_localConfigurationSection = new ConfigurationSection(localSection);

            //construct a clusterSections
            s_current_cluster_config = ClusterConfig._LegacyLoadClusterConfig(trinity_config_file);

            s_clusterConfigurations.Add(ConfigurationConstants.Values.DEFAULT_CLUSTER, s_current_cluster_config);
        }
Ejemplo n.º 3
0
        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;
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a cloud storage instance with the specified name.
 /// </summary>
 /// <param name="configFile">The file path of a configuration file.</param>
 /// <returns>The newly created cloud storage instance.</returns>
 public static MemoryCloud CreateCloudStorage(string configFile)
 {
     return(CreateCloudStorage(ClusterConfig._LegacyLoadClusterConfig(configFile)));
 }