개정판 9d5b4bc2
auto Update 기능 추가
Change-Id: I195d4506bd1dd9cfd58dbdeada74e89a1b9d307e
DownloadManager/Program.cs | ||
---|---|---|
1 |
using System; |
|
1 |
|
|
2 |
using System; |
|
2 | 3 |
using System.Collections.Generic; |
4 |
using System.Diagnostics; |
|
5 |
using System.Globalization; |
|
3 | 6 |
using System.Linq; |
4 | 7 |
using System.Text; |
5 | 8 |
using System.Threading.Tasks; |
... | ... | |
8 | 11 |
{ |
9 | 12 |
class Program |
10 | 13 |
{ |
14 |
private static string TEMP_FOLDER = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "MARKUS"); |
|
15 |
|
|
11 | 16 |
static IIpc.WcfClient wcfClient; |
12 | 17 |
static bool IsDownload; |
13 | 18 |
static bool IsDebug; |
14 | 19 |
static int TotalPages = 0; |
15 | 20 |
|
21 |
//private const string SECTION_DOWNLOAD_FILE = "DOWNLOAD_FILE"; |
|
22 |
|
|
23 |
//private const string SECTION_DOWNLOAD_DIR = "DOWNLOAD_DIR"; |
|
24 |
|
|
25 |
//private const string KEY_VALUES = "VALUE"; |
|
26 |
|
|
27 |
|
|
28 |
//private static string DOWNLOAD_LOG_FILE = System.IO.Path.Combine(TEMP_FOLDER, "Download.log"); |
|
29 |
|
|
30 |
//private static ConfigParser DOWNLOAD_LOG = new ConfigParser(DOWNLOAD_LOG_FILE, |
|
31 |
// new ConfigParserSettings |
|
32 |
// { |
|
33 |
// MultiLineValues = MultiLineValues.Simple | MultiLineValues.AllowValuelessKeys | MultiLineValues.QuoteDelimitedValues, |
|
34 |
// Culture = new CultureInfo("en-US") |
|
35 |
// }); |
|
36 |
|
|
37 |
|
|
16 | 38 |
static void Main(string[] args) |
17 | 39 |
{ |
18 |
if (args.Length > 0)
|
|
40 |
try
|
|
19 | 41 |
{ |
20 |
wcfClient = new IIpc.WcfClient(args[1]); |
|
21 |
IsDebug = bool.Parse(args[2]); |
|
22 | 42 |
|
23 |
if (args[0] == "THUMBNAIL")
|
|
43 |
if (args.Length > 0)
|
|
24 | 44 |
{ |
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]); |
|
45 |
for (int i = 0; i < args.Length; i++) |
|
46 |
{ |
|
47 |
ConsoleWrite(args[i]); |
|
48 |
} |
|
30 | 49 |
|
31 |
TotalPages = totalPages; |
|
50 |
//if (args[0] == IIpc.ProcessTypeDefine.DEFINE_DELETE) |
|
51 |
//{ |
|
52 |
// IsDebug = bool.Parse(args[1]); |
|
32 | 53 |
|
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()) |
|
54 |
// DeleteFiles(); |
|
55 |
//} |
|
56 |
if (args[0] == IIpc.ProcessTypeDefine.DEFINE_MONITOR) |
|
57 |
{ |
|
58 |
IsDebug = bool.Parse(args[1]); |
|
59 |
int processId = int.Parse(args[2]); /// kcom process id |
|
60 |
int thumbnamilPID = int.Parse(args[3]); |
|
61 |
int filePID = int.Parse(args[4]); |
|
62 |
|
|
63 |
string folder1 = args[5]; // folder |
|
64 |
string folder2 = args[6]; // folder |
|
65 |
string file = args[7]; // file |
|
66 |
|
|
67 |
try |
|
68 |
{ |
|
69 |
Process process = FindProcess(processId); |
|
70 |
|
|
71 |
while (process != null) |
|
72 |
{ |
|
73 |
process = FindProcess(processId); |
|
74 |
|
|
75 |
ConsoleWrite("Process Check"); |
|
76 |
|
|
77 |
System.Threading.Thread.Sleep(10000); |
|
78 |
} |
|
79 |
|
|
80 |
var p1 = FindProcess(thumbnamilPID); |
|
81 |
|
|
82 |
if (p1 != null) |
|
83 |
{ |
|
84 |
p1.Kill(); |
|
85 |
} |
|
86 |
|
|
87 |
|
|
88 |
var p2 = FindProcess(filePID); |
|
89 |
|
|
90 |
if (p2 != null) |
|
91 |
{ |
|
92 |
p2.Kill(); |
|
93 |
} |
|
94 |
} |
|
95 |
catch (Exception ex) |
|
96 |
{ |
|
97 |
ConsoleWrite(ex.ToString()); |
|
98 |
} |
|
99 |
|
|
100 |
DeleteFiles(IIpc.ProcessTypeDefine.DEFINE_THUMBNAIL, folder1); |
|
101 |
DeleteFiles(IIpc.ProcessTypeDefine.DEFINE_THUMBNAIL, folder2); |
|
102 |
DeleteFiles(IIpc.ProcessTypeDefine.DEFINE_FILE, file); |
|
103 |
} |
|
104 |
else |
|
40 | 105 |
{ |
41 |
client.DownloadFileCompleted += Client_DownloadFileCompleted; |
|
42 |
client.DownloadProgressChanged += Client_DownloadProgressChanged; |
|
43 |
client.UseDefaultCredentials = true; |
|
44 |
System.Net.IWebProxy webProxy = client.Proxy; |
|
106 |
wcfClient = new IIpc.WcfClient(args[1]); |
|
107 |
IsDebug = bool.Parse(args[2]); |
|
108 |
|
|
109 |
if (args[0] == IIpc.ProcessTypeDefine.DEFINE_THUMBNAIL) |
|
110 |
{ |
|
111 |
string BaseUri = args[3]; |
|
112 |
string localStoragePath = args[4]; |
|
113 |
string fileExt = args[5]; |
|
114 |
int totalPages = int.Parse(args[6]); |
|
115 |
int takeCount = int.Parse(args[6]); |
|
116 |
|
|
117 |
TotalPages = totalPages; |
|
45 | 118 |
|
46 |
if (webProxy != null) |
|
119 |
KCOM.PageManager.PageStorage pageStorage = new KCOM.PageManager.PageStorage(BaseUri, localStoragePath, fileExt, totalPages, takeCount); |
|
120 |
pageStorage.PageLoadCompleted += PageStorage_PageLoadCompleted; |
|
121 |
pageStorage.DownloadWork(1, totalPages); |
|
122 |
} |
|
123 |
else if (args[0] == IIpc.ProcessTypeDefine.DEFINE_FILE) |
|
124 |
{ |
|
125 |
using (System.Net.WebClient client = new System.Net.WebClient()) |
|
126 |
{ |
|
127 |
client.DownloadFileCompleted += Client_DownloadFileCompleted; |
|
128 |
client.DownloadProgressChanged += Client_DownloadProgressChanged; |
|
129 |
client.UseDefaultCredentials = true; |
|
130 |
System.Net.IWebProxy webProxy = client.Proxy; |
|
131 |
|
|
132 |
if (webProxy != null) |
|
133 |
{ |
|
134 |
webProxy.Credentials = System.Net.CredentialCache.DefaultCredentials; |
|
135 |
} |
|
136 |
|
|
137 |
client.DownloadFileAsync(new Uri(args[3]), args[4]); |
|
138 |
} |
|
139 |
} |
|
140 |
|
|
141 |
while (!IsDownload) |
|
47 | 142 |
{ |
48 |
webProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
|
|
143 |
System.Threading.Thread.Sleep(1000);
|
|
49 | 144 |
} |
50 | 145 |
|
51 |
client.DownloadFileAsync(new Uri(args[3]), args[4]); |
|
52 |
|
|
146 |
} |
|
147 |
|
|
148 |
if (IsDebug) |
|
149 |
{ |
|
150 |
Console.ReadLine(); |
|
53 | 151 |
} |
54 | 152 |
} |
153 |
} |
|
154 |
catch (Exception ex) |
|
155 |
{ |
|
156 |
|
|
157 |
System.Diagnostics.Debug.WriteLine(ex); |
|
158 |
} |
|
159 |
} |
|
160 |
|
|
161 |
public static void DeleteFiles(string processType, string path) |
|
162 |
{ |
|
163 |
if(processType == IIpc.ProcessTypeDefine.DEFINE_THUMBNAIL) |
|
164 |
{ |
|
165 |
var dir = System.IO.Directory.GetDirectories(path, "*.*", System.IO.SearchOption.AllDirectories); |
|
55 | 166 |
|
56 |
while (!IsDownload) |
|
167 |
for (int i = 0; i < dir.Length; i++) |
|
168 |
{ |
|
169 |
System.IO.Directory.Delete(dir[i],true); |
|
170 |
} |
|
171 |
} |
|
172 |
else |
|
173 |
{ |
|
174 |
if (System.IO.File.Exists(path)) |
|
57 | 175 |
{ |
58 |
System.Threading.Thread.Sleep(1000);
|
|
176 |
System.IO.File.Delete(path);
|
|
59 | 177 |
} |
178 |
} |
|
179 |
} |
|
60 | 180 |
|
61 |
if(IsDebug) |
|
181 |
private static Process FindProcess(int id) |
|
182 |
{ |
|
183 |
Process result = null; |
|
184 |
|
|
185 |
try |
|
186 |
{ |
|
187 |
var process = Process.GetProcesses().Where(x=>x.Id == id); |
|
188 |
|
|
189 |
if(process.Count()> 0) |
|
62 | 190 |
{ |
63 |
Console.ReadLine();
|
|
191 |
result = process.First();
|
|
64 | 192 |
} |
65 | 193 |
} |
194 |
catch (Exception) |
|
195 |
{ |
|
196 |
} |
|
197 |
|
|
198 |
return result; |
|
66 | 199 |
} |
67 | 200 |
|
201 |
|
|
68 | 202 |
private static void ConsoleWrite(string data) |
69 | 203 |
{ |
70 | 204 |
if (IsDebug) |
내보내기 Unified diff