public void Export(NodeGVL gvl) { try { XDocument xmlDoc = new XDocument(new XElement("DataSet")); if (gvl.GetChildNodes().Length == 0) { MessageBox.Show("DataSet not exported. No data to export !", "Export to Xml", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } foreach (NodeGData ngd in gvl.GetChildNodes()) { recursiveReadGvl(ngd, xmlDoc.Element("DataSet")); } using (SaveFileDialog exportSaveFileDialog = new SaveFileDialog()) { exportSaveFileDialog.Title = "Select XML File"; exportSaveFileDialog.Filter = "Xml File(*.xml)|*.xml"; if (DialogResult.OK == exportSaveFileDialog.ShowDialog()) { string fullFileName = exportSaveFileDialog.FileName; xmlDoc.Save(fullFileName); MessageBox.Show("DataSet exported successfully", "Export to Xml", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { Logger.getLogger().LogError("DataSet export Exception" + ex.Message); } }
public void ExportGoose(Hashtable gp, NodeGVL gvl) { try { XDocument xmlDoc = new XDocument(); XElement gooses = new XElement("Gooses"); xmlDoc.Add(gooses); if ((gp.Count == 17) && (gvl.GetChildNodes().Length > 0)) { XElement goose = new XElement("Goose_0"); gooses.Add(goose); XElement parameters = new XElement("Parameters"); goose.Add(parameters); foreach (DictionaryEntry param in gp) { parameters.Add(new XElement(param.Key.ToString(), new XAttribute("Value", param.Value.ToString()))); } XElement dataset = new XElement("DataSet"); goose.Add(dataset); foreach (NodeGData ngd in gvl.GetChildNodes()) { recursiveReadGvl(ngd, dataset); } using (SaveFileDialog exportSaveFileDialog = new SaveFileDialog()) { exportSaveFileDialog.Title = "Select XML File"; exportSaveFileDialog.Filter = "Xml File(*.xml)|*.xml"; if (DialogResult.OK == exportSaveFileDialog.ShowDialog()) { string fullFileName = exportSaveFileDialog.FileName; xmlDoc.Save(fullFileName); MessageBox.Show("Gosses exported successfully", "Export to Xml", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } else { MessageBox.Show("Goose not exported. No data to export !", "Export to Xml", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } catch (Exception ex) { Logger.getLogger().LogError("Goose export Exception" + ex.Message); } }
void updateTree() { Gvl = new NodeGVL("Data"); int i = 0; foreach (GOOSE_ASN1_Model.Data dataListCn in _dataList) { i = recursiveReadData(null, dataListCn, Gvl, i, DateTime.Now); } myTreeView_Goose.ImageList = new ImageList(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Resource1)); myTreeView_Goose.ImageList.Images.Add(((System.Drawing.Image)(resources.GetObject("page_white_text_width")))); myTreeView_Goose.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DO1")))); myTreeView_Goose.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DA1")))); myTreeView_Goose.Nodes.Clear(); makeTree_listNode(Gvl, null, myTreeView_Goose); myListView1_CheckDataIntegrity(); }
public void Import(ref int gooseItems, Control.ControlCollection cc, PacketDevice netDev) { using (OpenFileDialog importOpenFileDialog = new OpenFileDialog()) { importOpenFileDialog.Title = "Select XML File"; importOpenFileDialog.Filter = "Xml File(*.xml)|*.xml"; if (DialogResult.OK == importOpenFileDialog.ShowDialog()) { XDocument xmlDoc = XDocument.Load(importOpenFileDialog.FileName); XElement gooses = xmlDoc.Element("Gooses"); if (gooses != null && xmlDoc.Elements("Gooses").Count() == 1) { if (gooses.Elements().Count() > 0) { foreach (XElement goose in gooses.Elements()) { GooseControl gc = new GooseControl("Goose " + gooseItems++.ToString() + ":", "00:00:00:00:00:00", netDev); XElement parameters = goose.Element("Parameters"); if (parameters != null && goose.Elements("Parameters").Count() == 1) { if (parameters.Elements().Count() == 17) { foreach (XElement parameter in parameters.Elements()) { if (parameter.Attribute("Value") != null) { gc.gooseParameters[parameter.Name.ToString()] = parameter.Attribute("Value").Value.ToString(); } else { MessageBox.Show("Invalid XML file !", "Import from Xml", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } gc.updateComponents(); } else { MessageBox.Show("Invalid XML file !", "Import from Xml", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } XElement dataset = goose.Element("DataSet"); if (dataset != null && goose.Elements("DataSet").Count() == 1) { if (dataset.Elements("Data").Count() > 0) { foreach (XElement data in dataset.Elements("Data")) { recursiveCreateDataList(gc.dataList, data); } } } else { MessageBox.Show("Invalid XML file !", "Import from Xml", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } XElement seqdata = goose.Element("SeqData"); if (seqdata != null && goose.Elements("SeqData").Count() == 1) { if (seqdata.Elements("Data").Count() > 0) { NodeGVL gvl = new NodeGVL("Data"); GooseDataEdit gde = new GooseDataEdit(); int i = 0; foreach (GOOSE_ASN1_Model.Data dataListCn in gc.dataList) { i = gde.recursiveReadData(null, dataListCn, gvl, i, DateTime.Now); } gc.seqData.Clear(); foreach (XElement seqd in seqdata.Elements("Data")) { if (seqd.Attribute("Name") != null) { if (gvl.GetChildNodes().Length > 0) { foreach (NodeGData ngdcn in gvl.GetChildNodes()) { NodeGData fngd; if ((fngd = recursiveFindNodeGData(ngdcn, seqd.Attribute("Name").Value)) != null) { if (seqd.Attribute("Duration") != null && seqd.Attribute("Value") != null) { gc.seqData.Add(new SeqData(fngd, seqd.Attribute("Value").Value, Convert.ToInt32(seqd.Attribute("Duration").Value))); } else { MessageBox.Show("Invalid XML file !", "Import from Xml", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } break; } } } } else { MessageBox.Show("Invalid XML file !", "Import from Xml", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } else { MessageBox.Show("Invalid XML file !", "Import from Xml", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } else { MessageBox.Show("Invalid XML file !", "Import from Xml", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } gc.Dock = DockStyle.Top; cc.Add(gc); cc.SetChildIndex(gc, 0); } } else { MessageBox.Show("Invalid XML file !", "Import from Xml", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { MessageBox.Show("Invalid XML file !", "Import from Xml", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } }