프로젝트

일반

사용자정보

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

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

이력 | 보기 | 이력해설 | 다운로드 (11.2 KB)

1
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
    /// <summary>
18
    /// web service 목록
19
    /// </summary>
20
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
21
    //[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, IncludeExceptionDetailInFaults = true)]
22
    public partial class ServiceStation : IStationService
23
    {
24
        /// <summary>
25
        /// DB에 Convrert Item을 추가 하고 호출 
26
        /// CovnertWebService에서 호출시 사용
27
        /// </summary>
28
        /// <param name="ProjectNo"></param>
29
        /// <param name="ConvertID"></param>
30
        /// <returns></returns>
31
        public string ConvertAdd(string ProjectNo, string ConvertID)
32
        {
33
            string result = false.ToString();
34

    
35
            try
36
            {
37
                result = ConvertProcessAdd(ProjectNo,ConvertID);
38
            }
39
            catch (Exception ex)
40
            {
41
                result = $"ConvertAdd Error {ConvertID}";
42
                logger.Error($"ConvertAdd Error- {ConvertID}", ex);
43
            }
44

    
45
            return result;
46
        }
47

    
48
        /// <summary>
49
        /// 별도의 호출 사용 
50
        /// </summary>
51
        /// <param name="ProjectNo"></param>
52
        /// <param name="originfilePath"></param>
53
        /// <param name="DocumentID"></param>
54
        /// <returns></returns>
55
        public string ConvertMenualAdd(string ProjectNo, string originfilePath, string DocumentID)
56
        {
57
            string result = false.ToString();
58
            string convertID = new Guid().CreateUniqueGuid().ToString().Replace("-","");
59

    
60
            try
61
            {
62
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
63
                {
64
                    if (!database.SetConvertDoc(ProjectNo, convertID, originfilePath, DocumentID))
65
                    {
66
                        logger.Error($"Set Convert Document Error - ProjectNo:{ProjectNo} UniqueID:{convertID} originfilePath:{originfilePath} DocumentID:{DocumentID}");
67
                    }
68
                    else
69
                    {
70
                        result = ConvertProcessAdd(ProjectNo,convertID);
71
                    }
72
                }
73
            }
74
            catch (Exception ex)
75
            {
76
                result = "DataBase SetConvert Error";
77
                logger.Error($"ConvertMenualAdd Error-  database.SetConvertDoc ProjectNo:{ProjectNo} UniqueID:{convertID} originfilePath:{originfilePath} DocumentID:{DocumentID}", ex);
78
            }
79
            
80
            return result;
81
        }
82

    
83
        /// <summary>
84
        /// ConvertItem의 상태
85
        /// </summary>
86
        /// <param name="ProjectNo"></param>
87
        /// <param name="DocumentID"></param>
88
        /// <returns></returns>
89
        public Item GetConvertItem(string ProjectNo, string DocumentID)
90
        {
91
            Item result = null;
92

    
93
            try
94
            {
95
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
96
                {
97
                    var item = database.GetConvertItembyDocumentID(ProjectNo, DocumentID);
98

    
99
                    if (item != null)
100
                    {
101
                        result =
102
                        new Item
103
                        {
104
                            DocumentID = item.UniqueKey,
105
                            Status = item.ConvertState,
106
                            ProjectNo = item.ProjectNumber,
107
                            TotalPage = item.TotalPage,
108
                            CurrentPageNo = item.CurrentPageNo,
109
                            PdfPath = item.OriginfilePath,
110
                            ConvertPath = item.ConvertPath
111
                        };
112

    
113
                    }
114
                }
115
            }
116
            catch (Exception ex)
117
            {
118
                throw new FaultException("Get ConvertItem Error");
119
            }
120

    
121
            return result;
122
        }
123

    
124
        /// <summary>
125
        /// Convert Item을 DB에 추가 하고 프로세스 실행시 호출
126
        /// </summary>
127
        /// <param name="ProjectNo"></param>
128
        /// <param name="convertID"></param>
129
        /// <returns></returns>
130
        private string ConvertProcessAdd(string ProjectNo, string convertID)
131
        {
132
            string result = false.ToString();
133

    
134
            using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
135
            {
136
                var convertItem = database.GetConvertItem(ProjectNo,convertID);
137

    
138
                /// 순서별 Convert Item 처리 
139
                if (convertItem != null)
140
                {
141
                    try
142
                    {
143
                        if (ServiceStation.AliveConvertQueue.Count() < MultiProcessCount)
144
                        {
145
                            ConvertProcessStart(convertItem);
146
                            result = true.ToString();
147
                        }
148
                    }
149
                    catch (Exception ex)
150
                    {
151
                        result = "Convert Process Start Error";
152
                        logger.Error("ConvertMenualAdd  ConvertProcess call Error  ProjectNo:{ProjectNo} UniqueID:{UniqueID} originfilePath:{originfilePath} DocumentID:{DocumentID}", ex);
153
                    }
154
                }
155
                else
156
                {
157
                    result = "Get ConvertItem Error";
158
                }
159
            }
160

    
161
            return result;
162
        }
163

    
164
        /// <summary>
165
        /// 각 ConvertProcess의 상태값을 저장
166
        /// </summary>
167
        /// <param name="ConvertID"></param>
168
        /// <param name="status"></param>
169
        /// <param name="CurrentPage"></param>
170
        /// <param name="TotalPage"></param>
171
        /// <param name="Error"></param>
172
        /// <returns></returns>
173
        public bool ConvertProcessState(string ConvertID, int status, int CurrentPage, int TotalPage,string Error)
174
        {
175
            var items =AliveConvertQueue.Where(x => x.ConvertID == ConvertID);
176
            
177
            if(items.Count() > 0)
178
            {
179
                var item = items.First();
180

    
181
                item.TotalPage = TotalPage;
182
                item.CurrentPageNo = CurrentPage;
183
                item.ConvertState = ((StatusCodeType)status).ToString();
184
            }
185

    
186
            if (CurrentPage % SaveStatusInterval == 0 || !Error.IsNullOrEmpty())
187
            {
188
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
189
                {
190
                    if (!database.SetConvertState(ConvertID, status, CurrentPage, TotalPage, Error))
191
                    {
192
                        logger.Error($"DataBase Error database.SetConvertState({ConvertID}, {(int)status},{CurrentPage},{TotalPage}, {Error})");
193
                    }
194
                }
195
            }
196

    
197
            return true;
198
        }
199

    
200
        /// <summary>
201
        /// Convert Process 완료시 호출
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
        public bool ConvertFinish( string ConvertID, int status, int CurrentPage, int TotalPage, string Error)
210
        {
211
            using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
212
            {
213
                if (!database.SetConvertState(ConvertID, status, CurrentPage, TotalPage, Error))
214
                {
215
                    logger.Error($"DataBase Error database.SetConvertState({ConvertID}, {(int)status},{CurrentPage},{TotalPage}, {Error})");
216
                }
217
            }
218

    
219
            var _convertItem = ServiceStation.AliveConvertQueue.Where(f => f.ConvertID == ConvertID);
220

    
221
            if (_convertItem.Count() > 0)
222
                ConvertFinish(_convertItem.First());
223

    
224
            return true;
225
        }
226

    
227
        /// <summary>
228
        /// 대기중인 Convert Item을 가져옴
229
        /// </summary>
230
        /// <returns></returns>
231
        public List<ConvertItem> WaitConvertList()
232
        {
233
            List<ConvertItem> result = new List<ConvertItem>();
234

    
235
            using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
236
            {
237
                result = database.GetConvertItems(Message.StatusCodeType.Wait).ToList();
238
            }
239

    
240
            return result;
241
        }
242

    
243
        /// <summary>
244
        /// 현재 AliveConvertQueue에 있는 컨버터 리스트
245
        /// </summary>
246
        /// <returns></returns>
247
        public List<ConvertItem> AliveConvertList()
248
        {
249
            return ServiceStation.AliveConvertQueue.ToList();
250
        }
251

    
252
        /// <summary>
253
        /// 동시 작업 프로세스 갯수 변경
254
        /// </summary>
255
        /// <param name="Value"></param>
256
        /// <returns></returns>
257
        public bool SettingMultiProcess(int Value)
258
        {
259
            bool result = false;
260

    
261
            try
262
            {
263
                MultiProcessCount = Value;
264

    
265
                var config = ConfigHelper.AppConfig(configFileName);
266

    
267
                config.SetValue(CONFIG_DEFINE.SERVICE, CONFIG_DEFINE.CONVERT_SERVICE_PROCESS, Value.ToString());
268
                config.Save(configFileName);
269

    
270
                result = true;
271
            }
272
            catch (Exception ex)
273
            {
274
                logger.Error("SettingMultiProcess Error ", ex);
275
            }
276

    
277
            return result;
278
        }
279

    
280
        /// <summary>
281
        /// WCF 시작
282
        /// </summary>
283
        /// <returns></returns>
284
        public CommunicationState StartWcfService()
285
        {
286
            CommunicationState result = CommunicationState.Faulted;
287

    
288
            try
289
            {
290
                if (gServiceHostAddress != null)
291
                {
292
                    gWcfServiceHost = gWcfServiceHost.WcfCreate(this, typeof(IWcfService.IStationService), gServiceHostAddress);
293
                }
294

    
295
                if (gWcfServiceHost?.State != CommunicationState.Faulted)
296
                {
297
                    result = gWcfServiceHost.State;
298
                }
299
            }
300
            catch (Exception ex)
301
            {
302
                logger.Error("Start WCF Service Error ", ex);
303
            }
304

    
305
            return result;
306
        }
307

    
308
        /// <summary>
309
        /// WCF 중단
310
        /// </summary>
311
        /// <returns></returns>
312
        private bool StopWcfService()
313
        {
314
            bool result = false;
315
            try
316
            {
317
                gWcfServiceHost.Abort();
318
                result = true;
319
            }
320
            catch (Exception ex)
321
            {
322
                logger.Error("Stop WCF Service Error ", ex);
323
            }
324

    
325
            return result;
326
        }
327

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