コード例 #1
0
        private void LoadConfig()
        {
            XmlReader   xmlReader = XmlReader.Create("./Config.xml");
            XmlDocument doc       = new XmlDocument();

            try
            {
                doc.Load(xmlReader);
                this.Text = doc.SelectSingleNode("//Config/ToolID").InnerText;

                XmlNode  hostNode = doc.SelectSingleNode("//Config/Host");
                string[] tokens   = hostNode.InnerText.Split(':');
                hostTxt.Text = tokens[0];
                portTxt.Text = tokens[1];
                XmlNode freqNode = doc.SelectSingleNode("//Config/Freq");
                freqTxt.Text = freqNode.InnerText;

                dataTxt.Text = System.IO.File.ReadAllText(@"./Data.txt");


                bool isAutoSend = doc.SelectSingleNode("//Config/AutoSendFlag").InnerText == "1";
                if (isAutoSend)
                {
                    try
                    {
                        agent     = new SendDataAgent(this.Text, double.Parse(freqTxt.Text));
                        agent.log = new Log(DisplayLog);

                        agent.Connect(hostTxt.Text, Int32.Parse(portTxt.Text));
                        ChangeStatus();

                        agent.SetData(dataTxt.Text);
                        agent.Start();
                    }
                    catch (Exception e)
                    {
                        DisplayLog("auto send fail.");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("load config fail : " + ex.StackTrace);
            }
            finally
            {
                doc.Clone();
                xmlReader.Close();
            }
        }
コード例 #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            if (args == null)
            {
                LoadConfig();
            }
            else
            {
                string[] tokens = args[0].Split(':');
                hostTxt.Text = tokens[0];
                portTxt.Text = tokens[1];
                this.Text    = args[1];
                freqTxt.Text = args[2];

                string str = this.GetType().Assembly.Location;
                str          = str.Substring(0, str.LastIndexOf("\\") + 1);
                dataTxt.Text = System.IO.File.ReadAllText(str + "Data.txt");;

                try
                {
                    agent     = new SendDataAgent(this.Text, double.Parse(freqTxt.Text));
                    agent.log = new Log(DisplayLog);

                    agent.Connect(hostTxt.Text, Int32.Parse(portTxt.Text));
                    ChangeStatus();

                    agent.SetData(dataTxt.Text);
                    agent.Start();
                    this.WindowState = FormWindowState.Minimized;
                }
                catch (Exception ex)
                {
                    DisplayLog("auto send fail.");
                }
            }
        }
コード例 #3
0
 private void startBtn_Click(object sender, EventArgs e)
 {
     agent.SetData(dataTxt.Text);
     agent.Start();
 }