Exemplo n.º 1
0
 private void button5_Click(object sender, EventArgs e)
 {
     if (!this.timer4.Enabled)
     {
         counts[3] = 0;
         if (checkBox5.Checked == true)
         {
             T_Data data = new T_Data();
             data.data  = this.textBox4.Text;
             data.count = ++counts[3];
             Input_Topic_Queue[3].Enqueue(data);
             timer4_count         = 0;
             this.timer4.Interval = 1000;
         }
         else
         {
             this.timer4.Interval = Convert.ToInt32(textBox11.Text);
         }
         this.timer4.Start();
         ((Button)sender).Text = "停止";
     }
     else
     {
         this.timer4.Stop();
         ((Button)sender).Text = "開始";
     }
 }
Exemplo n.º 2
0
        public T_Data ReadSerializedData <T_Data>()
        {
            int packetLength = ReadInt32();

            _AssertNotOverflow(packetLength);
            var    memoryBuffer = new System.IO.MemoryStream(m_Buffer, m_Pointer, packetLength);
            T_Data dataReceived = Serializer.Deserialize <T_Data>(memoryBuffer);

            m_Pointer += packetLength;
            return(dataReceived);
        }
Exemplo n.º 3
0
 private void timer4_Tick(object sender, EventArgs e)
 {
     if (counts[3] == -1)
     {
         timer4.Stop();
         button5.Text = "開始";
     }
     if (checkBox5.Checked == true)
     {
         timer4_count++;
     }
     else
     {
         T_Data data = new T_Data();
         data.data  = this.textBox4.Text;
         data.count = counts[3]++;
         Input_Topic_Queue[3].Enqueue(data);
     }
 }
Exemplo n.º 4
0
 // 傳送訊息事件
 private void button1_Click(object sender, EventArgs e)
 {
     // 判斷是否傳送訊息
     for (int i = 0; i < 4; i++)
     {
         counts[i] = 0;
     }
     if (checkBox1.Checked == true)
     {
         T_Data data = new T_Data();
         data.data  = this.textBox1.Text;
         data.count = 0;
         Input_Topic_Queue[0].Enqueue(data);
     }
     if (checkBox2.Checked == true)
     {
         T_Data data = new T_Data();
         data.data  = this.textBox3.Text;
         data.count = 0;
         Input_Topic_Queue[1].Enqueue(data);
     }
     if (checkBox3.Checked == true)
     {
         T_Data data = new T_Data();
         data.data  = this.textBox2.Text;
         data.count = 0;
         Input_Topic_Queue[2].Enqueue(data);
     }
     if (checkBox4.Checked == true)
     {
         T_Data data = new T_Data();
         data.data  = this.textBox4.Text;
         data.count = 0;
         Input_Topic_Queue[3].Enqueue(data);
     }
 }
Exemplo n.º 5
0
        private void Form1_Load(object sender, EventArgs e)
        {
            // 初始化Topic queue
            for (int i = 0; i < 4; i++)
            {
                Input_Topic_Queue[i] = new ConcurrentQueue <T_Data>();
            }

            // 設定 Topic
            // Topic porperty
            // topic : 主題名稱
            // id :  Input Queue Array index 執行續溝通用
            // dateRecivedHanlder:接收 subscirbe 訊息的匿名函式
            T_Topic t1 = new T_Topic("A", 0);

            // 接收 subscirbe 訊息的實作
            t1.dateRecivedHanlder = (sendingProcess, outLine) =>
            {
                if (!String.IsNullOrEmpty(outLine.Data))
                {
                    string data   = outLine.Data;
                    string cstr   = "message count ";
                    string estr   = ";message time ";
                    int    tindex = data.IndexOf(cstr);
                    int    eindex = data.IndexOf(estr);
                    System.Diagnostics.Debug.WriteLine(outLine.Data);
                    if (tindex >= 0)
                    {
                        int  len   = eindex - (tindex + cstr.Length);
                        long count = Convert.ToInt64(data.Substring(tindex + cstr.Length, len));
                        SetText(label7, outLine.Data);
                        System.Diagnostics.Debug.WriteLine(outLine.Data);
                        T_Data da = new T_Data();
                        da.data = this.textBox1.Text;
                        if (checkBox5.Checked == true)
                        {
                            if (count != -1 && count >= Convert.ToInt64(textBox6.Text) && Convert.ToInt64(textBox6.Text) != 0)
                            {
                                counts[0] = -1;
                                return;
                            }
                            if (timer1_count == Convert.ToInt64(textBox5.Text) && Convert.ToInt64(textBox5.Text) != 0)
                            {
                                counts[0] = -1;
                                return;
                            }

                            if (count == counts[0] + 1)
                            {
                                counts[0] = counts[0] + 2;
                                da.count  = counts[0];
                                Input_Topic_Queue[0].Enqueue(da);
                            }
                        }
                    }
                }
            };

            T_Topic t2 = new T_Topic("B", 1);

            t2.dateRecivedHanlder = (sendingProcess, outLine) =>
            {
                if (!String.IsNullOrEmpty(outLine.Data))
                {
                    string data   = outLine.Data;
                    string cstr   = "message count ";
                    string estr   = ";message time ";
                    int    tindex = data.IndexOf(cstr);
                    int    eindex = data.IndexOf(estr);
                    System.Diagnostics.Debug.WriteLine(outLine.Data);
                    if (tindex >= 0)
                    {
                        SetText(label8, outLine.Data);
                        System.Diagnostics.Debug.WriteLine(outLine.Data);
                        int    len   = eindex - (tindex + cstr.Length);
                        long   count = Convert.ToInt64(data.Substring(tindex + cstr.Length, len));
                        T_Data da    = new T_Data();
                        da.data = this.textBox3.Text;
                        if (checkBox5.Checked == true)
                        {
                            if (count != -1 && count >= Convert.ToInt64(textBox8.Text) && Convert.ToInt64(textBox8.Text) != 0)
                            {
                                counts[1] = -1;
                                return;
                            }
                            if (timer2_count == Convert.ToInt64(textBox7.Text) && Convert.ToInt64(textBox7.Text) != 0)
                            {
                                counts[1] = -1;
                                return;
                            }
                            if (count == counts[1] + 1)
                            {
                                counts[1] = counts[1] + 2;
                                da.count  = counts[1];
                                Input_Topic_Queue[1].Enqueue(da);
                            }
                        }
                    }
                }
            };

            T_Topic t3 = new T_Topic("C", 2);

            t3.dateRecivedHanlder = (sendingProcess, outLine) =>
            {
                if (!String.IsNullOrEmpty(outLine.Data))
                {
                    string data   = outLine.Data;
                    string cstr   = "message count ";
                    string estr   = ";message time ";
                    int    tindex = data.IndexOf(cstr);
                    int    eindex = data.IndexOf(estr);
                    System.Diagnostics.Debug.WriteLine(outLine.Data);
                    if (tindex >= 0)
                    {
                        SetText(label9, outLine.Data);
                        System.Diagnostics.Debug.WriteLine(outLine.Data);
                        System.Diagnostics.Debug.WriteLine(outLine.Data);
                        int    len   = eindex - (tindex + cstr.Length);
                        long   count = Convert.ToInt64(data.Substring(tindex + cstr.Length, len));
                        T_Data da    = new T_Data();
                        da.data = this.textBox2.Text;
                        if (checkBox5.Checked == true)
                        {
                            if (count != -1 && count >= Convert.ToInt64(textBox10.Text) && Convert.ToInt64(textBox10.Text) != 0)
                            {
                                counts[2] = -1;
                                return;
                            }
                            if (timer3_count == Convert.ToInt64(textBox9.Text) && Convert.ToInt64(textBox9.Text) != 0)
                            {
                                counts[2] = -1;
                                return;
                            }
                            if (count == counts[2] + 1)
                            {
                                counts[2] = counts[2] + 2;
                                da.count  = counts[2];
                                Input_Topic_Queue[2].Enqueue(da);
                            }
                        }
                    }
                }
            };

            T_Topic t4 = new T_Topic("D", 3);

            t4.dateRecivedHanlder = (sendingProcess, outLine) =>
            {
                if (!String.IsNullOrEmpty(outLine.Data))
                {
                    string data   = outLine.Data;
                    string cstr   = "message count ";
                    string estr   = ";message time ";
                    int    tindex = data.IndexOf(cstr);
                    int    eindex = data.IndexOf(estr);
                    System.Diagnostics.Debug.WriteLine(outLine.Data);
                    if (tindex >= 0)
                    {
                        SetText(label10, outLine.Data);
                        System.Diagnostics.Debug.WriteLine(outLine.Data);
                        System.Diagnostics.Debug.WriteLine(outLine.Data);
                        int    len   = eindex - (tindex + cstr.Length);
                        long   count = Convert.ToInt64(data.Substring(tindex + cstr.Length, len));
                        T_Data da    = new T_Data();
                        da.data = this.textBox4.Text;
                        if (checkBox5.Checked == true)
                        {
                            if (count != -1 && count >= Convert.ToInt64(textBox12.Text) && Convert.ToInt64(textBox12.Text) != 0)
                            {
                                counts[3] = -1;
                                return;
                            }
                            if (timer4_count == Convert.ToInt64(textBox11.Text) && Convert.ToInt64(textBox11.Text) != 0)
                            {
                                counts[3] = -1;
                                return;
                            }
                            if (count == counts[3] + 1)
                            {
                                counts[3] = counts[3] + 2;
                                da.count  = counts[3];
                                Input_Topic_Queue[3].Enqueue(da);
                            }
                        }
                    }
                }
            };
            // 啟動執行續監控push,subscribe
            Thread oThread1 = new Thread(new ParameterizedThreadStart(push));

            // 啟用執行續並提供所需資訊
            oThread1.Start(t1);
            Thread oThread2 = new Thread(new ParameterizedThreadStart(push));

            oThread2.Start(t2);
            Thread oThread3 = new Thread(new ParameterizedThreadStart(push));

            oThread3.Start(t3);
            Thread oThread4 = new Thread(new ParameterizedThreadStart(push));

            oThread4.Start(t4);
            Thread oThread5 = new Thread(new ParameterizedThreadStart(recevie));

            oThread5.Start(t1);
            Thread oThread6 = new Thread(new ParameterizedThreadStart(recevie));

            oThread6.Start(t2);
            Thread oThread7 = new Thread(new ParameterizedThreadStart(recevie));

            oThread7.Start(t3);
            Thread oThread8 = new Thread(new ParameterizedThreadStart(recevie));

            oThread8.Start(t4);
        }