示例#1
0
        private void btnSendData_Click(object sender, EventArgs e)
        {
            this.rbHeartbeat.Enabled = false;
            this.rbLogin.Enabled     = false;
            this.rbBlacklist.Enabled = false;
            this.rbCurrency.Enabled  = false;

            DataCounter.Reset();

            this.TargetHeartbeatCount         = this.TargetClientCount * 1;
            this.TargetLoginCount             = this.TargetClientCount * 1;
            this.TargetBlacklistQueryCount    = this.TargetClientCount * 1;
            this.TargetBlacklistDownloadCount = 0;
            this.TargetCurrencyCount          = this.TargetClientCount * this.txtCurrencyCount.Text.Trim().ToInt() * this.txtDay.Text.Trim().ToInt();
            this.LastSencodCount = 0;
            this.MaxSecondCount  = 0;

            if (this.ClientList != null && this.ClientList.Count > 0)
            {
                this.IsSending           = true;
                this.StartTime           = DateTime.Now;
                this.btnSendData.Enabled = false;

                if (this.rbHeartbeat.Checked)
                {
                    Task.Factory.StartNew(() =>
                    {
                        Parallel.ForEach <CurrencyTerminal>(ClientList, obj => obj.SendHeartbeat());
                    });
                }

                if (this.rbLogin.Checked)
                {
                    Task.Factory.StartNew(() =>
                    {
                        Parallel.ForEach <CurrencyTerminal>(ClientList, obj => obj.SendLogin());
                    });
                }

                if (this.rbBlacklist.Checked)
                {
                    Task.Factory.StartNew(() =>
                    {
                        Parallel.ForEach <CurrencyTerminal>(ClientList, obj => obj.SendBlacklist());
                    });
                }

                if (this.rbCurrency.Checked)
                {
                    Task.Factory.StartNew(() =>
                    {
                        Parallel.ForEach <CurrencyTerminal>(ClientList, obj => obj.RestartSendCurrency());
                    });
                }
            }
        }
        private void DataReceived_Handler(byte[] data)
        {
            this.RoundTime = (int)DateTime.Now.Subtract(this.LastRecieveDatTime.Value).TotalMilliseconds;

            this.SendInterval = this.TimeOut - this.RoundTime;

            if (this.SendInterval < 0)
            {
                this.TimeOutCount += 1;
            }

            Datagram objDatagram = DatagramResolver.ResolveResponse(data);

            if (objDatagram != null)
            {
                if (objDatagram.Type == DatagramTypeEnum.HeartbeatResponse)
                {
                    this.SendHeartbeatCount += 1;

                    DataCounter.AddHeartbeat();
                }

                if (objDatagram.Type == DatagramTypeEnum.LoginResponse)
                {
                    this.SendLoginCount += 1;

                    DataCounter.AddLogin();
                }

                if (objDatagram.Type == DatagramTypeEnum.BlacklistQueryResponse)
                {
                    BlacklistQueryResponse response = objDatagram as BlacklistQueryResponse;

                    this.TargetDownloadBlacklist = response.BlacklistCount.ToInt16();
                    this.DownloadBlacklistCount  = 0;

                    DataCounter.AddBlacklistQuery();
                    DataCounter.AddSingleBlacklistDownload(this.TargetDownloadBlacklist);

                    if (this.TargetDownloadBlacklist > 0)
                    {
                        this.IsFinishDownloadBlacklist = false;

                        this.SendBlacklist();
                    }
                }

                if (objDatagram.Type == DatagramTypeEnum.BlacklistDownloadResponse)
                {
                    this.DownloadBlacklistCount += 1;

                    DataCounter.AddRealBlacklistDownload();

                    if (this.DownloadBlacklistCount >= this.TargetDownloadBlacklist)
                    {
                        this.IsFinishDownloadBlacklist = true;
                    }

                    else
                    {
                        this.SendBlacklist();
                    }
                }

                if (objDatagram.Type == DatagramTypeEnum.CurrencyResponse)
                {
                    this.SendCurrencyCount           += 1;
                    this.SendSingleDataCurrencyCount += 1;

                    DataCounter.AddCurrency();

                    if (this.SendCurrencyCount < this.TargetCurrencyCount)
                    {
                        if (this.SendSingleDataCurrencyCount == this.TargetSingleDayCurrencyCount)
                        {
                            this.SendDayCount += 1;
                            this.SendSingleDataCurrencyCount = 0;
                        }

                        if (this.FixedSendSpeed && this.SendInterval > 0)
                        {
                            Thread.Sleep(this.SendInterval);
                        }

                        this.SendCurrency();
                    }
                }
            }
        }
示例#3
0
        private void DataReceived_Handler(byte[] data)
        {
            if (this.IsTimeOut)
            {
                this.TimeOutCount += 1;
            }

            this.LastRecieveDatTime = DateTime.Now;

            Datagram objDatagram = DatagramResolver.ResolveResponse(data);

            if (objDatagram != null)
            {
                if (objDatagram.Type == DatagramTypeEnum.HeartbeatResponse)
                {
                    this.SendHeartbeatCount += 1;

                    DataCounter.AddHeartbeat();
                }

                if (objDatagram.Type == DatagramTypeEnum.LoginResponse)
                {
                    this.SendLoginCount += 1;

                    DataCounter.AddLogin();
                }

                if (objDatagram.Type == DatagramTypeEnum.BlacklistQueryResponse)
                {
                    BlacklistQueryResponse response = objDatagram as BlacklistQueryResponse;

                    this.TargetDownloadBlacklist = response.BlacklistCount.ToInt16();
                    this.DownloadBlacklistCount  = 0;

                    DataCounter.AddBlacklistQuery();
                    DataCounter.AddSingleBlacklistDownload(this.TargetDownloadBlacklist);

                    if (this.TargetCurrencyCount > 0)
                    {
                        this.IsFinishDownloadBlacklist = false;

                        this.SendBlacklist();
                    }
                }

                if (objDatagram.Type == DatagramTypeEnum.BlacklistDownloadResponse)
                {
                    this.DownloadBlacklistCount += 1;

                    DataCounter.AddRealBlacklistDownload();

                    if (this.DownloadBlacklistCount >= this.TargetDownloadBlacklist)
                    {
                        this.IsFinishDownloadBlacklist = true;
                    }

                    else
                    {
                        this.SendBlacklist();
                    }
                }

                if (objDatagram.Type == DatagramTypeEnum.CurrencyResponse)
                {
                    this.SendCurrencyCount += 1;

                    DataCounter.AddCurrency();

                    if (this.SendCurrencyCount < this.TargetCurrencyCount)
                    {
                        Thread.Sleep(this.SendInterval);

                        this.SendCurrency();
                    }
                }
            }
        }
示例#4
0
        private void btnRefresh_Click(object sender, EventArgs e)
        {
            float R = 7.0f;

            this.lvClientList.Items.Clear();

            DataCounter.ClearConnectedClient();

            if (this.ClientList != null && this.ClientList.Count > 0)
            {
                Task.Factory.StartNew(() =>
                {
                    int maxX = this.panelStatus.Width;
                    int maxY = this.panelStatus.Height;

                    int maxXCout = (int)(maxX / R);
                    int maxYCout = (int)(maxY / R);

                    if (maxXCout == 0)
                    {
                        return;
                    }

                    this.BeginInvoke(new EventHandler((ob, ca) =>
                    {
                        for (int p = 0; p < this.ClientList.Count; p++)
                        {
                            CurrencyTerminal client = this.ClientList[p];

                            XListViewItem lviClient = new XListViewItem(client.DeviceNumber, client.RealConnectCount, "",
                                                                        client.TimeOutCount, client.SendHeartbeatCount, client.SendLoginCount,
                                                                        client.DownloadBlacklistCount, client.SendCurrencyCount, client.ConnectMessage);

                            float drawX = p % maxXCout * R;
                            float drawY = p / maxXCout * R;

                            if (client != null)
                            {
                                using (Graphics g = Graphics.FromHwnd(this.panelStatus.Handle))
                                {
                                    if (client.IsConnected && client.IsRecieveNormal)
                                    {
                                        lviClient.DeviceStatus = "工作中";
                                        lviClient.ForeColor    = Color.Green;

                                        g.FillEllipse(Brushes.Green, drawX, drawY, R, R);

                                        DataCounter.AddConnectedClient();
                                    }
                                    else if (client.IsConnected)
                                    {
                                        lviClient.DeviceStatus = "已连接";
                                        lviClient.ForeColor    = Color.Blue;

                                        g.FillEllipse(Brushes.Blue, drawX, drawY, R, R);

                                        DataCounter.AddConnectedClient();
                                    }
                                    else if (!client.IsConnected)
                                    {
                                        lviClient.DeviceStatus = "未连接";
                                        lviClient.ForeColor    = Color.Red;

                                        g.FillEllipse(Brushes.Red, drawX, drawY, R, R);
                                    }
                                    else
                                    {
                                        lviClient.DeviceStatus = "未知";
                                        lviClient.ForeColor    = Color.Black;

                                        g.FillEllipse(Brushes.Black, drawX, drawY, R, R);
                                    }
                                    g.Save();

                                    this.lvClientList.Items.Add(lviClient);
                                }
                            }
                        }
                    }));
                });
            }
        }
示例#5
0
 static DataCounter()
 {
     DataCounter.ClearConnectedClient();
     DataCounter.Reset();
 }