markus / ConvertService / ServiceBase / Markus.Service.Convert / DownloadPlugin.cs @ 8ebd5302
이력 | 보기 | 이력해설 | 다운로드 (2.42 KB)
1 | 950e6b84 | taeseongkim | using Markus.Service.Extensions; |
---|---|---|---|
2 | using Markus.Service.Helper; |
||
3 | using System; |
||
4 | using System.Collections.Generic; |
||
5 | using System.Linq; |
||
6 | using System.Text; |
||
7 | using System.Threading.Tasks; |
||
8 | using Markus.Service.Convert.Plugin; |
||
9 | 1d79913e | taeseongkim | using Markus.Message; |
10 | 950e6b84 | taeseongkim | |
11 | namespace Markus.Service |
||
12 | { |
||
13 | public static class DownloadPluginService |
||
14 | { |
||
15 | private const string BasePath = "DownloadPlugin"; |
||
16 | |||
17 | 1d79913e | taeseongkim | public static FileDownloadResult Download(string PdfFileFullPath, string SaveDirectory) |
18 | 950e6b84 | taeseongkim | { |
19 | 1d79913e | taeseongkim | FileDownloadResult result = new FileDownloadResult(); |
20 | |||
21 | 950e6b84 | taeseongkim | string error = ""; |
22 | 43e1d368 | taeseongkim | var baseDir = new System.IO.DirectoryInfo(AppDomain.CurrentDomain.SetupInformation.ApplicationBase).Parent.FullName; |
23 | var pluginPath = System.IO.Path.Combine(baseDir, BasePath); |
||
24 | Console.WriteLine(pluginPath); |
||
25 | 950e6b84 | taeseongkim | |
26 | var plugins = GenericPluginLoader<IDownloadPlugin>.LoadPlugins(pluginPath); |
||
27 | |||
28 | if (plugins != null) |
||
29 | { |
||
30 | foreach (var item in plugins) |
||
31 | { |
||
32 | 1d79913e | taeseongkim | string downloadFilePath = null; |
33 | |||
34 | bool pluginResult = false; |
||
35 | |||
36 | try |
||
37 | 950e6b84 | taeseongkim | { |
38 | 1d79913e | taeseongkim | pluginResult = item.Do(PdfFileFullPath, SaveDirectory, ref downloadFilePath); |
39 | |||
40 | if (pluginResult) |
||
41 | { |
||
42 | result.DownloadFilePath = downloadFilePath; |
||
43 | result.IsSuccess = true; |
||
44 | break; |
||
45 | } |
||
46 | else |
||
47 | { |
||
48 | var msg = $" not working {item.Name} {item.Exception}"; |
||
49 | Console.WriteLine(msg); |
||
50 | error += msg; |
||
51 | } |
||
52 | 950e6b84 | taeseongkim | } |
53 | 1d79913e | taeseongkim | catch (Exception ex) |
54 | 950e6b84 | taeseongkim | { |
55 | 1d79913e | taeseongkim | var msg = $"plugin Error : {item.Name} {ex.ToString()}"; |
56 | d91efe5c | taeseongkim | Console.WriteLine(msg); |
57 | 1d79913e | taeseongkim | error += ex.ToString(); |
58 | 950e6b84 | taeseongkim | } |
59 | 1d79913e | taeseongkim | |
60 | 950e6b84 | taeseongkim | } |
61 | |||
62 | 1d79913e | taeseongkim | if (!result.IsSuccess) |
63 | 950e6b84 | taeseongkim | { |
64 | 1d79913e | taeseongkim | result.Exception = new Exception("download plugin Error : " + error); |
65 | 950e6b84 | taeseongkim | } |
66 | } |
||
67 | d91efe5c | taeseongkim | else |
68 | { |
||
69 | 1d79913e | taeseongkim | result.Exception = new Exception("plugins is null"); |
70 | |||
71 | d91efe5c | taeseongkim | } |
72 | 950e6b84 | taeseongkim | |
73 | return result; |
||
74 | } |
||
75 | |||
76 | } |
||
77 | } |