프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.DataBase / ConvertDatabase.cs @ e6281033

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

1 ff4b1e6e taeseongkim
using Markus.EntityModel;
2
using Markus.Message;
3 53c9637d taeseongkim
using Markus.Service.Extensions;
4
using System;
5
using System.Collections.Generic;
6
using System.IO;
7
using System.Linq;
8 2decfbdf alzkakdixm
using static Markus.Service.DataBase.ConvertDatabase;
9
using System.Windows;
10
using System.Linq.Expressions;
11
using Markus.Service.Interface;
12 53c9637d taeseongkim
13
namespace Markus.Service.DataBase
14
{
15
    public class ConvertDatabase : IDisposable
16
    {
17 e6281033 alzkakdixm
        #region Constructor
18
        /// <summary>
19
        ///해당 프로젝트의 데이터베이스 연결
20
        /// </summary>
21
22 ff4b1e6e taeseongkim
        Markus.EntityModel.MarkusModel entities;
23 53c9637d taeseongkim
24
        public ConvertDatabase(string ConnectionString)
25
        {
26
            try
27
            {
28 ff4b1e6e taeseongkim
                entities = new Markus.EntityModel.MarkusModel(ConnectionString);
29 53c9637d taeseongkim
            }
30
            catch (Exception ex)
31
            {
32
                System.Diagnostics.Debug.WriteLine(ex.ToString());
33 06f13e11 taeseongkim
                throw ex;
34 53c9637d taeseongkim
            }
35
        }
36
37
        public void Dispose()
38
        {
39
            entities.Dispose();
40
        }
41
42 e6281033 alzkakdixm
        #endregion
43
44
        #region DataBaseItemsModel Function
45
46
        #region Get WaitConvertItems
47
48 53c9637d taeseongkim
        /// <summary>
49 e6281033 alzkakdixm
        /// service에서 대기중이거나 오류인 아이템을 가져가서 컨버터 프로세스를 호출한다.
50
        /// 컨버터 상태가 에러이거나 2보다 작은 경우 
51
        /// UniqueKey는 각 데이터베이스의 문서 정보에서 유일한 키이며 컨버터저장에서 같은 폴더로의 저장을 방지 한다.
52
        /// 
53 53c9637d taeseongkim
        /// </summary>
54 e6281033 alzkakdixm
        /// <param name="aliveItems"></param>
55
        /// <param name="TakeCount"></param>
56 53c9637d taeseongkim
        /// <returns></returns>
57 e6281033 alzkakdixm
        public IEnumerable<CONVERTER_DOC> GetWaitConvertItems(List<string> projectList, int TakeCount)
58 53c9637d taeseongkim
        {
59 e6281033 alzkakdixm
            var convertWaitingItems = entities.CONVERTER_DOC.OrderBy(x => x.CREATE_DATETIME).Where(
60
                                        x =>
61
                                        //projectList.Contains(x.PROJECT_NO) && x.RECONVERTER < 2 &&
62
                                         x.RECONVERTER < 2 &&
63
                                        (x.STATUS == (int)StatusCodeType.None || x.STATUS == (int)StatusCodeType.FileError || x.STATUS == (int)StatusCodeType.Error))
64
                                    .GroupBy(x => x.DOCUMENT_ID).Select(x => x.FirstOrDefault())
65
                                    .Take(TakeCount);
66 53c9637d taeseongkim
67 e6281033 alzkakdixm
            return convertWaitingItems;
68
        }
69 53c9637d taeseongkim
70 e6281033 alzkakdixm
        #endregion
71 53c9637d taeseongkim
72 e6281033 alzkakdixm
        #region Get FilterConvertItems
73 53c9637d taeseongkim
74 e6281033 alzkakdixm
        /// <summary>
75
        /// 상단 그리드 선택된 Status에 따라 DB에서 값 가져온다.
76
        /// </summary>
77
        public IEnumerable<Interface.ConvertItem> GetConvertProjects(int status)
78
        {
79
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
80
            var query = from items in entities.CONVERTER_DOC
81
                        join documents in entities.DOCUMENT_ITEM on items.DOCUMENT_ID equals documents.DOCUMENT_ID into GroupItems
82
                        from subpet in GroupItems.DefaultIfEmpty()
83
                        where items.STATUS == status
84
                        orderby items.CREATE_DATETIME descending
85
                        select new
86
                        {
87
                            ID = items.ID,
88
                            DOCUMENT_URL = items.DOCUMENT_URL,
89
                            RECONVERTER = items.RECONVERTER,
90
                            SERVICE_ID = items.SERVICE_ID,
91
                            STATUS = items.STATUS,
92
                            CREATE_DATETIME = items.CREATE_DATETIME,
93
                            TOTAL_PAGE = items.TOTAL_PAGE,
94
                            CURRENT_PAGE = items.CURRENT_PAGE,
95
                            EXCEPTION = items.EXCEPTION,
96
                            PROJECT_NO = items.PROJECT_NO,
97
                            DOCUMENT_ID = items.DOCUMENT_ID,
98
                            REVISION = subpet.REVISION,
99
                            DOCUMENT_NO = subpet.DOCUMENT_NO,
100
                            DOCUMENT_NAME = subpet.DOCUMENT_NAME,
101
                            GROUP_NO = subpet.GROUP_NO
102
                            //REVISION = documents.REVISION,
103
                            //DOCUMENT_NO = documents.DOCUMENT_NO,
104
                            //DOCUMENT_NAME = documents.DOCUMENT_NAME,
105
                            //GROUP_NO = documents.GROUP_NO
106
                        };
107 53c9637d taeseongkim
108 e6281033 alzkakdixm
            if (query.Count() > 0)//세미
109 53c9637d taeseongkim
            {
110 e6281033 alzkakdixm
                foreach (var item in query)
111 53c9637d taeseongkim
                {
112 e6281033 alzkakdixm
                    Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
113 53c9637d taeseongkim
                    {
114
115 e6281033 alzkakdixm
                        ReConverter = item.RECONVERTER,
116
                        ServiceID = item.SERVICE_ID,
117
                        ConvertState = (StatusCodeType)item.STATUS,
118
                        CreateTime = item.CREATE_DATETIME,
119
                        TotalPage = item.TOTAL_PAGE,
120
                        CurrentPageNo = item.CURRENT_PAGE,
121
                        Exception = item.EXCEPTION,
122 53c9637d taeseongkim
123 e6281033 alzkakdixm
                        Revision = item.REVISION,
124
                        DocumnetNo = item.DOCUMENT_NO,
125
                        DocumnetName = item.DOCUMENT_NAME,
126
                        GroupNo = item.GROUP_NO,
127
                        DocumentID = item.DOCUMENT_ID
128
                    };
129
                    convertItems.Add(convertitem);
130 53c9637d taeseongkim
                }
131
            }
132 e6281033 alzkakdixm
            return convertItems;
133 53c9637d taeseongkim
134 e6281033 alzkakdixm
        }
135 53c9637d taeseongkim
136 e6281033 alzkakdixm
        #endregion
137 53c9637d taeseongkim
138 e6281033 alzkakdixm
        #region Update RealDataSelect 
139 53c9637d taeseongkim
140
        /// <summary>
141 e6281033 alzkakdixm
        /// 상단 그리드에서 선택된 RealDataSelect
142
        /// 용도: 중앙그리드 Items Update
143 53c9637d taeseongkim
        /// </summary>
144 e6281033 alzkakdixm
        public IEnumerable<Interface.ConvertItem> GetConvertProjects(System.Collections.ObjectModel.ObservableCollection<Interface.ConvertItem> selectedConvert)
145 53c9637d taeseongkim
        {
146 e6281033 alzkakdixm
            List<Interface.ConvertItem> StatusKeep = new List<Interface.ConvertItem>();
147 53c9637d taeseongkim
148 e6281033 alzkakdixm
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
149 53c9637d taeseongkim
150 e6281033 alzkakdixm
            foreach (var selectedConvertItem in selectedConvert)
151 53c9637d taeseongkim
            {
152 e6281033 alzkakdixm
                var query = from items in entities.CONVERTER_DOC //세미
153
                            join documents in entities.DOCUMENT_ITEM on items.DOCUMENT_ID equals documents.DOCUMENT_ID into GroupItems
154
                            from subpet in GroupItems.DefaultIfEmpty()
155
                            where items.PROJECT_NO == selectedConvertItem.ProjectNumber && items.ID == selectedConvertItem.ConvertID
156
                            select new
157
                            {
158
                                ID = items.ID,
159
                                DOCUMENT_URL = items.DOCUMENT_URL,
160
                                RECONVERTER = items.RECONVERTER,
161
                                SERVICE_ID = items.SERVICE_ID,
162
                                STATUS = items.STATUS,
163
                                CREATE_DATETIME = items.CREATE_DATETIME,
164
                                TOTAL_PAGE = items.TOTAL_PAGE,
165
                                CURRENT_PAGE = items.CURRENT_PAGE,
166
                                EXCEPTION = items.EXCEPTION,
167
                                PROJECT_NO = items.PROJECT_NO,
168
                                DOCUMENT_ID = items.DOCUMENT_ID,
169
                                REVISION = subpet.REVISION,
170
                                DOCUMENT_NO = subpet.DOCUMENT_NO,
171
                                DOCUMENT_NAME = subpet.DOCUMENT_NAME,
172
                                GROUP_NO = subpet.GROUP_NO
173
                            };
174 53c9637d taeseongkim
175 41fa3d98 djkim
176 e6281033 alzkakdixm
                if (query.Count() > 0)//세미
177 53c9637d taeseongkim
                {
178 e6281033 alzkakdixm
                    foreach (var item in query)
179 41fa3d98 djkim
                    {
180 e6281033 alzkakdixm
                        Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
181
                        {
182 53c9637d taeseongkim
183 e6281033 alzkakdixm
                            ReConverter = item.RECONVERTER,
184
                            ServiceID = item.SERVICE_ID,
185
                            ConvertState = (StatusCodeType)item.STATUS,
186
                            CreateTime = item.CREATE_DATETIME,
187
                            TotalPage = item.TOTAL_PAGE,
188
                            CurrentPageNo = item.CURRENT_PAGE,
189
                            Exception = item.EXCEPTION,
190
                            ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID),
191 53c9637d taeseongkim
192 e6281033 alzkakdixm
                            Revision = item.REVISION,
193
                            DocumnetNo = item.DOCUMENT_NO,
194
                            DocumnetName = item.DOCUMENT_NAME,
195
                            GroupNo = item.GROUP_NO
196
                        };
197 53c9637d taeseongkim
198 e6281033 alzkakdixm
                        StatusKeep.Add(convertitem);
199 53c9637d taeseongkim
200 e6281033 alzkakdixm
                    }
201
                }
202
            }
203
            return StatusKeep;
204 0157b158 taeseongkim
        }
205 53c9637d taeseongkim
206 e6281033 alzkakdixm
        #endregion
207 53c9637d taeseongkim
208 e6281033 alzkakdixm
        #region Data Convert
209 53c9637d taeseongkim
210 e6281033 alzkakdixm
        /// <summary>
211
        /// 상단 그리드에서 선택된 Convert 버튼 
212
        /// 용도: 중앙 그리드로 Convert된 row 값 저장 하기 위해서 입니다.
213
        /// </summary>
214
        public IEnumerable<Interface.ConvertItem> GetConvertProjects(Markus.Service.Interface.ConvertItem selectedConvert)
215 53c9637d taeseongkim
        {
216 e6281033 alzkakdixm
            List<Interface.ConvertItem> StatusKeep = new List<Interface.ConvertItem>();
217
218
219
            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
220
221
            stopwatch.Start();
222
223
224
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();//디비 다 조인 후 조건 비교 후 그리드 출력
225
            var query = from items in entities.CONVERTER_DOC //세미
226
                        join documents in entities.DOCUMENT_ITEM on items.DOCUMENT_ID equals documents.DOCUMENT_ID into GroupItems
227
                        from subpet in GroupItems.DefaultIfEmpty()
228
                        where items.PROJECT_NO == selectedConvert.ProjectNumber && items.DOCUMENT_ID == selectedConvert.DocumentID
229
                        orderby items.CREATE_DATETIME descending
230
                        select new
231
                        {
232
                            ID = items.ID,
233
                            DOCUMENT_URL = items.DOCUMENT_URL,
234
                            RECONVERTER = items.RECONVERTER,
235
                            SERVICE_ID = items.SERVICE_ID,
236
                            STATUS = items.STATUS,
237
                            CREATE_DATETIME = items.CREATE_DATETIME,
238
                            TOTAL_PAGE = items.TOTAL_PAGE,
239
                            CURRENT_PAGE = items.CURRENT_PAGE,
240
                            EXCEPTION = items.EXCEPTION,
241
                            PROJECT_NO = items.PROJECT_NO,
242
                            DOCUMENT_ID = items.DOCUMENT_ID,
243
                            REVISION = subpet.REVISION,
244
                            DOCUMENT_NO = subpet.DOCUMENT_NO,
245
                            DOCUMENT_NAME = subpet.DOCUMENT_NAME,
246
                            GROUP_NO = subpet.GROUP_NO
247
                        };
248
249
            if (query.Count() > 0)//세미
250 53c9637d taeseongkim
            {
251 e6281033 alzkakdixm
                foreach (var item in query)
252
                {
253
                    Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
254
                    {
255
256
                        ReConverter = item.RECONVERTER,
257
                        ServiceID = item.SERVICE_ID,
258
                        ConvertState = (StatusCodeType)item.STATUS,
259
                        CreateTime = item.CREATE_DATETIME,
260
                        TotalPage = item.TOTAL_PAGE,
261
                        CurrentPageNo = item.CURRENT_PAGE,
262
                        Exception = item.EXCEPTION,
263
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID),
264
                        Revision = item.REVISION,
265
                        DocumnetNo = item.DOCUMENT_NO,
266
                        DocumnetName = item.DOCUMENT_NAME,
267
                        GroupNo = item.GROUP_NO
268
                    };
269
                    StatusKeep.Add(convertitem);
270
                }
271 53c9637d taeseongkim
            }
272 e6281033 alzkakdixm
            System.Diagnostics.Debug.WriteLine(new TimeSpan(stopwatch.ElapsedTicks).ToString());
273
            return StatusKeep;
274 53c9637d taeseongkim
275
        }
276
277 e6281033 alzkakdixm
        #endregion
278 53c9637d taeseongkim
279 e6281033 alzkakdixm
        #region SetCleanUpItem
280 53c9637d taeseongkim
        /// <summary>
281
        /// 오류나 wait으로 남아 있는 데이터베이스의 Item을 StatusCodeType.None으로 복구
282
        /// </summary>
283 2bbea412 taeseongkim
        /// <param name="convertID">StatusCodeType을 변경하고자 하는 ConvertItem의 ID</param>
284
        /// <param name="ReConvert">ReConvert가 2이면 다시 Convert를 시도 안하기 때문에 기존 값으로 유지 하고 계속 시도 할수 있도록 0을 주는 경우가 있다.</param>
285 53c9637d taeseongkim
        /// <returns></returns>
286 2decfbdf alzkakdixm
        /// 
287
        public int SetCleanUpItem(ConvertItem _ConvertItem)
288 53c9637d taeseongkim
        {
289
            int result = 0;
290
291 2decfbdf alzkakdixm
            var items = entities.CONVERTER_DOC.Where(x => x.ID == _ConvertItem.ConvertID);
292 53c9637d taeseongkim
293
            result = items.Count();
294
295
            if (items.Count() > 0)
296
            {
297 0157b158 taeseongkim
                var item = items.First();
298
299 2decfbdf alzkakdixm
                item.RECONVERTER = item.RECONVERTER - _ConvertItem.ReConverter;
300 e6281033 alzkakdixm
                item.CREATE_DATETIME = DateTime.Now;
301
                item.STATUS = (int)StatusCodeType.None;
302 53c9637d taeseongkim
303 0157b158 taeseongkim
                result = entities.SaveChanges();
304 53c9637d taeseongkim
            }
305
306
            return result;
307
        }
308 2decfbdf alzkakdixm
309 e6281033 alzkakdixm
        #endregion
310
311
        #region Convert Path
312
313
        private string GetConvertPath(string ProjectNo, string DocumentID)
314
        {
315
            try
316
            {
317
                return Path.Combine(BaseStorage(ProjectNo), ProjectNo + "_Tile", (System.Convert.ToInt64(DocumentID) / 100).ToString(), DocumentID);
318
            }
319
            catch (Exception)
320
            {
321
                throw new Exception("GetConvertPath Error");
322
            }
323 2decfbdf alzkakdixm
324 e6281033 alzkakdixm
        }
325 2decfbdf alzkakdixm
326 e6281033 alzkakdixm
        private string BaseStorage(string ProjectNo)
327
        {
328
            string result = "";
329 2decfbdf alzkakdixm
330 e6281033 alzkakdixm
            var properties = entities.PROPERTIES.Where(f => f.PROPERTY == ProjectNo && f.TYPE == PROPERTIES_DEFINE.TILE_SOURCE_STORAGE);
331 2decfbdf alzkakdixm
332 e6281033 alzkakdixm
            if (properties.Count() > 0)
333
            {
334
                result = properties.First().VALUE;
335
            }
336
            else
337
            {
338
                throw new Exception($"Project {ProjectNo} BaseStorage Not Setting.");
339
            }
340 2decfbdf alzkakdixm
341 e6281033 alzkakdixm
            return result;
342
        }
343 2decfbdf alzkakdixm
344 e6281033 alzkakdixm
        #endregion
345 53c9637d taeseongkim
346 e6281033 alzkakdixm
        #region Remove
347 5d863c06 taeseongkim
348
        /// <summary>
349
        /// Item 삭제
350
        /// </summary>
351
        /// <returns></returns>
352
        public int RemoveItem(string convertID)
353
        {
354
            int result = 0;
355
356
            var items = entities.CONVERTER_DOC.Where(x => x.ID == convertID);
357
358
            if (items.Count() > 0)
359
            {
360
                CONVERTER_DOC item = items.First();
361
                entities.CONVERTER_DOC.Remove(item);
362
363
                result = entities.SaveChanges();
364
            }
365
366
            return result;
367
        }
368
369 e6281033 alzkakdixm
370
        #endregion
371
372
        #endregion
373
374
        #region DataBaseByStatusViewModel Function
375 53c9637d taeseongkim
        /// <summary>
376
        /// 전체 컨버터를 가져온다. 비동기로 변경하여야 한다.
377
        /// </summary>
378
        /// <returns></returns>
379 e6281033 alzkakdixm
        public List<Interface.ConvertItem> GetConvertItems(StatusCodeType statusCodeType, Func<CONVERTER_DOC, bool> @where, int takeCount = 100)
380 53c9637d taeseongkim
        {
381
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
382
383 e6281033 alzkakdixm
384
            var items = entities.CONVERTER_DOC.Where(x => x.STATUS == (int)statusCodeType).Take(takeCount).ToList();
385 53c9637d taeseongkim
386
            if (items.Count() > 0)
387
            {
388
                foreach (var item in items)
389
                {
390 06f13e11 taeseongkim
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
391
                    {
392
                        ReConverter = item.RECONVERTER,
393
                        ServiceID = item.SERVICE_ID,
394 2decfbdf alzkakdixm
                        ConvertState = ((StatusCodeType)item.STATUS),
395 06f13e11 taeseongkim
                        CreateTime = item.CREATE_DATETIME,
396
                        TotalPage = item.TOTAL_PAGE,
397
                        CurrentPageNo = item.CURRENT_PAGE,
398
399
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID)
400
                    };
401
402 53c9637d taeseongkim
                    convertItems.Add(convertitem);
403
                }
404
            }
405
            return convertItems;
406
        }
407 e6281033 alzkakdixm
        #endregion
408
409
        #region No 참조 
410 53c9637d taeseongkim
411 0157b158 taeseongkim
        /// <summary>
412 e6281033 alzkakdixm
        /// 컨버터서비스를 이용하는 문서 정보 저장
413
        /// UniqueID
414
        /// using Markus.Service.Extensions;  new Guid().CreateUniqueGuid().ToString();
415 b92f142f taeseongkim
        /// </summary>
416 e6281033 alzkakdixm
        /// <param name="ProjectNo">프로젝트</param>
417
        /// <param name="UniqueID">컨버터 서비스의 아이템 ID</param>
418
        /// <param name="originfilePath"></param>
419
        /// <param name="DocumentID"></param>
420 b92f142f taeseongkim
        /// <returns></returns>
421 e6281033 alzkakdixm
        public bool SetConvertDoc(string ProjectNo, string UniqueID, string originfilePath, string DocumentID)
422 b92f142f taeseongkim
        {
423 e6281033 alzkakdixm
            bool result = false;
424 b92f142f taeseongkim
425 e6281033 alzkakdixm
            if (ProjectNo.IsNullOrEmpty())
426
            {
427
                throw new Exception("ProjectNo is Null");
428
            }
429 60723dc9 taeseongkim
430 e6281033 alzkakdixm
            if (UniqueID.IsNullOrEmpty())
431
            {
432
                throw new Exception("UniqueID is Null");
433
            }
434 b92f142f taeseongkim
435 e6281033 alzkakdixm
            if (originfilePath.IsNullOrEmpty())
436 b92f142f taeseongkim
            {
437 e6281033 alzkakdixm
                throw new Exception("originfilePath is Null");
438
            }
439
440
            if (DocumentID.IsNullOrEmpty())
441
            {
442
                throw new Exception("DocumentID is Null");
443
            }
444
445
            if (DocumentID.IsNullOrEmpty())
446
            {
447
                long _lastDocId = 0;
448
449
                if (entities.CONVERTER_DOC.Count() > 0)
450 b92f142f taeseongkim
                {
451 e6281033 alzkakdixm
                    try
452 b92f142f taeseongkim
                    {
453 e6281033 alzkakdixm
                        string qry = @"SELECT * FROM CONVERTER_DOC order by CAST(DOCUMENT_ID as int) desc";
454
                        var _item = entities.CONVERTER_DOC.SqlQuery(qry).FirstOrDefault();
455 b92f142f taeseongkim
456 e6281033 alzkakdixm
                        if (_item != null)
457
                        {
458
                            _lastDocId = Convert.ToInt64(_item.DOCUMENT_ID) + 1;
459
                        }
460
                    }
461
                    catch (Exception)
462
                    {
463 b92f142f taeseongkim
464 e6281033 alzkakdixm
                        throw;
465
                    }
466 b92f142f taeseongkim
                }
467 e6281033 alzkakdixm
468
                DocumentID = _lastDocId.ToString();
469 b92f142f taeseongkim
            }
470
471 e6281033 alzkakdixm
            CONVERTER_DOC convert_doc = new CONVERTER_DOC
472
            {
473
                ID = UniqueID,
474
                PROJECT_NO = ProjectNo,
475
                DOCUMENT_URL = originfilePath,
476
                DOCUMENT_ID = DocumentID,
477
                CREATE_DATETIME = DateTime.Now,
478
                STATUS = 0,
479
                TOTAL_PAGE = 0,
480
                CURRENT_PAGE = 0,
481
                RECONVERTER = 0
482
            };
483
484
            
485
            entities.CONVERTER_DOC.Add(convert_doc);
486 a6e5055d alzkakdixm
487 e6281033 alzkakdixm
            if (entities.SaveChanges() == 1)
488
            {
489
                result = true;
490
            }
491
492
            return result;
493
        }
494
495
        /// <summary>
496
        /// 컨버터서비스를 이용하는 문서 정보 저장
497
        /// UniqueID
498
        /// using Markus.Service.Extensions;  new Guid().CreateUniqueGuid().ToString();
499
        /// </summary>
500
        /// <param name="ProjectNo">프로젝트</param>
501
        /// <param name="UniqueID">컨버터 서비스의 아이템 ID</param>
502
        /// <param name="originfilePath"></param>
503
        /// <param name="DocumentID"></param>
504
        /// <returns></returns>
505
        public bool SetDocumentInfo(string ConvertID, int totalPage, List<DOCPAGE> pageinfo)
506 2decfbdf alzkakdixm
        {
507 e6281033 alzkakdixm
            bool result = false;
508 2decfbdf alzkakdixm
509 e6281033 alzkakdixm
            var convertDocItems = entities.CONVERTER_DOC.Where(f => f.ID == ConvertID);
510
511
            if (convertDocItems.Count() > 0)
512 a6e5055d alzkakdixm
            {
513 e6281033 alzkakdixm
                var convertDoc = convertDocItems.First();
514
515
                string docId = new Guid().CreateUniqueGuid().ToString();
516
517
                var docinfo = entities.DOCINFO.FirstOrDefault(x => x.PROJECT_NO == convertDoc.PROJECT_NO && x.DOCUMENT_ID == convertDoc.DOCUMENT_ID);
518
                
519
                if (docinfo != null)
520
                {
521
                    // 기존 Docpage 삭제.
522
                    entities.DOCPAGE.RemoveRange(docinfo.DOCPAGE);
523
524
                    // 기존 코멘트 유지를 위한 Docinfo update                    
525
                    docinfo.PROJECT_NO = convertDoc.PROJECT_NO;
526
                    docinfo.ORIGINAL_FILE = convertDoc.DOCUMENT_URL;
527
                    docinfo.PAGE_COUNT = totalPage;                    
528
                    docinfo.DOCPAGE = pageinfo;                    
529
                    entities.SaveChanges();
530
                    result = true;
531
                }
532
                else
533 a6e5055d alzkakdixm
                {
534 e6281033 alzkakdixm
                    DOCINFO instace = new DOCINFO
535 a6e5055d alzkakdixm
                    {
536 e6281033 alzkakdixm
                        ID = docId,
537
                        PROJECT_NO = convertDoc.PROJECT_NO,
538
                        ORIGINAL_FILE = convertDoc.DOCUMENT_URL,
539
                        DOCUMENT_ID = convertDoc.DOCUMENT_ID,
540
                        PAGE_COUNT = totalPage,
541
                        DOCPAGE = pageinfo
542 a6e5055d alzkakdixm
                    };
543
544 e6281033 alzkakdixm
                    entities.DOCINFO.Add(instace);
545
                    var save = entities.SaveChanges();
546
547
                    if (save == pageinfo.Count() + 1)
548
                    {
549
                        result = true;
550
                    }
551 a6e5055d alzkakdixm
                }
552 2decfbdf alzkakdixm
553 e6281033 alzkakdixm
                
554
                
555
            }
556 a6e5055d alzkakdixm
557 e6281033 alzkakdixm
            return result;
558 2decfbdf alzkakdixm
        }
559 e6281033 alzkakdixm
560
        public Interface.ConvertItem GetConvertItem(string ProjectNo, string UniqueID)
561 a6e5055d alzkakdixm
        {
562 e6281033 alzkakdixm
            Interface.ConvertItem result = null;
563 a6e5055d alzkakdixm
564 e6281033 alzkakdixm
            //var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID);
565
            var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == ProjectNo && f.ID == UniqueID);
566
567
            if (items.Count() > 0)
568 2decfbdf alzkakdixm
            {
569 e6281033 alzkakdixm
                var convertItem = items.First();
570 2decfbdf alzkakdixm
571 e6281033 alzkakdixm
                string convertPath = Path.Combine(BaseStorage(convertItem.PROJECT_NO), convertItem.PROJECT_NO + "_Tile", (System.Convert.ToInt64(convertItem.DOCUMENT_ID) / 100).ToString(), convertItem.DOCUMENT_ID);
572 2decfbdf alzkakdixm
573 e6281033 alzkakdixm
                result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath);
574
            }
575 a6e5055d alzkakdixm
576 e6281033 alzkakdixm
            return result;
577
        }
578 2decfbdf alzkakdixm
579 a6e5055d alzkakdixm
580 e6281033 alzkakdixm
        public Interface.ConvertItem GetConvertItembyDocumentID(string ProjectNo, string DocumentID)
581
        {
582
            Interface.ConvertItem result = null;
583
584
            //var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID);
585
            var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == ProjectNo && f.DOCUMENT_ID == DocumentID);
586
587
            if (items.Count() > 0)
588
            {
589
                var convertItem = items.First();
590
                string convertPath = Path.Combine(BaseStorage(convertItem.PROJECT_NO), convertItem.PROJECT_NO + "_Tile", (System.Convert.ToInt64(convertItem.DOCUMENT_ID) / 100).ToString(), convertItem.DOCUMENT_ID);
591
592
                if (convertItem.STATUS == (int)StatusCodeType.Completed)
593
                {
594
                    result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath,
595
                                                        (StatusCodeType)convertItem.STATUS, convertItem.CURRENT_PAGE, convertItem.TOTAL_PAGE, convertItem.EXCEPTION);
596
                }
597
                else
598
                {
599
                    result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath);
600 2decfbdf alzkakdixm
                }
601
            }
602
603 e6281033 alzkakdixm
            return result;
604
        }
605
606
        public List<CONVERTER_DOC> GetConvertingItems(List<string> projectList)
607
        {
608
            var convertWaitingItems = entities.CONVERTER_DOC.OrderBy(x => x.CREATE_DATETIME).Where(
609
                                        x =>
610
                                        projectList.Contains(x.PROJECT_NO) &&
611
                                         (x.STATUS > (int)StatusCodeType.None && x.STATUS < (int)StatusCodeType.Completed) && x.RECONVERTER < 2);
612 2decfbdf alzkakdixm
613 e6281033 alzkakdixm
            return convertWaitingItems.ToList();
614 2decfbdf alzkakdixm
        }
615 e6281033 alzkakdixm
616
        /// <summary>
617
        /// 전체 컨버터를 가져온다. 비동기로 변경하여야 한다.
618
        /// </summary>
619
        /// <returns></returns>
620
        public List<Interface.ConvertItem> GetConvertItems(StatusCodeType statusCodeType)
621 2decfbdf alzkakdixm
        {
622 e6281033 alzkakdixm
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
623 2decfbdf alzkakdixm
624 e6281033 alzkakdixm
            var items = entities.CONVERTER_DOC.Where(x => x.STATUS == (int)statusCodeType).ToList(); //.Where(x => x.PROJECT_NO == gProjectNo);
625
626
            if (items.Count() > 0)
627 a6e5055d alzkakdixm
            {
628 e6281033 alzkakdixm
                foreach (var item in items)
629 a6e5055d alzkakdixm
                {
630 e6281033 alzkakdixm
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
631 a6e5055d alzkakdixm
                    {
632
                        ReConverter = item.RECONVERTER,
633
                        ServiceID = item.SERVICE_ID,
634 e6281033 alzkakdixm
                        ConvertState = ((StatusCodeType)item.STATUS),
635 a6e5055d alzkakdixm
                        CreateTime = item.CREATE_DATETIME,
636
                        TotalPage = item.TOTAL_PAGE,
637
                        CurrentPageNo = item.CURRENT_PAGE,
638
639 e6281033 alzkakdixm
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID)
640 2decfbdf alzkakdixm
                    };
641 e6281033 alzkakdixm
642
643
                    convertItems.Add(convertitem);
644 a6e5055d alzkakdixm
                }
645
            }
646 e6281033 alzkakdixm
            return convertItems;
647 a6e5055d alzkakdixm
        }
648
649
        public List<Interface.ConvertItem> GetConvertProjectsStatus(Func<CONVERTER_DOC, bool> @where)
650
        {
651
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
652
653
654
            //var items = entities.CONVERTER_DOC.Where(x => x.STATUS == (int)statusCodeType).Take(takeCount).ToList(); //.Where(x => x.PROJECT_NO == gProjectNo);
655 e6281033 alzkakdixm
            var items = entities.CONVERTER_DOC.Where(x => x.STATUS <= 4);
656 a6e5055d alzkakdixm
657
            if (items.Count() > 0)
658
            {
659
                foreach (var item in items)
660
                {
661
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
662
                    {
663
                        ReConverter = item.RECONVERTER,
664
                        ServiceID = item.SERVICE_ID,
665
                        //ConvertState = ((StatusCodeType)item.STATUS).ToString(),
666 2decfbdf alzkakdixm
                        //ConvertState = (item.STATUS).ToString(),
667
                        ConvertState = (StatusCodeType)item.STATUS,
668 a6e5055d alzkakdixm
                        CreateTime = item.CREATE_DATETIME,
669
                        TotalPage = item.TOTAL_PAGE,
670
                        CurrentPageNo = item.CURRENT_PAGE,
671
                        Exception = item.EXCEPTION,
672
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID)
673
                    };
674
675
676
                    convertItems.Add(convertitem);
677
                }
678
            }
679
680
            return convertItems;
681
        }
682
683 b92f142f taeseongkim
684 e6281033 alzkakdixm
        public bool SetConvertState(string ServiceID, string UniqueID, int State, int CurrentPage, int TotalPage, string Error)
685 53c9637d taeseongkim
        {
686
            bool result = false;
687
688
            try
689
            {
690
                var items = entities.CONVERTER_DOC.SingleOrDefault(f => f.ID == UniqueID);
691
                //var items = entities.CONVERTER_DOC.SingleOrDefault(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID);
692
693
                if (items != null)
694
                {
695 0157b158 taeseongkim
                    items.SERVICE_ID = ServiceID;
696 53c9637d taeseongkim
                    items.STATUS = State;
697
                    items.CURRENT_PAGE = CurrentPage;
698
                    items.TOTAL_PAGE = TotalPage;
699
700
                    StatusCodeType statusCode = (StatusCodeType)State;
701
702 65fbe3cb taeseongkim
                    if (items.START_DATETIME == null)
703 a8f1a865 taeseongkim
                    {
704
                        items.START_DATETIME = DateTime.Now;
705
                    }
706
707 53c9637d taeseongkim
                    switch (statusCode)
708
                    {
709
                        case StatusCodeType.None:
710
                            break;
711
                        case StatusCodeType.Wait:
712
                            items.START_DATETIME = DateTime.Now;
713
                            break;
714
                        case StatusCodeType.PageLoading:
715
                            break;
716
                        case StatusCodeType.Saving:
717
                            break;
718
                        case StatusCodeType.Completed:
719 a0341bef taeseongkim
                            items.CURRENT_PAGE = items.TOTAL_PAGE;
720 e6281033 alzkakdixm
                            items.END_DATETIME = DateTime.Now;
721 53c9637d taeseongkim
                            break;
722
                        case StatusCodeType.FileError:
723
                            Error = $" file Error :" + Error;
724
                            items.END_DATETIME = DateTime.Now;
725
                            break;
726
                        case StatusCodeType.PageError:
727
                            Error = $" Page No {CurrentPage} Error :" + Error;
728
                            break;
729
                        case StatusCodeType.NeedsPassword:
730
                            break;
731
                        case StatusCodeType.Error:
732
                            Error = $" Error :" + Error;
733
                            items.END_DATETIME = DateTime.Now;
734
                            break;
735
                        default:
736
                            break;
737
                    }
738
739 e6281033 alzkakdixm
                    if (items.EXCEPTION == null)
740 53c9637d taeseongkim
                    {
741
                        items.EXCEPTION = "";
742
                    }
743
744
                    if (items.EXCEPTION.Length < 255)
745
                    {
746
                        items.EXCEPTION = items.EXCEPTION + Error;
747
                    }
748
749
                    entities.SaveChanges();
750
                    result = true;
751
                }
752
            }
753
            catch (Exception ex)
754
            {
755 e6281033 alzkakdixm
                throw new Exception("SetConvertState", ex);
756 53c9637d taeseongkim
            }
757
758
            return result;
759
        }
760
761 e6281033 alzkakdixm
        public SERVICE_PROPERTIES GetServiceProperties(string ServiceID)
762 53c9637d taeseongkim
        {
763 e6281033 alzkakdixm
            SERVICE_PROPERTIES result = null;
764 53c9637d taeseongkim
765 e6281033 alzkakdixm
            var items = entities.SERVICE_PROPERTIES.Where(x => x.ID == ServiceID);
766 53c9637d taeseongkim
767 e6281033 alzkakdixm
            if (items.Count() > 0)
768 53c9637d taeseongkim
            {
769 e6281033 alzkakdixm
                result = items.First();
770 53c9637d taeseongkim
            }
771
772
            return result;
773
        }
774
775 e6281033 alzkakdixm
776
        /// <summary>
777
        /// 현재 서비스에서 컨버터중인 아이템.
778
        /// </summary>
779
        /// <returns></returns>
780
        public List<Interface.ConvertItem> GetServiceAliveItems(string ServiceID)
781
        {
782
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
783
784
            var items = entities.CONVERTER_DOC.Where(x => x.SERVICE_ID == ServiceID && x.STATUS > (int)StatusCodeType.None && x.STATUS < (int)StatusCodeType.Completed).ToList(); //.Where(x => x.PROJECT_NO == gProjectNo);
785
786
            if (items.Count() > 0)
787
            {
788
                foreach (var item in items)
789
                {
790
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL);
791
                    convertItems.Add(convertitem);
792
                }
793
            }
794
            return convertItems;
795
        }
796
797
        #endregion
798
799 53c9637d taeseongkim
    }
800
}
클립보드 이미지 추가 (최대 크기: 500 MB)