markus / ConvertService / ServiceBase / Markus.Service.Convert / DownloadPlugin.cs @ 8ebd5302
이력 | 보기 | 이력해설 | 다운로드 (2.42 KB)
1 |
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 |
using Markus.Message; |
10 |
|
11 |
namespace Markus.Service |
12 |
{ |
13 |
public static class DownloadPluginService |
14 |
{ |
15 |
private const string BasePath = "DownloadPlugin"; |
16 |
|
17 |
public static FileDownloadResult Download(string PdfFileFullPath, string SaveDirectory) |
18 |
{ |
19 |
FileDownloadResult result = new FileDownloadResult(); |
20 |
|
21 |
string error = ""; |
22 |
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 |
|
26 |
var plugins = GenericPluginLoader<IDownloadPlugin>.LoadPlugins(pluginPath); |
27 |
|
28 |
if (plugins != null) |
29 |
{ |
30 |
foreach (var item in plugins) |
31 |
{ |
32 |
string downloadFilePath = null; |
33 |
|
34 |
bool pluginResult = false; |
35 |
|
36 |
try |
37 |
{ |
38 |
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 |
} |
53 |
catch (Exception ex) |
54 |
{ |
55 |
var msg = $"plugin Error : {item.Name} {ex.ToString()}"; |
56 |
Console.WriteLine(msg); |
57 |
error += ex.ToString(); |
58 |
} |
59 |
|
60 |
} |
61 |
|
62 |
if (!result.IsSuccess) |
63 |
{ |
64 |
result.Exception = new Exception("download plugin Error : " + error); |
65 |
} |
66 |
} |
67 |
else |
68 |
{ |
69 |
result.Exception = new Exception("plugins is null"); |
70 |
|
71 |
} |
72 |
|
73 |
return result; |
74 |
} |
75 |
|
76 |
} |
77 |
} |