markus / KCOM / Extensions / DownloadProcess.cs @ cc749215
이력 | 보기 | 이력해설 | 다운로드 (4.54 KB)
1 | 9d5b4bc2 | taeseongkim | using Salaros.Configuration; |
---|---|---|---|
2 | using System; |
||
3 | 2007ecaa | taeseongkim | using System.Collections.Generic; |
4 | using System.Diagnostics; |
||
5 | 9d5b4bc2 | taeseongkim | using System.Globalization; |
6 | 2007ecaa | taeseongkim | using System.Linq; |
7 | using System.Reflection; |
||
8 | using System.Text; |
||
9 | using System.Threading.Tasks; |
||
10 | |||
11 | namespace KCOM |
||
12 | { |
||
13 | public static class DownloadProcess |
||
14 | { |
||
15 | 9d5b4bc2 | taeseongkim | |
16 | 2007ecaa | taeseongkim | private static List<int> processId = new List<int>(); |
17 | |||
18 | private static string PROCESS_FILE_NAME = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"plugin\DownloadManager.exe"); |
||
19 | |||
20 | public static bool ThumbnailDownloader(string endpoint,bool isDebug, string BaseUri, string localStoragePath, string fileExt, int totalPages) |
||
21 | { |
||
22 | bool result = false; |
||
23 | |||
24 | try |
||
25 | { |
||
26 | Process DownloadProcess = new Process(); |
||
27 | |||
28 | ProcessStartInfo startInfo = new ProcessStartInfo |
||
29 | { |
||
30 | 9d5b4bc2 | taeseongkim | UseShellExecute = isDebug, |
31 | 2007ecaa | taeseongkim | FileName = PROCESS_FILE_NAME, |
32 | WindowStyle = (isDebug) ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden, |
||
33 | CreateNoWindow = true, |
||
34 | ErrorDialog = false, |
||
35 | RedirectStandardError = false, |
||
36 | 9d5b4bc2 | taeseongkim | Arguments = $"{IIpc.ProcessTypeDefine.DEFINE_THUMBNAIL} {endpoint} {isDebug} {BaseUri} {localStoragePath} {fileExt} {totalPages}" |
37 | 2007ecaa | taeseongkim | }; |
38 | |||
39 | DownloadProcess.StartInfo = startInfo; |
||
40 | DownloadProcess.EnableRaisingEvents = false; |
||
41 | |||
42 | result = DownloadProcess.Start(); |
||
43 | |||
44 | processId.Add(DownloadProcess.Id); |
||
45 | } |
||
46 | catch (Exception ex) |
||
47 | { |
||
48 | result = false; |
||
49 | } |
||
50 | |||
51 | return result; |
||
52 | } |
||
53 | |||
54 | public static bool FileDownloader(string endpoint,bool isDebug, string OriginalUri, string localPath) |
||
55 | { |
||
56 | bool result = false; |
||
57 | |||
58 | try |
||
59 | { |
||
60 | Process DownloadProcess = new Process(); |
||
61 | |||
62 | ProcessStartInfo startInfo = new ProcessStartInfo |
||
63 | { |
||
64 | 9d5b4bc2 | taeseongkim | UseShellExecute = isDebug, |
65 | 2007ecaa | taeseongkim | FileName = PROCESS_FILE_NAME, |
66 | WindowStyle = (isDebug) ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden, |
||
67 | CreateNoWindow = true, |
||
68 | ErrorDialog = false, |
||
69 | RedirectStandardError = false, |
||
70 | 664ea2e1 | taeseongkim | Arguments = $"{IIpc.ProcessTypeDefine.DEFINE_FILE} {endpoint} {isDebug} {System.Web.HttpUtility.UrlEncode(OriginalUri)} {localPath}" |
71 | 2007ecaa | taeseongkim | }; |
72 | |||
73 | DownloadProcess.StartInfo = startInfo; |
||
74 | DownloadProcess.EnableRaisingEvents = false; |
||
75 | |||
76 | result = DownloadProcess.Start(); |
||
77 | |||
78 | processId.Add(DownloadProcess.Id); |
||
79 | } |
||
80 | catch (Exception ex) |
||
81 | { |
||
82 | result = false; |
||
83 | } |
||
84 | |||
85 | return result; |
||
86 | } |
||
87 | |||
88 | 9d5b4bc2 | taeseongkim | public static bool ProcessMonitor(bool isDebug,string thumbnailFolder) |
89 | { |
||
90 | bool result = false; |
||
91 | |||
92 | try |
||
93 | { |
||
94 | Process DownloadProcess = new Process(); |
||
95 | |||
96 | ProcessStartInfo startInfo = new ProcessStartInfo |
||
97 | { |
||
98 | UseShellExecute = isDebug, |
||
99 | FileName = PROCESS_FILE_NAME, |
||
100 | WindowStyle = (isDebug) ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden, |
||
101 | CreateNoWindow = true, |
||
102 | ErrorDialog = false, |
||
103 | RedirectStandardError = false, |
||
104 | Arguments = $"{IIpc.ProcessTypeDefine.DEFINE_MONITOR} {isDebug} {Process.GetCurrentProcess().Id} {string.Join(" ",processId)} {thumbnailFolder} {App.PageStorage.LocalStorage} {Common.ViewerDataModel.Instance.OriginalTempFile}" |
||
105 | }; |
||
106 | |||
107 | DownloadProcess.StartInfo = startInfo; |
||
108 | DownloadProcess.EnableRaisingEvents = false; |
||
109 | |||
110 | result = DownloadProcess.Start(); |
||
111 | } |
||
112 | catch (Exception ex) |
||
113 | { |
||
114 | result = false; |
||
115 | } |
||
116 | |||
117 | return result; |
||
118 | } |
||
119 | |||
120 | 2007ecaa | taeseongkim | public static void ProcessKill() |
121 | { |
||
122 | for (int i = 0; i < processId.Count; i++) |
||
123 | { |
||
124 | try |
||
125 | { |
||
126 | |||
127 | 9d5b4bc2 | taeseongkim | Process process = Process.GetProcessById(processId[i]); |
128 | process.Kill(); |
||
129 | 2007ecaa | taeseongkim | } |
130 | catch (Exception ex) |
||
131 | { |
||
132 | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
133 | } |
||
134 | } |
||
135 | } |
||
136 | } |
||
137 | } |