Пример #1
0
        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();
                    }
                }
            }
        }
Пример #2
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();
                    }
                }
            }
        }