markus / ConvertService / ServiceBase / Markus.Service.Convert / Plugin.cs @ 43e1d368
이력 | 보기 | 이력해설 | 다운로드 (2.6 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 log4net; |
10 |
|
11 |
namespace Markus.Service |
12 |
{ |
13 |
public static class PluginService |
14 |
{ |
15 |
private const string CONFIG_FILE = "Plugin.ini"; |
16 |
private const string PLUGIN_PATH = "Plugin"; |
17 |
|
18 |
public static bool Run(string ConvertID) |
19 |
{ |
20 |
bool result = false; |
21 |
|
22 |
var baseDir = new System.IO.DirectoryInfo(AppDomain.CurrentDomain.SetupInformation.ApplicationBase).Parent.FullName; |
23 |
var pluginPath = System.IO.Path.Combine(baseDir, PLUGIN_PATH); |
24 |
var plugins = GenericPluginLoader<IPlugin>.LoadPlugins(pluginPath); |
25 |
var config = ConfigHelper.AppConfig(System.IO.Path.Combine(baseDir, CONFIG_FILE)); |
26 |
|
27 |
if (plugins != null) |
28 |
{ |
29 |
foreach (var item in plugins) |
30 |
{ |
31 |
try |
32 |
{ |
33 |
Dictionary<string, object> parameters = new Dictionary<string, object>(); |
34 |
|
35 |
var sections = config.Sections.Where(x => x.SectionName == item.Name); |
36 |
|
37 |
if (sections.Count() > 0) |
38 |
{ |
39 |
foreach (var param in sections.First().Keys) |
40 |
{ |
41 |
parameters.Add(param.Name, param.Content); |
42 |
Console.WriteLine($"{param.Name}: {param.Content}"); |
43 |
} |
44 |
|
45 |
Console.WriteLine($"{item.Name}"); |
46 |
var pluginResult = item.Do(ConvertID, parameters); |
47 |
|
48 |
Console.WriteLine($"{item.Exception}"); |
49 |
if (!pluginResult) |
50 |
{ |
51 |
Exception innerException = null; |
52 |
|
53 |
if (!string.IsNullOrWhiteSpace(item.Exception)) |
54 |
{ |
55 |
innerException = new Exception(item.Exception); |
56 |
} |
57 |
|
58 |
throw new Exception($"Plugin run Error ConvertId : {ConvertID} {item.Name}", innerException); |
59 |
} |
60 |
} |
61 |
} |
62 |
catch (Exception ex) |
63 |
{ |
64 |
throw new Exception($"PlugIn run Error :{ConvertID} {item.Name}", ex); |
65 |
} |
66 |
} |
67 |
} |
68 |
|
69 |
return result; |
70 |
} |
71 |
|
72 |
} |
73 |
} |