프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.DataBase / ConvertDatabase.cs @ 508debb1

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

1
using Markus.EntityModel;
2
using Markus.Message;
3
using Markus.Service.Extensions;
4
using System;
5
using System.Collections.Generic;
6
using System.IO;
7
using System.Linq;
8
using static Markus.Service.DataBase.ConvertDatabase;
9
using System.Windows;
10
using System.Linq.Expressions;
11
using Markus.Service.Interface;
12

    
13
namespace Markus.Service.DataBase
14
{
15
    public class ConvertDatabase : IDisposable
16
    {
17
        #region Constructor
18
        /// <summary>
19
        ///해당 프로젝트의 데이터베이스 연결
20
        /// </summary>
21

    
22
        Markus.EntityModel.MarkusModel entities;
23

    
24
        public ConvertDatabase(string ConnectionString)
25
        {
26
            try
27
            {
28
                entities = new Markus.EntityModel.MarkusModel(ConnectionString);
29
            }
30
            catch (Exception ex)
31
            {
32
                System.Diagnostics.Debug.WriteLine(ex.ToString());
33
                throw ex;
34
            }
35
        }
36

    
37
        public void Dispose()
38
        {
39
            entities.Dispose();
40
        }
41

    
42
        #endregion
43

    
44
        #region DataBaseItemsModel Function
45

    
46
        #region Get WaitConvertItems
47

    
48
        /// <summary>
49
        /// service에서 대기중이거나 오류인 아이템을 가져가서 컨버터 프로세스를 호출한다.
50
        /// 컨버터 상태가 에러이거나 2보다 작은 경우 
51
        /// UniqueKey는 각 데이터베이스의 문서 정보에서 유일한 키이며 컨버터저장에서 같은 폴더로의 저장을 방지 한다.
52
        /// 
53
        /// </summary>
54
        /// <param name="aliveItems"></param>
55
        /// <param name="TakeCount"></param>
56
        /// <returns></returns>
57
        public IEnumerable<CONVERTER_DOC> GetWaitConvertItems(List<string> projectList, int TakeCount)
58
        {
59
            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

    
67
            return convertWaitingItems;
68
        }
69

    
70
        #endregion
71

    
72
        #region Get FilterConvertItems
73

    
74
        /// <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

    
108
            if (query.Count() > 0)//세미
109
            {
110
                foreach (var item in query)
111
                {
112
                    Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
113
                    {
114

    
115
                        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

    
123
                        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
                }
131
            }
132
            return convertItems;
133

    
134
        }
135

    
136
        #endregion
137

    
138
        #region Update RealDataSelect 
139

    
140
        /// <summary>
141
        /// 상단 그리드에서 선택된 RealDataSelect
142
        /// 용도: 중앙그리드 Items Update
143
        /// </summary>
144
        public IEnumerable<Interface.ConvertItem> GetConvertProjects(System.Collections.ObjectModel.ObservableCollection<Interface.ConvertItem> selectedConvert)
145
        {
146
            List<Interface.ConvertItem> StatusKeep = new List<Interface.ConvertItem>();
147

    
148
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
149

    
150
            foreach (var selectedConvertItem in selectedConvert)
151
            {
152
                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

    
175

    
176
                if (query.Count() > 0)//세미
177
                {
178
                    foreach (var item in query)
179
                    {
180
                        Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
181
                        {
182

    
183
                            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

    
192
                            Revision = item.REVISION,
193
                            DocumnetNo = item.DOCUMENT_NO,
194
                            DocumnetName = item.DOCUMENT_NAME,
195
                            GroupNo = item.GROUP_NO
196
                        };
197

    
198
                        StatusKeep.Add(convertitem);
199

    
200
                    }
201
                }
202
            }
203
            return StatusKeep;
204
        }
205

    
206
        #endregion
207

    
208
        #region Data Convert
209

    
210
        /// <summary>
211
        /// 상단 그리드에서 선택된 Convert 버튼 
212
        /// 용도: 중앙 그리드로 Convert된 row 값 저장 하기 위해서 입니다.
213
        /// </summary>
214
        public IEnumerable<Interface.ConvertItem> GetConvertProjects(Markus.Service.Interface.ConvertItem selectedConvert)
215
        {
216
            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
            {
251
                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
            }
272
            System.Diagnostics.Debug.WriteLine(new TimeSpan(stopwatch.ElapsedTicks).ToString());
273
            return StatusKeep;
274

    
275
        }
276

    
277
        #endregion
278

    
279
        #region SetCleanUpItem
280
        /// <summary>
281
        /// 오류나 wait으로 남아 있는 데이터베이스의 Item을 StatusCodeType.None으로 복구
282
        /// </summary>
283
        /// <param name="convertID">StatusCodeType을 변경하고자 하는 ConvertItem의 ID</param>
284
        /// <param name="ReConvert">ReConvert가 2이면 다시 Convert를 시도 안하기 때문에 기존 값으로 유지 하고 계속 시도 할수 있도록 0을 주는 경우가 있다.</param>
285
        /// <returns></returns>
286
        /// 
287
        public int SetCleanUpItem(ConvertItem _ConvertItem)
288
        {
289
            int result = 0;
290

    
291
            var items = entities.CONVERTER_DOC.Where(x => x.ID == _ConvertItem.ConvertID);
292

    
293
            result = items.Count();
294

    
295
            if (items.Count() > 0)
296
            {
297
                var item = items.First();
298

    
299
                item.RECONVERTER = item.RECONVERTER - _ConvertItem.ReConverter;
300

    
301
                item.CREATE_DATETIME = DateTime.Now;
302
                item.STATUS = (int)StatusCodeType.None;
303
                item.END_DATETIME = null;
304

    
305
                result = entities.SaveChanges();
306
            }
307

    
308
            return result;
309
        }
310

    
311
        public int SetCleanUpItem(string convertID, int ReConvert)
312
        {
313
            int result = 0;
314

    
315
            var items = entities.CONVERTER_DOC.Where(x => x.ID == convertID);
316

    
317
            result = items.Count();
318

    
319
            if (items.Count() > 0)
320
            {
321
                var item = items.First();
322

    
323
                item.RECONVERTER = item.RECONVERTER + ReConvert;
324
                item.CREATE_DATETIME = DateTime.Now;
325
                //item.START_DATETIME = null;
326
                item.END_DATETIME = null;
327
                item.STATUS = (int)StatusCodeType.None;
328

    
329
                result = entities.SaveChanges();
330
            }
331

    
332
            return result;
333
        }
334
        #endregion
335

    
336
        #region Convert Path
337

    
338
        private string GetConvertPath(string ProjectNo, string DocumentID)
339
        {
340
            try
341
            {
342
                return Path.Combine(BaseStorage(ProjectNo), ProjectNo + "_Tile", (System.Convert.ToInt64(DocumentID) / 100).ToString(), DocumentID);
343
            }
344
            catch (Exception)
345
            {
346
                throw new Exception("GetConvertPath Error");
347
            }
348

    
349
        }
350

    
351
        private string BaseStorage(string ProjectNo)
352
        {
353
            string result = "";
354

    
355
            var properties = entities.PROPERTIES.Where(f => f.PROPERTY == ProjectNo && f.TYPE == PROPERTIES_DEFINE.TILE_SOURCE_STORAGE);
356

    
357
            if (properties.Count() > 0)
358
            {
359
                result = properties.First().VALUE;
360
            }
361
            else
362
            {
363
                throw new Exception($"Project {ProjectNo} BaseStorage Not Setting.");
364
            }
365

    
366
            return result;
367
        }
368

    
369
        #endregion
370

    
371
        #region Remove
372

    
373
        /// <summary>
374
        /// Item 삭제
375
        /// </summary>
376
        /// <returns></returns>
377
        public int RemoveItem(string convertID)
378
        {
379
            int result = 0;
380

    
381
            var items = entities.CONVERTER_DOC.Where(x => x.ID == convertID);
382

    
383
            if (items.Count() > 0)
384
            {
385
                CONVERTER_DOC item = items.First();
386
                entities.CONVERTER_DOC.Remove(item);
387

    
388
                result = entities.SaveChanges();
389
            }
390

    
391
            return result;
392
        }
393

    
394

    
395
        #endregion
396

    
397
        #endregion
398

    
399
        #region DataBaseByStatusViewModel Function
400
        /// <summary>
401
        /// 전체 컨버터를 가져온다. 비동기로 변경하여야 한다.
402
        /// </summary>
403
        /// <returns></returns>
404
        public List<Interface.ConvertItem> GetConvertItems(StatusCodeType statusCodeType, Func<CONVERTER_DOC, bool> @where, int takeCount = 100)
405
        {
406
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
407

    
408

    
409
            var items = entities.CONVERTER_DOC.Where(x => x.STATUS == (int)statusCodeType).Take(takeCount).ToList();
410

    
411
            if (items.Count() > 0)
412
            {
413
                foreach (var item in items)
414
                {
415
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
416
                    {
417
                        ReConverter = item.RECONVERTER,
418
                        ServiceID = item.SERVICE_ID,
419
                        ConvertState = ((StatusCodeType)item.STATUS),
420
                        CreateTime = item.CREATE_DATETIME,
421
                        TotalPage = item.TOTAL_PAGE,
422
                        CurrentPageNo = item.CURRENT_PAGE,
423

    
424
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID)
425
                    };
426

    
427
                    convertItems.Add(convertitem);
428
                }
429
            }
430
            return convertItems;
431
        }
432
        #endregion
433

    
434
        #region No 참조 
435

    
436
        /// <summary>
437
        /// 컨버터서비스를 이용하는 문서 정보 저장
438
        /// UniqueID
439
        /// using Markus.Service.Extensions;  new Guid().CreateUniqueGuid().ToString();
440
        /// </summary>
441
        /// <param name="ProjectNo">프로젝트</param>
442
        /// <param name="UniqueID">컨버터 서비스의 아이템 ID</param>
443
        /// <param name="originfilePath"></param>
444
        /// <param name="DocumentID"></param>
445
        /// <returns></returns>
446
        public bool SetConvertDoc(string ProjectNo, string UniqueID, string originfilePath, string DocumentID)
447
        {
448
            bool result = false;
449

    
450
            if (ProjectNo.IsNullOrEmpty())
451
            {
452
                throw new Exception("ProjectNo is Null");
453
            }
454

    
455
            if (UniqueID.IsNullOrEmpty())
456
            {
457
                throw new Exception("UniqueID is Null");
458
            }
459

    
460
            if (originfilePath.IsNullOrEmpty())
461
            {
462
                throw new Exception("originfilePath is Null");
463
            }
464

    
465
            if (DocumentID.IsNullOrEmpty())
466
            {
467
                throw new Exception("DocumentID is Null");
468
            }
469

    
470
            if (DocumentID.IsNullOrEmpty())
471
            {
472
                long _lastDocId = 0;
473

    
474
                if (entities.CONVERTER_DOC.Count() > 0)
475
                {
476
                    try
477
                    {
478
                        string qry = @"SELECT * FROM CONVERTER_DOC order by CAST(DOCUMENT_ID as int) desc";
479
                        var _item = entities.CONVERTER_DOC.SqlQuery(qry).FirstOrDefault();
480

    
481
                        if (_item != null)
482
                        {
483
                            _lastDocId = Convert.ToInt64(_item.DOCUMENT_ID) + 1;
484
                        }
485
                    }
486
                    catch (Exception)
487
                    {
488

    
489
                        throw;
490
                    }
491
                }
492

    
493
                DocumentID = _lastDocId.ToString();
494
            }
495

    
496
            CONVERTER_DOC convert_doc = new CONVERTER_DOC
497
            {
498
                ID = UniqueID,
499
                PROJECT_NO = ProjectNo,
500
                DOCUMENT_URL = originfilePath,
501
                DOCUMENT_ID = DocumentID,
502
                CREATE_DATETIME = DateTime.Now,
503
                STATUS = 0,
504
                TOTAL_PAGE = 0,
505
                CURRENT_PAGE = 0,
506
                RECONVERTER = 0
507
            };
508

    
509
            
510
            entities.CONVERTER_DOC.Add(convert_doc);
511

    
512
            if (entities.SaveChanges() == 1)
513
            {
514
                result = true;
515
            }
516

    
517
            return result;
518
        }
519

    
520
        /// <summary>
521
        /// 컨버터서비스를 이용하는 문서 정보 저장
522
        /// UniqueID
523
        /// using Markus.Service.Extensions;  new Guid().CreateUniqueGuid().ToString();
524
        /// </summary>
525
        /// <param name="ProjectNo">프로젝트</param>
526
        /// <param name="UniqueID">컨버터 서비스의 아이템 ID</param>
527
        /// <param name="originfilePath"></param>
528
        /// <param name="DocumentID"></param>
529
        /// <returns></returns>
530
        public bool SetDocumentInfo(string ConvertID, int totalPage, List<DOCPAGE> pageinfo)
531
        {
532
            bool result = false;
533

    
534
            var convertDocItems = entities.CONVERTER_DOC.Where(f => f.ID == ConvertID);
535

    
536
            if (convertDocItems.Count() > 0)
537
            {
538
                var convertDoc = convertDocItems.First();
539

    
540
                string docId = new Guid().CreateUniqueGuid().ToString();
541

    
542
                var docinfo = entities.DOCINFO.FirstOrDefault(x => x.PROJECT_NO == convertDoc.PROJECT_NO && x.DOCUMENT_ID == convertDoc.DOCUMENT_ID);
543
                
544
                if (docinfo != null)
545
                {
546
                    // 기존 Docpage 삭제.
547
                    entities.DOCPAGE.RemoveRange(docinfo.DOCPAGE);
548

    
549
                    // 기존 코멘트 유지를 위한 Docinfo update                    
550
                    docinfo.PROJECT_NO = convertDoc.PROJECT_NO;
551
                    docinfo.ORIGINAL_FILE = convertDoc.DOCUMENT_URL;
552
                    docinfo.PAGE_COUNT = totalPage;                    
553
                    docinfo.DOCPAGE = pageinfo;                    
554
                    entities.SaveChanges();
555
                    result = true;
556
                }
557
                else
558
                {
559
                    DOCINFO instace = new DOCINFO
560
                    {
561
                        ID = docId,
562
                        PROJECT_NO = convertDoc.PROJECT_NO,
563
                        ORIGINAL_FILE = convertDoc.DOCUMENT_URL,
564
                        DOCUMENT_ID = convertDoc.DOCUMENT_ID,
565
                        PAGE_COUNT = totalPage,
566
                        DOCPAGE = pageinfo
567
                    };
568

    
569
                    entities.DOCINFO.Add(instace);
570
                    var save = entities.SaveChanges();
571

    
572
                    if (save == pageinfo.Count() + 1)
573
                    {
574
                        result = true;
575
                    }
576
                }
577

    
578
                
579
                
580
            }
581

    
582
            return result;
583
        }
584

    
585
        public Interface.ConvertItem GetConvertItem(string ProjectNo, string UniqueID)
586
        {
587
            Interface.ConvertItem result = null;
588

    
589
            //var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID);
590
            var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == ProjectNo && f.ID == UniqueID);
591

    
592
            if (items.Count() > 0)
593
            {
594
                var convertItem = items.First();
595

    
596
                string convertPath = Path.Combine(BaseStorage(convertItem.PROJECT_NO), convertItem.PROJECT_NO + "_Tile", (System.Convert.ToInt64(convertItem.DOCUMENT_ID) / 100).ToString(), convertItem.DOCUMENT_ID);
597

    
598
                result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath);
599
            }
600

    
601
            return result;
602
        }
603

    
604

    
605
        public Interface.ConvertItem GetConvertItembyDocumentID(string ProjectNo, string DocumentID)
606
        {
607
            Interface.ConvertItem result = null;
608

    
609
            //var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID);
610
            var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == ProjectNo && f.DOCUMENT_ID == DocumentID);
611

    
612
            if (items.Count() > 0)
613
            {
614
                var convertItem = items.First();
615
                string convertPath = Path.Combine(BaseStorage(convertItem.PROJECT_NO), convertItem.PROJECT_NO + "_Tile", (System.Convert.ToInt64(convertItem.DOCUMENT_ID) / 100).ToString(), convertItem.DOCUMENT_ID);
616

    
617
                if (convertItem.STATUS == (int)StatusCodeType.Completed)
618
                {
619
                    result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath,
620
                                                        (StatusCodeType)convertItem.STATUS, convertItem.CURRENT_PAGE, convertItem.TOTAL_PAGE, convertItem.EXCEPTION);
621
                }
622
                else
623
                {
624
                    result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath);
625
                }
626
            }
627

    
628
            return result;
629
        }
630

    
631
        public List<CONVERTER_DOC> GetConvertingItems(List<string> projectList)
632
        {
633
            var convertWaitingItems = entities.CONVERTER_DOC.OrderBy(x => x.CREATE_DATETIME).Where(
634
                                        x =>
635
                                        projectList.Contains(x.PROJECT_NO) &&
636
                                         (x.STATUS > (int)StatusCodeType.None && x.STATUS < (int)StatusCodeType.Completed) && x.RECONVERTER < 2);
637

    
638
            return convertWaitingItems.ToList();
639
        }
640

    
641
        /// <summary>
642
        /// 전체 컨버터를 가져온다. 비동기로 변경하여야 한다.
643
        /// </summary>
644
        /// <returns></returns>
645
        public List<Interface.ConvertItem> GetConvertItems(StatusCodeType statusCodeType)
646
        {
647
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
648

    
649
            var items = entities.CONVERTER_DOC.Where(x => x.STATUS == (int)statusCodeType).ToList(); //.Where(x => x.PROJECT_NO == gProjectNo);
650

    
651
            if (items.Count() > 0)
652
            {
653
                foreach (var item in items)
654
                {
655
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
656
                    {
657
                        ReConverter = item.RECONVERTER,
658
                        ServiceID = item.SERVICE_ID,
659
                        ConvertState = ((StatusCodeType)item.STATUS),
660
                        CreateTime = item.CREATE_DATETIME,
661
                        TotalPage = item.TOTAL_PAGE,
662
                        CurrentPageNo = item.CURRENT_PAGE,
663

    
664
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID)
665
                    };
666

    
667

    
668
                    convertItems.Add(convertitem);
669
                }
670
            }
671
            return convertItems;
672
        }
673

    
674
        public List<Interface.ConvertItem> GetConvertProjectsStatus(Func<CONVERTER_DOC, bool> @where)
675
        {
676
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
677

    
678

    
679
            //var items = entities.CONVERTER_DOC.Where(x => x.STATUS == (int)statusCodeType).Take(takeCount).ToList(); //.Where(x => x.PROJECT_NO == gProjectNo);
680
            var items = entities.CONVERTER_DOC.Where(x => x.STATUS <= 4);
681

    
682
            if (items.Count() > 0)
683
            {
684
                foreach (var item in items)
685
                {
686
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
687
                    {
688
                        ReConverter = item.RECONVERTER,
689
                        ServiceID = item.SERVICE_ID,
690
                        //ConvertState = ((StatusCodeType)item.STATUS).ToString(),
691
                        //ConvertState = (item.STATUS).ToString(),
692
                        ConvertState = (StatusCodeType)item.STATUS,
693
                        CreateTime = item.CREATE_DATETIME,
694
                        TotalPage = item.TOTAL_PAGE,
695
                        CurrentPageNo = item.CURRENT_PAGE,
696
                        Exception = item.EXCEPTION,
697
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID)
698
                    };
699

    
700

    
701
                    convertItems.Add(convertitem);
702
                }
703
            }
704

    
705
            return convertItems;
706
        }
707

    
708

    
709
        public bool SetConvertState(string ServiceID, string UniqueID, int State, int CurrentPage, int TotalPage, string Error)
710
        {
711
            bool result = false;
712

    
713
            try
714
            {
715
                var items = entities.CONVERTER_DOC.SingleOrDefault(f => f.ID == UniqueID);
716
                //var items = entities.CONVERTER_DOC.SingleOrDefault(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID);
717

    
718
                if (items != null)
719
                {
720
                    items.SERVICE_ID = ServiceID;
721
                    items.STATUS = State;
722
                    items.CURRENT_PAGE = CurrentPage;
723
                    items.TOTAL_PAGE = TotalPage;
724

    
725
                    StatusCodeType statusCode = (StatusCodeType)State;
726

    
727
                    if (items.START_DATETIME == null)
728
                    {
729
                        items.START_DATETIME = DateTime.Now;
730
                    }
731

    
732
                    switch (statusCode)
733
                    {
734
                        case StatusCodeType.None:
735
                            break;
736
                        case StatusCodeType.Wait:
737
                            items.START_DATETIME = DateTime.Now;
738
                            break;
739
                        case StatusCodeType.PageLoading:
740
                            break;
741
                        case StatusCodeType.Saving:
742
                            break;
743
                        case StatusCodeType.Completed:
744
                            items.CURRENT_PAGE = items.TOTAL_PAGE;
745
                            items.END_DATETIME = DateTime.Now;
746
                            break;
747
                        case StatusCodeType.FileError:
748
                            Error = $" file Error :" + Error;
749
                            items.END_DATETIME = DateTime.Now;
750
                            break;
751
                        case StatusCodeType.PageError:
752
                            Error = $" Page No {CurrentPage} Error :" + Error;
753
                            break;
754
                        case StatusCodeType.NeedsPassword:
755
                            break;
756
                        case StatusCodeType.Error:
757
                            Error = $" Error :" + Error;
758
                            items.END_DATETIME = DateTime.Now;
759
                            break;
760
                        default:
761
                            break;
762
                    }
763

    
764
                    if (items.EXCEPTION == null)
765
                    {
766
                        items.EXCEPTION = "";
767
                    }
768

    
769
                    if (items.EXCEPTION.Length < 255)
770
                    {
771
                        items.EXCEPTION = items.EXCEPTION + Error;
772
                    }
773

    
774
                    entities.SaveChanges();
775
                    result = true;
776
                }
777
            }
778
            catch (Exception ex)
779
            {
780
                throw new Exception("SetConvertState", ex);
781
            }
782

    
783
            return result;
784
        }
785

    
786
        public SERVICE_PROPERTIES GetServiceProperties(string ServiceID)
787
        {
788
            SERVICE_PROPERTIES result = null;
789

    
790
            var items = entities.SERVICE_PROPERTIES.Where(x => x.ID == ServiceID);
791

    
792
            if (items.Count() > 0)
793
            {
794
                result = items.First();
795
            }
796

    
797
            return result;
798
        }
799

    
800

    
801
        /// <summary>
802
        /// 현재 서비스에서 컨버터중인 아이템.
803
        /// </summary>
804
        /// <returns></returns>
805
        public List<Interface.ConvertItem> GetServiceAliveItems(string ServiceID)
806
        {
807
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
808

    
809
            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);
810

    
811
            if (items.Count() > 0)
812
            {
813
                foreach (var item in items)
814
                {
815
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL);
816
                    convertItems.Add(convertitem);
817
                }
818
            }
819
            return convertItems;
820
        }
821

    
822
        #endregion
823

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