markus / ConvertService / ServiceBase / Markus.Service.Station / StationService / ServiceStationWCF.cs @ 48e1ab34
이력 | 보기 | 이력해설 | 다운로드 (12.1 KB)
1 | 53c9637d | taeseongkim | using Markus.Message; |
---|---|---|---|
2 | using Markus.Service.Extensions; |
||
3 | using Markus.Service.Interface; |
||
4 | using Markus.Service.IWcfService; |
||
5 | using System; |
||
6 | using System.Collections.Generic; |
||
7 | using System.Diagnostics; |
||
8 | using System.Linq; |
||
9 | using System.ServiceModel; |
||
10 | using System.ServiceModel.Activation; |
||
11 | using System.ServiceModel.Web; |
||
12 | using System.Text; |
||
13 | using System.Threading.Tasks; |
||
14 | |||
15 | namespace Markus.Service |
||
16 | { |
||
17 | a53dfe45 | taeseongkim | /// <summary> |
18 | /// web service 목록 |
||
19 | /// </summary> |
||
20 | 53c9637d | taeseongkim | [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] |
21 | //[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, IncludeExceptionDetailInFaults = true)] |
||
22 | public partial class ServiceStation : IStationService |
||
23 | { |
||
24 | a53dfe45 | taeseongkim | /// <summary> |
25 | /// DB에 Convrert Item을 추가 하고 호출 |
||
26 | /// CovnertWebService에서 호출시 사용 |
||
27 | /// </summary> |
||
28 | /// <param name="ProjectNo"></param> |
||
29 | /// <param name="ConvertID"></param> |
||
30 | /// <returns></returns> |
||
31 | 53c9637d | taeseongkim | public string ConvertAdd(string ProjectNo, string ConvertID) |
32 | { |
||
33 | string result = false.ToString(); |
||
34 | |||
35 | try |
||
36 | { |
||
37 | result = ConvertProcessAdd(ProjectNo,ConvertID); |
||
38 | 949d5058 | taeseongkim | |
39 | logger.Info($"ConvertAdd Call Item ProjectNo : {ProjectNo} ConvertID : {ConvertID} result : {result}"); |
||
40 | 53c9637d | taeseongkim | } |
41 | catch (Exception ex) |
||
42 | { |
||
43 | result = $"ConvertAdd Error {ConvertID}"; |
||
44 | logger.Error($"ConvertAdd Error- {ConvertID}", ex); |
||
45 | } |
||
46 | |||
47 | return result; |
||
48 | } |
||
49 | |||
50 | a53dfe45 | taeseongkim | /// <summary> |
51 | /// 별도의 호출 사용 |
||
52 | /// </summary> |
||
53 | /// <param name="ProjectNo"></param> |
||
54 | /// <param name="originfilePath"></param> |
||
55 | /// <param name="DocumentID"></param> |
||
56 | /// <returns></returns> |
||
57 | 53c9637d | taeseongkim | public string ConvertMenualAdd(string ProjectNo, string originfilePath, string DocumentID) |
58 | { |
||
59 | string result = false.ToString(); |
||
60 | string convertID = new Guid().CreateUniqueGuid().ToString().Replace("-",""); |
||
61 | |||
62 | try |
||
63 | { |
||
64 | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
||
65 | { |
||
66 | if (!database.SetConvertDoc(ProjectNo, convertID, originfilePath, DocumentID)) |
||
67 | { |
||
68 | logger.Error($"Set Convert Document Error - ProjectNo:{ProjectNo} UniqueID:{convertID} originfilePath:{originfilePath} DocumentID:{DocumentID}"); |
||
69 | } |
||
70 | else |
||
71 | { |
||
72 | result = ConvertProcessAdd(ProjectNo,convertID); |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 | catch (Exception ex) |
||
77 | { |
||
78 | result = "DataBase SetConvert Error"; |
||
79 | logger.Error($"ConvertMenualAdd Error- database.SetConvertDoc ProjectNo:{ProjectNo} UniqueID:{convertID} originfilePath:{originfilePath} DocumentID:{DocumentID}", ex); |
||
80 | } |
||
81 | |||
82 | return result; |
||
83 | } |
||
84 | |||
85 | a53dfe45 | taeseongkim | /// <summary> |
86 | /// ConvertItem의 상태 |
||
87 | /// </summary> |
||
88 | /// <param name="ProjectNo"></param> |
||
89 | /// <param name="DocumentID"></param> |
||
90 | /// <returns></returns> |
||
91 | public Item GetConvertItem(string ProjectNo, string DocumentID) |
||
92 | { |
||
93 | Item result = null; |
||
94 | |||
95 | try |
||
96 | { |
||
97 | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
||
98 | { |
||
99 | var item = database.GetConvertItembyDocumentID(ProjectNo, DocumentID); |
||
100 | |||
101 | if (item != null) |
||
102 | { |
||
103 | result = |
||
104 | new Item |
||
105 | { |
||
106 | DocumentID = item.UniqueKey, |
||
107 | Status = item.ConvertState, |
||
108 | ProjectNo = item.ProjectNumber, |
||
109 | TotalPage = item.TotalPage, |
||
110 | CurrentPageNo = item.CurrentPageNo, |
||
111 | PdfPath = item.OriginfilePath, |
||
112 | ConvertPath = item.ConvertPath |
||
113 | }; |
||
114 | 53c9637d | taeseongkim | |
115 | a53dfe45 | taeseongkim | } |
116 | } |
||
117 | } |
||
118 | catch (Exception ex) |
||
119 | { |
||
120 | throw new FaultException("Get ConvertItem Error"); |
||
121 | } |
||
122 | 53c9637d | taeseongkim | |
123 | a53dfe45 | taeseongkim | return result; |
124 | } |
||
125 | |||
126 | /// <summary> |
||
127 | /// Convert Item을 DB에 추가 하고 프로세스 실행시 호출 |
||
128 | /// </summary> |
||
129 | /// <param name="ProjectNo"></param> |
||
130 | /// <param name="convertID"></param> |
||
131 | /// <returns></returns> |
||
132 | 53c9637d | taeseongkim | private string ConvertProcessAdd(string ProjectNo, string convertID) |
133 | { |
||
134 | string result = false.ToString(); |
||
135 | |||
136 | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
||
137 | { |
||
138 | var convertItem = database.GetConvertItem(ProjectNo,convertID); |
||
139 | |||
140 | /// 순서별 Convert Item 처리 |
||
141 | if (convertItem != null) |
||
142 | { |
||
143 | try |
||
144 | { |
||
145 | cdfb57ff | taeseongkim | if (AliveConvertQueue.Count(c => c.UniqueKey == convertItem.UniqueKey) == 0) |
146 | { |
||
147 | if (ServiceStation.AliveConvertQueue.Count() < MultiProcessCount) |
||
148 | { |
||
149 | ConvertProcessStart(convertItem); |
||
150 | result = true.ToString(); |
||
151 | } |
||
152 | 949d5058 | taeseongkim | else |
153 | { |
||
154 | logger.Info($"ConvertAdd ConvertProcess Wait ProcessCount ProjectNo:{ProjectNo} convertID:{convertID} "); |
||
155 | result = true.ToString(); |
||
156 | } |
||
157 | cdfb57ff | taeseongkim | } |
158 | else |
||
159 | 53c9637d | taeseongkim | { |
160 | 0157b158 | taeseongkim | PassConvertItem(ProjectNo, convertID); |
161 | 53c9637d | taeseongkim | result = true.ToString(); |
162 | } |
||
163 | } |
||
164 | catch (Exception ex) |
||
165 | { |
||
166 | result = "Convert Process Start Error"; |
||
167 | 949d5058 | taeseongkim | logger.Error($"ConvertAdd ConvertProcess call Error ProjectNo:{ProjectNo} convertID:{convertID} ", ex); |
168 | 53c9637d | taeseongkim | } |
169 | } |
||
170 | else |
||
171 | { |
||
172 | 949d5058 | taeseongkim | logger.Error($"ConvertAdd ConvertProcess call Error ProjectNo:{ProjectNo} convertID:{convertID} item Null "); |
173 | 53c9637d | taeseongkim | result = "Get ConvertItem Error"; |
174 | } |
||
175 | } |
||
176 | |||
177 | return result; |
||
178 | } |
||
179 | |||
180 | a53dfe45 | taeseongkim | /// <summary> |
181 | /// 각 ConvertProcess의 상태값을 저장 |
||
182 | /// </summary> |
||
183 | /// <param name="ConvertID"></param> |
||
184 | /// <param name="status"></param> |
||
185 | /// <param name="CurrentPage"></param> |
||
186 | /// <param name="TotalPage"></param> |
||
187 | /// <param name="Error"></param> |
||
188 | /// <returns></returns> |
||
189 | 53c9637d | taeseongkim | public bool ConvertProcessState(string ConvertID, int status, int CurrentPage, int TotalPage,string Error) |
190 | { |
||
191 | var items =AliveConvertQueue.Where(x => x.ConvertID == ConvertID); |
||
192 | |||
193 | if(items.Count() > 0) |
||
194 | { |
||
195 | var item = items.First(); |
||
196 | |||
197 | item.TotalPage = TotalPage; |
||
198 | item.CurrentPageNo = CurrentPage; |
||
199 | item.ConvertState = ((StatusCodeType)status).ToString(); |
||
200 | } |
||
201 | |||
202 | if (CurrentPage % SaveStatusInterval == 0 || !Error.IsNullOrEmpty()) |
||
203 | { |
||
204 | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
||
205 | { |
||
206 | 0157b158 | taeseongkim | if (!database.SetConvertState(this.ServiceID, ConvertID, status, CurrentPage, TotalPage, Error)) |
207 | 53c9637d | taeseongkim | { |
208 | logger.Error($"DataBase Error database.SetConvertState({ConvertID}, {(int)status},{CurrentPage},{TotalPage}, {Error})"); |
||
209 | } |
||
210 | } |
||
211 | } |
||
212 | |||
213 | return true; |
||
214 | } |
||
215 | |||
216 | a53dfe45 | taeseongkim | /// <summary> |
217 | /// Convert Process 완료시 호출 |
||
218 | /// </summary> |
||
219 | /// <param name="ConvertID"></param> |
||
220 | /// <param name="status"></param> |
||
221 | /// <param name="CurrentPage"></param> |
||
222 | /// <param name="TotalPage"></param> |
||
223 | /// <param name="Error"></param> |
||
224 | /// <returns></returns> |
||
225 | 53c9637d | taeseongkim | public bool ConvertFinish( string ConvertID, int status, int CurrentPage, int TotalPage, string Error) |
226 | { |
||
227 | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
||
228 | { |
||
229 | 0157b158 | taeseongkim | if (!database.SetConvertState(this.ServiceID, ConvertID, status, CurrentPage, TotalPage, Error)) |
230 | 53c9637d | taeseongkim | { |
231 | logger.Error($"DataBase Error database.SetConvertState({ConvertID}, {(int)status},{CurrentPage},{TotalPage}, {Error})"); |
||
232 | } |
||
233 | } |
||
234 | |||
235 | var _convertItem = ServiceStation.AliveConvertQueue.Where(f => f.ConvertID == ConvertID); |
||
236 | |||
237 | if (_convertItem.Count() > 0) |
||
238 | ConvertFinish(_convertItem.First()); |
||
239 | |||
240 | return true; |
||
241 | } |
||
242 | |||
243 | a53dfe45 | taeseongkim | /// <summary> |
244 | /// 대기중인 Convert Item을 가져옴 |
||
245 | /// </summary> |
||
246 | /// <returns></returns> |
||
247 | 53c9637d | taeseongkim | public List<ConvertItem> WaitConvertList() |
248 | { |
||
249 | List<ConvertItem> result = new List<ConvertItem>(); |
||
250 | |||
251 | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
||
252 | { |
||
253 | result = database.GetConvertItems(Message.StatusCodeType.Wait).ToList(); |
||
254 | } |
||
255 | |||
256 | return result; |
||
257 | } |
||
258 | |||
259 | a53dfe45 | taeseongkim | /// <summary> |
260 | /// 현재 AliveConvertQueue에 있는 컨버터 리스트 |
||
261 | /// </summary> |
||
262 | /// <returns></returns> |
||
263 | 53c9637d | taeseongkim | public List<ConvertItem> AliveConvertList() |
264 | { |
||
265 | return ServiceStation.AliveConvertQueue.ToList(); |
||
266 | } |
||
267 | |||
268 | a53dfe45 | taeseongkim | /// <summary> |
269 | /// 동시 작업 프로세스 갯수 변경 |
||
270 | /// </summary> |
||
271 | /// <param name="Value"></param> |
||
272 | /// <returns></returns> |
||
273 | 53c9637d | taeseongkim | public bool SettingMultiProcess(int Value) |
274 | { |
||
275 | bool result = false; |
||
276 | |||
277 | try |
||
278 | { |
||
279 | MultiProcessCount = Value; |
||
280 | |||
281 | var config = ConfigHelper.AppConfig(configFileName); |
||
282 | |||
283 | config.SetValue(CONFIG_DEFINE.SERVICE, CONFIG_DEFINE.CONVERT_SERVICE_PROCESS, Value.ToString()); |
||
284 | config.Save(configFileName); |
||
285 | |||
286 | result = true; |
||
287 | } |
||
288 | catch (Exception ex) |
||
289 | { |
||
290 | logger.Error("SettingMultiProcess Error ", ex); |
||
291 | } |
||
292 | |||
293 | return result; |
||
294 | } |
||
295 | |||
296 | a53dfe45 | taeseongkim | /// <summary> |
297 | /// WCF 시작 |
||
298 | /// </summary> |
||
299 | /// <returns></returns> |
||
300 | 53c9637d | taeseongkim | public CommunicationState StartWcfService() |
301 | { |
||
302 | CommunicationState result = CommunicationState.Faulted; |
||
303 | |||
304 | try |
||
305 | { |
||
306 | if (gServiceHostAddress != null) |
||
307 | { |
||
308 | gWcfServiceHost = gWcfServiceHost.WcfCreate(this, typeof(IWcfService.IStationService), gServiceHostAddress); |
||
309 | } |
||
310 | |||
311 | if (gWcfServiceHost?.State != CommunicationState.Faulted) |
||
312 | { |
||
313 | result = gWcfServiceHost.State; |
||
314 | } |
||
315 | } |
||
316 | catch (Exception ex) |
||
317 | { |
||
318 | logger.Error("Start WCF Service Error ", ex); |
||
319 | } |
||
320 | |||
321 | return result; |
||
322 | } |
||
323 | |||
324 | a53dfe45 | taeseongkim | /// <summary> |
325 | /// WCF 중단 |
||
326 | /// </summary> |
||
327 | /// <returns></returns> |
||
328 | 53c9637d | taeseongkim | private bool StopWcfService() |
329 | { |
||
330 | bool result = false; |
||
331 | try |
||
332 | { |
||
333 | gWcfServiceHost.Abort(); |
||
334 | result = true; |
||
335 | } |
||
336 | catch (Exception ex) |
||
337 | { |
||
338 | logger.Error("Stop WCF Service Error ", ex); |
||
339 | } |
||
340 | |||
341 | return result; |
||
342 | } |
||
343 | |||
344 | } |
||
345 | } |