markus / KCOM / Extensions / DownloadProcess.cs @ 2007ecaa
이력 | 보기 | 이력해설 | 다운로드 (3.15 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Diagnostics; |
4 |
using System.Linq; |
5 |
using System.Reflection; |
6 |
using System.Text; |
7 |
using System.Threading.Tasks; |
8 |
|
9 |
namespace KCOM |
10 |
{ |
11 |
public static class DownloadProcess |
12 |
{ |
13 |
private static List<int> processId = new List<int>(); |
14 |
|
15 |
private static string PROCESS_FILE_NAME = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"plugin\DownloadManager.exe"); |
16 |
|
17 |
public static bool ThumbnailDownloader(string endpoint,bool isDebug, string BaseUri, string localStoragePath, string fileExt, int totalPages) |
18 |
{ |
19 |
bool result = false; |
20 |
|
21 |
try |
22 |
{ |
23 |
Process DownloadProcess = new Process(); |
24 |
|
25 |
ProcessStartInfo startInfo = new ProcessStartInfo |
26 |
{ |
27 |
UseShellExecute = false, |
28 |
FileName = PROCESS_FILE_NAME, |
29 |
WindowStyle = (isDebug) ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden, |
30 |
CreateNoWindow = true, |
31 |
ErrorDialog = false, |
32 |
RedirectStandardError = false, |
33 |
Arguments = $"THUMBNAIL {endpoint} {isDebug} {BaseUri} {localStoragePath} {fileExt} {totalPages}" |
34 |
}; |
35 |
|
36 |
DownloadProcess.StartInfo = startInfo; |
37 |
DownloadProcess.EnableRaisingEvents = false; |
38 |
|
39 |
result = DownloadProcess.Start(); |
40 |
|
41 |
processId.Add(DownloadProcess.Id); |
42 |
} |
43 |
catch (Exception ex) |
44 |
{ |
45 |
result = false; |
46 |
} |
47 |
|
48 |
return result; |
49 |
} |
50 |
|
51 |
public static bool FileDownloader(string endpoint,bool isDebug, string OriginalUri, string localPath) |
52 |
{ |
53 |
bool result = false; |
54 |
|
55 |
try |
56 |
{ |
57 |
Process DownloadProcess = new Process(); |
58 |
|
59 |
ProcessStartInfo startInfo = new ProcessStartInfo |
60 |
{ |
61 |
UseShellExecute = false, |
62 |
FileName = PROCESS_FILE_NAME, |
63 |
WindowStyle = (isDebug) ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden, |
64 |
CreateNoWindow = true, |
65 |
ErrorDialog = false, |
66 |
RedirectStandardError = false, |
67 |
Arguments = $"FILE {endpoint} {isDebug} {OriginalUri} {localPath}" |
68 |
}; |
69 |
|
70 |
DownloadProcess.StartInfo = startInfo; |
71 |
DownloadProcess.EnableRaisingEvents = false; |
72 |
|
73 |
result = DownloadProcess.Start(); |
74 |
|
75 |
processId.Add(DownloadProcess.Id); |
76 |
} |
77 |
catch (Exception ex) |
78 |
{ |
79 |
result = false; |
80 |
} |
81 |
|
82 |
return result; |
83 |
} |
84 |
|
85 |
public static void ProcessKill() |
86 |
{ |
87 |
for (int i = 0; i < processId.Count; i++) |
88 |
{ |
89 |
try |
90 |
{ |
91 |
|
92 |
Process.GetProcessById(processId[i]).Kill(); |
93 |
} |
94 |
catch (Exception ex) |
95 |
{ |
96 |
System.Diagnostics.Debug.WriteLine(ex.ToString()); |
97 |
} |
98 |
} |
99 |
} |
100 |
} |
101 |
} |