프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / ConvertService / ServiceBase / Markus.Service.Station / StationService / ServiceStationWCF.cs @ 43e1d368

이력 | 보기 | 이력해설 | 다운로드 (12.5 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 1ae729e4 taeseongkim
    //[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, IncludeExceptionDetailInFaults = true)]
22 53c9637d taeseongkim
    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 06f13e11 taeseongkim
                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 06f13e11 taeseongkim
            string convertID = new Guid().CreateUniqueGuid().ToString().Replace("-", "");
61 53c9637d taeseongkim
62
            try
63
            {
64
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
65
                {
66 5d863c06 taeseongkim
                    var convertItem = database.GetConvertItembyDocumentID(ProjectNo, DocumentID);
67
68
                    if(convertItem != null)
69
                    {
70 43e1d368 taeseongkim
                        var aliveItems = AliveConvertQueue.Where(x => x.UniqueKey == convertItem.UniqueKey);
71 5d863c06 taeseongkim
                    }
72
73 53c9637d taeseongkim
                    if (!database.SetConvertDoc(ProjectNo, convertID, originfilePath, DocumentID))
74
                    {
75
                        logger.Error($"Set Convert Document Error - ProjectNo:{ProjectNo} UniqueID:{convertID} originfilePath:{originfilePath} DocumentID:{DocumentID}");
76
                    }
77
                    else
78
                    {
79 06f13e11 taeseongkim
                        result = ConvertProcessAdd(ProjectNo, convertID);
80 53c9637d taeseongkim
                    }
81
                }
82
            }
83
            catch (Exception ex)
84
            {
85
                result = "DataBase SetConvert Error";
86
                logger.Error($"ConvertMenualAdd Error-  database.SetConvertDoc ProjectNo:{ProjectNo} UniqueID:{convertID} originfilePath:{originfilePath} DocumentID:{DocumentID}", ex);
87
            }
88 06f13e11 taeseongkim
89 53c9637d taeseongkim
            return result;
90
        }
91
92 a53dfe45 taeseongkim
        /// <summary>
93
        /// ConvertItem의 상태
94
        /// </summary>
95
        /// <param name="ProjectNo"></param>
96
        /// <param name="DocumentID"></param>
97
        /// <returns></returns>
98
        public Item GetConvertItem(string ProjectNo, string DocumentID)
99
        {
100
            Item result = null;
101
102
            try
103
            {
104
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
105
                {
106
                    var item = database.GetConvertItembyDocumentID(ProjectNo, DocumentID);
107
108
                    if (item != null)
109
                    {
110
                        result =
111
                        new Item
112
                        {
113
                            DocumentID = item.UniqueKey,
114 508debb1 taeseongkim
                            Status = item.ConvertState.ToString(),
115 a53dfe45 taeseongkim
                            ProjectNo = item.ProjectNumber,
116
                            TotalPage = item.TotalPage,
117
                            CurrentPageNo = item.CurrentPageNo,
118
                            PdfPath = item.OriginfilePath,
119
                            ConvertPath = item.ConvertPath
120
                        };
121 53c9637d taeseongkim
122 a53dfe45 taeseongkim
                    }
123
                }
124
            }
125
            catch (Exception ex)
126
            {
127
                throw new FaultException("Get ConvertItem Error");
128
            }
129 53c9637d taeseongkim
130 a53dfe45 taeseongkim
            return result;
131
        }
132
133
        /// <summary>
134
        /// Convert Item을 DB에 추가 하고 프로세스 실행시 호출
135
        /// </summary>
136
        /// <param name="ProjectNo"></param>
137
        /// <param name="convertID"></param>
138
        /// <returns></returns>
139 53c9637d taeseongkim
        private string ConvertProcessAdd(string ProjectNo, string convertID)
140
        {
141
            string result = false.ToString();
142 43e1d368 taeseongkim
            logger.Warn($"WCF ConvertProcessAdd Call ProjectNo:{ProjectNo} convertID:{convertID} ");
143 53c9637d taeseongkim
144
            using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
145
            {
146 06f13e11 taeseongkim
                var convertItem = database.GetConvertItem(ProjectNo, convertID);
147 53c9637d taeseongkim
148
                /// 순서별 Convert Item 처리 
149
                if (convertItem != null)
150
                {
151
                    try
152
                    {
153 cdfb57ff taeseongkim
                        if (AliveConvertQueue.Count(c => c.UniqueKey == convertItem.UniqueKey) == 0)
154
                        {
155 43e1d368 taeseongkim
                            if (AliveConvertQueue.Count() < ServiceProperty.PROCESS_COUNT)
156 cdfb57ff taeseongkim
                            {
157 0a89a17f taeseongkim
                                convertItem.ServiceID = this.ServiceID;
158 43e1d368 taeseongkim
                                AliveConvertQueue.Add(convertItem);
159
160
                                var startResult = ConvertProcessStart(convertItem);
161
162
                                if(!startResult)
163
                                {
164
                                    AliveConvertQueue.Remove(convertItem);
165
                                }
166
167 cdfb57ff taeseongkim
                                result = true.ToString();
168
                            }
169 949d5058 taeseongkim
                            else
170
                            {
171 43e1d368 taeseongkim
                                //logger.Warn($"ConvertProcessAdd  PassConvertItem ProcessCount ProjectNo:{ProjectNo} convertID:{convertID} ");
172
                                ///// sub service (다른ip의 서비스로 보낸다) 이중화
173
                                //PassConvertItem(ProjectNo, convertID, convertItem.UniqueKey,true);
174 eeb0a39c taeseongkim
                     
175 43e1d368 taeseongkim
                                
176 949d5058 taeseongkim
                                result = true.ToString();
177
                            }
178 cdfb57ff taeseongkim
                        }
179
                        else
180 53c9637d taeseongkim
                        {
181
                            result = true.ToString();
182
                        }
183
                    }
184
                    catch (Exception ex)
185
                    {
186
                        result = "Convert Process Start Error";
187 949d5058 taeseongkim
                        logger.Error($"ConvertAdd  ConvertProcess call Error  ProjectNo:{ProjectNo} convertID:{convertID} ", ex);
188 53c9637d taeseongkim
                    }
189
                }
190
                else
191
                {
192 949d5058 taeseongkim
                    logger.Error($"ConvertAdd  ConvertProcess call Error  ProjectNo:{ProjectNo} convertID:{convertID} item Null ");
193 53c9637d taeseongkim
                    result = "Get ConvertItem Error";
194
                }
195
            }
196
197
            return result;
198
        }
199
200 a53dfe45 taeseongkim
        /// <summary>
201
        /// 각 ConvertProcess의 상태값을 저장
202
        /// </summary>
203
        /// <param name="ConvertID"></param>
204
        /// <param name="status"></param>
205
        /// <param name="CurrentPage"></param>
206
        /// <param name="TotalPage"></param>
207
        /// <param name="Error"></param>
208
        /// <returns></returns>
209 06f13e11 taeseongkim
        public bool ConvertProcessState(string ConvertID, int status, int CurrentPage, int TotalPage, string Error)
210 53c9637d taeseongkim
        {
211 06f13e11 taeseongkim
            var items = AliveConvertQueue.Where(x => x.ConvertID == ConvertID);
212
213
            if (items.Count() > 0)
214 53c9637d taeseongkim
            {
215
                var item = items.First();
216
217
                item.TotalPage = TotalPage;
218
                item.CurrentPageNo = CurrentPage;
219 508debb1 taeseongkim
                item.ConvertState = (StatusCodeType)status;
220 53c9637d taeseongkim
            }
221
222
            if (CurrentPage % SaveStatusInterval == 0 || !Error.IsNullOrEmpty())
223
            {
224
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
225
                {
226 0157b158 taeseongkim
                    if (!database.SetConvertState(this.ServiceID, ConvertID, status, CurrentPage, TotalPage, Error))
227 53c9637d taeseongkim
                    {
228
                        logger.Error($"DataBase Error database.SetConvertState({ConvertID}, {(int)status},{CurrentPage},{TotalPage}, {Error})");
229
                    }
230
                }
231
            }
232
233
            return true;
234
        }
235
236 a53dfe45 taeseongkim
        /// <summary>
237
        /// Convert Process 완료시 호출
238
        /// </summary>
239
        /// <param name="ConvertID"></param>
240
        /// <param name="status"></param>
241
        /// <param name="CurrentPage"></param>
242
        /// <param name="TotalPage"></param>
243
        /// <param name="Error"></param>
244
        /// <returns></returns>
245 06f13e11 taeseongkim
        public bool ConvertFinish(string ConvertID, int status, int CurrentPage, int TotalPage, string Error)
246 53c9637d taeseongkim
        {
247
            using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
248
            {
249 0157b158 taeseongkim
                if (!database.SetConvertState(this.ServiceID, ConvertID, status, CurrentPage, TotalPage, Error))
250 53c9637d taeseongkim
                {
251
                    logger.Error($"DataBase Error database.SetConvertState({ConvertID}, {(int)status},{CurrentPage},{TotalPage}, {Error})");
252
                }
253
            }
254
255 43e1d368 taeseongkim
            var _convertItem = AliveConvertQueue.Where(f => f.ConvertID == ConvertID);
256 53c9637d taeseongkim
257
            if (_convertItem.Count() > 0)
258 06f13e11 taeseongkim
            {
259 53c9637d taeseongkim
                ConvertFinish(_convertItem.First());
260 06f13e11 taeseongkim
            }
261 53c9637d taeseongkim
262
            return true;
263
        }
264
265 a53dfe45 taeseongkim
        /// <summary>
266
        /// 대기중인 Convert Item을 가져옴
267
        /// </summary>
268
        /// <returns></returns>
269 53c9637d taeseongkim
        public List<ConvertItem> WaitConvertList()
270
        {
271
            List<ConvertItem> result = new List<ConvertItem>();
272
273
            using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
274
            {
275
                result = database.GetConvertItems(Message.StatusCodeType.Wait).ToList();
276
            }
277
278
            return result;
279
        }
280
281 a53dfe45 taeseongkim
        /// <summary>
282
        /// 현재 AliveConvertQueue에 있는 컨버터 리스트
283
        /// </summary>
284
        /// <returns></returns>
285 53c9637d taeseongkim
        public List<ConvertItem> AliveConvertList()
286
        {
287 06f13e11 taeseongkim
            return ServiceStation.AliveConvertQueue;
288 53c9637d taeseongkim
        }
289
290 a53dfe45 taeseongkim
        /// <summary>
291
        /// WCF 시작
292
        /// </summary>
293
        /// <returns></returns>
294 53c9637d taeseongkim
        public CommunicationState StartWcfService()
295
        {
296
            CommunicationState result = CommunicationState.Faulted;
297
298
            try
299
            {
300
                if (gServiceHostAddress != null)
301
                {
302
                    gWcfServiceHost = gWcfServiceHost.WcfCreate(this, typeof(IWcfService.IStationService), gServiceHostAddress);
303
                }
304
305
                if (gWcfServiceHost?.State != CommunicationState.Faulted)
306
                {
307
                    result = gWcfServiceHost.State;
308
                }
309
            }
310
            catch (Exception ex)
311
            {
312
                logger.Error("Start WCF Service Error ", ex);
313
            }
314
315
            return result;
316
        }
317
318 a53dfe45 taeseongkim
        /// <summary>
319
        /// WCF 중단
320
        /// </summary>
321
        /// <returns></returns>
322 53c9637d taeseongkim
        private bool StopWcfService()
323
        {
324
            bool result = false;
325
            try
326
            {
327
                gWcfServiceHost.Abort();
328
                result = true;
329
            }
330
            catch (Exception ex)
331
            {
332
                logger.Error("Stop WCF Service Error ", ex);
333
            }
334
335
            return result;
336
        }
337
338 06f13e11 taeseongkim
        public bool ReleaseConvertItems()
339
        {
340
            System.Diagnostics.Debug.WriteLine("Call ReleaseConvertItems");
341 60723dc9 taeseongkim
            if (!IsReleaseItems)
342
            {
343
                ReleaseItems();
344
            }
345
346 06f13e11 taeseongkim
            System.Diagnostics.Debug.WriteLine("end ReleaseConvertItems");
347
            return true;
348
        }
349 53c9637d taeseongkim
    }
350
}
클립보드 이미지 추가 (최대 크기: 500 MB)