프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / DownloadManager / Program.cs @ 2007ecaa

이력 | 보기 | 이력해설 | 다운로드 (3.86 KB)

1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6

    
7
namespace DownloadManager
8
{
9
    class Program
10
    {
11
        static IIpc.WcfClient wcfClient;
12
        static bool IsDownload;
13
        static bool IsDebug;
14
        static int TotalPages = 0;
15

    
16
        static void Main(string[] args)
17
        {
18
            if (args.Length > 0)
19
            {
20
                wcfClient = new IIpc.WcfClient(args[1]);
21
                IsDebug = bool.Parse(args[2]);
22

    
23
                if (args[0] == "THUMBNAIL")
24
                {
25
                    string BaseUri = args[3];
26
                    string localStoragePath = args[4];
27
                    string fileExt = args[5];
28
                    int totalPages = int.Parse(args[6]);
29
                    int takeCount = int.Parse(args[6]);
30

    
31
                    TotalPages = totalPages;
32

    
33
                    KCOM.PageManager.PageStorage pageStorage = new KCOM.PageManager.PageStorage(BaseUri, localStoragePath, fileExt, totalPages, takeCount);
34
                    pageStorage.PageLoadCompleted += PageStorage_PageLoadCompleted;
35
                    pageStorage.DownloadWork(1, totalPages);
36
                }
37
                else if(args[0] == "FILE")
38
                {
39
                    using (System.Net.WebClient client = new System.Net.WebClient())
40
                    {
41
                        client.DownloadFileCompleted += Client_DownloadFileCompleted;
42
                        client.DownloadProgressChanged += Client_DownloadProgressChanged;
43
                        client.UseDefaultCredentials = true;
44
                        System.Net.IWebProxy webProxy = client.Proxy;
45

    
46
                        if (webProxy != null)
47
                        {
48
                            webProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
49
                        }
50

    
51
                        client.DownloadFileAsync(new Uri(args[3]), args[4]);
52
                        
53
                    }
54
                }
55

    
56
                while (!IsDownload)
57
                {
58
                    System.Threading.Thread.Sleep(1000);
59
                }
60

    
61
                if(IsDebug)
62
                {
63
                    Console.ReadLine();
64
                }
65
            }
66
        }
67

    
68
        private static void ConsoleWrite(string data)
69
        {
70
            if (IsDebug)
71
            {
72
                Console.WriteLine(data);
73
            }
74
        }
75

    
76

    
77
        private static void Client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
78
        {
79
            try
80
            {
81
                wcfClient.SendFileDownloadReceived(100, true);
82

    
83
                ConsoleWrite($"Download file Completed");
84
                IsDownload = true;
85
            }
86
            catch (Exception ex)
87
            {
88
                ConsoleWrite(ex.ToString());
89
            }
90
        }
91

    
92
        private static void Client_DownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e)
93
        {
94
            try
95
            {
96
                wcfClient.SendFileDownloadReceived(e.ProgressPercentage, false);
97

    
98
                ConsoleWrite($"Download file {e.ProgressPercentage}");
99
            }
100
            catch (Exception ex)
101
            {
102
                ConsoleWrite(ex.ToString());
103
            }
104
        }
105

    
106
        private static void PageStorage_PageLoadCompleted(object sender, KCOM.PageManager.PageLoadCompletedEventArgs e)
107
        {
108
            try
109
            {
110
                wcfClient.SendThumbnailReceived(e.PageItem.PageNo, e.PageItem.LocalFilePath);
111

    
112
                ConsoleWrite($"{e.PageItem.PageNo} {e.PageItem.LocalUri}");
113

    
114
                if (e.PageItem.PageNo == TotalPages)
115
                {
116
                    IsDownload = true;
117
                }
118
            }
119
            catch (Exception ex)
120
            {
121
                ConsoleWrite(ex.ToString());
122
            }
123
            
124
        }
125
    }
126
}
클립보드 이미지 추가 (최대 크기: 500 MB)