프로젝트

일반

사용자정보

개정판 db0d3db3

IDdb0d3db3ed2cdd5973b82d5cb6456112cabafbf5
상위 9d62a702
하위 150747cb

김태성이(가) 5년 이상 전에 추가함

플러그인 실행시점 변경.

Change-Id: I947238b7503125168178c893fe47732c93fb0ef8

차이점 보기:

ConvertService/ServiceBase/Markus.Service.Convert/ConvertService.cs
90 90
            }
91 91
        }
92 92

  
93

  
94 93
        /// <summary>
95 94
        ///  markus lib에서 받는 이벤트
96 95
        /// </summary>
......
161 160

  
162 161
                result = await ConvertAsync(saveitem);
163 162

  
163
                // 플러그인 실행
164
                PluginService.Run(saveitem.Id);
165
             
164 166
                StationServiceClient.ConvertFinish(saveitem.Id, (int)result.StatusCode, saveitem.CurrentPage, saveitem.TotalPages,result.Message);
165 167
            }
166 168
            catch (Exception ex)
167 169
            {
170
                result.StatusCode = StatusCodeType.Error;
168 171
                logger.Error($"File Convert Error",ex);
169
                StationServiceClient.ConvertFinish(saveitem.Id, (int)result.StatusCode, saveitem.CurrentPage, saveitem.TotalPages, $"ConvertService Error    {saveitem.Id}");
172
                StationServiceClient.ConvertFinish(saveitem.Id, (int)result.StatusCode, saveitem.CurrentPage, saveitem.TotalPages, $"ConvertService Error    {saveitem.Id} {ex.Message} {ex.InnerException?.ToString()}");
170 173
            }
171 174

  
172 175
            return result;
ConvertService/ServiceBase/Markus.Service.Convert/Markus.Service.Convert.csproj
51 51
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
52 52
  </PropertyGroup>
53 53
  <ItemGroup>
54
    <Reference Include="ConfigParser, Version=0.3.3.6, Culture=neutral, processorArchitecture=MSIL">
55
      <HintPath>..\packages\Salaros.ConfigParser.0.3.3\lib\net45\ConfigParser.dll</HintPath>
56
    </Reference>
54 57
    <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
55 58
      <HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath>
56 59
    </Reference>
......
85 88
  </ItemGroup>
86 89
  <ItemGroup>
87 90
    <Compile Include="ConvertService.cs" />
91
    <Compile Include="Plugin.cs" />
88 92
    <Compile Include="Properties\AssemblyInfo.cs" />
89 93
  </ItemGroup>
90 94
  <ItemGroup>
......
92 96
      <Project>{4a465fd0-8130-4d6b-a65f-c3cd6cc355a4}</Project>
93 97
      <Name>Markus.Service.Interface</Name>
94 98
    </ProjectReference>
99
    <ProjectReference Include="..\Markus.Service.Convert.IPlugin\Markus.Service.Convert.IPlugin.csproj">
100
      <Project>{a5ba7325-379c-4ccb-b156-1704fc2175e3}</Project>
101
      <Name>Markus.Service.Convert.IPlugin</Name>
102
    </ProjectReference>
95 103
    <ProjectReference Include="..\Markus.Service.DataBase\Markus.Service.DataBase.csproj">
96 104
      <Project>{400736fb-92c9-4bc0-b447-e8274103d813}</Project>
97 105
      <Name>Markus.Service.DataBase</Name>
ConvertService/ServiceBase/Markus.Service.Convert/Plugin.cs
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 ConfigFileName = "Plugin.ini";
16
        private const string BasePath = "Plugin";
17

  
18
        public static bool Run(string ConvertID)
19
        {
20
            bool result = false;
21

  
22
            var pluginPath = System.IO.Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, BasePath);
23
            var plugins = GenericPluginLoader<IPlugin>.LoadPlugins(pluginPath);
24
            var config = ConfigHelper.AppConfig(ConfigFileName);
25

  
26
            if (plugins != null)
27
            {
28
                foreach (var item in plugins)
29
                {
30
                    Dictionary<string, object> parameters = new Dictionary<string, object>();
31

  
32
                    var sections = config.Sections.Where(x => x.SectionName == item.Name);
33

  
34
                    if (sections.Count() > 0)
35
                    {
36
                        foreach (var param in sections.First().Keys)
37
                        {
38
                            parameters.Add(param.Name, param.Content);
39
                        }
40
                    }
41

  
42
                    var pluginResult = item.Do(ConvertID, parameters);
43

  
44
                    if (!pluginResult)
45
                    {
46

  
47
                       throw new Exception($"Markus.Service.ConvertProcess Error ConvertId : {ConvertID} PlugIn Error : ", new Exception(item.Exception.ToString()));
48
                    }
49
                }
50
            }
51

  
52
            return result;
53
        }
54

  
55
    }
56
}
ConvertService/ServiceBase/Markus.Service.Convert/packages.config
5 5
  <package id="Markus.Message" version="1.5.4" targetFramework="net45" />
6 6
  <package id="MarkusDatabase" version="1.7.2" targetFramework="net45" />
7 7
  <package id="MarkusPDF" version="1.7.0" targetFramework="net45" />
8
  <package id="Microsoft.CSharp" version="4.5.0" targetFramework="net45" />
9
  <package id="Salaros.ConfigParser" version="0.3.3" targetFramework="net45" />
8 10
</packages>
ConvertService/ServiceBase/Markus.Service.ConvertProcess/Exntensions/CollectionExtenstions.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Linq.Expressions;
5
using System.Text;
6
using System.Threading.Tasks;
7

  
8
namespace Markus.Service.Extensions
9
{
10
    public static class CollectionExtensions
11
    {
12
        //public static void Update<T>(this IList<T> source,IList<T> Target,IList<string> Keys)
13
        //{
14
        //    for (int i = source.Count; i == 0 ; --i)
15
        //    {
16
        //        var item = source[i];
17
        //         Target.Where(f=>)
18
        //        item.GetType().GetProperty()
19
        //    }
20
        //}
21

  
22
        /// <summary>
23
        /// Changes all elements of IEnumerable by the change function
24
        /// </summary>
25
        /// <param name="enumerable">The enumerable where you want to change stuff</param>
26
        /// <param name="change">The way you want to change the stuff</param>
27
        /// <returns>An IEnumerable with all changes applied</returns>
28
        public static IEnumerable<T> Change<T>(this IEnumerable<T> enumerable, Func<T, T> change)
29
        {
30
            ArgumentCheck.IsNullorWhiteSpace(enumerable, "enumerable");
31
            ArgumentCheck.IsNullorWhiteSpace(change, "change");
32

  
33
            foreach (var item in enumerable)
34
            {
35
                yield return change(item);
36
            }
37
        }
38

  
39
        /// <summary>
40
        /// Changes all elements of IEnumerable by the change function, that fullfill the where function
41
        /// </summary>
42
        /// <param name="enumerable">The enumerable where you want to change stuff</param>
43
        /// <param name="change">The way you want to change the stuff</param>
44
        /// <param name="where">The function to check where changes should be made</param>
45
        /// <returns>
46
        /// An IEnumerable with all changes applied
47
        /// </returns>
48
        public static IEnumerable<T> ChangeWhere<T>(this IEnumerable<T> enumerable,
49
                                                    Func<T, T> change,
50
                                                    Func<T, bool> @where)
51
        {
52
            ArgumentCheck.IsNullorWhiteSpace(enumerable, "enumerable");
53
            ArgumentCheck.IsNullorWhiteSpace(change, "change");
54
            ArgumentCheck.IsNullorWhiteSpace(@where, "where");
55

  
56
            foreach (var item in enumerable)
57
            {
58
                if (@where(item))
59
                {
60
                    yield return change(item);
61
                }
62
                else
63
                {
64
                    yield return item;
65
                }
66
            }
67
        }
68

  
69
        public static class ArgumentCheck
70
        {
71

  
72

  
73
            /// <summary>
74
            /// Checks if a value is string or any other object if it is string
75
            /// it checks for nullorwhitespace otherwhise it checks for null only
76
            /// </summary>
77
            /// <typeparam name="T">Type of the item you want to check</typeparam>
78
            /// <param name="item">The item you want to check</param>
79
            /// <param name="nameOfTheArgument">Name of the argument</param>
80
            public static void IsNullorWhiteSpace<T>(T item, string nameOfTheArgument = "")
81
            {
82

  
83
                Type type = typeof(T);
84
                if (type == typeof(string) ||
85
                    type == typeof(String))
86
                {
87
                    if (string.IsNullOrWhiteSpace(item as string))
88
                    {
89
                        throw new ArgumentException(nameOfTheArgument + " is null or Whitespace");
90
                    }
91
                }
92
                else
93
                {
94
                    if (item == null)
95
                    {
96
                        throw new ArgumentException(nameOfTheArgument + " is null");
97
                    }
98
                }
99

  
100
            }
101
        }
102

  
103
        /// <summary>
104
        /// Changes all elements of IEnumerable by the change function that do not fullfill the except function
105
        /// </summary>
106
        /// <param name="enumerable">The enumerable where you want to change stuff</param>
107
        /// <param name="change">The way you want to change the stuff</param>
108
        /// <param name="where">The function to check where changes should not be made</param>
109
        /// <returns>
110
        /// An IEnumerable with all changes applied
111
        /// </returns>
112
        public static IEnumerable<T> ChangeExcept<T>(this IEnumerable<T> enumerable,
113
                                                     Func<T, T> change,
114
                                                     Func<T, bool> @where)
115
        {
116
            ArgumentCheck.IsNullorWhiteSpace(enumerable, "enumerable");
117
            ArgumentCheck.IsNullorWhiteSpace(change, "change");
118
            ArgumentCheck.IsNullorWhiteSpace(@where, "where");
119

  
120
            foreach (var item in enumerable)
121
            {
122
                if (!@where(item))
123
                {
124
                    yield return change(item);
125
                }
126
                else
127
                {
128
                    yield return item;
129
                }
130
            }
131
        }
132

  
133
        /// <summary>
134
        /// Update all elements of IEnumerable by the update function (only works with reference types)
135
        /// </summary>
136
        /// <param name="enumerable">The enumerable where you want to change stuff</param>
137
        /// <param name="update">The way you want to change the stuff</param>
138
        /// <returns>
139
        /// The same enumerable you passed in
140
        /// </returns>
141
        public static IEnumerable<T> Update<T>(this IEnumerable<T> enumerable,
142
                                               Action<T> update) where T : class
143
        {
144
            ArgumentCheck.IsNullorWhiteSpace(enumerable, "enumerable");
145
            ArgumentCheck.IsNullorWhiteSpace(update, "update");
146
            foreach (var item in enumerable)
147
            {
148
                update(item);
149
            }
150
            return enumerable;
151
        }
152

  
153
        /// <summary>
154
        /// Update all elements of IEnumerable by the update function (only works with reference types)
155
        /// where the where function returns true
156
        /// </summary>
157
        /// <param name="enumerable">The enumerable where you want to change stuff</param>
158
        /// <param name="update">The way you want to change the stuff</param>
159
        /// <param name="where">The function to check where updates should be made</param>
160
        /// <returns>
161
        /// The same enumerable you passed in
162
        /// </returns>
163
        public static IEnumerable<T> UpdateWhere<T>(this IEnumerable<T> enumerable,
164
                                               Action<T> update, Func<T, bool> where) where T : class
165
        {
166
            ArgumentCheck.IsNullorWhiteSpace(enumerable, "enumerable");
167
            ArgumentCheck.IsNullorWhiteSpace(update, "update");
168
            foreach (var item in enumerable)
169
            {
170
                if (where(item))
171
                {
172
                    update(item);
173
                }
174
            }
175
            return enumerable;
176
        }
177

  
178
        /// <summary>
179
        /// Update all elements of IEnumerable by the update function (only works with reference types)
180
        /// Except the elements from the where function
181
        /// </summary>
182
        /// <param name="enumerable">The enumerable where you want to change stuff</param>
183
        /// <param name="update">The way you want to change the stuff</param>
184
        /// <param name="where">The function to check where changes should not be made</param>
185
        /// <returns>
186
        /// The same enumerable you passed in
187
        /// </returns>
188
        public static IEnumerable<T> UpdateExcept<T>(this IEnumerable<T> enumerable,
189
                                               Action<T> update, Func<T, bool> where) where T : class
190
        {
191
            ArgumentCheck.IsNullorWhiteSpace(enumerable, "enumerable");
192
            ArgumentCheck.IsNullorWhiteSpace(update, "update");
193

  
194
            foreach (var item in enumerable)
195
            {
196
                if (!where(item))
197
                {
198
                    update(item);
199
                }
200
            }
201
            return enumerable;
202
        }
203
    }
204
}
ConvertService/ServiceBase/Markus.Service.ConvertProcess/Exntensions/Encrypt.cs
1
using System;
2
using System.Collections.Generic;
3
using System.IO;
4
using System.Linq;
5
using System.Security.Cryptography;
6
using System.Text;
7
using System.Threading.Tasks;
8

  
9
namespace Markus.Service.Extensions
10
{
11
    public class Encrypt
12
    {
13
        public static class AESEncrypter
14
        {
15
            private static RijndaelManaged _rManaged = new RijndaelManaged();
16
            private static UTF8Encoding _utf8Encoder = new UTF8Encoding();
17

  
18
            static AESEncrypter()
19
            {
20
                MD5 _md5 = new MD5CryptoServiceProvider();
21

  
22
                _rManaged.KeySize = 256;
23
                _rManaged.BlockSize = 128;
24
                _rManaged.Mode = CipherMode.CBC;
25
                _rManaged.Padding = PaddingMode.PKCS7;
26
                _rManaged.Key = _md5.ComputeHash(_utf8Encoder.GetBytes("zxcvbnmasdfghjklqwertyuiop098765"));
27
                _rManaged.IV = _md5.ComputeHash(_utf8Encoder.GetBytes("qwertyuiopasdfghjklzxcvbnm123456"));
28
            }
29
            /// <summary>암호화</summary>
30
            /// <param name="val">암호화할 값</param>
31
            /// <returns>암호화된 값</returns>
32
            public static string Encrypt(string val)
33
            {
34
                string _resVal = string.Empty;
35
                byte[] _utf8Val = null;
36
                byte[] _encryptVal = null;
37
                ICryptoTransform tForm = _rManaged.CreateEncryptor();
38

  
39
                try
40
                {
41
                    if (!string.IsNullOrEmpty(val))
42
                    {
43
                        _utf8Val = _utf8Encoder.GetBytes(val);
44
                        _encryptVal = tForm.TransformFinalBlock(_utf8Val, 0, _utf8Val.Length);
45
                        _resVal = Convert.ToBase64String(_encryptVal);
46
                    }
47
                    else
48
                        _resVal = string.Empty;
49
                }
50
                catch
51
                {
52
                    _resVal = string.Empty;
53
                }
54

  
55
                return _resVal;
56
            }
57
            /// <summary>복호화</summary>
58
            /// <param name="val">복호화할 값</param>
59
            /// <returns>복호화된 값</returns>
60
            public static string Decrypt(string val)
61
            {
62
                string _resVal = string.Empty;
63
                byte[] _decryptVal = null;
64
                byte[] _encryptVal = null;
65
                ICryptoTransform tForm = _rManaged.CreateDecryptor();
66

  
67
                try
68
                {
69
                    if (!string.IsNullOrEmpty(val))
70
                    {
71
                        _encryptVal = Convert.FromBase64String(val);
72
                        _decryptVal = tForm.TransformFinalBlock(_encryptVal, 0, _encryptVal.Length);
73
                        _resVal = _utf8Encoder.GetString(_decryptVal);
74
                    }
75
                    else
76
                        _resVal = string.Empty;
77
                }
78
                catch
79
                {
80
                    _resVal = string.Empty;
81
                }
82

  
83
                return _resVal;
84
            }
85
        }
86
    }
87
}
ConvertService/ServiceBase/Markus.Service.ConvertProcess/Exntensions/Process.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Diagnostics;
4
using System.Linq;
5
using System.Management;
6
using System.Text;
7
using System.Threading.Tasks;
8

  
9
namespace Markus.Service.Extensions
10
{
11
    public static class ProcessExtension
12
    {
13
        /// <summary>
14
        /// 프로세스의 명령줄을 가져온다.
15
        /// </summary>
16
        /// <param name="process"></param>
17
        /// <returns></returns>
18
        public static ProcessArguments Arguments(this Process process)
19
        {
20
            ProcessArguments result = new ProcessArguments();
21

  
22
            var commandLine = ProcessCommandLinesQuery(process.Id);
23

  
24
            try
25
            {
26
                result.WorkingDirectory = ProcessWorkingDirectory(commandLine);
27

  
28
                result.CommandLine = SplitArguments(RemoveCommadLinesFilePath(commandLine)).ToList();
29
            }
30
            catch (Exception ex)
31
            {
32
                System.Diagnostics.Debug.WriteLine(ex.ToString());
33
            }
34
            return result;
35
        }
36

  
37
        /// <summary>
38
        /// 프로세스의 실행 경로
39
        /// </summary>
40
        /// <param name="process"></param>
41
        /// <returns></returns>
42
        public static string WorkingDirectory(this Process process)
43
        {
44
            var commandLine = ProcessCommandLinesQuery(process.Id);
45
            return ProcessWorkingDirectory(commandLine);
46
        }
47

  
48
        private static string ProcessCommandLinesQuery(int processId)
49
        {
50
            string result = "";
51

  
52
            string wmiQuery = string.Format("select CommandLine from Win32_Process where ProcessId ='{0}'", processId);
53

  
54
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(wmiQuery);
55
            ManagementObjectCollection retObjectCollection = searcher.Get();
56

  
57
            if (retObjectCollection.Count > 0)
58
            {
59
                if (retObjectCollection.Cast<ManagementObject>().First()["CommandLine"] != null)
60
                {
61
                    result = retObjectCollection.Cast<ManagementObject>().First()["CommandLine"]?.ToString();
62
                }
63
                else
64
                {
65
                    result = "";
66
                }
67
            }
68

  
69
            return result;
70
        }
71

  
72
        private static string ProcessWorkingDirectory(string commandLine)
73
        {
74
            var splitCommand = commandLine.Split(' ');
75
            string filePath = "";
76

  
77
            for (int i = 0; i < splitCommand.Count(); i++)
78
            {
79
                filePath += " " + splitCommand[i].Replace("\"", "");
80

  
81
                if (IO.FileExists(filePath))
82
                {
83
                    System.IO.FileInfo info = new System.IO.FileInfo(filePath);
84
                    filePath = info.DirectoryName;
85
                    break;
86
                }
87
                else if (i == splitCommand.Count() - 1)
88
                {
89
                    var firstCmd = splitCommand.First();
90

  
91
                    if (firstCmd.StartsWith("\"") && firstCmd.EndsWith("\""))
92
                    {
93
                        filePath = firstCmd.Replace("\"", "");
94
                    }
95
                }
96
                else
97
                {
98
                    filePath = commandLine;
99
                }
100
            }
101

  
102
            return filePath;
103
        }
104

  
105
        /// <summary>
106
        /// command line에서 처음에 있는 파일 경로가 \"로 묶여 있거나 묶여 있지 않은 경우가 있다.
107
        /// 파일 경로를 제거하기 위한 코드
108
        /// </summary>
109
        /// <param name="commandLine"></param>
110
        /// <returns></returns>
111
        private static string RemoveCommadLinesFilePath(string commandLine)
112
        {
113
            string result = "";
114

  
115
            var splitCommand = commandLine.Split(' ');
116
            string filePath = "";
117

  
118
            for (int i = 0; i < splitCommand.Count(); i++)
119
            {
120
                filePath += " " + splitCommand[i];
121

  
122
                if (IO.FileExists(filePath.Replace("\"", "")))
123
                {
124
                    result = string.Join(" ", splitCommand.Skip(i + 1).Take(splitCommand.Count() - i));
125
                    break;
126
                }
127
                else if (i == splitCommand.Count() - 1)
128
                {
129
                    var firstCmd = splitCommand.First();
130

  
131
                    if (firstCmd.StartsWith("\"") && firstCmd.EndsWith("\""))
132
                    {
133
                        result = string.Join(" ", splitCommand.Skip(1).Take(splitCommand.Count() - 1));
134
                    }
135
                }
136
                else
137
                {
138
                    result = commandLine;
139
                }
140
            }
141

  
142
            return result;
143
        }
144

  
145
        public static string[] SplitArguments(string commandLine)
146
        {
147
            List<string> args = new List<string>();
148
            List<char> currentArg = new List<char>();
149
            char? quoteSection = null; // Keeps track of a quoted section (and the type of quote that was used to open it)
150
            char[] quoteChars = new[] { '\'', '\"' };
151
            char previous = ' '; // Used for escaping double quotes
152

  
153
            for (var index = 0; index < commandLine.Length; index++)
154
            {
155
                char c = commandLine[index];
156
                if (quoteChars.Contains(c))
157
                {
158
                    if (previous == c) // Escape sequence detected
159
                    {
160
                        previous = ' '; // Prevent re-escaping
161
                        if (!quoteSection.HasValue)
162
                        {
163
                            quoteSection = c; // oops, we ended the quoted section prematurely
164
                            continue;         // don't add the 2nd quote (un-escape)
165
                        }
166

  
167
                        if (quoteSection.Value == c)
168
                            quoteSection = null; // appears to be an empty string (not an escape sequence)
169
                    }
170
                    else if (quoteSection.HasValue)
171
                    {
172
                        if (quoteSection == c)
173
                            quoteSection = null; // End quoted section
174
                    }
175
                    else
176
                        quoteSection = c; // Start quoted section
177
                }
178
                else if (char.IsWhiteSpace(c))
179
                {
180
                    if (!quoteSection.HasValue)
181
                    {
182
                        args.Add(new string(currentArg.ToArray()));
183
                        currentArg.Clear();
184
                        previous = c;
185
                        continue;
186
                    }
187
                }
188

  
189
                currentArg.Add(c);
190
                previous = c;
191
            }
192

  
193
            if (currentArg.Count > 0)
194
                args.Add(new string(currentArg.ToArray()));
195

  
196
            return args.ToArray();
197
        }
198
    }
199
}
ConvertService/ServiceBase/Markus.Service.ConvertProcess/Exntensions/ProcessArguments.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6

  
7
namespace Markus.Service.Extensions
8
{
9
    public class ProcessArguments
10
    {
11
        public string WorkingDirectory { get; set; }
12
        public List<string> CommandLine { get; set; }
13
    }
14
}
ConvertService/ServiceBase/Markus.Service.ConvertProcess/Exntensions/Sytem.IO.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6

  
7

  
8
namespace Markus.Service.Extensions
9
{
10
    public static class IO
11
    {
12
        /// <summary>
13
        /// System.IO.PathTooLongException 방지를 위해서 생성
14
        /// </summary>
15
        /// <param name="path"></param>
16
        /// <returns></returns>
17
        public static bool FileExists(string path)
18
        {
19
            bool result = false;
20

  
21
            if (path.Length < 260)
22
            {
23
                if (System.IO.File.Exists(path))
24
                {
25
                    result = true;
26
                }
27
            }
28

  
29
            return result;
30
        }
31

  
32
    }
33
}
ConvertService/ServiceBase/Markus.Service.ConvertProcess/Exntensions/SytemNet.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Net.NetworkInformation;
5
using System.Text;
6
using System.Threading.Tasks;
7

  
8
namespace Markus.Service.Extensions
9
{
10

  
11
    /// <summary>
12
    /// 네트워크 관련 확장코드
13
    /// </summary>
14
   public static  class SytemNet
15
    {
16
        /// <summary>
17
        /// 웹uri 활성화 상태 체크
18
        /// </summary>
19
        /// <param name="strUri"></param>
20
        /// <returns></returns>
21
        public static async Task<bool> PingAsync(string strUri)
22
        {
23
            bool result = false;
24

  
25
            try
26
            {
27
                Uri uri = new Uri(strUri);
28

  
29
                Ping pingSender = new Ping();
30
                PingReply reply = pingSender.Send(uri.Host);
31

  
32
                if (reply.Status == IPStatus.Success)
33
                {
34
                    using (System.Net.Http.HttpClient Client = new System.Net.Http.HttpClient())
35
                    {
36
                        Client.Timeout = new TimeSpan(0, 1,0);
37

  
38
                        var message = await Client.GetAsync(uri);
39

  
40
                        System.Net.Http.HttpResponseMessage responseMessage = message;
41
                        System.Net.HttpStatusCode StatusCode = responseMessage.StatusCode;
42
                        switch (StatusCode)
43
                        {
44

  
45
                            case System.Net.HttpStatusCode.Accepted:
46
                            case System.Net.HttpStatusCode.OK:
47
                                result = true;
48
                                break;
49
                        }
50
                    }
51
                }
52
                else
53
                {
54
                    result = false;
55
                }
56
            }
57
            catch (AggregateException ae)
58
            {
59
                foreach (var e in ae.InnerExceptions)
60
                {
61
                    // Handle the custom exception.
62
                    if (e is CustomException)
63
                    {
64
                        Console.WriteLine(e.Message);
65
                    }
66
                    // Rethrow any other exception.
67
                    else
68
                    {
69
                        Console.WriteLine(strUri + " Connection Error");
70
                    }
71
                }
72
            }
73
            catch (Exception)
74
            {
75

  
76
            }
77

  
78
            return result;
79
        }
80
    }
81

  
82
    public class CustomException : Exception
83
    {
84
        public CustomException(String message) : base(message)
85
        { }
86
    }
87
}
ConvertService/ServiceBase/Markus.Service.ConvertProcess/Exntensions/guid.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Security.Cryptography;
5
using System.Text;
6
using System.Threading.Tasks;
7

  
8
namespace Markus.Service.Extensions
9
{
10
    public static class GuidExtension
11
    {
12
        public static Guid CreateUniqueGuid(this Guid guid)
13
        {
14
            return GetUniqueGuid();
15
        }
16

  
17
        private static Guid GetUniqueGuid()
18
        {
19
            char[] chars = "ABCDEF1234567890".ToCharArray();
20
            byte[] data = new byte[1];
21
            System.Security.Cryptography.RNGCryptoServiceProvider crypto = new System.Security.Cryptography.RNGCryptoServiceProvider();
22
            crypto.GetNonZeroBytes(data);
23
            data = new byte[32];
24
            crypto.GetNonZeroBytes(data);
25
            StringBuilder result = new StringBuilder(32);
26

  
27
            foreach (byte b in data)
28
            {
29
                result.Append(chars[b % (chars.Length - 1)]);
30
            }
31

  
32
            return Guid.ParseExact(result.ToString(0, 8) + "-" + result.ToString(8, 4) + "-" + result.ToString(11, 4) + "-"
33
                + result.ToString(16, 4) + "-" + result.ToString(20, 12), "D");
34
        }
35

  
36
        public static string shortGuid()
37
        {
38
            byte[] numArray = new byte[16];
39
            using (RandomNumberGenerator randomNumberGenerator = RandomNumberGenerator.Create())
40
                randomNumberGenerator.GetBytes(numArray);
41
            return Convert.ToBase64String(new Guid(numArray).ToByteArray()).Substring(0, 10).Replace("/", "").Replace("+", "") + DateTime.UtcNow.Ticks.ToString("x");
42
        }
43
    }
44
}
ConvertService/ServiceBase/Markus.Service.ConvertProcess/Exntensions/string.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6

  
7
namespace Markus.Service.Extensions
8
{
9
    public static class StringExtension
10
    {
11
        public static bool IsNullOrEmpty(this string value)
12
        {
13
            if(!string.IsNullOrWhiteSpace(value))
14
            {
15
                return false;
16
            }
17
            else
18
            {
19
                return true;
20
            }
21
        }
22

  
23
        public static bool IsNumber(this string value)
24
        {
25
            int outValue = 0;
26
            return int.TryParse(value, out outValue);
27
        }
28
    }
29
}
ConvertService/ServiceBase/Markus.Service.ConvertProcess/GenericPluginLoader.cs
1
/*
2
   Copyright 2013 Christoph Gattnar
3

  
4
   Licensed under the Apache License, Version 2.0 (the "License");
5
   you may not use this file except in compliance with the License.
6
   You may obtain a copy of the License at
7

  
8
	   http://www.apache.org/licenses/LICENSE-2.0
9

  
10
   Unless required by applicable law or agreed to in writing, software
11
   distributed under the License is distributed on an "AS IS" BASIS,
12
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
   See the License for the specific language governing permissions and
14
   limitations under the License.
15
*/
16

  
17
using System;
18
using System.Collections.Generic;
19
using System.IO;
20
using System.Reflection;
21

  
22
namespace Markus.Service.ConvertProcess
23
{
24
	public static class GenericPluginLoader<T>
25
	{
26
		public static ICollection<T> LoadPlugins(string path)
27
		{
28
			string[] dllFileNames = null;
29

  
30
			if(Directory.Exists(path))
31
			{
32
				dllFileNames = Directory.GetFiles(path, "*.dll");
33

  
34
				ICollection<Assembly> assemblies = new List<Assembly>(dllFileNames.Length);
35
				foreach(string dllFile in dllFileNames)
36
				{
37
					AssemblyName an = AssemblyName.GetAssemblyName(dllFile);
38
					Assembly assembly = Assembly.Load(an);
39
					assemblies.Add(assembly);
40
				}
41

  
42
				Type pluginType = typeof(T);
43
				ICollection<Type> pluginTypes = new List<Type>();
44
				foreach(Assembly assembly in assemblies)
45
				{
46
					if(assembly != null)
47
					{
48
						Type[] types = assembly.GetTypes();
49

  
50
						foreach(Type type in types)
51
						{
52
							if(type.IsInterface || type.IsAbstract)
53
							{
54
								continue;
55
							}
56
							else
57
							{
58
								if(type.GetInterface(pluginType.FullName) != null)
59
								{
60
									pluginTypes.Add(type);
61
								}
62
							}
63
						}
64
					}
65
				}
66

  
67
				ICollection<T> plugins = new List<T>(pluginTypes.Count);
68
				foreach(Type type in pluginTypes)
69
				{
70
					T plugin = (T)Activator.CreateInstance(type);
71
					plugins.Add(plugin);
72
				}
73

  
74
				return plugins;
75
			}
76

  
77
			return null;
78
		}
79
	}
80
}
ConvertService/ServiceBase/Markus.Service.ConvertProcess/Markus.Service.ConvertProcess.csproj
59 59
    <SignAssembly>true</SignAssembly>
60 60
  </PropertyGroup>
61 61
  <ItemGroup>
62
    <Reference Include="ConfigParser, Version=0.3.3.6, Culture=neutral, processorArchitecture=MSIL">
63
      <HintPath>..\packages\Salaros.ConfigParser.0.3.3\lib\net45\ConfigParser.dll</HintPath>
64
    </Reference>
65 62
    <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
66 63
      <HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath>
67 64
    </Reference>
......
89 86
    <Reference Include="System.Xml" />
90 87
  </ItemGroup>
91 88
  <ItemGroup>
92
    <Compile Include="GenericPluginLoader.cs" />
93 89
    <Compile Include="Program.cs" />
94 90
    <Compile Include="Properties\AssemblyInfo.cs" />
95 91
  </ItemGroup>
......
114 110
      <Project>{4a465fd0-8130-4d6b-a65f-c3cd6cc355a4}</Project>
115 111
      <Name>Markus.Service.Interface</Name>
116 112
    </ProjectReference>
117
    <ProjectReference Include="..\Markus.Service.Convert.IPlugin\Markus.Service.Convert.IPlugin.csproj">
118
      <Project>{a5ba7325-379c-4ccb-b156-1704fc2175e3}</Project>
119
      <Name>Markus.Service.Convert.IPlugin</Name>
120
    </ProjectReference>
121 113
    <ProjectReference Include="..\Markus.Service.Convert\Markus.Service.Convert.csproj">
122 114
      <Project>{867e065c-3c22-47b1-9c2a-130a78dddd51}</Project>
123 115
      <Name>Markus.Service.Convert</Name>
......
130 122
      <Project>{5F983789-3E8F-4F9A-A601-138C3A83CA5F}</Project>
131 123
      <Name>Markus.Service.Extensions</Name>
132 124
    </ProjectReference>
133
    <ProjectReference Include="..\Markus.Service.WcfService\Markus.Service.IWcfService.csproj">
134
      <Project>{0523c15e-b197-4c34-83ba-d62b384e2b77}</Project>
135
      <Name>Markus.Service.IWcfService</Name>
125
    <ProjectReference Include="..\Markus.Service.WcfClient\Markus.Service.WcfClient.csproj">
126
      <Project>{691078d3-be0e-4697-bab6-ed3aca842d19}</Project>
127
      <Name>Markus.Service.WcfClient</Name>
136 128
    </ProjectReference>
137 129
  </ItemGroup>
138 130
  <ItemGroup>
ConvertService/ServiceBase/Markus.Service.ConvertProcess/Program.cs
11 11
using System.Web.Script.Serialization;
12 12
using System.Windows.Forms;
13 13
using static Markus.Service.Extensions.Encrypt;
14
using ConvertPlugin = Markus.Service.Convert.Plugin;
15 14

  
16 15
namespace Markus.Service.ConvertProcess
17 16
{
......
48 47
                    }
49 48
                    else
50 49
                    {
51
                        var pluginPath = System.IO.Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "Plugin");
52
                        var plugins = GenericPluginLoader<ConvertPlugin.IPlugin>.LoadPlugins(pluginPath);
53
                        var config = ConfigHelper.AppConfig("Plugin.ini");
54

  
55
                        if(plugins != null)
56
                        { 
57
                            foreach (var item in plugins)
58
                            {
59
                                Dictionary<string, object> parameters = new Dictionary<string, object>();
60

  
61
                                var sections = config.Sections.Where(x=>x.SectionName == item.Name);
62

  
63
                                if (sections.Count() > 0)
64
                                {
65
                                    foreach (var param in sections.First().Keys)
66
                                    {
67
                                        parameters.Add(param.Name, param.Content);
68
                                    }
69
                                }
70

  
71
                                var result = item.Do(convetContext.ConvertID, parameters);
72

  
73
                                if(!result)
74
                                {
75
                                    logger.Error($"Markus.Service.ConvertProcess Error ConvertId : {convetContext.ConvertID} PlugIn Error : ",new Exception(item.Exception.ToString()));
76
                                }
77
                            }
78
                        }
79
                        else
80
                        {
81
                            logger.Error($"Markus.Service.ConvertProcess Error Plugin Directory {pluginPath}");
82
                        }
50
                        
83 51
                    }
84 52
                }
85 53
            }
ConvertService/ServiceBase/Markus.Service.ConvertProcess/packages.config
5 5
  <package id="Markus.Message" version="1.5.4" targetFramework="net45" />
6 6
  <package id="Microsoft.CSharp" version="4.5.0" targetFramework="net45" />
7 7
  <package id="Obfuscar" version="2.2.19" targetFramework="net45" developmentDependency="true" />
8
  <package id="Salaros.ConfigParser" version="0.3.3" targetFramework="net45" />
9 8
</packages>
ConvertService/ServiceBase/Markus.Service.Extensions/Exntensions/GenericPluginLoader.cs
1
/*
2
   Copyright 2013 Christoph Gattnar
3

  
4
   Licensed under the Apache License, Version 2.0 (the "License");
5
   you may not use this file except in compliance with the License.
6
   You may obtain a copy of the License at
7

  
8
	   http://www.apache.org/licenses/LICENSE-2.0
9

  
10
   Unless required by applicable law or agreed to in writing, software
11
   distributed under the License is distributed on an "AS IS" BASIS,
12
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
   See the License for the specific language governing permissions and
14
   limitations under the License.
15
*/
16

  
17
using System;
18
using System.Collections.Generic;
19
using System.IO;
20
using System.Reflection;
21

  
22
namespace Markus.Service.Extensions
23
{
24
	public static class GenericPluginLoader<T>
25
	{
26
		public static ICollection<T> LoadPlugins(string path)
27
		{
28
			string[] dllFileNames = null;
29

  
30
			if(Directory.Exists(path))
31
			{
32
				dllFileNames = Directory.GetFiles(path, "*.dll");
33

  
34
				ICollection<Assembly> assemblies = new List<Assembly>(dllFileNames.Length);
35
				foreach(string dllFile in dllFileNames)
36
				{
37
					AssemblyName an = AssemblyName.GetAssemblyName(dllFile);
38
					Assembly assembly = Assembly.Load(an);
39
					assemblies.Add(assembly);
40
				}
41

  
42
				Type pluginType = typeof(T);
43
				ICollection<Type> pluginTypes = new List<Type>();
44
				foreach(Assembly assembly in assemblies)
45
				{
46
					if(assembly != null)
47
					{
48
						Type[] types = assembly.GetTypes();
49

  
50
						foreach(Type type in types)
51
						{
52
							if(type.IsInterface || type.IsAbstract)
53
							{
54
								continue;
55
							}
56
							else
57
							{
58
								if(type.GetInterface(pluginType.FullName) != null)
59
								{
60
									pluginTypes.Add(type);
61
								}
62
							}
63
						}
64
					}
65
				}
66

  
67
				ICollection<T> plugins = new List<T>(pluginTypes.Count);
68
				foreach(Type type in pluginTypes)
69
				{
70
					T plugin = (T)Activator.CreateInstance(type);
71
					plugins.Add(plugin);
72
				}
73

  
74
				return plugins;
75
			}
76

  
77
			return null;
78
		}
79
	}
80
}
ConvertService/ServiceBase/Markus.Service.Extensions/Markus.Service.Extensions.csproj
67 67
  </ItemGroup>
68 68
  <ItemGroup>
69 69
    <Compile Include="Exntensions\CollectionExtenstions.cs" />
70
    <Compile Include="Exntensions\GenericPluginLoader.cs" />
70 71
    <Compile Include="Exntensions\Sytem.IO.cs" />
71 72
    <Compile Include="Exntensions\SytemNet.cs" />
72 73
    <Compile Include="Helper\Compress.cs" />

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)