프로젝트

일반

사용자정보

개정판 ff4b1e6e

IDff4b1e6ecae92cf17ac75f7d78674deee4ccd0f8
상위 c517099d
하위 0630b634

김태성이(가) 5년 이상 전에 추가함

데이터베이스 nuget으로 변경

Change-Id: I6167ddf20d4cdae727b0d9047dec4fdad0dcf81a

차이점 보기:

ConvertService/ServiceBase/Markus.Service.Extensions/Exntensions/SytemNet.cs
1 1
using System;
2 2
using System.Collections.Generic;
3 3
using System.Linq;
4
using System.Net.NetworkInformation;
4 5
using System.Text;
5 6
using System.Threading.Tasks;
6 7

  
7 8
namespace Markus.Service.Extensions
8 9
{
10

  
11
    /// <summary>
12
    /// 네트워크 관련 확장코드
13
    /// </summary>
9 14
   public static  class SytemNet
10 15
    {
11
        public static bool Ping(string uri)
16
        /// <summary>
17
        /// 웹uri 활성화 상태 체크
18
        /// </summary>
19
        /// <param name="strUri"></param>
20
        /// <returns></returns>
21
        public static bool Ping(string strUri)
12 22
        {
13 23
            bool result = false;
14 24

  
15 25
            try
16 26
            {
17
                using (System.Net.Http.HttpClient Client = new System.Net.Http.HttpClient())
18
                {
19
                    var task = Client.GetAsync(uri);
27
                Uri uri = new Uri(strUri);
20 28

  
21
                    if (!task.IsFaulted)
29
                Ping pingSender = new Ping();
30
                PingReply reply = pingSender.Send(uri.Host);
31

  
32
                if (reply.Status == IPStatus.Success)
33
                {
34
                    using (System.Net.Http.HttpClient Client = new System.Net.Http.HttpClient())
22 35
                    {
23
                        System.Net.Http.HttpResponseMessage responseMessage = task.Result;
24
                        System.Net.HttpStatusCode StatusCode = responseMessage.StatusCode;
25
                        switch (StatusCode)
36
                        Client.Timeout = new TimeSpan(0, 0, 10);
37

  
38
                        var task = Client.GetAsync(uri);
39

  
40
                        if (!task.IsFaulted)
26 41
                        {
42
                            System.Net.Http.HttpResponseMessage responseMessage = task.Result;
43
                            System.Net.HttpStatusCode StatusCode = responseMessage.StatusCode;
44
                            switch (StatusCode)
45
                            {
27 46

  
28
                            case System.Net.HttpStatusCode.Accepted:
29
                            case System.Net.HttpStatusCode.OK:
30
                                result = true;
31
                                break;
47
                                case System.Net.HttpStatusCode.Accepted:
48
                                case System.Net.HttpStatusCode.OK:
49
                                    result = true;
50
                                    break;
51
                            }
32 52
                        }
33 53
                    }
34 54
                }
55
                else
56
                {
57
                    result = false;
58
                }
35 59
            }
36 60
            catch (AggregateException ae)
37 61
            {
......
45 69
                    // Rethrow any other exception.
46 70
                    else
47 71
                    {
48
                        Console.WriteLine(uri + " Connection Error");
72
                        Console.WriteLine(strUri + " Connection Error");
49 73
                    }
50 74
                }
51 75
            }

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)