Beispiel #1
0
        private string GetStatusDescription(IpStatus status)
        {
            switch (status)
            {
            case IpStatus.Good:
                return("正常");

            case IpStatus.Timeout:
                return("超时");

            case IpStatus.ContentError:
                return("网页内容错误");

            case IpStatus.ConnectionReset:
                return("连接被重置");

            case IpStatus.Exception:
                return("其他异常");

            default:
                return("未知");
            }
        }
Beispiel #2
0
        public async Task <EntityMetadata <IpStatus, IpLookupErrors> > GetIpStatus(string ip, List <string> services)
        {
            var tasks = new List <IpTask <IpProcessorResponse> >();

            foreach (var svc in services)
            {
                switch (svc.ToLower())
                {
                case "rdap":
                    tasks.Add(new IpTask <IpProcessorResponse>("rdap", _httpIpProcessorService.GetRdap(ip)));
                    break;

                case "rdns":
                    tasks.Add(new IpTask <IpProcessorResponse>("rdns", _httpIpProcessorService.GetRdns(ip)));
                    break;

                case "ping":
                    tasks.Add(new IpTask <IpProcessorResponse>("ping", _httpIpProcessorService.GetPing(ip)));
                    break;

                case "geo":
                    tasks.Add(new IpTask <IpProcessorResponse>("geo", _httpIpProcessorService.GetGeo(ip)));
                    break;

                default:
                    break;
                }
            }

            await Task.WhenAll(tasks.Select(s => s.Task));

            var errors = new List <ErrorInfo <IpLookupErrors> >();
            var result = new IpStatus();

            foreach (var t in tasks)
            {
                var taskResult = t.Task.Result;
                if (taskResult == null)
                {
                    errors.Add(new ErrorInfo <IpLookupErrors>(GetErrorType(t.ServiceName)));
                    continue;
                }

                switch (t.ServiceName.ToLower())
                {
                case "rdap":
                    result.Rdap = taskResult as RdapResponse;
                    break;

                case "rdns":
                    result.Rdns = taskResult as RdnsResponse;
                    break;

                case "ping":
                    result.Ping = taskResult as PingResponse;
                    break;

                case "geo":
                    result.GeoIp = taskResult as GeoIpResponse;
                    break;

                default:
                    break;
                }
            }

            var entityResponse = new EntityMetadata <IpStatus, IpLookupErrors>(result, errors);

            return(entityResponse);
        }