프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.DataBase / ConvertDatabase.cs @ 05fd750b

이력 | 보기 | 이력해설 | 다운로드 (32.2 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
                        orderby items.CREATE_DATETIME descending
88
                        select new
89
                        {
90
                            ID = items.ID,
91
                            DOCUMENT_URL = items.DOCUMENT_URL,
92
                            RECONVERTER = items.RECONVERTER,
93
                            SERVICE_ID = items.SERVICE_ID,
94
                            STATUS = items.STATUS,
95
                            CREATE_DATETIME = items.CREATE_DATETIME,
96
                            TOTAL_PAGE = items.TOTAL_PAGE,
97
                            CURRENT_PAGE = items.CURRENT_PAGE,
98
                            EXCEPTION = items.EXCEPTION,
99
                            PROJECT_NO = items.PROJECT_NO,
100
                            DOCUMENT_ID = items.DOCUMENT_ID,
101
                            REVISION = subpet.REVISION,
102
                            DOCUMENT_NO = subpet.DOCUMENT_NO,
103
                            DOCUMENT_NAME = subpet.DOCUMENT_NAME,
104
                            GROUP_NO = subpet.GROUP_NO
105
                            //REVISION = documents.REVISION,
106
                            //DOCUMENT_NO = documents.DOCUMENT_NO,
107
                            //DOCUMENT_NAME = documents.DOCUMENT_NAME,
108
                            //GROUP_NO = documents.GROUP_NO
109
                        };
110

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

    
118
                        ReConverter = item.RECONVERTER,
119
                        ServiceID = item.SERVICE_ID,
120
                        ConvertState = (StatusCodeType)item.STATUS,
121
                        CreateTime = item.CREATE_DATETIME,
122
                        TotalPage = item.TOTAL_PAGE,
123
                        CurrentPageNo = item.CURRENT_PAGE,
124
                        Exception = item.EXCEPTION,
125

    
126
                        Revision = item.REVISION,
127
                        DocumnetNo = item.DOCUMENT_NO,
128
                        DocumnetName = item.DOCUMENT_NAME,
129
                        GroupNo = item.GROUP_NO,
130
                        DocumentID = item.DOCUMENT_ID,
131

    
132
                        MarkusLink = Markus.Service.DataBase.Extensions.MarkusAPI.CreateMarkusParam(item.PROJECT_NO, item.DOCUMENT_ID, "doftech")
133
                    };
134
                    convertItems.Add(convertitem);
135
                }
136
            }
137
            return convertItems;
138

    
139
        }
140

    
141
        #endregion
142

    
143
        #region Update RealDataSelect 
144

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

    
153
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
154

    
155
            foreach (var selectedConvertItem in selectedConvert)
156
            {
157
                var query = from items in entities.CONVERTER_DOC //세미
158
                            join documents in entities.DOCUMENT_ITEM on items.DOCUMENT_ID equals documents.DOCUMENT_ID into GroupItems
159
                            from subpet in GroupItems.DefaultIfEmpty()
160
                            where items.PROJECT_NO == selectedConvertItem.ProjectNumber && items.ID == selectedConvertItem.ConvertID
161
                            select new
162
                            {
163
                                ID = items.ID,
164
                                DOCUMENT_URL = items.DOCUMENT_URL,
165
                                RECONVERTER = items.RECONVERTER,
166
                                SERVICE_ID = items.SERVICE_ID,
167
                                STATUS = items.STATUS,
168
                                CREATE_DATETIME = items.CREATE_DATETIME,
169
                                TOTAL_PAGE = items.TOTAL_PAGE,
170
                                CURRENT_PAGE = items.CURRENT_PAGE,
171
                                EXCEPTION = items.EXCEPTION,
172
                                PROJECT_NO = items.PROJECT_NO,
173
                                DOCUMENT_ID = items.DOCUMENT_ID,
174
                                REVISION = subpet.REVISION,
175
                                DOCUMENT_NO = subpet.DOCUMENT_NO,
176
                                DOCUMENT_NAME = subpet.DOCUMENT_NAME,
177
                                GROUP_NO = subpet.GROUP_NO
178
                            };
179

    
180

    
181
                if (query.Count() > 0)//세미
182
                {
183
                    foreach (var item in query)
184
                    {
185
                        Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
186
                        {
187

    
188
                            ReConverter = item.RECONVERTER,
189
                            ServiceID = item.SERVICE_ID,
190
                            ConvertState = (StatusCodeType)item.STATUS,
191
                            CreateTime = item.CREATE_DATETIME,
192
                            TotalPage = item.TOTAL_PAGE,
193
                            CurrentPageNo = item.CURRENT_PAGE,
194
                            Exception = item.EXCEPTION,
195
                            ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID),
196

    
197
                            Revision = item.REVISION,
198
                            DocumnetNo = item.DOCUMENT_NO,
199
                            DocumnetName = item.DOCUMENT_NAME,
200
                            GroupNo = item.GROUP_NO,
201

    
202
                            MarkusLink = MarkusAPI.CreateMarkusParam(item.PROJECT_NO, item.DOCUMENT_ID, "doftech")
203
                        };
204

    
205
                        StatusKeep.Add(convertitem);
206

    
207
                    }
208
                }
209
            }
210
            return StatusKeep;
211
        }
212

    
213
        #endregion
214

    
215
        #region Data Convert
216

    
217
        /// <summary>
218
        /// 상단 그리드에서 선택된 Convert 버튼 
219
        /// 용도: 중앙 그리드로 Convert된 row 값 저장 하기 위해서 입니다.
220
        /// </summary>
221
        public IEnumerable<Interface.ConvertItem> GetConvertProjects(Markus.Service.Interface.ConvertItem selectedConvert)
222
        {
223
            List<Interface.ConvertItem> StatusKeep = new List<Interface.ConvertItem>();
224

    
225

    
226
            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
227

    
228
            stopwatch.Start();
229

    
230

    
231
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();//디비 다 조인 후 조건 비교 후 그리드 출력
232
            var query = from items in entities.CONVERTER_DOC //세미
233
                        join documents in entities.DOCUMENT_ITEM on items.DOCUMENT_ID equals documents.DOCUMENT_ID into GroupItems
234
                        from subpet in GroupItems.DefaultIfEmpty()
235
                        where items.PROJECT_NO == selectedConvert.ProjectNumber && items.DOCUMENT_ID == selectedConvert.DocumentID
236
                        orderby items.CREATE_DATETIME descending
237
                        select new
238
                        {
239
                            ID = items.ID,
240
                            DOCUMENT_URL = items.DOCUMENT_URL,
241
                            RECONVERTER = items.RECONVERTER,
242
                            SERVICE_ID = items.SERVICE_ID,
243
                            STATUS = items.STATUS,
244
                            CREATE_DATETIME = items.CREATE_DATETIME,
245
                            TOTAL_PAGE = items.TOTAL_PAGE,
246
                            CURRENT_PAGE = items.CURRENT_PAGE,
247
                            EXCEPTION = items.EXCEPTION,
248
                            PROJECT_NO = items.PROJECT_NO,
249
                            DOCUMENT_ID = items.DOCUMENT_ID,
250
                            REVISION = subpet.REVISION,
251
                            DOCUMENT_NO = subpet.DOCUMENT_NO,
252
                            DOCUMENT_NAME = subpet.DOCUMENT_NAME,
253
                            GROUP_NO = subpet.GROUP_NO
254
                        };
255

    
256
            if (query.Count() > 0)//세미
257
            {
258
                foreach (var item in query)
259
                {
260
                    Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
261
                    {
262

    
263
                        ReConverter = item.RECONVERTER,
264
                        ServiceID = item.SERVICE_ID,
265
                        ConvertState = (StatusCodeType)item.STATUS,
266
                        CreateTime = item.CREATE_DATETIME,
267
                        TotalPage = item.TOTAL_PAGE,
268
                        CurrentPageNo = item.CURRENT_PAGE,
269
                        Exception = item.EXCEPTION,
270
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID),
271
                        Revision = item.REVISION,
272
                        DocumnetNo = item.DOCUMENT_NO,
273
                        DocumnetName = item.DOCUMENT_NAME,
274
                        GroupNo = item.GROUP_NO,
275

    
276
                        MarkusLink = Markus.Service.DataBase.Extensions.MarkusAPI.CreateMarkusParam(item.PROJECT_NO, item.DOCUMENT_ID, "doftech")
277
                    };
278
                    StatusKeep.Add(convertitem);
279
                }
280
            }
281
            System.Diagnostics.Debug.WriteLine(new TimeSpan(stopwatch.ElapsedTicks).ToString());
282
            return StatusKeep;
283

    
284
        }
285

    
286
        #endregion
287

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

    
300
            var items = entities.CONVERTER_DOC.Where(x => x.ID == _ConvertItem.ConvertID);
301

    
302
            result = items.Count();
303

    
304
            if (items.Count() > 0)
305
            {
306
                var item = items.First();
307

    
308
                item.RECONVERTER = item.RECONVERTER - _ConvertItem.ReConverter;
309
                item.CREATE_DATETIME = DateTime.Now;
310
                item.STATUS = (int)StatusCodeType.None;
311

    
312
                result = entities.SaveChanges();
313
            }
314

    
315
            return result;
316
        }
317

    
318
        #endregion
319

    
320
        #region Convert Path
321

    
322
        private string GetConvertPath(string ProjectNo, string DocumentID)
323
        {
324
            try
325
            {
326
                return Path.Combine(BaseStorage(ProjectNo), ProjectNo + "_Tile", (System.Convert.ToInt64(DocumentID) / 100).ToString(), DocumentID);
327
            }
328
            catch (Exception)
329
            {
330
                throw new Exception("GetConvertPath Error");
331
            }
332

    
333
        }
334

    
335
        private string BaseStorage(string ProjectNo)
336
        {
337
            string result = "";
338

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

    
341
            if (properties.Count() > 0)
342
            {
343
                result = properties.First().VALUE;
344
            }
345
            else
346
            {
347
                throw new Exception($"Project {ProjectNo} BaseStorage Not Setting.");
348
            }
349

    
350
            return result;
351
        }
352

    
353
        #endregion
354

    
355
        #region Remove
356

    
357
        /// <summary>
358
        /// Item 삭제
359
        /// </summary>
360
        /// <returns></returns>
361
        public int RemoveItem(string convertID)
362
        {
363
            int result = 0;
364

    
365
            var items = entities.CONVERTER_DOC.Where(x => x.ID == convertID);
366

    
367
            if (items.Count() > 0)
368
            {
369
                CONVERTER_DOC item = items.First();
370
                entities.CONVERTER_DOC.Remove(item);
371

    
372
                result = entities.SaveChanges();
373
            }
374

    
375
            return result;
376
        }
377

    
378

    
379
        #endregion
380

    
381
        #region MarkusLink
382

    
383

    
384
        ////// userID는 관리자 계정인 doftech
385
        ////string markusLink = "kcom://" + MarkusAPI.CreateMarkusParam(projectNo, documentID, userID);
386
        //public static string CreateMarkusParam(string projectNo, string documentID, string userID)
387
        //{
388
        //    ViewInfo viewInfo = new ViewInfo();
389

    
390
        //    viewInfo.DocumentItemID = documentID;
391
        //    viewInfo.ProjectNO = projectNo;
392
        //    viewInfo.UserID = userID;
393

    
394
        //    return ParamEncoding(JsonConvert.SerializeObject(viewInfo));
395

    
396
        //}
397

    
398
        //public static string ParamEncoding(string EncodingText, System.Text.Encoding oEncoding = null)
399
        //{
400

    
401
        //    if (oEncoding == null)
402
        //        oEncoding = System.Text.Encoding.UTF8;
403

    
404
        //    return Convert.ToBase64String(oEncoding.GetBytes(EncodingText));
405

    
406
        //}
407

    
408

    
409
        #endregion
410

    
411
        #endregion
412

    
413
        #region DataBaseByStatusViewModel Function
414
        /// <summary>
415
        /// 전체 컨버터를 가져온다. 비동기로 변경하여야 한다.
416
        /// </summary>
417
        /// <returns></returns>
418
        public List<Interface.ConvertItem> GetConvertItems(StatusCodeType statusCodeType, Func<CONVERTER_DOC, bool> @where, int takeCount = 100)
419
        {
420
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
421

    
422

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

    
425
            if (items.Count() > 0)
426
            {
427
                foreach (var item in items)
428
                {
429
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
430
                    {
431
                        ReConverter = item.RECONVERTER,
432
                        ServiceID = item.SERVICE_ID,
433
                        ConvertState = ((StatusCodeType)item.STATUS),
434
                        CreateTime = item.CREATE_DATETIME,
435
                        TotalPage = item.TOTAL_PAGE,
436
                        CurrentPageNo = item.CURRENT_PAGE,
437

    
438
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID)
439
                    };
440

    
441
                    convertItems.Add(convertitem);
442
                }
443
            }
444
            return convertItems;
445
        }
446
        #endregion
447

    
448
        #region No 참조 
449

    
450
        /// <summary>
451
        /// 컨버터서비스를 이용하는 문서 정보 저장
452
        /// UniqueID
453
        /// using Markus.Service.Extensions;  new Guid().CreateUniqueGuid().ToString();
454
        /// </summary>
455
        /// <param name="ProjectNo">프로젝트</param>
456
        /// <param name="UniqueID">컨버터 서비스의 아이템 ID</param>
457
        /// <param name="originfilePath"></param>
458
        /// <param name="DocumentID"></param>
459
        /// <returns></returns>
460
        public bool SetConvertDoc(string ProjectNo, string UniqueID, string originfilePath, string DocumentID)
461
        {
462
            bool result = false;
463

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

    
469
            if (UniqueID.IsNullOrEmpty())
470
            {
471
                throw new Exception("UniqueID is Null");
472
            }
473

    
474
            if (originfilePath.IsNullOrEmpty())
475
            {
476
                throw new Exception("originfilePath is Null");
477
            }
478

    
479
            if (DocumentID.IsNullOrEmpty())
480
            {
481
                throw new Exception("DocumentID is Null");
482
            }
483

    
484
            if (DocumentID.IsNullOrEmpty())
485
            {
486
                long _lastDocId = 0;
487

    
488
                if (entities.CONVERTER_DOC.Count() > 0)
489
                {
490
                    try
491
                    {
492
                        string qry = @"SELECT * FROM CONVERTER_DOC order by CAST(DOCUMENT_ID as int) desc";
493
                        var _item = entities.CONVERTER_DOC.SqlQuery(qry).FirstOrDefault();
494

    
495
                        if (_item != null)
496
                        {
497
                            _lastDocId = Convert.ToInt64(_item.DOCUMENT_ID) + 1;
498
                        }
499
                    }
500
                    catch (Exception)
501
                    {
502

    
503
                        throw;
504
                    }
505
                }
506

    
507
                DocumentID = _lastDocId.ToString();
508
            }
509

    
510
            CONVERTER_DOC convert_doc = new CONVERTER_DOC
511
            {
512
                ID = UniqueID,
513
                PROJECT_NO = ProjectNo,
514
                DOCUMENT_URL = originfilePath,
515
                DOCUMENT_ID = DocumentID,
516
                CREATE_DATETIME = DateTime.Now,
517
                STATUS = 0,
518
                TOTAL_PAGE = 0,
519
                CURRENT_PAGE = 0,
520
                RECONVERTER = 0
521
            };
522

    
523
            
524
            entities.CONVERTER_DOC.Add(convert_doc);
525

    
526
            if (entities.SaveChanges() == 1)
527
            {
528
                result = true;
529
            }
530

    
531
            return result;
532
        }
533

    
534
        /// <summary>
535
        /// 컨버터서비스를 이용하는 문서 정보 저장
536
        /// UniqueID
537
        /// using Markus.Service.Extensions;  new Guid().CreateUniqueGuid().ToString();
538
        /// </summary>
539
        /// <param name="ProjectNo">프로젝트</param>
540
        /// <param name="UniqueID">컨버터 서비스의 아이템 ID</param>
541
        /// <param name="originfilePath"></param>
542
        /// <param name="DocumentID"></param>
543
        /// <returns></returns>
544
        public bool SetDocumentInfo(string ConvertID, int totalPage, List<DOCPAGE> pageinfo)
545
        {
546
            bool result = false;
547

    
548
            var convertDocItems = entities.CONVERTER_DOC.Where(f => f.ID == ConvertID);
549

    
550
            if (convertDocItems.Count() > 0)
551
            {
552
                var convertDoc = convertDocItems.First();
553

    
554
                string docId = new Guid().CreateUniqueGuid().ToString();
555

    
556
                var docinfo = entities.DOCINFO.FirstOrDefault(x => x.PROJECT_NO == convertDoc.PROJECT_NO && x.DOCUMENT_ID == convertDoc.DOCUMENT_ID);
557
                
558
                if (docinfo != null)
559
                {
560
                    // 기존 Docpage 삭제.
561
                    entities.DOCPAGE.RemoveRange(docinfo.DOCPAGE);
562

    
563
                    // 기존 코멘트 유지를 위한 Docinfo update                    
564
                    docinfo.PROJECT_NO = convertDoc.PROJECT_NO;
565
                    docinfo.ORIGINAL_FILE = convertDoc.DOCUMENT_URL;
566
                    docinfo.PAGE_COUNT = totalPage;                    
567
                    docinfo.DOCPAGE = pageinfo;                    
568
                    entities.SaveChanges();
569
                    result = true;
570
                }
571
                else
572
                {
573
                    DOCINFO instace = new DOCINFO
574
                    {
575
                        ID = docId,
576
                        PROJECT_NO = convertDoc.PROJECT_NO,
577
                        ORIGINAL_FILE = convertDoc.DOCUMENT_URL,
578
                        DOCUMENT_ID = convertDoc.DOCUMENT_ID,
579
                        PAGE_COUNT = totalPage,
580
                        DOCPAGE = pageinfo
581
                    };
582

    
583
                    entities.DOCINFO.Add(instace);
584
                    var save = entities.SaveChanges();
585

    
586
                    if (save == pageinfo.Count() + 1)
587
                    {
588
                        result = true;
589
                    }
590
                }
591

    
592
                
593
                
594
            }
595

    
596
            return result;
597
        }
598

    
599
        public Interface.ConvertItem GetConvertItem(string ProjectNo, string UniqueID)
600
        {
601
            Interface.ConvertItem result = null;
602

    
603
            //var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID);
604
            var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == ProjectNo && f.ID == UniqueID);
605

    
606
            if (items.Count() > 0)
607
            {
608
                var convertItem = items.First();
609

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

    
612
                result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath);
613
            }
614

    
615
            return result;
616
        }
617

    
618

    
619
        public Interface.ConvertItem GetConvertItembyDocumentID(string ProjectNo, string DocumentID)
620
        {
621
            Interface.ConvertItem result = null;
622

    
623
            //var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID);
624
            var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == ProjectNo && f.DOCUMENT_ID == DocumentID);
625

    
626
            if (items.Count() > 0)
627
            {
628
                var convertItem = items.First();
629
                string convertPath = Path.Combine(BaseStorage(convertItem.PROJECT_NO), convertItem.PROJECT_NO + "_Tile", (System.Convert.ToInt64(convertItem.DOCUMENT_ID) / 100).ToString(), convertItem.DOCUMENT_ID);
630

    
631
                if (convertItem.STATUS == (int)StatusCodeType.Completed)
632
                {
633
                    result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath,
634
                                                        (StatusCodeType)convertItem.STATUS, convertItem.CURRENT_PAGE, convertItem.TOTAL_PAGE, convertItem.EXCEPTION);
635
                }
636
                else
637
                {
638
                    result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath);
639
                }
640
            }
641

    
642
            return result;
643
        }
644

    
645
        public List<CONVERTER_DOC> GetConvertingItems(List<string> projectList)
646
        {
647
            var convertWaitingItems = entities.CONVERTER_DOC.OrderBy(x => x.CREATE_DATETIME).Where(
648
                                        x =>
649
                                        projectList.Contains(x.PROJECT_NO) &&
650
                                         (x.STATUS > (int)StatusCodeType.None && x.STATUS < (int)StatusCodeType.Completed) && x.RECONVERTER < 2);
651

    
652
            return convertWaitingItems.ToList();
653
        }
654

    
655
        /// <summary>
656
        /// 전체 컨버터를 가져온다. 비동기로 변경하여야 한다.
657
        /// </summary>
658
        /// <returns></returns>
659
        public List<Interface.ConvertItem> GetConvertItems(StatusCodeType statusCodeType)
660
        {
661
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
662

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

    
665
            if (items.Count() > 0)
666
            {
667
                foreach (var item in items)
668
                {
669
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
670
                    {
671
                        ReConverter = item.RECONVERTER,
672
                        ServiceID = item.SERVICE_ID,
673
                        ConvertState = ((StatusCodeType)item.STATUS),
674
                        CreateTime = item.CREATE_DATETIME,
675
                        TotalPage = item.TOTAL_PAGE,
676
                        CurrentPageNo = item.CURRENT_PAGE,
677

    
678
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID)
679
                    };
680

    
681

    
682
                    convertItems.Add(convertitem);
683
                }
684
            }
685
            return convertItems;
686
        }
687

    
688
        public List<Interface.ConvertItem> GetConvertProjectsStatus(Func<CONVERTER_DOC, bool> @where)
689
        {
690
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
691

    
692

    
693
            //var items = entities.CONVERTER_DOC.Where(x => x.STATUS == (int)statusCodeType).Take(takeCount).ToList(); //.Where(x => x.PROJECT_NO == gProjectNo);
694
            var items = entities.CONVERTER_DOC.Where(x => x.STATUS <= 4);
695

    
696
            if (items.Count() > 0)
697
            {
698
                foreach (var item in items)
699
                {
700
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
701
                    {
702
                        ReConverter = item.RECONVERTER,
703
                        ServiceID = item.SERVICE_ID,
704
                        //ConvertState = ((StatusCodeType)item.STATUS).ToString(),
705
                        //ConvertState = (item.STATUS).ToString(),
706
                        ConvertState = (StatusCodeType)item.STATUS,
707
                        CreateTime = item.CREATE_DATETIME,
708
                        TotalPage = item.TOTAL_PAGE,
709
                        CurrentPageNo = item.CURRENT_PAGE,
710
                        Exception = item.EXCEPTION,
711
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID)
712
                    };
713

    
714

    
715
                    convertItems.Add(convertitem);
716
                }
717
            }
718

    
719
            return convertItems;
720
        }
721

    
722

    
723
        public bool SetConvertState(string ServiceID, string UniqueID, int State, int CurrentPage, int TotalPage, string Error)
724
        {
725
            bool result = false;
726

    
727
            try
728
            {
729
                var items = entities.CONVERTER_DOC.SingleOrDefault(f => f.ID == UniqueID);
730
                //var items = entities.CONVERTER_DOC.SingleOrDefault(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID);
731

    
732
                if (items != null)
733
                {
734
                    items.SERVICE_ID = ServiceID;
735
                    items.STATUS = State;
736
                    items.CURRENT_PAGE = CurrentPage;
737
                    items.TOTAL_PAGE = TotalPage;
738

    
739
                    StatusCodeType statusCode = (StatusCodeType)State;
740

    
741
                    if (items.START_DATETIME == null)
742
                    {
743
                        items.START_DATETIME = DateTime.Now;
744
                    }
745

    
746
                    switch (statusCode)
747
                    {
748
                        case StatusCodeType.None:
749
                            break;
750
                        case StatusCodeType.Wait:
751
                            items.START_DATETIME = DateTime.Now;
752
                            break;
753
                        case StatusCodeType.PageLoading:
754
                            break;
755
                        case StatusCodeType.Saving:
756
                            break;
757
                        case StatusCodeType.Completed:
758
                            items.CURRENT_PAGE = items.TOTAL_PAGE;
759
                            items.END_DATETIME = DateTime.Now;
760
                            break;
761
                        case StatusCodeType.FileError:
762
                            Error = $" file Error :" + Error;
763
                            items.END_DATETIME = DateTime.Now;
764
                            break;
765
                        case StatusCodeType.PageError:
766
                            Error = $" Page No {CurrentPage} Error :" + Error;
767
                            break;
768
                        case StatusCodeType.NeedsPassword:
769
                            break;
770
                        case StatusCodeType.Error:
771
                            Error = $" Error :" + Error;
772
                            items.END_DATETIME = DateTime.Now;
773
                            break;
774
                        default:
775
                            break;
776
                    }
777

    
778
                    if (items.EXCEPTION == null)
779
                    {
780
                        items.EXCEPTION = "";
781
                    }
782

    
783
                    if (items.EXCEPTION.Length < 255)
784
                    {
785
                        items.EXCEPTION = items.EXCEPTION + Error;
786
                    }
787

    
788
                    entities.SaveChanges();
789
                    result = true;
790
                }
791
            }
792
            catch (Exception ex)
793
            {
794
                throw new Exception("SetConvertState", ex);
795
            }
796

    
797
            return result;
798
        }
799

    
800
        public SERVICE_PROPERTIES GetServiceProperties(string ServiceID)
801
        {
802
            SERVICE_PROPERTIES result = null;
803

    
804
            var items = entities.SERVICE_PROPERTIES.Where(x => x.ID == ServiceID);
805

    
806
            if (items.Count() > 0)
807
            {
808
                result = items.First();
809
            }
810

    
811
            return result;
812
        }
813

    
814

    
815
        /// <summary>
816
        /// 현재 서비스에서 컨버터중인 아이템.
817
        /// </summary>
818
        /// <returns></returns>
819
        public List<Interface.ConvertItem> GetServiceAliveItems(string ServiceID)
820
        {
821
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
822

    
823
            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);
824

    
825
            if (items.Count() > 0)
826
            {
827
                foreach (var item in items)
828
                {
829
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL);
830
                    convertItems.Add(convertitem);
831
                }
832
            }
833
            return convertItems;
834
        }
835

    
836
        #endregion
837

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