Ejemplo n.º 1
0
        private async Task<RestResults> Send(IRestRequest request, bool hasResponse)
        {
            object payload = request.Payload;
            string requestJson = null;
            if (payload != null)
				requestJson = Serialize(payload);

            Stopwatch stopwatch = Stopwatch.StartNew();
            string responseJson = await _engine.Send(request.Method, request.Endpoint, requestJson, CancelToken).ConfigureAwait(false);
            stopwatch.Stop();

            double milliseconds = Math.Round((double)stopwatch.ElapsedTicks / (double)Stopwatch.Frequency * 1000.0, 2);            
            return new RestResults(responseJson, milliseconds);
		}
Ejemplo n.º 2
0
        private async Task <string> Send(HttpMethod method, string path, object content, bool hasResponse)
        {
            Stopwatch stopwatch   = null;
            string    requestJson = null;

            if (content != null)
            {
                requestJson = JsonConvert.SerializeObject(content);
            }

            if (_config.LogLevel >= LogMessageSeverity.Verbose)
            {
                stopwatch = Stopwatch.StartNew();
            }

            string responseJson = await _engine.Send(method, path, requestJson, _cancelToken).ConfigureAwait(false);

#if TEST_RESPONSES
            if (!hasResponse && !string.IsNullOrEmpty(responseJson))
            {
                throw new Exception("API check failed: Response is not empty.");
            }
#endif

            if (_config.LogLevel >= LogMessageSeverity.Verbose)
            {
                stopwatch.Stop();
                if (content != null && _config.LogLevel >= LogMessageSeverity.Debug)
                {
                    if (path.StartsWith(Endpoints.Auth))
                    {
                        RaiseOnRequest(method, path, "[Hidden]", stopwatch.ElapsedTicks / (double)TimeSpan.TicksPerMillisecond);
                    }
                    else
                    {
                        RaiseOnRequest(method, path, requestJson, stopwatch.ElapsedTicks / (double)TimeSpan.TicksPerMillisecond);
                    }
                }
                else
                {
                    RaiseOnRequest(method, path, null, stopwatch.ElapsedTicks / (double)TimeSpan.TicksPerMillisecond);
                }
            }

            return(responseJson);
        }
Ejemplo n.º 3
0
        private async Task <string> Send(IRestRequest request, bool hasResponse)
        {
            var    method    = request.Method;
            var    path      = request.Endpoint;
            object payload   = request.Payload;
            var    isPrivate = request.IsPrivate;

            string requestJson = null;

            if (payload != null)
            {
                requestJson = JsonConvert.SerializeObject(payload);
            }

            Stopwatch stopwatch = null;

            if (Logger.Level >= LogSeverity.Verbose)
            {
                stopwatch = Stopwatch.StartNew();
            }

            string responseJson = await _engine.Send(method, path, requestJson, CancelToken).ConfigureAwait(false);

            if (Logger.Level >= LogSeverity.Verbose)
            {
                stopwatch.Stop();
                double milliseconds = Math.Round(stopwatch.ElapsedTicks / (double)TimeSpan.TicksPerMillisecond, 2);

                string log = $"{method} {path}: {milliseconds} ms";
                if (payload != null && _config.LogLevel >= LogSeverity.Debug)
                {
                    if (isPrivate)
                    {
                        log += $" [Hidden]";
                    }
                    else
                    {
                        log += $" {requestJson}";
                    }
                }
                Logger.Verbose(log);
            }

            return(responseJson);
        }