프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.Station / StationService / ServiceStationWCF.cs @ 508debb1

이력 | 보기 | 이력해설 | 다운로드 (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 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
                        var aliveItems = AliveConvertQueue.Where(x => x.ConvertID == convertItem.ConvertID);
71
                    }
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
143
            using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
144
            {
145 06f13e11 taeseongkim
                var convertItem = database.GetConvertItem(ProjectNo, convertID);
146 53c9637d taeseongkim
147
                /// 순서별 Convert Item 처리 
148
                if (convertItem != null)
149
                {
150
                    try
151
                    {
152 cdfb57ff taeseongkim
                        if (AliveConvertQueue.Count(c => c.UniqueKey == convertItem.UniqueKey) == 0)
153
                        {
154 60723dc9 taeseongkim
                            if (ServiceStation.AliveConvertQueue.Count() < ServiceProperty.PROCESS_COUNT)
155 cdfb57ff taeseongkim
                            {
156 0a89a17f taeseongkim
                                convertItem.ServiceID = this.ServiceID;
157 cdfb57ff taeseongkim
                                ConvertProcessStart(convertItem);
158
                                result = true.ToString();
159
                            }
160 949d5058 taeseongkim
                            else
161
                            {
162 eeb0a39c taeseongkim
                                PassConvertItem(ProjectNo, convertID, convertItem.UniqueKey);
163
                     
164 949d5058 taeseongkim
                                logger.Info($"ConvertAdd  ConvertProcess Wait ProcessCount ProjectNo:{ProjectNo} convertID:{convertID} ");
165
                                result = true.ToString();
166
                            }
167 cdfb57ff taeseongkim
                        }
168
                        else
169 53c9637d taeseongkim
                        {
170
                            result = true.ToString();
171
                        }
172
                    }
173
                    catch (Exception ex)
174
                    {
175
                        result = "Convert Process Start Error";
176 949d5058 taeseongkim
                        logger.Error($"ConvertAdd  ConvertProcess call Error  ProjectNo:{ProjectNo} convertID:{convertID} ", ex);
177 53c9637d taeseongkim
                    }
178
                }
179
                else
180
                {
181 949d5058 taeseongkim
                    logger.Error($"ConvertAdd  ConvertProcess call Error  ProjectNo:{ProjectNo} convertID:{convertID} item Null ");
182 53c9637d taeseongkim
                    result = "Get ConvertItem Error";
183
                }
184
            }
185
186
            return result;
187
        }
188
189 a53dfe45 taeseongkim
        /// <summary>
190
        /// 각 ConvertProcess의 상태값을 저장
191
        /// </summary>
192
        /// <param name="ConvertID"></param>
193
        /// <param name="status"></param>
194
        /// <param name="CurrentPage"></param>
195
        /// <param name="TotalPage"></param>
196
        /// <param name="Error"></param>
197
        /// <returns></returns>
198 06f13e11 taeseongkim
        public bool ConvertProcessState(string ConvertID, int status, int CurrentPage, int TotalPage, string Error)
199 53c9637d taeseongkim
        {
200 06f13e11 taeseongkim
            var items = AliveConvertQueue.Where(x => x.ConvertID == ConvertID);
201
202
            if (items.Count() > 0)
203 53c9637d taeseongkim
            {
204
                var item = items.First();
205
206
                item.TotalPage = TotalPage;
207
                item.CurrentPageNo = CurrentPage;
208 508debb1 taeseongkim
                item.ConvertState = (StatusCodeType)status;
209 53c9637d taeseongkim
            }
210
211
            if (CurrentPage % SaveStatusInterval == 0 || !Error.IsNullOrEmpty())
212
            {
213
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
214
                {
215 0157b158 taeseongkim
                    if (!database.SetConvertState(this.ServiceID, ConvertID, status, CurrentPage, TotalPage, Error))
216 53c9637d taeseongkim
                    {
217
                        logger.Error($"DataBase Error database.SetConvertState({ConvertID}, {(int)status},{CurrentPage},{TotalPage}, {Error})");
218
                    }
219
                }
220
            }
221
222
            return true;
223
        }
224
225 a53dfe45 taeseongkim
        /// <summary>
226
        /// Convert Process 완료시 호출
227
        /// </summary>
228
        /// <param name="ConvertID"></param>
229
        /// <param name="status"></param>
230
        /// <param name="CurrentPage"></param>
231
        /// <param name="TotalPage"></param>
232
        /// <param name="Error"></param>
233
        /// <returns></returns>
234 06f13e11 taeseongkim
        public bool ConvertFinish(string ConvertID, int status, int CurrentPage, int TotalPage, string Error)
235 53c9637d taeseongkim
        {
236
            using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
237
            {
238 0157b158 taeseongkim
                if (!database.SetConvertState(this.ServiceID, ConvertID, status, CurrentPage, TotalPage, Error))
239 53c9637d taeseongkim
                {
240
                    logger.Error($"DataBase Error database.SetConvertState({ConvertID}, {(int)status},{CurrentPage},{TotalPage}, {Error})");
241
                }
242
            }
243
244
            var _convertItem = ServiceStation.AliveConvertQueue.Where(f => f.ConvertID == ConvertID);
245
246
            if (_convertItem.Count() > 0)
247 06f13e11 taeseongkim
            {
248 53c9637d taeseongkim
                ConvertFinish(_convertItem.First());
249 06f13e11 taeseongkim
            }
250 53c9637d taeseongkim
251
            return true;
252
        }
253
254 a53dfe45 taeseongkim
        /// <summary>
255
        /// 대기중인 Convert Item을 가져옴
256
        /// </summary>
257
        /// <returns></returns>
258 53c9637d taeseongkim
        public List<ConvertItem> WaitConvertList()
259
        {
260
            List<ConvertItem> result = new List<ConvertItem>();
261
262
            using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
263
            {
264
                result = database.GetConvertItems(Message.StatusCodeType.Wait).ToList();
265
            }
266
267
            return result;
268
        }
269
270 a53dfe45 taeseongkim
        /// <summary>
271
        /// 현재 AliveConvertQueue에 있는 컨버터 리스트
272
        /// </summary>
273
        /// <returns></returns>
274 53c9637d taeseongkim
        public List<ConvertItem> AliveConvertList()
275
        {
276 06f13e11 taeseongkim
            return ServiceStation.AliveConvertQueue;
277 53c9637d taeseongkim
        }
278
279 a53dfe45 taeseongkim
        /// <summary>
280
        /// WCF 시작
281
        /// </summary>
282
        /// <returns></returns>
283 53c9637d taeseongkim
        public CommunicationState StartWcfService()
284
        {
285
            CommunicationState result = CommunicationState.Faulted;
286
287
            try
288
            {
289
                if (gServiceHostAddress != null)
290
                {
291
                    gWcfServiceHost = gWcfServiceHost.WcfCreate(this, typeof(IWcfService.IStationService), gServiceHostAddress);
292
                }
293
294
                if (gWcfServiceHost?.State != CommunicationState.Faulted)
295
                {
296
                    result = gWcfServiceHost.State;
297
                }
298
            }
299
            catch (Exception ex)
300
            {
301
                logger.Error("Start WCF Service Error ", ex);
302
            }
303
304
            return result;
305
        }
306
307 a53dfe45 taeseongkim
        /// <summary>
308
        /// WCF 중단
309
        /// </summary>
310
        /// <returns></returns>
311 53c9637d taeseongkim
        private bool StopWcfService()
312
        {
313
            bool result = false;
314
            try
315
            {
316
                gWcfServiceHost.Abort();
317
                result = true;
318
            }
319
            catch (Exception ex)
320
            {
321
                logger.Error("Stop WCF Service Error ", ex);
322
            }
323
324
            return result;
325
        }
326
327 06f13e11 taeseongkim
        public bool ReleaseConvertItems()
328
        {
329
            System.Diagnostics.Debug.WriteLine("Call ReleaseConvertItems");
330 60723dc9 taeseongkim
            if (!IsReleaseItems)
331
            {
332
                ReleaseItems();
333
            }
334
335 06f13e11 taeseongkim
            System.Diagnostics.Debug.WriteLine("end ReleaseConvertItems");
336
            return true;
337
        }
338 53c9637d taeseongkim
    }
339
}
클립보드 이미지 추가 (최대 크기: 500 MB)