Exemple #1
0
        public object Any(Ping request)
        {
            var ret = new PingResponse
            {
                Responses = new Dictionary<string, ResponseStatus>()
            };

            foreach (var url in urls)
            {
                var name = url.Replace("https", "http").Replace("http://", "").SplitOnFirst('.').First();
                try
                {
                    var sw = Stopwatch.StartNew();
                    var response = url.GetStringFromUrl(requestFilter: req => req.UserAgent = "TestServices");
                    ret.Responses[name] = new ResponseStatus
                    {
                        Message = "OK {0}ms".Fmt(sw.ElapsedMilliseconds)
                    };
                }
                catch (Exception ex)
                {
                    ret.Responses[name] = ex.ToResponseStatus();
                    var body = ex.GetResponseBody();
                    ret.Responses[name].Message = body;
                }
            }

            ret.ResponseStatus = ret.Responses
                .Where(x => x.Value.ErrorCode != null)
                .Select(x => x.Value)
                .FirstOrDefault();

            if (ret.ResponseStatus != null)
            {
                Response.StatusCode = 500;

                try {
                    Any(new ResetConnections());
                } catch {}
            }

            return ret;
        }
Exemple #2
0
        public object Any(Ping request)
        {
            var ret = new PingResponse
            {
                Responses = new Dictionary <string, ResponseStatus>()
            };

            foreach (var url in urls)
            {
                var name = url.Replace("https", "http").Replace("http://", "").SplitOnFirst('.').First();
                try
                {
                    var sw       = Stopwatch.StartNew();
                    var response = url.GetStringFromUrl(requestFilter: req => req.UserAgent = "TestServices");
                    ret.Responses[name] = new ResponseStatus
                    {
                        Message = "OK {0}ms".Fmt(sw.ElapsedMilliseconds)
                    };
                }
                catch (Exception ex)
                {
                    ret.Responses[name] = ex.ToResponseStatus();
                    var body = ex.GetResponseBody();
                    ret.Responses[name].Message = body;
                }
            }

            ret.ResponseStatus = ret.Responses
                                 .Where(x => x.Value.ErrorCode != null)
                                 .Select(x => x.Value)
                                 .FirstOrDefault();

            if (ret.ResponseStatus != null)
            {
                Response.StatusCode = 500;

                try {
                    Any(new ResetConnections());
                } catch {}
            }

            return(ret);
        }