示例#1
0
        public NGinConfig( string configFile )
        {
            this.nginConfig = this.DeserializeConfigFile( configFile );

            DependenciesConfigXml dependenciesConfig = this.DeserializeDependenciesConfig( nginConfig );
            this.DependencyResolver = new DependencyResolver( dependenciesConfig );

            foreach ( IModuleXml module in this.nginConfig.Modules )
            {
                INGinModuleConfig moduleConfig = new NGinModuleConfig( module );
                this.modules.Add( moduleConfig.Name, moduleConfig );
            }
        }
示例#2
0
        internal DependenciesConfigXml DeserializeDependenciesConfig( INGinConfigXml config )
        {
            DependenciesConfigXml result = null;

            ISectionXml dependenciesConfigSection = config.GetModule( GlobalConstants.XmlConfiguration.ModuleNames.CoreModule ).GetSection( GlobalConstants.XmlConfiguration.SectionNames.DependenciesSection );
            byte[] rawXmlAsBytes = System.Text.Encoding.UTF8.GetBytes( dependenciesConfigSection.XmlRaw );
            MemoryStream memStream = new MemoryStream( rawXmlAsBytes );
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.IgnoreWhitespace = true;
            settings.CloseInput = true;

            XmlReader reader = null;

            try
            {
                reader = XmlReader.Create( memStream, settings );
            }
            catch ( InvalidOperationException ivoEx )
            {
                throw new CoreConfigException( "An error occurred while processing the byte stream as xml.", ivoEx );
            }
            finally
            {
                if ( reader == null )
                {
                    memStream.Close();
                    memStream.Dispose();
                }
            }

            XmlSerializer serializer = new XmlSerializer( typeof(DependenciesConfigXml) );

            try
            {
                result = serializer.Deserialize( reader ) as DependenciesConfigXml;
            }
            catch ( InvalidOperationException ivoEx )
            {
                throw new CoreConfigException( "An error occurred during deserialization to type '" + typeof(DependenciesConfigXml).FullName + "'.", ivoEx );
            }
            catch ( System.Text.DecoderFallbackException dfbEx )
            {
                throw new CoreConfigException( "The text encoding caused an error during deserialization of type '" + typeof(DependenciesConfigXml).FullName + "'", dfbEx );
            }
            finally
            {
                reader.Close();
            }

            return result;
        }