프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.Station / StationService / ServiceStationWCF.cs @ 06f13e11

이력 | 보기 | 이력해설 | 다운로드 (12.3 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 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
                    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 06f13e11 taeseongkim
                        result = ConvertProcessAdd(ProjectNo, convertID);
73 53c9637d taeseongkim
                    }
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 06f13e11 taeseongkim
82 53c9637d taeseongkim
            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 06f13e11 taeseongkim
                var convertItem = database.GetConvertItem(ProjectNo, convertID);
139 53c9637d taeseongkim
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 06f13e11 taeseongkim
        public bool ConvertProcessState(string ConvertID, int status, int CurrentPage, int TotalPage, string Error)
190 53c9637d taeseongkim
        {
191 06f13e11 taeseongkim
            var items = AliveConvertQueue.Where(x => x.ConvertID == ConvertID);
192
193
            if (items.Count() > 0)
194 53c9637d taeseongkim
            {
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 06f13e11 taeseongkim
        public bool ConvertFinish(string ConvertID, int status, int CurrentPage, int TotalPage, string Error)
226 53c9637d taeseongkim
        {
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 06f13e11 taeseongkim
            {
239 53c9637d taeseongkim
                ConvertFinish(_convertItem.First());
240 06f13e11 taeseongkim
            }
241 53c9637d taeseongkim
242
            return true;
243
        }
244
245 a53dfe45 taeseongkim
        /// <summary>
246
        /// 대기중인 Convert Item을 가져옴
247
        /// </summary>
248
        /// <returns></returns>
249 53c9637d taeseongkim
        public List<ConvertItem> WaitConvertList()
250
        {
251
            List<ConvertItem> result = new List<ConvertItem>();
252
253
            using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
254
            {
255
                result = database.GetConvertItems(Message.StatusCodeType.Wait).ToList();
256
            }
257
258
            return result;
259
        }
260
261 a53dfe45 taeseongkim
        /// <summary>
262
        /// 현재 AliveConvertQueue에 있는 컨버터 리스트
263
        /// </summary>
264
        /// <returns></returns>
265 53c9637d taeseongkim
        public List<ConvertItem> AliveConvertList()
266
        {
267 06f13e11 taeseongkim
            return ServiceStation.AliveConvertQueue;
268 53c9637d taeseongkim
        }
269
270 a53dfe45 taeseongkim
        /// <summary>
271
        /// 동시 작업 프로세스 갯수 변경
272
        /// </summary>
273
        /// <param name="Value"></param>
274
        /// <returns></returns>
275 53c9637d taeseongkim
        public bool SettingMultiProcess(int Value)
276
        {
277
            bool result = false;
278
279
            try
280
            {
281
                MultiProcessCount = Value;
282
283
                var config = ConfigHelper.AppConfig(configFileName);
284
285
                config.SetValue(CONFIG_DEFINE.SERVICE, CONFIG_DEFINE.CONVERT_SERVICE_PROCESS, Value.ToString());
286
                config.Save(configFileName);
287
288
                result = true;
289
            }
290
            catch (Exception ex)
291
            {
292
                logger.Error("SettingMultiProcess Error ", ex);
293
            }
294
295
            return result;
296
        }
297
298 a53dfe45 taeseongkim
        /// <summary>
299
        /// WCF 시작
300
        /// </summary>
301
        /// <returns></returns>
302 53c9637d taeseongkim
        public CommunicationState StartWcfService()
303
        {
304
            CommunicationState result = CommunicationState.Faulted;
305
306
            try
307
            {
308
                if (gServiceHostAddress != null)
309
                {
310
                    gWcfServiceHost = gWcfServiceHost.WcfCreate(this, typeof(IWcfService.IStationService), gServiceHostAddress);
311
                }
312
313
                if (gWcfServiceHost?.State != CommunicationState.Faulted)
314
                {
315
                    result = gWcfServiceHost.State;
316
                }
317
            }
318
            catch (Exception ex)
319
            {
320
                logger.Error("Start WCF Service Error ", ex);
321
            }
322
323
            return result;
324
        }
325
326 a53dfe45 taeseongkim
        /// <summary>
327
        /// WCF 중단
328
        /// </summary>
329
        /// <returns></returns>
330 53c9637d taeseongkim
        private bool StopWcfService()
331
        {
332
            bool result = false;
333
            try
334
            {
335
                gWcfServiceHost.Abort();
336
                result = true;
337
            }
338
            catch (Exception ex)
339
            {
340
                logger.Error("Stop WCF Service Error ", ex);
341
            }
342
343
            return result;
344
        }
345
346 06f13e11 taeseongkim
        public bool ReleaseConvertItems()
347
        {
348
            System.Diagnostics.Debug.WriteLine("Call ReleaseConvertItems");
349
            setDataBaseWaitingList();
350
            System.Diagnostics.Debug.WriteLine("end ReleaseConvertItems");
351
            return true;
352
        }
353 53c9637d taeseongkim
    }
354
}
클립보드 이미지 추가 (최대 크기: 500 MB)