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