public KeySet GetKeySet(string path, char delimiter) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } if (delimiter == 0) { throw new ArgumentNullException("delimiter"); } string[] sPath = path.Split(new char[] { delimiter }); KeySet oKeySet = this; for (int i = 0; i < sPath.Length; i++) { if (i < sPath.Length - 1) { oKeySet = oKeySet.KeySets[sPath[i]]; } else { return(oKeySet.KeySets[sPath[i]]); } } return(null); }
/// <summary> /// Saves a Keyset object to the a UTF-16 encoded xml file. /// </summary> /// <param name="filePath">Fully qualified path to save the XML document to</param> /// <param name="keySetData">The Keyset to persist to the document</param> public static void Save(string filePath, KeySet keySetData) { if (string.IsNullOrEmpty(filePath)) { throw new ArgumentNullException("filePath"); } if (keySetData == null) { throw new ArgumentNullException("keySetData"); } FileStream oStream = null; try { oStream = new FileStream(filePath, FileMode.Create); Serialize(keySetData, oStream); } finally { if (oStream != null) { oStream.Close(); } } }
public object Create(object parent, object configContext, XmlNode section) { try { if (section == null) { throw(new ArgumentNullException("section", string.Format(ResourceData.Culture, ResourceData.MissingConfigSection))); } XmlNodeList nodes = section.SelectNodes(ROOTNODE); if ((nodes.Count != 1)) { throw (new KeySetConfigurationException(string.Format(ResourceData.Culture, ResourceData.MissingConfigSectionRootKeySet))); } KeySet config = new KeySet(nodes[0]); return(config); } catch (Exception ex) { throw (new KeySetConfigurationException(string.Format(ResourceData.Culture, ResourceData.FailedToLoadConfiguration), ex)); } }
protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey) { try { if (reader == null) { throw (new ArgumentNullException("reader", string.Format(ResourceData.Culture, ResourceData.MissingConfigSection))); } XmlDocument doc = new XmlDocument(); doc.Load(reader); XmlNodeList nodes = doc.DocumentElement.SelectNodes(ROOTNODE); if ((nodes.Count != 1)) { throw (new KeySetConfigurationException(string.Format(ResourceData.Culture, ResourceData.MissingConfigSectionRootKeySet))); } _rootKeySet = new KeySet(nodes[0]); } catch (Exception ex) { throw (new KeySetConfigurationException(string.Format(ResourceData.Culture, ResourceData.FailedToLoadConfiguration), ex)); } }
/// <summary> /// Returns the root keyset for a given configuration section /// </summary> /// <param name="sectionName">configuration section name</param> /// <returns></returns> public static KeySet Config(string sectionName) { if (string.IsNullOrEmpty(sectionName)) { throw new ArgumentNullException("sectionName"); } KeySet config = ConfigurationManager.GetSection(sectionName) as KeySet; return(config); }
/// <summary> /// Deserializes an XML Keyset document given from a stream /// </summary> /// <param name="dataIn">An initilzied stream object</param> /// <returns></returns> public static KeySet Deserialize(Stream dataIn) { if (dataIn == null) { throw new ArgumentNullException("dataIn"); } XmlSerializer oSerializer = new XmlSerializer(typeof(KeySet)); KeySet keySetData = (KeySet)oSerializer.Deserialize(dataIn); return(keySetData); }
/// <summary> /// Serializes a Keyset object to a UTF-16 encoded xml document /// </summary> /// <param name="keySetData">Keyset object to serialize</param> /// <param name="dataOut">Stream to serialized to Keyset to</param> public static void Serialize(KeySet keySetData, Stream dataOut) { if (keySetData == null) { throw new ArgumentNullException("keySetData"); } if (dataOut == null) { throw new ArgumentNullException("dataOut"); } XmlWriter oWriter = new XmlTextWriter(dataOut, Encoding.Unicode); XmlSerializer oSerializer = new XmlSerializer(typeof(KeySet)); oSerializer.Serialize(oWriter, keySetData); }
/// <summary> /// Serializes a Keyset object to a UTF-16 encoded XML document /// </summary> /// <param name="keySetData">Keyset object to serialize</param> /// <returns></returns> public static string Serialize(KeySet keySetData) { if (keySetData == null) { throw new ArgumentNullException("keySetData"); } using (MemoryStream oStream = new MemoryStream()) { Serialize(keySetData, oStream); oStream.Seek(0, SeekOrigin.Begin); XmlTextReader oReader = new XmlTextReader(oStream); while (oReader.Read() == true && oReader.NodeType != XmlNodeType.Element) { } return(oReader.ReadOuterXml()); } }