public SourceNodeCollection ReadNode(XmlElement elem, XmlDocument doc) { SourceNodeCollection snc = new SourceNodeCollection(); foreach (XmlElement e2 in elem.ChildNodes) { if (e2.Name.Equals("SourceNode")) { SourceNode sn = new SourceNode(); snc.Add(sn); if (e2.HasAttribute("offset")) { long.TryParse(e2.GetAttribute("offset"), out sn.offset); } if (e2.HasAttribute("type")) { sn.type = e2.GetAttribute("type"); } foreach (XmlElement e3 in e2.ChildNodes) { if (e3.Name.Equals("value")) sn.value = e3.InnerText; else if (e3.Name.Equals("comments")) sn.comments = e3.InnerText; else if (e3.Name.Equals("nodes")) sn.Nodes = ReadNode(e3, doc); } } } return snc; }
public void AddRange(SourceNodeCollection sn) { CheckExistenceNodes(); if (sn != null && sn.Nodes != null) { Nodes.AddRange(sn.Nodes); } }
private void buttonReadInputC_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { SourceNodeCollection snc = new SourceNodeCollection(); snc.ReadXml(ofd.FileName); outputA = snc; } }
public override void Run() { StringBuilder sb = new StringBuilder(); makeRegexes(Script); int start = 0; int state = 0; Elements = new SourceNodeCollection(); Success = true; while (start < InputText.Length) { bool b = false; foreach (rgx r in Regexes) { if (r.state == state) { Match m = r.regex.Match(InputText, start); if (m.Success && m.Length > 0 && m.Index == start) { SourceNode dr = new SourceNode(); dr.offset = start; dr.type = r.name; dr.value = (r.printMatch ? InputText.Substring(start, m.Length) : ""); Elements.Add(dr); start += m.Length; b = true; if (r.nextState >= 0) state = r.nextState; break; } } } if (!b) { sb.AppendFormat("unrecognized sequence at {0} for state {1}\n", start, state); LastPosition = start; Success = false; break; } } Message = sb.ToString(); }
public void AddSubnodes(SourceNode sn) { if (Nodes == null) Nodes = new SourceNodeCollection(); Nodes.AddRange(sn.Nodes); }
public void AddNode(SourceNode sn) { if (Nodes == null) Nodes = new SourceNodeCollection(); Nodes.Add(sn); }
/// <summary> /// Processing of input stream with script /// Output is table /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void onButtonRunStreamToTable(object sender, EventArgs e) { string appdir = Path.GetDirectoryName(Application.ExecutablePath); StreamToTable stt = new StreamToTable(); // STEP A - initialization stt.Script = richTextBoxScriptA.Text; stt.InputText = richTextBoxInputA.Text + "\r\n"; // STEP A - processing stt.Run(); // STEP A - publish the results if (!stt.Success) { string temp = stt.InputText.Substring(stt.LastPosition); textBoxMessageA.Text = stt.Message + "\r\n\r\nLAST POSITION: " + stt.LastPosition + "\r\n\r\n== REST OF THE FILE ==\r\n" + temp; } else { textBoxMessageA.Text = stt.Message; } outputA = stt.Elements; DataTable dt = new DataTable(); dt.Columns.Add("Index", typeof(int)); dt.Columns.Add("Position", typeof(long)); dt.Columns.Add("Type", typeof(string)); dt.Columns.Add("Value", typeof(string)); for (int i = 0; i < outputA.Count; i++) { SourceNode sn = outputA[i]; DataRow dr = dt.NewRow(); dr.SetField<int>(0, i); dr.SetField<long>(1, sn.offset); dr.SetField<string>(2, sn.type); dr.SetField<string>(3, sn.value); dt.Rows.Add(dr); } dataGridView1.DataSource = dt; }