Exemplo n.º 1
0
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            switch (operationRequest.OperationCode)
            {
                default:
                    {
                        string message = string.Format("Unknown operation code {0}", operationRequest.OperationCode);
                        this.SendOperationResponse(new OperationResponse { OperationCode = operationRequest.OperationCode, ReturnCode = -1, DebugMessage = message }, sendParameters);
                        break;
                    }

                case 1:
                    {
                        var pingOperation = new LatencyOperation(this.Protocol, operationRequest.Parameters);
                        if (pingOperation.IsValid == false)
                        {
                            this.SendOperationResponse(new OperationResponse { OperationCode = operationRequest.OperationCode, ReturnCode = -1, DebugMessage = pingOperation.GetErrorMessage() }, sendParameters);
                            return;
                        }

                        Thread.Sleep(5);

                        var response = new OperationResponse(operationRequest.OperationCode, pingOperation);
                        this.SendOperationResponse(response, sendParameters);
                        break;
                    }
            }
        }
Exemplo n.º 2
0
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            switch (operationRequest.OperationCode)
            {
            default:
            {
                string message = string.Format("Unknown operation code {0}", operationRequest.OperationCode);
                this.SendOperationResponse(new OperationResponse {
                        OperationCode = operationRequest.OperationCode, ReturnCode = -1, DebugMessage = message
                    }, sendParameters);
                break;
            }

            case 1:
            {
                var pingOperation = new LatencyOperation(this.Protocol, operationRequest.Parameters);
                if (pingOperation.IsValid == false)
                {
                    this.SendOperationResponse(new OperationResponse {
                            OperationCode = operationRequest.OperationCode, ReturnCode = -1, DebugMessage = pingOperation.GetErrorMessage()
                        }, sendParameters);
                    return;
                }

                Thread.Sleep(5);

                var response = new OperationResponse(operationRequest.OperationCode, pingOperation);
                this.SendOperationResponse(response, sendParameters);
                break;
            }
            }
        }
Exemplo n.º 3
0
        private void Ping()
        {
            var contract = new LatencyOperation {
                SentTime = Environment.TickCount
            };
            var request = new OperationRequest(this.operationCode, contract);

            this.SendOperationRequest(request, new SendParameters());
        }
Exemplo n.º 4
0
        private void Ping()
        {
            var contract = new LatencyOperation {
                SentTime = this.stopWatch.GetTimestamp()
            };
            var request = new OperationRequest(this.operationCode, contract);

            this.SendOperationRequest(request, new SendParameters());
        }
Exemplo n.º 5
0
        protected override void OnOperationResponse(OperationResponse operationResponse, SendParameters sendParameters)
        {
            if (operationResponse.ReturnCode == 0)
            {
                var contract = new LatencyOperation(this.Protocol, operationResponse.Parameters);
                if (!contract.IsValid)
                {
                    log.Error("LatencyOperation contract error: " + contract.GetErrorMessage());
                    return;
                }

                long now = Environment.TickCount;

                var      sentTime     = contract.SentTime;
                long     latencyTicks = now - sentTime.GetValueOrDefault();
                TimeSpan latencyTime  = TimeSpan.FromTicks(latencyTicks);
                var      latencyMs    = (int)latencyTime.TotalMilliseconds;

                Interlocked.Exchange(ref this.lastLatencyMs, latencyMs);
                this.latencyHistory.Add(latencyMs);
                if (this.NetworkProtocol == NetworkProtocolType.Udp)
                {
                    Counter.LatencyUdp.RawValue = latencyMs;
                }
                else
                {
                    Counter.LatencyTcp.RawValue = latencyMs;
                }
                var newAverage = (int)this.latencyHistory.Average();
                if (newAverage == 0)
                {
                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("LatencyAvg=0!");
                    }
                }

                Interlocked.Exchange(ref this.averageLatencyMs, newAverage);
            }
            else
            {
                log.ErrorFormat("Received Ping Response with Error {0}: {1}", operationResponse.ReturnCode, operationResponse.DebugMessage);
            }
        }
Exemplo n.º 6
0
        protected override void OnOperationResponse(OperationResponse operationResponse, SendParameters sendParameters)
        {
            if (operationResponse.ReturnCode == 0)
            {
                var contract = new LatencyOperation(this.Protocol, operationResponse.Parameters);
                if (!contract.IsValid)
                {
                    log.Error("LatencyOperation contract error: " + contract.GetErrorMessage());
                    return;
                }

                long now = this.stopWatch.GetTimestamp();

                var    sentTime     = contract.SentTime;
                long   latencyTicks = now - sentTime.GetValueOrDefault();
                double time         = (double)latencyTicks / (double)Stopwatch.Frequency * (double)1000;
                var    latencyMs    = (int)time;

                Interlocked.Exchange(ref this.lastLatencyMs, latencyMs);
                this.latencyHistory.Add(latencyMs);
                if (this.NetworkProtocol == NetworkProtocolType.Udp)
                {
                    Counter.LatencyUdp.RawValue = latencyMs;
                }
                else
                {
                    Counter.LatencyTcp.RawValue = latencyMs;
                }
                var newAverage = (int)this.latencyHistory.Average();
                if (newAverage == 0)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.InfoFormat("LatancyAvg=0!");
                    }
                }

                Interlocked.Exchange(ref this.averageLatencyMs, newAverage);
            }
            else
            {
                log.ErrorFormat("Received Ping Response with Error {0}: {1}", operationResponse.ReturnCode, operationResponse.DebugMessage);
            }
        }
Exemplo n.º 7
0
 private void Ping()
 {
     var contract = new LatencyOperation { SentTime = Environment.TickCount };
     var request = new OperationRequest(this.operationCode, contract);
     this.SendOperationRequest(request, new SendParameters());
 }
Exemplo n.º 8
0
        protected override void OnOperationResponse(OperationResponse operationResponse, SendParameters sendParameters)
        {
            if (operationResponse.ReturnCode == 0)
            {
                var contract = new LatencyOperation(this.Protocol, operationResponse.Parameters);
                if (!contract.IsValid)
                {
                    log.Error("LatencyOperation contract error: " + contract.GetErrorMessage());
                    return;
                }

                long now = Environment.TickCount;

                var sentTime = contract.SentTime;
                long latencyTicks = now - sentTime.GetValueOrDefault();
                TimeSpan latencyTime = TimeSpan.FromTicks(latencyTicks);
                var latencyMs = (int)latencyTime.TotalMilliseconds;

                Interlocked.Exchange(ref this.lastLatencyMs, latencyMs);
                this.latencyHistory.Add(latencyMs);
                if (this.NetworkProtocol == NetworkProtocolType.Udp)
                {
                    Counter.LatencyUdp.RawValue = latencyMs;
                }
                else
                {
                    Counter.LatencyTcp.RawValue = latencyMs;
                }
                var newAverage = (int)this.latencyHistory.Average();
                Interlocked.Exchange(ref this.averageLatencyMs, newAverage);
            }
            else
            {
                log.ErrorFormat("Received Ping Response with Error {0}: {1}", operationResponse.ReturnCode, operationResponse.DebugMessage);
            }
        }
Exemplo n.º 9
0
 private void Ping()
 {
     var contract = new LatencyOperation { SentTime = this.stopWatch.GetTimestamp() };
     var request = new OperationRequest(this.operationCode, contract);
     this.SendOperationRequest(request, new SendParameters());
 }
Exemplo n.º 10
0
        protected override void OnOperationResponse(OperationResponse operationResponse, SendParameters sendParameters)
        {
            if (operationResponse.ReturnCode == 0)
            {
                var contract = new LatencyOperation(this.Protocol, operationResponse.Parameters);
                if (!contract.IsValid)
                {
                    log.Error("LatencyOperation contract error: " + contract.GetErrorMessage());
                    return;
                }

                long now = this.stopWatch.GetTimestamp();

                var sentTime = contract.SentTime;
                long latencyTicks = now - sentTime.GetValueOrDefault();
                double time = (double)latencyTicks / (double)Stopwatch.Frequency * (double)1000;
                var latencyMs = (int)time;

                Interlocked.Exchange(ref this.lastLatencyMs, latencyMs);
                this.latencyHistory.Add(latencyMs);
                if (this.NetworkProtocol == NetworkProtocolType.Udp)
                {
                    Counter.LatencyUdp.RawValue = latencyMs;
                }
                else
                {
                    Counter.LatencyTcp.RawValue = latencyMs;
                }
                var newAverage = (int)this.latencyHistory.Average();
                if (newAverage == 0)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.InfoFormat("LatancyAvg=0!");
                    }
                }

                Interlocked.Exchange(ref this.averageLatencyMs, newAverage);
            }
            else
            {
                log.ErrorFormat("Received Ping Response with Error {0}: {1}", operationResponse.ReturnCode, operationResponse.DebugMessage);
            }
        }