프로젝트

일반

사용자정보

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

markus / KCOM / Extensions / DownloadProcess.cs @ 03960fa5

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

1
using System;
2
using System.Collections.Generic;
3
using System.Diagnostics;
4
using System.Globalization;
5
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

    
15
        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
                    UseShellExecute = isDebug,
30
                    FileName = PROCESS_FILE_NAME,
31
                    WindowStyle = (isDebug) ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden,
32
                    CreateNoWindow = true,
33
                    ErrorDialog = false,
34
                    Verb = "runas",
35
                    RedirectStandardInput = false,
36
                    RedirectStandardError = false,
37
                    Arguments = $"{IIpc.ProcessTypeDefine.DEFINE_THUMBNAIL} {endpoint} {isDebug} {BaseUri} {localStoragePath} {fileExt} {totalPages}"
38
                };
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
        public static bool FileDownloader(string endpoint,bool isDebug, string OriginalUri, string localPath)
56
        {
57
            bool result = false;
58

    
59
            try
60
            {
61
                Process DownloadProcess = new Process();
62

    
63
                ProcessStartInfo startInfo = new ProcessStartInfo
64
                {
65
                    UseShellExecute = isDebug,
66
                    FileName = PROCESS_FILE_NAME,
67
                    WindowStyle = (isDebug) ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden,
68
                    CreateNoWindow = true,
69
                    ErrorDialog = false,
70
                    RedirectStandardError = false,
71
                    Arguments = $"{IIpc.ProcessTypeDefine.DEFINE_FILE} {endpoint} {isDebug} {System.Web.HttpUtility.UrlEncode(OriginalUri)} {localPath}"
72
                };
73

    
74
                DownloadProcess.StartInfo = startInfo;
75
                DownloadProcess.EnableRaisingEvents = false;
76

    
77
                result = DownloadProcess.Start();
78

    
79
                processId.Add(DownloadProcess.Id);
80
            }
81
            catch (Exception ex)
82
            {
83
                result = false;
84
            }
85

    
86
            return result;
87
        }
88

    
89
        public static bool ProcessMonitor(bool isDebug,string thumbnailFolder,string tempFolder,string tempFile)
90
        {
91
            bool result = false;
92

    
93
            try
94
            {
95
                Process DownloadProcess = new Process();
96

    
97
                ProcessStartInfo startInfo = new ProcessStartInfo
98
                {
99
                    UseShellExecute = isDebug,
100
                    FileName = PROCESS_FILE_NAME,
101
                    WindowStyle = (isDebug) ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden,
102
                    CreateNoWindow = true,
103
                    ErrorDialog = false,
104
                    RedirectStandardError = false,
105
                    Arguments = $"{IIpc.ProcessTypeDefine.DEFINE_MONITOR} {isDebug} {Process.GetCurrentProcess().Id} {string.Join(" ",processId)} {thumbnailFolder} {tempFolder} {tempFile}"
106
                };
107

    
108
                DownloadProcess.StartInfo = startInfo;
109
                DownloadProcess.EnableRaisingEvents = false;
110

    
111
                result = DownloadProcess.Start();
112
            }
113
            catch (Exception ex)
114
            {
115
                result = false;
116
            }
117

    
118
            return result;
119
        }
120

    
121
        public static void ProcessKill()
122
        {
123
            for (int i = 0; i < processId.Count; i++)
124
            {
125
                try
126
                {
127

    
128
                    Process process = Process.GetProcessById(processId[i]);
129
                    process.Kill();
130
                }
131
                catch (Exception ex)
132
                {
133
                    System.Diagnostics.Debug.WriteLine(ex.ToString());
134
                }
135
            }
136
        }
137
    }
138
}
클립보드 이미지 추가 (최대 크기: 500 MB)