コード例 #1
0
        /// <summary>
        /// Reads generic RASP configuration from a file
        /// </summary>
        public ConfigurationDocument GetFromFile()
        {
            if (!File.Exists(ConfigFilePath))
            {
                return(this);
            }

            StreamReader streamReader = null;

            try
            {
                XmlSerializer xmlSerializer = new XmlSerializer(typeof(ConfigurationDocument), configurationTypes.ToArray());
                xmlSerializer.UnknownAttribute   += new XmlAttributeEventHandler(Serializer_UnknownAttribute);
                xmlSerializer.UnknownElement     += xmlSerializer_UnknownElement;
                xmlSerializer.UnknownNode        += xmlSerializer_UnknownNode;
                xmlSerializer.UnreferencedObject += xmlSerializer_UnreferencedObject;
                streamReader = new StreamReader(ConfigFilePath);
                ConfigurationDocument newDoc = (ConfigurationDocument)xmlSerializer.Deserialize(streamReader);
                return(newDoc);
            }
            catch (Exception e)
            {
                throw new ConfigurationCouldNotBeReadFromFileException(ConfigFilePath, e);
            }
            finally
            {
                if (streamReader != null)
                {
                    streamReader.Close();
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Adds all configuration sections from the configuration file, that hasn't been
        /// loaded/modified in the session
        /// </summary>
        internal void AddUnrecognizedSectionsFromFile()
        {
            ConfigurationDocument configurationFromFile = GetFromFile();

            foreach (var configurationSection in configurationFromFile.ConfigurationSections)
            {
                if (HasConfigurationSection(configurationSection.GetType()) == false)
                {
                    AddConfigurationSection(configurationSection);
                }
            }
        }
コード例 #3
0
        internal void ReloadConfigurationFile()
        {
            ConfigurationDocument configurationDocumentFromFile = GetFromFile();
            var configurationsSectionsFromFile = configurationDocumentFromFile.GetConfigurationSectionsCopy();

            foreach (var configurationSection in configurationsSectionsFromFile)
            {
                if (configurationTypes.Contains(configurationSection.GetType()))
                {
                    AddReplaceConfigurationSection(configurationSection);
                }
            }
        }
コード例 #4
0
        internal T ReloadConfigSectionFromFile <T>(Type configSectionType) where T : new()
        {
            DeleteUnrecognizedConfigurationSections();
            RegisterType <T>();
            ConfigurationDocument configurationDocumentFromFile = GetFromFile();

            if (configurationDocumentFromFile.HasConfigurationSection(configSectionType))
            {
                T configSection = configurationDocumentFromFile.GetConfigurationSection <T>(configSectionType);
                AddReplaceConfigurationSection(configSection);
                return(configSection);
            }
            return(AddNewConfigurationSection <T>(configSectionType));
        }
コード例 #5
0
 /// <summary>
 /// Singleton implementation
 /// </summary>
 private ConfigurationHandler()
 {
     logger = LoggerFactory.Create(this.GetType());
     configurationDocument = new ConfigurationDocument().GetFromFile();
     configSectionsCache   = new Dictionary <Type, object>();
 }