프로젝트

일반

사용자정보

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

markus / KCOM / Extensions / DownloadProcess.cs @ 2421b3ea

이력 | 보기 | 이력해설 | 다운로드 (4.62 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 1223cf64 taeseongkim
                    Verb = "runas",
36
                    RedirectStandardInput = false,
37 2007ecaa taeseongkim
                    RedirectStandardError = false,
38 9d5b4bc2 taeseongkim
                    Arguments = $"{IIpc.ProcessTypeDefine.DEFINE_THUMBNAIL} {endpoint} {isDebug} {BaseUri} {localStoragePath} {fileExt} {totalPages}"
39 2007ecaa taeseongkim
                };
40
      
41
                DownloadProcess.StartInfo = startInfo;
42
                DownloadProcess.EnableRaisingEvents = false;
43
44
                result = DownloadProcess.Start();
45
46
                processId.Add(DownloadProcess.Id);
47
            }
48
            catch (Exception ex)
49
            {
50
                result = false;
51
            }
52
53
            return result;
54
        }
55
56
        public static bool FileDownloader(string endpoint,bool isDebug, string OriginalUri, string localPath)
57
        {
58
            bool result = false;
59
60
            try
61
            {
62
                Process DownloadProcess = new Process();
63
64
                ProcessStartInfo startInfo = new ProcessStartInfo
65
                {
66 9d5b4bc2 taeseongkim
                    UseShellExecute = isDebug,
67 2007ecaa taeseongkim
                    FileName = PROCESS_FILE_NAME,
68
                    WindowStyle = (isDebug) ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden,
69
                    CreateNoWindow = true,
70
                    ErrorDialog = false,
71
                    RedirectStandardError = false,
72 664ea2e1 taeseongkim
                    Arguments = $"{IIpc.ProcessTypeDefine.DEFINE_FILE} {endpoint} {isDebug} {System.Web.HttpUtility.UrlEncode(OriginalUri)} {localPath}"
73 2007ecaa taeseongkim
                };
74
75
                DownloadProcess.StartInfo = startInfo;
76
                DownloadProcess.EnableRaisingEvents = false;
77
78
                result = DownloadProcess.Start();
79
80
                processId.Add(DownloadProcess.Id);
81
            }
82
            catch (Exception ex)
83
            {
84
                result = false;
85
            }
86
87
            return result;
88
        }
89
90 9d5b4bc2 taeseongkim
        public static bool ProcessMonitor(bool isDebug,string thumbnailFolder)
91
        {
92
            bool result = false;
93
94
            try
95
            {
96
                Process DownloadProcess = new Process();
97
98
                ProcessStartInfo startInfo = new ProcessStartInfo
99
                {
100
                    UseShellExecute = isDebug,
101
                    FileName = PROCESS_FILE_NAME,
102
                    WindowStyle = (isDebug) ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden,
103
                    CreateNoWindow = true,
104
                    ErrorDialog = false,
105
                    RedirectStandardError = false,
106
                    Arguments = $"{IIpc.ProcessTypeDefine.DEFINE_MONITOR} {isDebug} {Process.GetCurrentProcess().Id} {string.Join(" ",processId)} {thumbnailFolder} {App.PageStorage.LocalStorage} {Common.ViewerDataModel.Instance.OriginalTempFile}"
107
                };
108
109
                DownloadProcess.StartInfo = startInfo;
110
                DownloadProcess.EnableRaisingEvents = false;
111
112
                result = DownloadProcess.Start();
113
            }
114
            catch (Exception ex)
115
            {
116
                result = false;
117
            }
118
119
            return result;
120
        }
121
122 2007ecaa taeseongkim
        public static void ProcessKill()
123
        {
124
            for (int i = 0; i < processId.Count; i++)
125
            {
126
                try
127
                {
128
129 9d5b4bc2 taeseongkim
                    Process process = Process.GetProcessById(processId[i]);
130
                    process.Kill();
131 2007ecaa taeseongkim
                }
132
                catch (Exception ex)
133
                {
134
                    System.Diagnostics.Debug.WriteLine(ex.ToString());
135
                }
136
            }
137
        }
138
    }
139
}
클립보드 이미지 추가 (최대 크기: 500 MB)