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 ); } }
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; }