프로젝트

일반

사용자정보

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

markus / KCOM / Extensions / DownloadProcess.cs @ 9d5b4bc2

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

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

    
16
        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
                    UseShellExecute = isDebug,
31
                    FileName = PROCESS_FILE_NAME,
32
                    WindowStyle = (isDebug) ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden,
33
                    CreateNoWindow = true,
34
                    ErrorDialog = false,
35
                    RedirectStandardError = false,
36
                    Arguments = $"{IIpc.ProcessTypeDefine.DEFINE_THUMBNAIL} {endpoint} {isDebug} {BaseUri} {localStoragePath} {fileExt} {totalPages}"
37
                };
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
                    UseShellExecute = isDebug,
65
                    FileName = PROCESS_FILE_NAME,
66
                    WindowStyle = (isDebug) ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden,
67
                    CreateNoWindow = true,
68
                    ErrorDialog = false,
69
                    RedirectStandardError = false,
70
                    Arguments = $"{IIpc.ProcessTypeDefine.DEFINE_FILE} {endpoint} {isDebug} {OriginalUri} {localPath}"
71
                };
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
        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
        public static void ProcessKill()
121
        {
122
            for (int i = 0; i < processId.Count; i++)
123
            {
124
                try
125
                {
126

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