Esempio n. 1
0
        public static TypeSettings Load(string basePath, XmlNode sectionNode)
        {
            if (TypeSettings.log.IsWarnEnabled)
            {
                TypeSettings.log.WarnFormat("Attempting Load of Legacy 'RelayTypeSettings' config file. Consider updating the file so it conforms to the new RelayTypeSettings Schema. Config basePath: {0}", basePath);
            }

            TypeSettings typeSettings = null;
            string       configSource = string.Empty;
            string       path         = string.Empty;

            try
            {
                configSource = sectionNode.Attributes["configSource"].Value;
                if (!String.IsNullOrEmpty(configSource))
                {
                    path = Path.Combine(Path.GetDirectoryName(basePath), configSource);
                    XmlDocument TypeSettingsConfig = new XmlDocument();
                    TypeSettingsConfig.Load(path);
                    typeSettings = CreateTypeSettings(TypeSettingsConfig);
                }
            }
            catch (Exception ex)
            {
                if (TypeSettings.log.IsErrorEnabled)
                {
                    TypeSettings.log.ErrorFormat("Error loading config file for source: {0}, path: {1}: {2}", configSource, path, ex);
                }
            }

            return(typeSettings);
        }
Esempio n. 2
0
        private static TypeSettings CreateTypeSettings(XmlDocument TypeSettingsConfig)
        {
            XmlNamespaceManager NamespaceMgr = new XmlNamespaceManager(TypeSettingsConfig.NameTable);

            NamespaceMgr.AddNamespace("ms", "http://myspace.com/RelayTypeSettings.xsd");

            TypeSettings typeSettings = new TypeSettings();

            typeSettings.TypeSettingCollection = new TypeSettingCollection();

            foreach (XmlNode TypeNameMapping in TypeSettingsConfig.SelectSingleNode("//ms:TypeNameMappings", NamespaceMgr))
            {
                // avoid comments
                if (TypeNameMapping is XmlElement)
                {
                    TypeSetting typeSetting = new TypeSetting();

                    try
                    {
                        #region TypeName, TypeId (Required)
                        typeSetting.TypeName = TypeNameMapping.Attributes["TypeName"].Value;
                        typeSetting.TypeId   = short.Parse(GetSafeChildNodeVal(TypeNameMapping, "ms:TypeId", NamespaceMgr));
                        #endregion

                        #region Disabled, Compress (Not Required)
                        bool.TryParse(GetSafeChildNodeVal(TypeNameMapping, "ms:Disabled", NamespaceMgr), out typeSetting.Disabled);
                        bool.TryParse(GetSafeChildNodeVal(TypeNameMapping, "ms:Compress", NamespaceMgr), out typeSetting.Compress);
                        #endregion

                        #region GroupName (Required)
                        XmlNode TypeIdMapping = TypeSettingsConfig.DocumentElement.SelectSingleNode("//ms:TypeIdMapping[@TypeId=" + typeSetting.TypeId + "]", NamespaceMgr);
                        typeSetting.GroupName = TypeIdMapping.SelectSingleNode("ms:GroupName", NamespaceMgr).InnerText;
                        #endregion

                        #region CheckRaceCondition (Not Required)
                        // legacy config file does not provide this value
                        bool.TryParse(GetSafeChildNodeVal(TypeNameMapping, "ms:CheckRaceCondition", NamespaceMgr), out typeSetting.CheckRaceCondition);
                        #endregion

                        #region TTLSetting : Enabled, DefaultTTLSeconds  (Not required)
                        typeSetting.TTLSetting = new TTLSetting();
                        XmlNode TTLSettingConfig = TypeSettingsConfig.DocumentElement.SelectSingleNode("//ms:TTLSetting[@TypeId=" + typeSetting.TypeId + "]", NamespaceMgr);
                        if (TTLSettingConfig != null)
                        {
                            bool.TryParse(GetSafeChildNodeVal(TTLSettingConfig, "ms:Enabled", NamespaceMgr), out typeSetting.TTLSetting.Enabled);

                            if (typeSetting.TTLSetting.Enabled)
                            {
                                int.TryParse(GetSafeChildNodeVal(TTLSettingConfig, "ms:DefaultTTLSeconds", NamespaceMgr), out typeSetting.TTLSetting.DefaultTTLSeconds);
                                typeSetting.TTLSetting.DefaultTTLSeconds = (typeSetting.TTLSetting.DefaultTTLSeconds == 0) ? -1 : typeSetting.TTLSetting.DefaultTTLSeconds;
                            }
                            else
                            {
                                typeSetting.TTLSetting.DefaultTTLSeconds = -1;
                            }
                        }
                        else
                        {
                            // set defaults
                            typeSetting.TTLSetting.Enabled           = false;
                            typeSetting.TTLSetting.DefaultTTLSeconds = -1;
                        }
                        #endregion

                        // add to collection
                        typeSettings.TypeSettingCollection.Add(typeSetting);
                    }
                    catch (Exception ex)
                    {
                        if (TypeSettings.log.IsErrorEnabled)
                        {
                            TypeSettings.log.ErrorFormat("Error loading TypeSetting for TypeName {0}, TypeID {1}: {2}", typeSetting.TypeName, typeSetting.TypeId, ex);
                        }
                    }
                }
            }

            return(typeSettings);
        }