Esempio n. 1
0
        private void button_Run_Click(object sender, EventArgs e)
        {
            if (!_run && _senderThread == null)
            {
                _run          = true;
                _senderThread = new Thread(new ParameterizedThreadStart(WorkerThreadProc));
                _senderThread.Start(this);
                (sender as Button).Text = "Stop";

                if (gooseDataEdit == null)
                {
                    this.gooseDataEdit = new GooseDataEdit(this.Name, dataList, seqData, Data_ValueChanged);
                }

                button_SendOnce.Enabled = false;

                this._gooseCnt = 0;
                this.textBox_GoosesCnt.Text = this._gooseCnt.ToString();

                gooseDataEdit.DataEditModeOnly(true);
            }
            else
            {
                _run = false;
                _senderThread.Abort();
                _senderThread = null;
                gooseDataEdit.DataEditModeOnly(false);
                (sender as Button).Text = "Run";

                button_SendOnce.Enabled = true;
            }
        }
Esempio n. 2
0
        private void button_EditData_Click(object sender, EventArgs e)
        {
            if (gooseDataEdit == null)
            {
                this.gooseDataEdit = Env.getEnv().winMgr.AddGooseDataEdit(this.Name, dataList, seqData, Data_ValueChanged);
            }
            //new GooseDataEdit(this.Name, dataList, seqData, Data_ValueChanged);

            gooseDataEdit.Show();
        }
Esempio n. 3
0
        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;
                    }
                }
            }
        }