private void Read_Configuration_File(string config_file) { System.IO.StreamReader reader = new System.IO.StreamReader(config_file); System.Xml.XmlTextReader xmlReader = new System.Xml.XmlTextReader(reader); while (xmlReader.Read()) { if (xmlReader.NodeType == System.Xml.XmlNodeType.Element) { string node_name = xmlReader.Name.ToLower(); switch (node_name) { case "connection_string": if (xmlReader.MoveToAttribute("type")) { db_type = xmlReader.Value.ToString(); } xmlReader.Read(); connection_string = xmlReader.Value; break; case "error_emails": xmlReader.Read(); error_emails = xmlReader.Value; break; case "error_page": xmlReader.Read(); error_page = xmlReader.Value; break; case "ghostscript_executable": xmlReader.Read(); ghostscript = xmlReader.Value; break; case "imagemagick_executable": xmlReader.Read(); imagemagick = xmlReader.Value; break; } } } xmlReader.Close(); reader.Close(); }
/// <summary> Reads the inficated configuration file </summary> /// <param name="ConfigFile"> Configuration file to read </param> /// <exception>File is checked for existence first, otherwise all encountered exceptions will be thrown</exception> public static void Read_Configuration_File(string ConfigFile) { if (!File.Exists(ConfigFile)) return; databaseInfo.Clear(); StreamReader reader = new StreamReader(ConfigFile); System.Xml.XmlTextReader xmlReader = new System.Xml.XmlTextReader(reader); while (xmlReader.Read()) { if (xmlReader.NodeType == System.Xml.XmlNodeType.Element) { string node_name = xmlReader.Name.ToLower(); switch (node_name) { case "connection_string": Database_Instance_Configuration newDb = new Database_Instance_Configuration(); if (xmlReader.MoveToAttribute("type")) { if (xmlReader.Value.ToLower() == "postgresql") newDb.Database_Type = SobekCM_Database_Type_Enum.PostgreSQL; } if (xmlReader.MoveToAttribute("active")) { if (xmlReader.Value.ToLower() == "false") newDb.Is_Active = false; } if (xmlReader.MoveToAttribute("canAbort")) { if (xmlReader.Value.ToLower() == "false") newDb.Can_Abort = false; } if (xmlReader.MoveToAttribute("isHosted")) { if (xmlReader.Value.ToLower() == "true") isHosted = true; } if (xmlReader.MoveToAttribute("name")) newDb.Name = xmlReader.Value.Trim(); xmlReader.Read(); newDb.Connection_String = xmlReader.Value; if (newDb.Name.Length == 0) newDb.Name = "Connection" + (databaseInfo.Count + 1); databaseInfo.Add(newDb); break; case "erroremails": xmlReader.Read(); systemErrorEmail = xmlReader.Value; break; case "errorpage": xmlReader.Read(); System_Error_URL = xmlReader.Value; break; case "ghostscript_executable": xmlReader.Read(); ghostscriptExecutable = xmlReader.Value; break; case "imagemagick_executable": xmlReader.Read(); imageMagickExecutable = xmlReader.Value; break; case "pause_between_polls": xmlReader.Read(); int testValue; if (Int32.TryParse(xmlReader.Value, out testValue)) Builder_Override_Seconds_Between_Polls = testValue; break; case "publish_logs_directory": xmlReader.Read(); Builder_Logs_Publish_Directory = xmlReader.Value; break; } } } xmlReader.Close(); reader.Close(); }
private static Bamboo.Xml.XmlElement Read(System.Xml.XmlTextReader xmlTextReader) { System.Collections.Stack elementsStack = new System.Collections.Stack(); while (xmlTextReader.Read()) { switch (xmlTextReader.NodeType) { case System.Xml.XmlNodeType.Element: { Bamboo.Xml.XmlElement element = new Bamboo.Xml.XmlElement(); element.Name = xmlTextReader.LocalName; if (xmlTextReader.IsEmptyElement) { if (elementsStack.Count == 0) { elementsStack.Push(element); } else { Bamboo.Xml.XmlElement parent = (XmlElement)elementsStack.Peek(); parent.Elements.Add(element); } } else { if (elementsStack.Count > 0) { Bamboo.Xml.XmlElement parent = (XmlElement)elementsStack.Peek(); parent.Elements.Add(element); } elementsStack.Push(element); } for (int i = 0; i < xmlTextReader.AttributeCount; i++) { xmlTextReader.MoveToAttribute(i); Bamboo.Xml.XmlAttribute xmlAttribute = new Bamboo.Xml.XmlAttribute(); xmlAttribute.Name = xmlTextReader.LocalName; xmlAttribute.Value = xmlTextReader.Value; element.Attributes.Add(xmlAttribute); } break; } case System.Xml.XmlNodeType.EndElement: { if (elementsStack.Count > 1) { elementsStack.Pop(); } break; } case System.Xml.XmlNodeType.CDATA: case System.Xml.XmlNodeType.Text: { ((XmlElement)elementsStack.Peek()).Value = xmlTextReader.Value; break; } } } if (elementsStack.Count == 0) { throw new System.Exception("Document does not contain any elements."); } else if (elementsStack.Count > 1) { throw new System.Exception("Document contains more than one root element."); } return((XmlElement)elementsStack.Pop()); }
/// <summary> /// Gets basic event information. /// </summary> /// <param name="log">The event's log.</param> /// <param name="source">The event's source. Can be <c>null</c>.</param> /// <param name="eventId">The event's id. Can be <c>null</c>.</param> /// <returns><c>true</c> if subscription represents a basic event, <c>false</c> if not.</returns> public bool GetBasic(out string log, out string source, out int? eventId) { log = source = null; eventId = null; if (!string.IsNullOrEmpty(this.Subscription)) { using (System.IO.MemoryStream str = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(this.Subscription))) { using (System.Xml.XmlTextReader rdr = new System.Xml.XmlTextReader(str)) { rdr.MoveToContent(); rdr.ReadStartElement("QueryList"); if (rdr.Name == "Query" && rdr.MoveToAttribute("Path")) { string path = rdr.Value; if (rdr.MoveToElement() && rdr.ReadToDescendant("Select") && path.Equals(rdr["Path"], StringComparison.InvariantCultureIgnoreCase)) { string content = rdr.ReadString(); System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(content, @"\*(?:\[System\[(?:Provider\[\@Name='(?<s>[^']+)'\])?(?:\s+and\s+)?(?:EventID=(?<e>\d+))?\]\])", System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.Singleline | System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace); if (m.Success) { log = path; if (m.Groups["s"].Success) source = m.Groups["s"].Value; if (m.Groups["e"].Success) eventId = Convert.ToInt32(m.Groups["e"].Value); return true; } } } } } } return false; }
public static void Read_Configuration_File( string config_file ) { if (!File.Exists(config_file)) return; System.IO.StreamReader reader = new System.IO.StreamReader(config_file); System.Xml.XmlTextReader xmlReader = new System.Xml.XmlTextReader(reader); while (xmlReader.Read()) { if (xmlReader.NodeType == System.Xml.XmlNodeType.Element) { string node_name = xmlReader.Name.ToLower(); switch (node_name) { case "connection_string": if (xmlReader.MoveToAttribute("type")) { if (xmlReader.Value.ToString().ToLower() == "postgresql") sobekDatabaseType = SobekCM_Database_Type_Enum.PostgreSQL; } xmlReader.Read(); Database_Connection_String = xmlReader.Value; break; case "error_emails": xmlReader.Read(); systemErrorEmail = xmlReader.Value; break; case "error_page": xmlReader.Read(); System_Error_URL = xmlReader.Value; break; case "ghostscript_executable": xmlReader.Read(); ghostscriptExecutable = xmlReader.Value; break; case "imagemagick_executable": xmlReader.Read(); imageMagickExecutable = xmlReader.Value; break; } } } xmlReader.Close(); reader.Close(); }