프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.DataBase / ConvertDatabase.cs @ 902f397c

이력 | 보기 | 이력해설 | 다운로드 (33.8 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
using Markus.Service.DataBase.Data;
13
using Markus.Service.DataBase.Extensions;
14

    
15

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

    
25
        Markus.EntityModel.MarkusModel entities;
26

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

    
40
        public void Dispose()
41
        {
42
            entities.Dispose();
43
        }
44

    
45
        #endregion
46

    
47
        #region DataBaseItemsModel Function
48

    
49
        #region Get WaitConvertItems
50

    
51
        /// <summary>
52
        /// service에서 대기중이거나 오류인 아이템을 가져가서 컨버터 프로세스를 호출한다.
53
        /// 컨버터 상태가 에러이거나 2보다 작은 경우 
54
        /// UniqueKey는 각 데이터베이스의 문서 정보에서 유일한 키이며 컨버터저장에서 같은 폴더로의 저장을 방지 한다.
55
        /// 
56
        /// </summary>
57
        /// <param name="aliveItems"></param>
58
        /// <param name="TakeCount"></param>
59
        /// <returns></returns>
60
        public IEnumerable<CONVERTER_DOC> GetWaitConvertItems(List<string> projectList, int TakeCount)
61
        {
62
            var convertWaitingItems = entities.CONVERTER_DOC.OrderBy(x => x.CREATE_DATETIME).Where(
63
                                        x =>
64
                                        //projectList.Contains(x.PROJECT_NO) && x.RECONVERTER < 2 &&
65
                                         x.RECONVERTER < 2 &&
66
                                        (x.STATUS == (int)StatusCodeType.None || x.STATUS == (int)StatusCodeType.FileError || x.STATUS == (int)StatusCodeType.Error))
67
                                    .GroupBy(x => x.DOCUMENT_ID).Select(x => x.FirstOrDefault())
68
                                    .Take(TakeCount);
69

    
70
            return convertWaitingItems;
71
        }
72

    
73
        #endregion
74

    
75
        #region Get FilterConvertItems
76

    
77
        /// <summary>
78
        /// 상단 그리드 선택된 Status에 따라 DB에서 값 가져온다.
79
        /// </summary>
80
        public IEnumerable<Interface.ConvertItem> GetConvertProjects(int status)
81
        {
82
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
83
            var query = from items in entities.CONVERTER_DOC
84
                        join documents in entities.DOCUMENT_ITEM on items.DOCUMENT_ID equals documents.DOCUMENT_ID into GroupItems
85
                        from subpet in GroupItems.DefaultIfEmpty()
86
                        where items.STATUS == status
87
                        select items;
88

    
89

    
90
                        //orderby items.CREATE_DATETIME descending
91
                        //select new
92
                        //{
93
                        //    ID = items.ID,
94
                        //    DOCUMENT_URL = items.DOCUMENT_URL,
95
                        //    RECONVERTER = items.RECONVERTER,
96
                        //    SERVICE_ID = items.SERVICE_ID,
97
                        //    STATUS = items.STATUS,
98
                        //    CREATE_DATETIME = items.CREATE_DATETIME,
99
                        //    START_DATETIME = items.START_DATETIME,
100
                        //    END_DATETIME = items.END_DATETIME,
101
                        //    TOTAL_PAGE = items.TOTAL_PAGE,
102
                        //    CURRENT_PAGE = items.CURRENT_PAGE,
103
                        //    EXCEPTION = items.EXCEPTION,
104
                        //    PROJECT_NO = items.PROJECT_NO,
105
                        //    DOCUMENT_ID = items.DOCUMENT_ID,
106
                        //    REVISION = subpet.REVISION,
107
                        //    DOCUMENT_NO = subpet.DOCUMENT_NO,
108
                        //    DOCUMENT_NAME = subpet.DOCUMENT_NAME,
109
                        //    GROUP_NO = subpet.GROUP_NO,  
110
                        //    //REVISION = documents.REVISION,
111
                        //    //DOCUMENT_NO = documents.DOCUMENT_NO,
112
                        //    //DOCUMENT_NAME = documents.DOCUMENT_NAME,
113
                        //    //GROUP_NO = documents.GROUP_NO
114
                        //};
115

    
116
            if (query.Count() > 0)//세미
117
            {
118
                foreach (var item in query)
119
                {
120
                    Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
121
                    {
122

    
123
                        ReConverter = item.RECONVERTER,
124
                        ServiceID = item.SERVICE_ID,
125
                        ConvertState = (StatusCodeType)item.STATUS,
126
                        CreateTime = item.CREATE_DATETIME,
127
                        StartTime = (DateTime)item.START_DATETIME,
128
                        EndTime = (DateTime)item.END_DATETIME,
129
                        TotalPage = item.TOTAL_PAGE,
130
                        CurrentPageNo = item.CURRENT_PAGE,
131
                        Exception = item.EXCEPTION,
132
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID),
133

    
134
                        Revision = item.REVISION,
135
                        DocumnetNo = item.DOCUMENT_NO,
136
                        DocumnetName = item.DOCUMENT_NAME,
137
                        GroupNo = item.GROUP_NO,
138
                        DocumentID = item.DOCUMENT_ID,
139

    
140
                        MarkusLink = "kcom://" + Markus.Service.DataBase.Extensions.MarkusAPI.CreateMarkusParam(item.PROJECT_NO, item.DOCUMENT_ID, "doftech")
141
                    };
142
                    convertItems.Add(convertitem);
143
                }
144
            }
145
            return convertItems;
146

    
147
        }
148

    
149
        #endregion
150

    
151
        #region Update RealDataSelect 
152

    
153
        /// <summary>
154
        /// 상단 그리드에서 선택된 RealDataSelect
155
        /// 용도: 중앙그리드 Items Update
156
        /// </summary>
157
        public IEnumerable<Interface.ConvertItem> GetConvertProjects(System.Collections.ObjectModel.ObservableCollection<Interface.ConvertItem> selectedConvert)
158
        {
159
            List<Interface.ConvertItem> StatusKeep = new List<Interface.ConvertItem>();
160

    
161
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
162

    
163
            foreach (var selectedConvertItem in selectedConvert)
164
            {
165
                var query = from items in entities.CONVERTER_DOC //세미
166
                            join documents in entities.DOCUMENT_ITEM on items.DOCUMENT_ID equals documents.DOCUMENT_ID into GroupItems
167
                            from subpet in GroupItems.DefaultIfEmpty()
168
                            where items.PROJECT_NO == selectedConvertItem.ProjectNumber && items.ID == selectedConvertItem.ConvertID
169
                            select new
170
                            {
171
                                ID = items.ID,
172
                                DOCUMENT_URL = items.DOCUMENT_URL,
173
                                RECONVERTER = items.RECONVERTER,
174
                                SERVICE_ID = items.SERVICE_ID,
175
                                STATUS = items.STATUS,
176
                                CREATE_DATETIME = items.CREATE_DATETIME,
177
                                START_DATETIME  = items.START_DATETIME,
178
                                END_DATETIME = items.END_DATETIME,
179
                                TOTAL_PAGE = items.TOTAL_PAGE,
180
                                CURRENT_PAGE = items.CURRENT_PAGE,
181
                                EXCEPTION = items.EXCEPTION,
182
                                PROJECT_NO = items.PROJECT_NO,
183
                                DOCUMENT_ID = items.DOCUMENT_ID,
184
                                REVISION = subpet.REVISION,
185
                                DOCUMENT_NO = subpet.DOCUMENT_NO,
186
                                DOCUMENT_NAME = subpet.DOCUMENT_NAME,
187
                                GROUP_NO = subpet.GROUP_NO
188
                            };
189

    
190

    
191
                if (query.Count() > 0)//세미
192
                {
193
                    foreach (var item in query)
194
                    {
195
                        Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
196
                        {
197

    
198
                            ReConverter = item.RECONVERTER,
199
                            ServiceID = item.SERVICE_ID,
200
                            ConvertState = (StatusCodeType)item.STATUS,
201
                            CreateTime = item.CREATE_DATETIME,
202
                            StartTime = item.START_DATETIME,
203
                            EndTime = item.END_DATETIME,
204
                            TotalPage = item.TOTAL_PAGE,
205
                            CurrentPageNo = item.CURRENT_PAGE,
206
                            Exception = item.EXCEPTION,
207
                            ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID),
208

    
209
                            Revision = item.REVISION,
210
                            DocumnetNo = item.DOCUMENT_NO,
211
                            DocumnetName = item.DOCUMENT_NAME,
212
                            GroupNo = item.GROUP_NO,
213

    
214
                            MarkusLink = "kcom://" + MarkusAPI.CreateMarkusParam(item.PROJECT_NO, item.DOCUMENT_ID, "doftech")
215
                        };
216

    
217
                        StatusKeep.Add(convertitem);
218

    
219
                    }
220
                }
221
            }
222
            return StatusKeep;
223
        }
224

    
225
        #endregion
226

    
227
        #region Data Convert
228

    
229
        /// <summary>
230
        /// 상단 그리드에서 선택된 Convert 버튼 
231
        /// 용도: 중앙 그리드로 Convert된 row 값 저장 하기 위해서 입니다.
232
        /// </summary>
233
        public IEnumerable<Interface.ConvertItem> GetConvertProjects(Markus.Service.Interface.ConvertItem selectedConvert)
234
        {
235
            List<Interface.ConvertItem> StatusKeep = new List<Interface.ConvertItem>();
236

    
237

    
238
            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
239

    
240
            stopwatch.Start();
241

    
242

    
243
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();//디비 다 조인 후 조건 비교 후 그리드 출력
244
            var query = from items in entities.CONVERTER_DOC //세미
245
                        join documents in entities.DOCUMENT_ITEM on items.DOCUMENT_ID equals documents.DOCUMENT_ID into GroupItems
246
                        from subpet in GroupItems.DefaultIfEmpty()
247
                        where items.PROJECT_NO == selectedConvert.ProjectNumber && items.DOCUMENT_ID == selectedConvert.DocumentID
248
                        orderby items.CREATE_DATETIME descending
249
                        select new
250
                        {
251
                            ID = items.ID,
252
                            DOCUMENT_URL = items.DOCUMENT_URL,
253
                            RECONVERTER = items.RECONVERTER,
254
                            SERVICE_ID = items.SERVICE_ID,
255
                            STATUS = items.STATUS,
256
                            CREATE_DATETIME = items.CREATE_DATETIME,
257
                            START_DATETIME = items.START_DATETIME,
258
                            END_DATETIME = items.END_DATETIME,
259
                            TOTAL_PAGE = items.TOTAL_PAGE,
260
                            CURRENT_PAGE = items.CURRENT_PAGE,
261
                            EXCEPTION = items.EXCEPTION,
262
                            PROJECT_NO = items.PROJECT_NO,
263
                            DOCUMENT_ID = items.DOCUMENT_ID,
264
                            REVISION = subpet.REVISION,
265
                            DOCUMENT_NO = subpet.DOCUMENT_NO,
266
                            DOCUMENT_NAME = subpet.DOCUMENT_NAME,
267
                            GROUP_NO = subpet.GROUP_NO
268
                        };
269

    
270
            if (query.Count() > 0)//세미
271
            {
272
                foreach (var item in query)
273
                {
274
                    Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
275
                    {
276

    
277
                        ReConverter = item.RECONVERTER,
278
                        ServiceID = item.SERVICE_ID,
279
                        ConvertState = (StatusCodeType)item.STATUS,
280
                        CreateTime = item.CREATE_DATETIME,
281
                        StartTime = item.START_DATETIME,
282
                        EndTime = item.END_DATETIME,
283
                        TotalPage = item.TOTAL_PAGE,
284
                        CurrentPageNo = item.CURRENT_PAGE,
285
                        Exception = item.EXCEPTION,
286
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID),
287
                        Revision = item.REVISION,
288
                        DocumnetNo = item.DOCUMENT_NO,
289
                        DocumnetName = item.DOCUMENT_NAME,
290
                        GroupNo = item.GROUP_NO,
291

    
292
                        MarkusLink = "kcom://" + Markus.Service.DataBase.Extensions.MarkusAPI.CreateMarkusParam(item.PROJECT_NO, item.DOCUMENT_ID, "doftech")
293
                    };
294
                    StatusKeep.Add(convertitem);
295
                }
296
            }
297
            System.Diagnostics.Debug.WriteLine(new TimeSpan(stopwatch.ElapsedTicks).ToString());
298
            return StatusKeep;
299

    
300
        }
301

    
302
        #endregion
303

    
304
        #region SetCleanUpItem
305
        /// <summary>
306
        /// 오류나 wait으로 남아 있는 데이터베이스의 Item을 StatusCodeType.None으로 복구
307
        /// </summary>
308
        /// <param name="convertID">StatusCodeType을 변경하고자 하는 ConvertItem의 ID</param>
309
        /// <param name="ReConvert">ReConvert가 2이면 다시 Convert를 시도 안하기 때문에 기존 값으로 유지 하고 계속 시도 할수 있도록 0을 주는 경우가 있다.</param>
310
        /// <returns></returns>
311
        /// 
312
        public int SetCleanUpItem(ConvertItem _ConvertItem)
313
        {
314
            int result = 0;
315

    
316
            var items = entities.CONVERTER_DOC.Where(x => x.ID == _ConvertItem.ConvertID);
317

    
318
            result = items.Count();
319

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

    
324
                item.RECONVERTER = item.RECONVERTER - _ConvertItem.ReConverter;
325

    
326
                item.CREATE_DATETIME = DateTime.Now;
327
                item.STATUS = (int)StatusCodeType.None;
328
                item.END_DATETIME = null;
329

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

    
333
            return result;
334
        }
335

    
336
        public int SetCleanUpItem(string convertID, int ReConvert)
337
        {
338
            int result = 0;
339

    
340
            var items = entities.CONVERTER_DOC.Where(x => x.ID == convertID);
341

    
342
            result = items.Count();
343

    
344
            if (items.Count() > 0)
345
            {
346
                var item = items.First();
347

    
348
                item.RECONVERTER = item.RECONVERTER + ReConvert;
349
                item.CREATE_DATETIME = DateTime.Now;
350
                //item.START_DATETIME = null;
351
                item.END_DATETIME = null;
352
                item.STATUS = (int)StatusCodeType.None;
353

    
354
                result = entities.SaveChanges();
355
            }
356

    
357
            return result;
358
        }
359
        #endregion
360

    
361
        #region Convert Path
362

    
363
        private string GetConvertPath(string ProjectNo, string DocumentID)
364
        {
365
            try
366
            {
367
                return Path.Combine(BaseStorage(ProjectNo), ProjectNo + "_Tile", (System.Convert.ToInt64(DocumentID) / 100).ToString(), DocumentID);
368
            }
369
            catch (Exception)
370
            {
371
                throw new Exception("GetConvertPath Error");
372
            }
373

    
374
        }
375

    
376
        private string BaseStorage(string ProjectNo)
377
        {
378
            string result = "";
379

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

    
382
            if (properties.Count() > 0)
383
            {
384
                result = properties.First().VALUE;
385
            }
386
            else
387
            {
388
                throw new Exception($"Project {ProjectNo} BaseStorage Not Setting.");
389
            }
390

    
391
            return result;
392
        }
393

    
394
        #endregion
395

    
396
        #region Remove
397

    
398
        /// <summary>
399
        /// Item 삭제
400
        /// </summary>
401
        /// <returns></returns>
402
        public int RemoveItem(string convertID)
403
        {
404
            int result = 0;
405

    
406
            var items = entities.CONVERTER_DOC.Where(x => x.ID == convertID);
407

    
408
            if (items.Count() > 0)
409
            {
410
                CONVERTER_DOC item = items.First();
411
                entities.CONVERTER_DOC.Remove(item);
412

    
413
                result = entities.SaveChanges();
414
            }
415

    
416
            return result;
417
        }
418

    
419

    
420
        #endregion
421

    
422
        #region MarkusLink
423

    
424

    
425
        ////// userID는 관리자 계정인 doftech
426
        ////string markusLink = "kcom://" + MarkusAPI.CreateMarkusParam(projectNo, documentID, userID);
427
        //public static string CreateMarkusParam(string projectNo, string documentID, string userID)
428
        //{
429
        //    ViewInfo viewInfo = new ViewInfo();
430

    
431
        //    viewInfo.DocumentItemID = documentID;
432
        //    viewInfo.ProjectNO = projectNo;
433
        //    viewInfo.UserID = userID;
434

    
435
        //    return ParamEncoding(JsonConvert.SerializeObject(viewInfo));
436

    
437
        //}
438

    
439
        //public static string ParamEncoding(string EncodingText, System.Text.Encoding oEncoding = null)
440
        //{
441

    
442
        //    if (oEncoding == null)
443
        //        oEncoding = System.Text.Encoding.UTF8;
444

    
445
        //    return Convert.ToBase64String(oEncoding.GetBytes(EncodingText));
446

    
447
        //}
448

    
449

    
450
        #endregion
451

    
452
        #endregion
453

    
454
        #region DataBaseByStatusViewModel Function
455
        /// <summary>
456
        /// 전체 컨버터를 가져온다. 비동기로 변경하여야 한다.
457
        /// </summary>
458
        /// <returns></returns>
459
        public List<Interface.ConvertItem> GetConvertItems(StatusCodeType statusCodeType, Func<CONVERTER_DOC, bool> @where, int takeCount = 100)
460
        {
461
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
462

    
463

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

    
466
            if (items.Count() > 0)
467
            {
468
                foreach (var item in items)
469
                {
470
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
471
                    {
472
                        ReConverter = item.RECONVERTER,
473
                        ServiceID = item.SERVICE_ID,
474
                        ConvertState = ((StatusCodeType)item.STATUS),
475
                        CreateTime = item.CREATE_DATETIME,
476
                        TotalPage = item.TOTAL_PAGE,
477
                        CurrentPageNo = item.CURRENT_PAGE,
478

    
479
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID)
480
                    };
481

    
482
                    convertItems.Add(convertitem);
483
                }
484
            }
485
            return convertItems;
486
        }
487
        #endregion
488

    
489
        #region No 참조 
490

    
491
        /// <summary>
492
        /// 컨버터서비스를 이용하는 문서 정보 저장
493
        /// UniqueID
494
        /// using Markus.Service.Extensions;  new Guid().CreateUniqueGuid().ToString();
495
        /// </summary>
496
        /// <param name="ProjectNo">프로젝트</param>
497
        /// <param name="UniqueID">컨버터 서비스의 아이템 ID</param>
498
        /// <param name="originfilePath"></param>
499
        /// <param name="DocumentID"></param>
500
        /// <returns></returns>
501
        public bool SetConvertDoc(string ProjectNo, string UniqueID, string originfilePath, string DocumentID)
502
        {
503
            bool result = false;
504

    
505
            if (ProjectNo.IsNullOrEmpty())
506
            {
507
                throw new Exception("ProjectNo is Null");
508
            }
509

    
510
            if (UniqueID.IsNullOrEmpty())
511
            {
512
                throw new Exception("UniqueID is Null");
513
            }
514

    
515
            if (originfilePath.IsNullOrEmpty())
516
            {
517
                throw new Exception("originfilePath is Null");
518
            }
519

    
520
            if (DocumentID.IsNullOrEmpty())
521
            {
522
                throw new Exception("DocumentID is Null");
523
            }
524

    
525
            if (DocumentID.IsNullOrEmpty())
526
            {
527
                long _lastDocId = 0;
528

    
529
                if (entities.CONVERTER_DOC.Count() > 0)
530
                {
531
                    try
532
                    {
533
                        string qry = @"SELECT * FROM CONVERTER_DOC order by CAST(DOCUMENT_ID as int) desc";
534
                        var _item = entities.CONVERTER_DOC.SqlQuery(qry).FirstOrDefault();
535

    
536
                        if (_item != null)
537
                        {
538
                            _lastDocId = Convert.ToInt64(_item.DOCUMENT_ID) + 1;
539
                        }
540
                    }
541
                    catch (Exception)
542
                    {
543

    
544
                        throw;
545
                    }
546
                }
547

    
548
                DocumentID = _lastDocId.ToString();
549
            }
550

    
551
            CONVERTER_DOC convert_doc = new CONVERTER_DOC
552
            {
553
                ID = UniqueID,
554
                PROJECT_NO = ProjectNo,
555
                DOCUMENT_URL = originfilePath,
556
                DOCUMENT_ID = DocumentID,
557
                CREATE_DATETIME = DateTime.Now,
558
                STATUS = 0,
559
                TOTAL_PAGE = 0,
560
                CURRENT_PAGE = 0,
561
                RECONVERTER = 0
562
            };
563

    
564
            
565
            entities.CONVERTER_DOC.Add(convert_doc);
566

    
567
            if (entities.SaveChanges() == 1)
568
            {
569
                result = true;
570
            }
571

    
572
            return result;
573
        }
574

    
575
        /// <summary>
576
        /// 컨버터서비스를 이용하는 문서 정보 저장
577
        /// UniqueID
578
        /// using Markus.Service.Extensions;  new Guid().CreateUniqueGuid().ToString();
579
        /// </summary>
580
        /// <param name="ProjectNo">프로젝트</param>
581
        /// <param name="UniqueID">컨버터 서비스의 아이템 ID</param>
582
        /// <param name="originfilePath"></param>
583
        /// <param name="DocumentID"></param>
584
        /// <returns></returns>
585
        public bool SetDocumentInfo(string ConvertID, int totalPage, List<DOCPAGE> pageinfo)
586
        {
587
            bool result = false;
588

    
589
            var convertDocItems = entities.CONVERTER_DOC.Where(f => f.ID == ConvertID);
590

    
591
            if (convertDocItems.Count() > 0)
592
            {
593
                var convertDoc = convertDocItems.First();
594

    
595
                string docId = new Guid().CreateUniqueGuid().ToString();
596

    
597
                var docinfo = entities.DOCINFO.FirstOrDefault(x => x.PROJECT_NO == convertDoc.PROJECT_NO && x.DOCUMENT_ID == convertDoc.DOCUMENT_ID);
598
                
599
                if (docinfo != null)
600
                {
601
                    // 기존 Docpage 삭제.
602
                    entities.DOCPAGE.RemoveRange(docinfo.DOCPAGE);
603

    
604
                    // 기존 코멘트 유지를 위한 Docinfo update                    
605
                    docinfo.PROJECT_NO = convertDoc.PROJECT_NO;
606
                    docinfo.ORIGINAL_FILE = convertDoc.DOCUMENT_URL;
607
                    docinfo.PAGE_COUNT = totalPage;                    
608
                    docinfo.DOCPAGE = pageinfo;                    
609
                    entities.SaveChanges();
610
                    result = true;
611
                }
612
                else
613
                {
614
                    DOCINFO instace = new DOCINFO
615
                    {
616
                        ID = docId,
617
                        PROJECT_NO = convertDoc.PROJECT_NO,
618
                        ORIGINAL_FILE = convertDoc.DOCUMENT_URL,
619
                        DOCUMENT_ID = convertDoc.DOCUMENT_ID,
620
                        PAGE_COUNT = totalPage,
621
                        DOCPAGE = pageinfo
622
                    };
623

    
624
                    entities.DOCINFO.Add(instace);
625
                    var save = entities.SaveChanges();
626

    
627
                    if (save == pageinfo.Count() + 1)
628
                    {
629
                        result = true;
630
                    }
631
                }
632

    
633
                
634
                
635
            }
636

    
637
            return result;
638
        }
639

    
640
        public Interface.ConvertItem GetConvertItem(string ProjectNo, string UniqueID)
641
        {
642
            Interface.ConvertItem result = null;
643

    
644
            //var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID);
645
            var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == ProjectNo && f.ID == UniqueID);
646

    
647
            if (items.Count() > 0)
648
            {
649
                var convertItem = items.First();
650

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

    
653
                result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath);
654
            }
655

    
656
            return result;
657
        }
658

    
659

    
660
        public Interface.ConvertItem GetConvertItembyDocumentID(string ProjectNo, string DocumentID)
661
        {
662
            Interface.ConvertItem result = null;
663

    
664
            //var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID);
665
            var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == ProjectNo && f.DOCUMENT_ID == DocumentID);
666

    
667
            if (items.Count() > 0)
668
            {
669
                var convertItem = items.First();
670
                string convertPath = Path.Combine(BaseStorage(convertItem.PROJECT_NO), convertItem.PROJECT_NO + "_Tile", (System.Convert.ToInt64(convertItem.DOCUMENT_ID) / 100).ToString(), convertItem.DOCUMENT_ID);
671

    
672
                if (convertItem.STATUS == (int)StatusCodeType.Completed)
673
                {
674
                    result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath,
675
                                                        (StatusCodeType)convertItem.STATUS, convertItem.CURRENT_PAGE, convertItem.TOTAL_PAGE, convertItem.EXCEPTION);
676
                }
677
                else
678
                {
679
                    result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath);
680
                }
681
            }
682

    
683
            return result;
684
        }
685

    
686
        public List<CONVERTER_DOC> GetConvertingItems(List<string> projectList)
687
        {
688
            var convertWaitingItems = entities.CONVERTER_DOC.OrderBy(x => x.CREATE_DATETIME).Where(
689
                                        x =>
690
                                        projectList.Contains(x.PROJECT_NO) &&
691
                                         (x.STATUS > (int)StatusCodeType.None && x.STATUS < (int)StatusCodeType.Completed) && x.RECONVERTER < 2);
692

    
693
            return convertWaitingItems.ToList();
694
        }
695

    
696
        /// <summary>
697
        /// 전체 컨버터를 가져온다. 비동기로 변경하여야 한다.
698
        /// </summary>
699
        /// <returns></returns>
700
        public List<Interface.ConvertItem> GetConvertItems(StatusCodeType statusCodeType)
701
        {
702
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
703

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

    
706
            if (items.Count() > 0)
707
            {
708
                foreach (var item in items)
709
                {
710
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
711
                    {
712
                        ReConverter = item.RECONVERTER,
713
                        ServiceID = item.SERVICE_ID,
714
                        ConvertState = ((StatusCodeType)item.STATUS),
715
                        CreateTime = item.CREATE_DATETIME,
716
                        TotalPage = item.TOTAL_PAGE,
717
                        CurrentPageNo = item.CURRENT_PAGE,
718

    
719
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID)
720
                    };
721

    
722

    
723
                    convertItems.Add(convertitem);
724
                }
725
            }
726
            return convertItems;
727
        }
728

    
729
        public List<Interface.ConvertItem> GetConvertProjectsStatus(Func<CONVERTER_DOC, bool> @where)
730
        {
731
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
732

    
733

    
734
            //var items = entities.CONVERTER_DOC.Where(x => x.STATUS == (int)statusCodeType).Take(takeCount).ToList(); //.Where(x => x.PROJECT_NO == gProjectNo);
735
            var items = entities.CONVERTER_DOC.Where(x => x.STATUS <= 4);
736

    
737
            if (items.Count() > 0)
738
            {
739
                foreach (var item in items)
740
                {
741
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
742
                    {
743
                        ReConverter = item.RECONVERTER,
744
                        ServiceID = item.SERVICE_ID,
745
                        //ConvertState = ((StatusCodeType)item.STATUS).ToString(),
746
                        //ConvertState = (item.STATUS).ToString(),
747
                        ConvertState = (StatusCodeType)item.STATUS,
748
                        CreateTime = item.CREATE_DATETIME,
749
                        TotalPage = item.TOTAL_PAGE,
750
                        CurrentPageNo = item.CURRENT_PAGE,
751
                        Exception = item.EXCEPTION,
752
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID)
753
                    };
754

    
755

    
756
                    convertItems.Add(convertitem);
757
                }
758
            }
759

    
760
            return convertItems;
761
        }
762

    
763

    
764
        public bool SetConvertState(string ServiceID, string UniqueID, int State, int CurrentPage, int TotalPage, string Error)
765
        {
766
            bool result = false;
767

    
768
            try
769
            {
770
                var items = entities.CONVERTER_DOC.SingleOrDefault(f => f.ID == UniqueID);
771
                //var items = entities.CONVERTER_DOC.SingleOrDefault(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID);
772

    
773
                if (items != null)
774
                {
775
                    items.SERVICE_ID = ServiceID;
776
                    items.STATUS = State;
777
                    items.CURRENT_PAGE = CurrentPage;
778
                    items.TOTAL_PAGE = TotalPage;
779

    
780
                    StatusCodeType statusCode = (StatusCodeType)State;
781

    
782
                    if (items.START_DATETIME == null)
783
                    {
784
                        items.START_DATETIME = DateTime.Now;
785
                    }
786

    
787
                    switch (statusCode)
788
                    {
789
                        case StatusCodeType.None:
790
                            break;
791
                        case StatusCodeType.Wait:
792
                            items.START_DATETIME = DateTime.Now;
793
                            break;
794
                        case StatusCodeType.PageLoading:
795
                            break;
796
                        case StatusCodeType.Saving:
797
                            break;
798
                        case StatusCodeType.Completed:
799
                            items.CURRENT_PAGE = items.TOTAL_PAGE;
800
                            items.END_DATETIME = DateTime.Now;
801
                            break;
802
                        case StatusCodeType.FileError:
803
                            Error = $" file Error :" + Error;
804
                            items.END_DATETIME = DateTime.Now;
805
                            break;
806
                        case StatusCodeType.PageError:
807
                            Error = $" Page No {CurrentPage} Error :" + Error;
808
                            break;
809
                        case StatusCodeType.NeedsPassword:
810
                            break;
811
                        case StatusCodeType.Error:
812
                            Error = $" Error :" + Error;
813
                            items.END_DATETIME = DateTime.Now;
814
                            break;
815
                        default:
816
                            break;
817
                    }
818

    
819
                    if (items.EXCEPTION == null)
820
                    {
821
                        items.EXCEPTION = "";
822
                    }
823

    
824
                    if (items.EXCEPTION.Length < 255)
825
                    {
826
                        items.EXCEPTION = items.EXCEPTION + Error;
827
                    }
828

    
829
                    entities.SaveChanges();
830
                    result = true;
831
                }
832
            }
833
            catch (Exception ex)
834
            {
835
                throw new Exception("SetConvertState", ex);
836
            }
837

    
838
            return result;
839
        }
840

    
841
        public SERVICE_PROPERTIES GetServiceProperties(string ServiceID)
842
        {
843
            SERVICE_PROPERTIES result = null;
844

    
845
            var items = entities.SERVICE_PROPERTIES.Where(x => x.ID == ServiceID);
846

    
847
            if (items.Count() > 0)
848
            {
849
                result = items.First();
850
            }
851

    
852
            return result;
853
        }
854

    
855

    
856
        /// <summary>
857
        /// 현재 서비스에서 컨버터중인 아이템.
858
        /// </summary>
859
        /// <returns></returns>
860
        public List<Interface.ConvertItem> GetServiceAliveItems(string ServiceID)
861
        {
862
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
863

    
864
            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);
865

    
866
            if (items.Count() > 0)
867
            {
868
                foreach (var item in items)
869
                {
870
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL);
871
                    convertItems.Add(convertitem);
872
                }
873
            }
874
            return convertItems;
875
        }
876

    
877
        #endregion
878

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