/// <summary> /// Get runtime object. /// </summary> /// <returns>Runtime object.</returns> protected internal virtual object GetRuntimeObject() { if (SectionHandler != null) { try { XmlReader reader = new XmlTextReader(new StringReader(RawXml)); DoDeserializeSection(reader); if (!String.IsNullOrEmpty(SectionInformation.Source)) { RawXml = File.ReadAllText(SectionInformation.Source); SectionInformation.SetRawXml(RawXml); } } catch { } XmlDocument doc = new XmlDocument(); doc.LoadXml(RawXml); return(SectionHandler.Create(GenContext, doc.DocumentElement)); } return(this); }
public void TestGetConfigNullSection() { var handler = new SectionHandler(); var section = new XmlDocument(); object result = handler.Create(null, null, section); Assert.NotNull(result); Assert.True(result is CacheConfig[]); var caches = result as CacheConfig[]; Assert.Equal(0, caches.Length); }
protected internal virtual object GetRuntimeObject() { if (SectionHandler != null) { ConfigurationSection parentSection = sectionInformation != null?sectionInformation.GetParentSection() : null; object parent = parentSection != null?parentSection.GetRuntimeObject() : null; if (RawXml == null) { return(parent); } try { // This code requires some re-thinking... XmlReader reader = new ConfigXmlTextReader( new StringReader(RawXml), Configuration.FilePath); DoDeserializeSection(reader); if (!String.IsNullOrEmpty(SectionInformation.ConfigSource)) { string fileDir = SectionInformation.ConfigFilePath; if (!String.IsNullOrEmpty(fileDir)) { fileDir = Path.GetDirectoryName(fileDir); } else { fileDir = String.Empty; } string path = Path.Combine(fileDir, SectionInformation.ConfigSource); if (File.Exists(path)) { RawXml = File.ReadAllText(path); SectionInformation.SetRawXml(RawXml); } } } catch { // ignore, it can fail - we deserialize only in order to get // the configSource attribute } XmlDocument doc = new ConfigurationXmlDocument(); doc.LoadXml(RawXml); return(SectionHandler.Create(parent, ConfigContext, doc.DocumentElement)); } return(this); }
public void TestGetConfigFromFile() { const string xmlSimple = "<rediscache><cache region=\"foo\" expiration=\"500\" priority=\"4\" /></rediscache>"; var handler = new SectionHandler(); XmlNode section = GetConfigurationSection(xmlSimple); object result = handler.Create(null, null, section); Assert.NotNull(result); Assert.True(result is CacheConfig[]); var caches = result as CacheConfig[]; Assert.Equal(1, caches.Length); Assert.Equal(new Dictionary <string, string>() { { "expiration", "500" }, { "priority", "4" } }, caches[0].Properties); }