프로젝트

일반

사용자정보

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

markus / KCOM / Extensions / DownloadProcess.cs @ 552af7c7

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

1 03960fa5 taeseongkim
using System;
2 2007ecaa taeseongkim
using System.Collections.Generic;
3
using System.Diagnostics;
4 9d5b4bc2 taeseongkim
using System.Globalization;
5 2007ecaa taeseongkim
using System.Linq;
6
using System.Reflection;
7
using System.Text;
8
using System.Threading.Tasks;
9
10
namespace KCOM
11
{
12
    public static class DownloadProcess
13
    {
14 9d5b4bc2 taeseongkim
15 2007ecaa taeseongkim
        private static List<int> processId = new List<int>();
16
17
        private static string PROCESS_FILE_NAME = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"plugin\DownloadManager.exe");
18
19
        public static bool ThumbnailDownloader(string endpoint,bool isDebug, string BaseUri, string localStoragePath, string fileExt, int totalPages)
20
        {
21
            bool result = false;
22
23
            try
24
            {
25
                Process DownloadProcess = new Process();
26
27
                ProcessStartInfo startInfo = new ProcessStartInfo
28
                {
29 9d5b4bc2 taeseongkim
                    UseShellExecute = isDebug,
30 2007ecaa taeseongkim
                    FileName = PROCESS_FILE_NAME,
31
                    WindowStyle = (isDebug) ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden,
32
                    CreateNoWindow = true,
33
                    ErrorDialog = false,
34 1223cf64 taeseongkim
                    Verb = "runas",
35
                    RedirectStandardInput = false,
36 2007ecaa taeseongkim
                    RedirectStandardError = false,
37 9d5b4bc2 taeseongkim
                    Arguments = $"{IIpc.ProcessTypeDefine.DEFINE_THUMBNAIL} {endpoint} {isDebug} {BaseUri} {localStoragePath} {fileExt} {totalPages}"
38 2007ecaa taeseongkim
                };
39
      
40
                DownloadProcess.StartInfo = startInfo;
41
                DownloadProcess.EnableRaisingEvents = false;
42
43
                result = DownloadProcess.Start();
44
45
                processId.Add(DownloadProcess.Id);
46
            }
47
            catch (Exception ex)
48
            {
49
                result = false;
50
            }
51
52
            return result;
53
        }
54
55 77cdac33 taeseongkim
        public static bool FileDownloader(string endpoint,bool isDebug, string OriginalUri, string localPath,bool IsRest)
56 2007ecaa taeseongkim
        {
57
            bool result = false;
58
59
            try
60
            {
61 77cdac33 taeseongkim
                string processType = IIpc.ProcessTypeDefine.DEFINE_FILE;
62
63
                if(IsRest)
64
                {
65
                    processType = IIpc.ProcessTypeDefine.DEFINE_REST_FILE;
66
                }
67
68 2007ecaa taeseongkim
                Process DownloadProcess = new Process();
69
70
                ProcessStartInfo startInfo = new ProcessStartInfo
71
                {
72 9d5b4bc2 taeseongkim
                    UseShellExecute = isDebug,
73 2007ecaa taeseongkim
                    FileName = PROCESS_FILE_NAME,
74
                    WindowStyle = (isDebug) ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden,
75
                    CreateNoWindow = true,
76
                    ErrorDialog = false,
77
                    RedirectStandardError = false,
78 77cdac33 taeseongkim
                    Arguments = $"{processType} {endpoint} {isDebug} {System.Web.HttpUtility.UrlEncode(OriginalUri)} {localPath}"
79 2007ecaa taeseongkim
                };
80
81
                DownloadProcess.StartInfo = startInfo;
82
                DownloadProcess.EnableRaisingEvents = false;
83
84
                result = DownloadProcess.Start();
85
86
                processId.Add(DownloadProcess.Id);
87
            }
88
            catch (Exception ex)
89
            {
90
                result = false;
91
            }
92
93
            return result;
94
        }
95
96 03960fa5 taeseongkim
        public static bool ProcessMonitor(bool isDebug,string thumbnailFolder,string tempFolder,string tempFile)
97 9d5b4bc2 taeseongkim
        {
98
            bool result = false;
99
100
            try
101
            {
102
                Process DownloadProcess = new Process();
103
104
                ProcessStartInfo startInfo = new ProcessStartInfo
105
                {
106
                    UseShellExecute = isDebug,
107
                    FileName = PROCESS_FILE_NAME,
108
                    WindowStyle = (isDebug) ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden,
109
                    CreateNoWindow = true,
110
                    ErrorDialog = false,
111
                    RedirectStandardError = false,
112 b42dd24d taeseongkim
#if DOWNLOAD_TEST
113
                    Arguments = $"{IIpc.ProcessTypeDefine.DEFINE_MONITOR} {isDebug} {Process.GetCurrentProcess().Id} {string.Join(" ",processId)} {thumbnailFolder} {tempFolder} {tempFile} {"http://localhost:44301"}"
114
#else
115 77cdac33 taeseongkim
                    Arguments = $"{IIpc.ProcessTypeDefine.DEFINE_MONITOR} {isDebug} {Process.GetCurrentProcess().Id} {string.Join(" ",processId)} {thumbnailFolder} {tempFolder} {tempFile} {App.BaseAddress}"
116 b42dd24d taeseongkim
#endif
117 9d5b4bc2 taeseongkim
                };
118
119
                DownloadProcess.StartInfo = startInfo;
120
                DownloadProcess.EnableRaisingEvents = false;
121
122
                result = DownloadProcess.Start();
123
            }
124
            catch (Exception ex)
125
            {
126
                result = false;
127
            }
128
129
            return result;
130
        }
131
132 2007ecaa taeseongkim
        public static void ProcessKill()
133
        {
134
            for (int i = 0; i < processId.Count; i++)
135
            {
136
                try
137
                {
138
139 9d5b4bc2 taeseongkim
                    Process process = Process.GetProcessById(processId[i]);
140
                    process.Kill();
141 2007ecaa taeseongkim
                }
142
                catch (Exception ex)
143
                {
144
                    System.Diagnostics.Debug.WriteLine(ex.ToString());
145
                }
146
            }
147
        }
148
    }
149
}
클립보드 이미지 추가 (최대 크기: 500 MB)