/// <summary> /// Outputs the data for this query object as an XMLSection. /// </summary> /// <returns>An XML representation of this object.</returns> public XMLSection ToXML() { XMLSection section = new XMLSection("query"); section.AddChild("name", Name); section.AddChild("database", Database); section.AddChild("dataview", DataView); section.AddChild("interval", Interval.ToString()); section.AddChild("time", Time.ToString()); if (Delimiter != ",") { section.AddChild("delimiter", Delimiter); } if (Transpose) { section.AddChild("transpose", Transpose); } if (PrintHeaders) { section.AddChild("printHeaders", PrintHeaders); } if (Paused) { section.AddChild("paused", Paused); } section.AddSection(Output.ToXML()); return(section); }
// Use this for initialization void Start() { XMLParser parser = new XMLParser(); XMLSection root = parser.loadXML("<root>" + " <row>"+ " <Item>100</Item>"+ " <Item>200</Item>"+ " <Item>300</Item>"+ " </row>"+ " <row>"+ " <Item> 123 456 789 </Item>"+ " <Item> 444 555 666 </Item>"+ " <Item> 777 888 999 </Item>"+ " </row>"+ "</root>"); //XMLSection root = parser.loadFile( "test" ); Debug.Log("root.child[0].name = " + root.child(0).name); Debug.Log("root.child[1].name = " + root.child(1).name); Debug.Log("row/Item = " + root.readInt("row/Item")); Debug.Log("not/in/path = " + root.readVector2("not/in/path")); XMLSection childSection = root.child(0); foreach (int i in childSection.readInts("Item")) { Debug.Log("root.child[0] item = " + i); } childSection = root.child(1); foreach (Vector3 i in childSection.readVector3s("Item")) { Debug.Log("root.child[1] item = " + i); } }
/// <summary> /// Outputs the data for this output object as an XMLSection. /// </summary> /// <returns>An XML representation of this object.</returns> public XMLSection ToXML() { XMLSection section = new XMLSection("output"); section.AddChild("type", "file"); section.AddChild("location", OutputLocation); return(section); }
/// <summary> /// Converts the contents of this list into an XMLFile. /// </summary> /// <returns>An XMLFile object containing all the queries in this list.</returns> public XMLFile ToXML() { XMLFile file = new XMLFile(FilePath); file.Children.Clear(); XMLSection top = new XMLSection("queries"); foreach (Query q in this) { top.AddSection(q.ToXML()); } file.AddSection(top); return(file); }
/// <summary> /// Outputs the data for this output object as an XMLSection. /// </summary> /// <returns>An XML representation of this object.</returns> public XMLSection ToXML() { XMLSection section = new XMLSection("output"); section.AddChild("type", "email"); section.AddChild("from", From); section.AddChild("to", To.Join()); section.AddChild("subject", Subject); section.AddChild("body", Body); if (AttachmentInfo != null) { section.AddChild("attachmentFilepath", AttachmentInfo.OutputLocation); } return(section); }
/// <summary> /// Delete the specified property. /// </summary> /// <param name="property">The property to delete.</param> public override void DeleteProperty(string property) { XMLSection section = file.FindSection(parentNode); if (section == null) { throw new InvalidConfigException("Parent node \"" + parentNode + "\" not found."); } XMLNode node = section.FindNode(property); if (node != null) { section.Children.Remove(node); } }
/// <summary> /// Outputs the data for this output object as an XMLSection. /// </summary> /// <returns>An XML representation of this object.</returns> public XMLSection ToXML() { XMLSection section = new XMLSection("output"); section.AddChild("type", "ftp"); section.AddChild("filename", FileName); section.AddChild("address", Address); section.AddChild("remotepath", RemotePath); if (Username.Length > 0) { section.AddChild("username", Username); } if (Password.Length > 0) { section.AddChild("password", Password); } return(section); }
/// <summary> /// Overwrites the config to include a new value for the specified key. If the specified key is not found, it will be appended to the config. /// </summary> /// <param name="property">The property whose value will be overwritten</param> /// <param name="value">The value to assign to the specified key</param> public override void Set(string property, object value) { XMLSection section = file.FindSection(parentNode); if (section == null) { throw new InvalidConfigException("Parent node \"" + parentNode + "\" not found."); } XMLNode node = section.FindNode(property); if (node == null) { section.AddChild(property, value.ToString()); } else { node.Value = value.ToString(); } }
/// <summary> /// Load a QueryList from a Queries.xml file. /// </summary> /// <param name="path">The path of the XML file for this list.</param> /// <returns>A QueryList containing all queries in the file.</returns> public static QueryList FromXML(string path = "Queries.xml") { QueryList queries = new QueryList(path); XMLFile qFile = new XMLFile(path); foreach (XMLSection section in qFile.GetSections()[0].GetSections()) { if (!section.HasSections("output")) { continue; } XMLSection outputSection = section.GetSections("output")[0]; QueryOutput output = null; switch (outputSection.Get("type").ToLower()) { case "file": string outputLocation = outputSection.Get("location").Replace('/', '\\'); outputLocation = Path.GetFullPath(outputLocation); if (outputSection.HasValue("dateformat")) { DateTime date = DateTime.Now; //if (interval == "daily") date = date.AddDays(-1); string[] dateformat = outputSection.Get("dateformat").ToLower().Split(','); StringBuilder formattedDate = new StringBuilder(); foreach (string f in dateformat) { switch (f) { case "dayofyear": formattedDate.Append(date.DayOfYear.ToString("000")); break; default: try { formattedDate.Append(date.ToString(f)); } catch (FormatException) { continue; } break; } } outputLocation = outputLocation.Replace("*", formattedDate.ToString()); } output = new QueryOutputFile(outputLocation); break; case "email": output = new QueryOutputEmail( outputSection.Get("from"), outputSection.Get("to").Split(','), outputSection.Get("subject"), outputSection.Get("body"), outputSection.Get("openers", false), outputSection.Get("attachmentFilepath") ); break; case "ftp": string filename = outputSection.Get("filename"); if (outputSection.HasValue("dateformat")) { DateTime date = DateTime.Now.AddDays(outputSection.Get("dateOffset", 0)); //if (interval == "daily") date = date.AddDays(-1); string[] dateformat = outputSection.Get("dateformat").ToLower().Split(','); StringBuilder formattedDate = new StringBuilder(); foreach (string f in dateformat) { switch (f) { case "dayofyear": formattedDate.Append(date.DayOfYear.ToString("000")); break; default: try { formattedDate.Append(date.ToString(f)); } catch (FormatException) { continue; } break; } } filename = filename.Replace("*", formattedDate.ToString()); } output = new QueryOutputFTP( outputSection.Get("address"), filename, outputSection.Get("remotepath"), outputSection.Get("username"), outputSection.Get("password") ); break; } if (output == null) { continue; } Query q = new Query(output, section.GetEnum <QueryInterval>("interval"), section.Get("name"), section.Get("database"), section.Get("dataview", ""), section.Get("transpose", false), section.Get("time", -1), section.Get("delimiter", ","), section.Get("printHeaders", false)); if (section.HasValue("queryStatement") && section.Get("queryStatement").Length > 0) { q.QueryStatement = section.Get("queryStatement"); } if (section.HasValue("paused")) { q.Paused = section.Get("paused", true); } queries.Add(q); } return(queries); }