프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.DataBase / ConvertDatabase.cs @ 3bde451b

이력 | 보기 | 이력해설 | 다운로드 (50.7 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,string ProjectNumberFilter, string UniqueKeyFilter, string Document_NameFilter, string Service_IDFilter, string Docuemnt_NOFilter, int? ReconverterFilter
81
            , string RevisionFilter)
82
        {
83
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
84
            var query = from items in entities.CONVERTER_DOC
85
                        join documents in entities.DOCUMENT_ITEM on items.DOCUMENT_ID equals documents.DOCUMENT_ID into GroupItems
86
                        from subpet in GroupItems.DefaultIfEmpty()
87
                        where items.STATUS == status &&
88
                        //
89
                        (
90
                         items.PROJECT_NO.Contains(ProjectNumberFilter)
91
                         || subpet.DOCUMENT_NAME.Contains(Document_NameFilter)
92
                         || items.SERVICE_ID.Contains(Service_IDFilter)
93
                         || subpet.ID.Contains(UniqueKeyFilter)
94
                         || subpet.DOCUMENT_NO.Contains(Docuemnt_NOFilter)
95
                         || items.RECONVERTER == ReconverterFilter
96
                         || subpet.REVISION.Contains(RevisionFilter)
97
                         )
98
                       //
99
                        orderby items.CREATE_DATETIME descending
100
                        select new
101
                        {
102
                            ID = items.ID,
103
                            DOCUMENT_URL = items.DOCUMENT_URL,
104
                            RECONVERTER = items.RECONVERTER,
105
                            SERVICE_ID = items.SERVICE_ID,
106
                            STATUS = items.STATUS,
107
                            CREATE_DATETIME = items.CREATE_DATETIME,
108
                            START_DATETIME = items.START_DATETIME,
109
                            END_DATETIME = items.END_DATETIME,
110
                            TOTAL_PAGE = items.TOTAL_PAGE,
111
                            CURRENT_PAGE = items.CURRENT_PAGE,
112
                            EXCEPTION = items.EXCEPTION,
113
                            PROJECT_NO = items.PROJECT_NO,
114
                            DOCUMENT_ID = items.DOCUMENT_ID,
115
                            REVISION = subpet.REVISION,
116
                            DOCUMENT_NO = subpet.DOCUMENT_NO,
117
                            DOCUMENT_NAME = subpet.DOCUMENT_NAME,
118
                            GROUP_NO = subpet.GROUP_NO,
119
                        };
120

    
121
            if (query.Count() > 0)//세미
122
            {
123
                foreach (var item in query)
124
                {
125
                    Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
126
                    {
127

    
128
                        ReConverter = item.RECONVERTER,
129
                        ServiceID = item.SERVICE_ID,
130
                        ConvertState = (StatusCodeType)item.STATUS,
131
                        CreateTime = item.CREATE_DATETIME,
132
                       // StartTime = (DateTime)item.START_DATETIME,
133
                        //EndTime = (DateTime)item.END_DATETIME,
134
                        TotalPage = item.TOTAL_PAGE,
135
                        CurrentPageNo = item.CURRENT_PAGE,
136
                        Exception = item.EXCEPTION,
137
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID),
138

    
139
                        Revision = item.REVISION,
140
                        DocumnetNo = item.DOCUMENT_NO,
141
                        DocumnetName = item.DOCUMENT_NAME,
142
                        GroupNo = item.GROUP_NO,
143
                        DocumentID = item.DOCUMENT_ID,
144

    
145
                        MarkusLink = "kcom://" + Markus.Service.DataBase.Extensions.MarkusAPI.CreateMarkusParam(item.PROJECT_NO, item.DOCUMENT_ID, "doftech")
146
                    };
147
                    if(item.START_DATETIME == null)
148
                    {
149
                        convertitem.StartTime = null;
150
                    }
151
                    else
152
                    {
153
                        convertitem.StartTime = (DateTime)item.START_DATETIME;
154
                    }
155
                    if (item.END_DATETIME == null)
156
                    {
157
                        convertitem.EndTime = null;
158
                    }
159
                    else
160
                    {
161
                        convertitem.EndTime = (DateTime)item.END_DATETIME;
162
                    }
163
                    convertItems.Add(convertitem);
164
                }
165
            }
166
            return convertItems;
167

    
168
        }
169

    
170
        /// <summary>Final PDF
171
        /// 상단 그리드 선택된 Status에 따라 DB에서 값 가져온다.
172
        /// </summary>
173
        public IEnumerable<Interface.ConvertItem> GetFinalPDFProjects(int status, string ProjectNumberFilter, string DocumentIDFIlter, string MarkupInfo_IDFilter, string DOCINFO_IDFilter, string Document_NameFilter,
174
            string Docuemnt_NOFilter, string CreateUser_IDFilter)
175
        {
176
            var MarkupInfo_IDFilter_Int = 0;
177
            if (MarkupInfo_IDFilter != null)
178
            {
179
                MarkupInfo_IDFilter_Int = int.Parse(MarkupInfo_IDFilter);
180
            }
181

    
182
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
183
            var query = from items in entities.FINAL_PDF
184
                        join documents in entities.DOCUMENT_ITEM on items.DOCUMENT_ID equals documents.DOCUMENT_ID into GroupItems
185
                        from subpet in GroupItems.DefaultIfEmpty()
186
                        where items.STATUS == status &&
187
                        //
188
                        (
189
                         items.PROJECT_NO.Contains(ProjectNumberFilter)
190
                         || subpet.DOCUMENT_ID.Contains(DocumentIDFIlter)
191
                         || items.MARKUPINFO_ID == MarkupInfo_IDFilter_Int
192
                         || items.DOCINFO_ID.Contains(DOCINFO_IDFilter)
193
                         || subpet.DOCUMENT_NAME.Contains(Document_NameFilter)
194
                         || subpet.DOCUMENT_NO.Contains(Docuemnt_NOFilter)
195
                         || items.CREATE_USER_ID.Contains(CreateUser_IDFilter)
196
                         )
197
                        //
198
                        orderby items.CREATE_DATETIME descending
199
                        select new
200
                        {
201
                            ID = items.ID,
202
                            PROJECT_NO = items.PROJECT_NO,
203
                            DOCINFO_ID = items.DOCINFO_ID,
204
                            MARKUPINFO_ID = items.MARKUPINFO_ID,
205
                            CREATE_USER_ID = items.CREATE_USER_ID,
206
                            CREATE_DATETIME = items.CREATE_DATETIME,
207
                            STATUS = items.STATUS,
208
                            TOTAL_PAGE = items.TOTAL_PAGE,
209
                            CURRENT_PAGE = items.CURRENT_PAGE,
210
                            EXCEPTION = items.EXCEPTION,
211
                            END_DATETIME = items.END_DATETIME,
212
                            START_DATETIME = items.START_DATETIME,
213
                            DOCUMENT_ID = items.DOCUMENT_ID,
214
                            DOCUMENT_URL = subpet.ORIGINAL_FILE,
215

    
216
                            REVISION = subpet.REVISION,
217
                            GROUP_NO = subpet.GROUP_NO,
218
                            RESULT_FILE = subpet.RESULT_FILE,
219
                            RESULT = subpet.RESULT,
220

    
221

    
222
                            DOCUMENT_NO = subpet.DOCUMENT_NO,
223
                            DOCUMENT_NAME = subpet.DOCUMENT_NAME
224
                        };
225

    
226
            if (query.Count() > 0)//세미
227
            {
228
                foreach (var item in query)
229
                {
230
                    Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
231
                    {
232
                        ConvertID = item.ID,
233
                        DocInfo_ID = item.DOCINFO_ID,
234
                        MarkupInfo_ID = item.MARKUPINFO_ID.ToString(),
235
                        Create_User_ID = item.CREATE_USER_ID,
236
                        CreateTime = item.CREATE_DATETIME,
237
                        ConvertState = (StatusCodeType)item.STATUS,
238
                        TotalPage = item.TOTAL_PAGE,
239
                        CurrentPageNo = item.CURRENT_PAGE,
240
                        Exception = item.EXCEPTION,
241
                        EndTime = (DateTime)item.END_DATETIME,
242
                        StartTime = (DateTime)item.START_DATETIME,
243
                        DocumnetNo = item.DOCUMENT_NO,
244
                        DocumnetName = item.DOCUMENT_NAME,
245
                        GroupNo = item.GROUP_NO,
246
                        Revision = item.REVISION,
247

    
248
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID),
249
                        MarkusLink = "kcom://" + Markus.Service.DataBase.Extensions.MarkusAPI.CreateMarkusParam(item.PROJECT_NO, item.DOCUMENT_ID, "doftech")
250
                    };
251
                   
252
                    convertItems.Add(convertitem);
253
                }
254
            }
255
            return convertItems;
256

    
257
        }
258

    
259

    
260
        public IEnumerable<Interface.ConvertItem> GetConvertProjects(int status)
261
        {
262
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
263
            var query = from items in entities.CONVERTER_DOC
264
                        join documents in entities.DOCUMENT_ITEM on items.DOCUMENT_ID equals documents.DOCUMENT_ID into GroupItems
265
                        from subpet in GroupItems.DefaultIfEmpty()
266
                        where items.STATUS == status
267
                        orderby items.CREATE_DATETIME descending
268
                        select new
269
                        {
270
                            ID = items.ID,
271
                            DOCUMENT_URL = items.DOCUMENT_URL,
272
                            RECONVERTER = items.RECONVERTER,
273
                            SERVICE_ID = items.SERVICE_ID,
274
                            STATUS = items.STATUS,
275
                            CREATE_DATETIME = items.CREATE_DATETIME,
276
                            START_DATETIME = items.START_DATETIME,
277
                            END_DATETIME = items.END_DATETIME,
278
                            TOTAL_PAGE = items.TOTAL_PAGE,
279
                            CURRENT_PAGE = items.CURRENT_PAGE,
280
                            EXCEPTION = items.EXCEPTION,
281
                            PROJECT_NO = items.PROJECT_NO,
282
                            DOCUMENT_ID = items.DOCUMENT_ID,
283
                            REVISION = subpet.REVISION,
284
                            DOCUMENT_NO = subpet.DOCUMENT_NO,
285
                            DOCUMENT_NAME = subpet.DOCUMENT_NAME,
286
                            GROUP_NO = subpet.GROUP_NO
287
                        };
288

    
289
            if (query.Count() > 0)//세미
290
            {
291
                foreach (var item in query)
292
                {
293
                    Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
294
                    {
295

    
296
                        ReConverter = item.RECONVERTER,
297
                        ServiceID = item.SERVICE_ID,
298
                        ConvertState = (StatusCodeType)item.STATUS,
299
                        CreateTime = item.CREATE_DATETIME,
300
                        StartTime = (DateTime)item.START_DATETIME,
301
                        EndTime = (DateTime)item.END_DATETIME,
302
                        TotalPage = item.TOTAL_PAGE,
303
                        CurrentPageNo = item.CURRENT_PAGE,
304
                        Exception = item.EXCEPTION,
305
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID),
306

    
307
                        Revision = item.REVISION,
308
                        DocumnetNo = item.DOCUMENT_NO,
309
                        DocumnetName = item.DOCUMENT_NAME,
310
                        GroupNo = item.GROUP_NO,
311
                        DocumentID = item.DOCUMENT_ID,
312

    
313

    
314
                        MarkusLink = "kcom://" + Markus.Service.DataBase.Extensions.MarkusAPI.CreateMarkusParam(item.PROJECT_NO, item.DOCUMENT_ID, "doftech")
315
                    };
316
                    convertItems.Add(convertitem);
317
                }
318
            }
319
            return convertItems;
320

    
321
        }
322

    
323
        public string[] GetSearchConvertPathAndMarkus(string PROJECT_NO, string DOCUMENT_ID)
324
        {
325
            string[] ConvertPath = new string[2];
326
            ConvertPath[0] = GetConvertPath(PROJECT_NO, DOCUMENT_ID);
327
            ConvertPath[1] = "kcom://" + Markus.Service.DataBase.Extensions.MarkusAPI.CreateMarkusParam(PROJECT_NO, DOCUMENT_ID, "doftech");
328

    
329
            return ConvertPath;
330
        }
331

    
332
        #endregion
333

    
334
        #region Update RealDataSelect 
335

    
336
        /// <summary>
337
        /// 상단 그리드에서 선택된 RealDataSelect
338
        /// 용도: 중앙그리드 Items Update
339
        /// </summary>
340

    
341

    
342
        public IEnumerable<Interface.ConvertItem> GetConvertFinalPDFProjects(System.Collections.ObjectModel.ObservableCollection<Interface.ConvertItem> selectedConvert)
343
        {
344
            List<Interface.ConvertItem> StatusKeep = new List<Interface.ConvertItem>();
345

    
346
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
347

    
348
            foreach (var selectedConvertItem in selectedConvert)
349
            {
350
                var query = from items in entities.FINAL_PDF //세미
351
                            join documents in entities.DOCUMENT_ITEM on items.DOCUMENT_ID equals documents.DOCUMENT_ID into GroupItems
352
                            from subpet in GroupItems.DefaultIfEmpty()
353
                            where items.PROJECT_NO == selectedConvertItem.ProjectNumber && items.ID == selectedConvertItem.ConvertID
354
                            select new
355
                            {
356
                                ID = items.ID,
357
                                PROJECT_NO = items.PROJECT_NO,
358
                                DOCINFO_ID = items.DOCINFO_ID,
359
                                MARKUPINFO_ID = items.MARKUPINFO_ID,
360
                                CREATE_USER_ID = items.CREATE_USER_ID,
361
                                CREATE_DATETIME = items.CREATE_DATETIME,
362
                                STATUS = items.STATUS,
363
                                TOTAL_PAGE = items.TOTAL_PAGE,
364
                                CURRENT_PAGE = items.CURRENT_PAGE,
365
                                EXCEPTION = items.EXCEPTION,
366
                                END_DATETIME = items.END_DATETIME,
367
                                START_DATETIME = items.START_DATETIME,
368
                                DOCUMENT_ID = items.DOCUMENT_ID,
369

    
370
                                DOCUMENT_URL = subpet.ORIGINAL_FILE,
371
                                DOCUMENT_NO = subpet.DOCUMENT_NO,
372
                                DOCUMENT_NAME = subpet.DOCUMENT_NAME
373
                            };
374

    
375

    
376
                if (query.Count() > 0)//세미
377
                {
378
                    foreach (var item in query)
379
                    {
380
                        Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
381
                        {
382

    
383
                            DocInfo_ID = item.DOCINFO_ID,
384
                            MarkupInfo_ID = item.MARKUPINFO_ID.ToString(),
385
                            Create_User_ID = item.CREATE_USER_ID,
386
                            CreateTime = item.CREATE_DATETIME,
387
                            ConvertState = (StatusCodeType)item.STATUS,
388
                            TotalPage = item.TOTAL_PAGE,
389
                            CurrentPageNo = item.CURRENT_PAGE,
390
                            Exception = item.EXCEPTION,
391
                            EndTime = (DateTime)item.END_DATETIME,
392
                            StartTime = (DateTime)item.START_DATETIME,
393
                            DocumnetNo = item.DOCUMENT_NO,
394
                            DocumnetName = item.DOCUMENT_NAME,
395

    
396
                            ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID),
397
                            MarkusLink = "kcom://" + Markus.Service.DataBase.Extensions.MarkusAPI.CreateMarkusParam(item.PROJECT_NO, item.DOCUMENT_ID, "doftech")
398
                        };
399

    
400
                        StatusKeep.Add(convertitem);
401

    
402
                    }
403
                }
404
            }
405
            return StatusKeep;
406
        }
407

    
408

    
409
        public IEnumerable<Interface.ConvertItem> GetConvertProjects(System.Collections.ObjectModel.ObservableCollection<Interface.ConvertItem> selectedConvert)
410
        {
411
            List<Interface.ConvertItem> StatusKeep = new List<Interface.ConvertItem>();
412

    
413
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
414

    
415
            foreach (var selectedConvertItem in selectedConvert)
416
            {
417
                var query = from items in entities.CONVERTER_DOC //세미
418
                            join documents in entities.DOCUMENT_ITEM on items.DOCUMENT_ID equals documents.DOCUMENT_ID into GroupItems
419
                            from subpet in GroupItems.DefaultIfEmpty()
420
                            where items.PROJECT_NO == selectedConvertItem.ProjectNumber && items.ID == selectedConvertItem.ConvertID
421
                            select new
422
                            {
423
                                ID = items.ID,
424
                                DOCUMENT_URL = items.DOCUMENT_URL,
425
                                RECONVERTER = items.RECONVERTER,
426
                                SERVICE_ID = items.SERVICE_ID,
427
                                STATUS = items.STATUS,
428
                                CREATE_DATETIME = items.CREATE_DATETIME,
429
                                START_DATETIME  = items.START_DATETIME,
430
                                END_DATETIME = items.END_DATETIME,
431
                                TOTAL_PAGE = items.TOTAL_PAGE,
432
                                CURRENT_PAGE = items.CURRENT_PAGE,
433
                                EXCEPTION = items.EXCEPTION,
434
                                PROJECT_NO = items.PROJECT_NO,
435
                                DOCUMENT_ID = items.DOCUMENT_ID,
436
                                REVISION = subpet.REVISION,
437
                                DOCUMENT_NO = subpet.DOCUMENT_NO,
438
                                DOCUMENT_NAME = subpet.DOCUMENT_NAME,
439
                                GROUP_NO = subpet.GROUP_NO
440
                            };
441

    
442

    
443
                if (query.Count() > 0)//세미
444
                {
445
                    foreach (var item in query)
446
                    {
447
                        Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
448
                        {
449

    
450
                            ReConverter = item.RECONVERTER,
451
                            ServiceID = item.SERVICE_ID,
452
                            ConvertState = (StatusCodeType)item.STATUS,
453
                            CreateTime = item.CREATE_DATETIME,
454
                            StartTime = item.START_DATETIME,
455
                            EndTime = item.END_DATETIME,
456
                            TotalPage = item.TOTAL_PAGE,
457
                            CurrentPageNo = item.CURRENT_PAGE,
458
                            Exception = item.EXCEPTION,
459
                            ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID),
460

    
461
                            Revision = item.REVISION,
462
                            DocumnetNo = item.DOCUMENT_NO,
463
                            DocumnetName = item.DOCUMENT_NAME,
464
                            GroupNo = item.GROUP_NO,
465

    
466
                            MarkusLink = "kcom://" + MarkusAPI.CreateMarkusParam(item.PROJECT_NO, item.DOCUMENT_ID, "doftech")
467
                        };
468

    
469
                        StatusKeep.Add(convertitem);
470

    
471
                    }
472
                }
473
            }
474
            return StatusKeep;
475
        }
476

    
477
        #endregion
478

    
479
        #region Data Convert
480

    
481
        /// <summary>
482
        /// 상단 그리드에서 선택된 Convert 버튼 
483
        /// 용도: 중앙 그리드로 Convert된 row 값 저장 하기 위해서 입니다.
484
        /// </summary>
485

    
486
        public IEnumerable<Interface.ConvertItem> GetConvertFinalPDFProjects(Markus.Service.Interface.ConvertItem selectedConvert)
487
        {
488
            List<Interface.ConvertItem> StatusKeep = new List<Interface.ConvertItem>();
489

    
490

    
491
            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
492

    
493
            stopwatch.Start();
494

    
495

    
496
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();//디비 다 조인 후 조건 비교 후 그리드 출력
497
            var query = from items in entities.FINAL_PDF //세미
498
                        join documents in entities.DOCUMENT_ITEM on items.DOCUMENT_ID equals documents.DOCUMENT_ID into GroupItems
499
                        from subpet in GroupItems.DefaultIfEmpty()
500
                        where items.PROJECT_NO == selectedConvert.ProjectNumber && items.DOCUMENT_ID == selectedConvert.DocumentID
501
                        orderby items.CREATE_DATETIME descending
502
                        select new
503
                        {
504
                            ID = items.ID,
505
                            PROJECT_NO = items.PROJECT_NO,
506
                            DOCINFO_ID = items.DOCINFO_ID,
507
                            MARKUPINFO_ID = items.MARKUPINFO_ID,
508
                            CREATE_USER_ID = items.CREATE_USER_ID,
509
                            CREATE_DATETIME = items.CREATE_DATETIME,
510
                            STATUS = items.STATUS,
511
                            TOTAL_PAGE = items.TOTAL_PAGE,
512
                            CURRENT_PAGE = items.CURRENT_PAGE,
513
                            EXCEPTION = items.EXCEPTION,
514
                            END_DATETIME = items.END_DATETIME,
515
                            START_DATETIME = items.START_DATETIME,
516
                            DOCUMENT_ID = items.DOCUMENT_ID,
517

    
518
                            DOCUMENT_URL = subpet.ORIGINAL_FILE,
519
                            DOCUMENT_NO = subpet.DOCUMENT_NO,
520
                            DOCUMENT_NAME = subpet.DOCUMENT_NAME
521
                        };
522

    
523
            if (query.Count() > 0)//세미
524
            {
525
                foreach (var item in query)
526
                {
527
                    Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
528
                    {
529

    
530
                        DocInfo_ID = item.DOCINFO_ID,
531
                        MarkupInfo_ID = item.MARKUPINFO_ID.ToString(),
532
                        Create_User_ID = item.CREATE_USER_ID,
533
                        CreateTime = item.CREATE_DATETIME,
534
                        ConvertState = (StatusCodeType)item.STATUS,
535
                        TotalPage = item.TOTAL_PAGE,
536
                        CurrentPageNo = item.CURRENT_PAGE,
537
                        Exception = item.EXCEPTION,
538
                        EndTime = (DateTime)item.END_DATETIME,
539
                        StartTime = (DateTime)item.START_DATETIME,
540
                        DocumnetNo = item.DOCUMENT_NO,
541
                        DocumnetName = item.DOCUMENT_NAME,
542

    
543
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID),
544
                        MarkusLink = "kcom://" + Markus.Service.DataBase.Extensions.MarkusAPI.CreateMarkusParam(item.PROJECT_NO, item.DOCUMENT_ID, "doftech")
545
                    };
546
                    StatusKeep.Add(convertitem);
547
                }
548
            }
549
            System.Diagnostics.Debug.WriteLine(new TimeSpan(stopwatch.ElapsedTicks).ToString());
550
            return StatusKeep;
551

    
552
        }
553

    
554
        public IEnumerable<Interface.ConvertItem> GetConvertProjects(Markus.Service.Interface.ConvertItem selectedConvert)
555
        {
556
            List<Interface.ConvertItem> StatusKeep = new List<Interface.ConvertItem>();
557

    
558

    
559
            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
560

    
561
            stopwatch.Start();
562

    
563

    
564
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();//디비 다 조인 후 조건 비교 후 그리드 출력
565
            var query = from items in entities.CONVERTER_DOC //세미
566
                        join documents in entities.DOCUMENT_ITEM on items.DOCUMENT_ID equals documents.DOCUMENT_ID into GroupItems
567
                        from subpet in GroupItems.DefaultIfEmpty()
568
                        where items.PROJECT_NO == selectedConvert.ProjectNumber && items.DOCUMENT_ID == selectedConvert.DocumentID
569
                        orderby items.CREATE_DATETIME descending
570
                        select new
571
                        {
572
                            ID = items.ID,
573
                            DOCUMENT_URL = items.DOCUMENT_URL,
574
                            RECONVERTER = items.RECONVERTER,
575
                            SERVICE_ID = items.SERVICE_ID,
576
                            STATUS = items.STATUS,
577
                            CREATE_DATETIME = items.CREATE_DATETIME,
578
                            START_DATETIME = items.START_DATETIME,
579
                            END_DATETIME = items.END_DATETIME,
580
                            TOTAL_PAGE = items.TOTAL_PAGE,
581
                            CURRENT_PAGE = items.CURRENT_PAGE,
582
                            EXCEPTION = items.EXCEPTION,
583
                            PROJECT_NO = items.PROJECT_NO,
584
                            DOCUMENT_ID = items.DOCUMENT_ID,
585
                            REVISION = subpet.REVISION,
586
                            DOCUMENT_NO = subpet.DOCUMENT_NO,
587
                            DOCUMENT_NAME = subpet.DOCUMENT_NAME,
588
                            GROUP_NO = subpet.GROUP_NO
589
                        };
590

    
591
            if (query.Count() > 0)//세미
592
            {
593
                foreach (var item in query)
594
                {
595
                    Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
596
                    {
597

    
598
                        ReConverter = item.RECONVERTER,
599
                        ServiceID = item.SERVICE_ID,
600
                        ConvertState = (StatusCodeType)item.STATUS,
601
                        CreateTime = item.CREATE_DATETIME,
602
                        StartTime = item.START_DATETIME,
603
                        EndTime = item.END_DATETIME,
604
                        TotalPage = item.TOTAL_PAGE,
605
                        CurrentPageNo = item.CURRENT_PAGE,
606
                        Exception = item.EXCEPTION,
607
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID),
608
                        Revision = item.REVISION,
609
                        DocumnetNo = item.DOCUMENT_NO,
610
                        DocumnetName = item.DOCUMENT_NAME,
611
                        GroupNo = item.GROUP_NO,
612

    
613
                        MarkusLink = "kcom://" + Markus.Service.DataBase.Extensions.MarkusAPI.CreateMarkusParam(item.PROJECT_NO, item.DOCUMENT_ID, "doftech")
614
                    };
615
                    StatusKeep.Add(convertitem);
616
                }
617
            }
618
            System.Diagnostics.Debug.WriteLine(new TimeSpan(stopwatch.ElapsedTicks).ToString());
619
            return StatusKeep;
620

    
621
        }
622

    
623

    
624
        #endregion
625

    
626
        #region SetCleanUpItem
627
        /// <summary>
628
        /// 오류나 wait으로 남아 있는 데이터베이스의 Item을 StatusCodeType.None으로 복구
629
        /// </summary>
630
        /// <param name="convertID">StatusCodeType을 변경하고자 하는 ConvertItem의 ID</param>
631
        /// <param name="ReConvert">ReConvert가 2이면 다시 Convert를 시도 안하기 때문에 기존 값으로 유지 하고 계속 시도 할수 있도록 0을 주는 경우가 있다.</param>
632
        /// <returns></returns>
633
        /// 
634
        public int SetCleanUpFinalPDFItem(ConvertItem _ConvertItem)
635
        {
636
            int result = 0;
637

    
638
            var items = entities.FINAL_PDF.Where(x => x.ID == _ConvertItem.ConvertID);
639

    
640
            result = items.Count();
641

    
642
            if (items.Count() > 0)
643
            {
644
                var item = items.First();
645

    
646
                //item.RECONVERTER = item.RECONVERTER - _ConvertItem.ReConverter;
647

    
648
                item.CREATE_DATETIME = DateTime.Now;
649
                item.STATUS = (int)StatusCodeType.None;
650
                item.END_DATETIME = null;
651

    
652
                result = entities.SaveChanges();
653
            }
654

    
655
            return result;
656
        }
657

    
658
        //public int SetCleanUpItem(ConvertItem _ConvertItem)
659
        //{
660
        //    int result = 0;
661

    
662
        //    var items = entities.CONVERTER_DOC.Where(x => x.ID == _ConvertItem.ConvertID);
663

    
664
        //    result = items.Count();
665

    
666
        //    if (items.Count() > 0)
667
        //    {
668
        //        var item = items.First();
669

    
670
        //        item.RECONVERTER = item.RECONVERTER - _ConvertItem.ReConverter;
671

    
672
        //        item.CREATE_DATETIME = DateTime.Now;
673
        //        item.STATUS = (int)StatusCodeType.None;
674
        //        item.END_DATETIME = null;
675

    
676
        //        result = entities.SaveChanges();
677
        //    }
678

    
679
        //    return result;
680
        //}
681

    
682
        public int SetCleanUpItem(string convertID, int ReConvert)
683
        {
684
            int result = 0;
685

    
686
            var items = entities.CONVERTER_DOC.Where(x => x.ID == convertID);
687

    
688
            result = items.Count();
689

    
690
            if (items.Count() > 0)
691
            {
692
                var item = items.First();
693

    
694
                item.RECONVERTER = item.RECONVERTER + ReConvert;
695
                item.CREATE_DATETIME = DateTime.Now;
696
                //item.START_DATETIME = null;
697
                item.END_DATETIME = null;
698
                item.STATUS = (int)StatusCodeType.None;
699

    
700
                result = entities.SaveChanges();
701
            }
702

    
703
            return result;
704
        }
705
        #endregion
706

    
707
        #region Convert Path
708

    
709
        private string GetConvertPath(string ProjectNo, string DocumentID)
710
        {
711
            try
712
            {
713
                return Path.Combine(BaseStorage(ProjectNo), ProjectNo + "_Tile", (System.Convert.ToInt64(DocumentID) / 100).ToString(), DocumentID);
714
            }
715
            catch (Exception)
716
            {
717
                throw new Exception("GetConvertPath Error");
718
            }
719

    
720
        }
721

    
722
        private string BaseStorage(string ProjectNo)
723
        {
724
            string result = "";
725

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

    
728
            if (properties.Count() > 0)
729
            {
730
                result = properties.First().VALUE;
731
            }
732
            else
733
            {
734
                throw new Exception($"Project {ProjectNo} BaseStorage Not Setting.");
735
            }
736

    
737
            return result;
738
        }
739

    
740
        #endregion
741

    
742
        #region Remove
743

    
744
        /// <summary>
745
        /// Item 삭제
746
        /// </summary>
747
        /// <returns></returns>
748
        /// 
749

    
750
        public int RemoveFinalPDFItem(string convertID)
751
        {
752
            int result = 0;
753

    
754
            var items = entities.FINAL_PDF.Where(x => x.ID == convertID);
755

    
756
            if (items.Count() > 0)
757
            {
758
                FINAL_PDF item = items.First();
759
                entities.FINAL_PDF.Remove(item);
760

    
761
                result = entities.SaveChanges();
762
            }
763

    
764
            return result;
765
        } 
766

    
767
        public int RemoveItem(string convertID)
768
        {
769
            int result = 0;
770

    
771
            var items = entities.CONVERTER_DOC.Where(x => x.ID == convertID);
772

    
773
            if (items.Count() > 0)
774
            {
775
                CONVERTER_DOC item = items.First();
776
                entities.CONVERTER_DOC.Remove(item);
777

    
778
                result = entities.SaveChanges();
779
            }
780

    
781
            return result;
782
        }
783

    
784

    
785
        #endregion
786

    
787
        #region MarkusLink
788

    
789

    
790
        ////// userID는 관리자 계정인 doftech
791
        ////string markusLink = "kcom://" + MarkusAPI.CreateMarkusParam(projectNo, documentID, userID);
792
        //public static string CreateMarkusParam(string projectNo, string documentID, string userID)
793
        //{
794
        //    ViewInfo viewInfo = new ViewInfo();
795

    
796
        //    viewInfo.DocumentItemID = documentID;
797
        //    viewInfo.ProjectNO = projectNo;
798
        //    viewInfo.UserID = userID;
799

    
800
        //    return ParamEncoding(JsonConvert.SerializeObject(viewInfo));
801

    
802
        //}
803

    
804
        //public static string ParamEncoding(string EncodingText, System.Text.Encoding oEncoding = null)
805
        //{
806

    
807
        //    if (oEncoding == null)
808
        //        oEncoding = System.Text.Encoding.UTF8;
809

    
810
        //    return Convert.ToBase64String(oEncoding.GetBytes(EncodingText));
811

    
812
        //}
813

    
814

    
815
        #endregion
816

    
817
        #endregion
818

    
819
        #region DataBaseByStatusViewModel Function
820
        /// <summary>
821
        /// 전체 컨버터를 가져온다. 비동기로 변경하여야 한다.
822
        /// </summary>
823
        /// <returns></returns>
824
        public List<Interface.ConvertItem> GetConvertItems(StatusCodeType statusCodeType, Func<CONVERTER_DOC, bool> @where, int takeCount = 100)
825
        {
826
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
827

    
828

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

    
831
            if (items.Count() > 0)
832
            {
833
                foreach (var item in items)
834
                {
835
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
836
                    {
837
                        ReConverter = item.RECONVERTER,
838
                        ServiceID = item.SERVICE_ID,
839
                        ConvertState = ((StatusCodeType)item.STATUS),
840
                        CreateTime = item.CREATE_DATETIME,
841
                        TotalPage = item.TOTAL_PAGE,
842
                        CurrentPageNo = item.CURRENT_PAGE,
843

    
844
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID)
845
                    };
846

    
847
                    convertItems.Add(convertitem);
848
                }
849
            }
850
            return convertItems;
851
        }
852
        #endregion
853

    
854
        #region No 참조 
855

    
856
        /// <summary>
857
        /// 컨버터서비스를 이용하는 문서 정보 저장
858
        /// UniqueID
859
        /// using Markus.Service.Extensions;  new Guid().CreateUniqueGuid().ToString();
860
        /// </summary>
861
        /// <param name="ProjectNo">프로젝트</param>
862
        /// <param name="UniqueID">컨버터 서비스의 아이템 ID</param>
863
        /// <param name="originfilePath"></param>
864
        /// <param name="DocumentID"></param>
865
        /// <returns></returns>
866
        public bool SetConvertDoc(string ProjectNo, string UniqueID, string originfilePath, string DocumentID)
867
        {
868
            bool result = false;
869

    
870
            if (ProjectNo.IsNullOrEmpty())
871
            {
872
                throw new Exception("ProjectNo is Null");
873
            }
874

    
875
            if (UniqueID.IsNullOrEmpty())
876
            {
877
                throw new Exception("UniqueID is Null");
878
            }
879

    
880
            if (originfilePath.IsNullOrEmpty())
881
            {
882
                throw new Exception("originfilePath is Null");
883
            }
884

    
885
            if (DocumentID.IsNullOrEmpty())
886
            {
887
                throw new Exception("DocumentID is Null");
888
            }
889

    
890
            if (DocumentID.IsNullOrEmpty())
891
            {
892
                long _lastDocId = 0;
893

    
894
                if (entities.CONVERTER_DOC.Count() > 0)
895
                {
896
                    try
897
                    {
898
                        string qry = @"SELECT * FROM CONVERTER_DOC order by CAST(DOCUMENT_ID as int) desc";
899
                        var _item = entities.CONVERTER_DOC.SqlQuery(qry).FirstOrDefault();
900

    
901
                        if (_item != null)
902
                        {
903
                            _lastDocId = Convert.ToInt64(_item.DOCUMENT_ID) + 1;
904
                        }
905
                    }
906
                    catch (Exception)
907
                    {
908

    
909
                        throw;
910
                    }
911
                }
912

    
913
                DocumentID = _lastDocId.ToString();
914
            }
915

    
916
            CONVERTER_DOC convert_doc = new CONVERTER_DOC
917
            {
918
                ID = UniqueID,
919
                PROJECT_NO = ProjectNo,
920
                DOCUMENT_URL = originfilePath,
921
                DOCUMENT_ID = DocumentID,
922
                CREATE_DATETIME = DateTime.Now,
923
                STATUS = 0,
924
                TOTAL_PAGE = 0,
925
                CURRENT_PAGE = 0,
926
                RECONVERTER = 0
927
            };
928

    
929
            
930
            entities.CONVERTER_DOC.Add(convert_doc);
931

    
932
            if (entities.SaveChanges() == 1)
933
            {
934
                result = true;
935
            }
936

    
937
            return result;
938
        }
939

    
940
        /// <summary>
941
        /// 컨버터서비스를 이용하는 문서 정보 저장
942
        /// UniqueID
943
        /// using Markus.Service.Extensions;  new Guid().CreateUniqueGuid().ToString();
944
        /// </summary>
945
        /// <param name="ProjectNo">프로젝트</param>
946
        /// <param name="UniqueID">컨버터 서비스의 아이템 ID</param>
947
        /// <param name="originfilePath"></param>
948
        /// <param name="DocumentID"></param>
949
        /// <returns></returns>
950
        public bool SetDocumentInfo(string ConvertID, int totalPage, List<DOCPAGE> pageinfo)
951
        {
952
            bool result = false;
953

    
954
            var convertDocItems = entities.CONVERTER_DOC.Where(f => f.ID == ConvertID);
955

    
956
            if (convertDocItems.Count() > 0)
957
            {
958
                var convertDoc = convertDocItems.First();
959

    
960
                string docId = new Guid().CreateUniqueGuid().ToString();
961

    
962
                var docinfo = entities.DOCINFO.FirstOrDefault(x => x.PROJECT_NO == convertDoc.PROJECT_NO && x.DOCUMENT_ID == convertDoc.DOCUMENT_ID);
963
                
964
                if (docinfo != null)
965
                {
966
                    // 기존 Docpage 삭제.
967
                    entities.DOCPAGE.RemoveRange(docinfo.DOCPAGE);
968

    
969
                    // 기존 코멘트 유지를 위한 Docinfo update                    
970
                    docinfo.PROJECT_NO = convertDoc.PROJECT_NO;
971
                    docinfo.ORIGINAL_FILE = convertDoc.DOCUMENT_URL;
972
                    docinfo.PAGE_COUNT = totalPage;                    
973
                    docinfo.DOCPAGE = pageinfo;                    
974
                    entities.SaveChanges();
975
                    result = true;
976
                }
977
                else
978
                {
979
                    DOCINFO instace = new DOCINFO
980
                    {
981
                        ID = docId,
982
                        PROJECT_NO = convertDoc.PROJECT_NO,
983
                        ORIGINAL_FILE = convertDoc.DOCUMENT_URL,
984
                        DOCUMENT_ID = convertDoc.DOCUMENT_ID,
985
                        PAGE_COUNT = totalPage,
986
                        DOCPAGE = pageinfo
987
                    };
988

    
989
                    entities.DOCINFO.Add(instace);
990
                    var save = entities.SaveChanges();
991

    
992
                    if (save == pageinfo.Count() + 1)
993
                    {
994
                        result = true;
995
                    }
996
                }
997

    
998
                
999
                
1000
            }
1001

    
1002
            return result;
1003
        }
1004

    
1005
        public Interface.ConvertItem GetConvertItem(string ProjectNo, string UniqueID)
1006
        {
1007
            Interface.ConvertItem result = null;
1008

    
1009
            //var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID);
1010
            var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == ProjectNo && f.ID == UniqueID);
1011

    
1012
            if (items.Count() > 0)
1013
            {
1014
                var convertItem = items.First();
1015

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

    
1018
                result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath);
1019
            }
1020

    
1021
            return result;
1022
        }
1023

    
1024

    
1025
        public Interface.ConvertItem GetConvertItembyDocumentID(string ProjectNo, string DocumentID)
1026
        {
1027
            Interface.ConvertItem result = null;
1028

    
1029
            //var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID);
1030
            var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == ProjectNo && f.DOCUMENT_ID == DocumentID);
1031

    
1032
            if (items.Count() > 0)
1033
            {
1034
                var convertItem = items.First();
1035
                string convertPath = Path.Combine(BaseStorage(convertItem.PROJECT_NO), convertItem.PROJECT_NO + "_Tile", (System.Convert.ToInt64(convertItem.DOCUMENT_ID) / 100).ToString(), convertItem.DOCUMENT_ID);
1036

    
1037
                if (convertItem.STATUS == (int)StatusCodeType.Completed)
1038
                {
1039
                    result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath,
1040
                                                        (StatusCodeType)convertItem.STATUS, convertItem.CURRENT_PAGE, convertItem.TOTAL_PAGE, convertItem.EXCEPTION);
1041
                }
1042
                else
1043
                {
1044
                    result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath);
1045
                }
1046
            }
1047

    
1048
            return result;
1049
        }
1050

    
1051
        public List<CONVERTER_DOC> GetConvertingItems(List<string> projectList)
1052
        {
1053
            var convertWaitingItems = entities.CONVERTER_DOC.OrderBy(x => x.CREATE_DATETIME).Where(
1054
                                        x =>
1055
                                        projectList.Contains(x.PROJECT_NO) &&
1056
                                         (x.STATUS > (int)StatusCodeType.None && x.STATUS < (int)StatusCodeType.Completed) && x.RECONVERTER < 2);
1057

    
1058
            return convertWaitingItems.ToList();
1059
        }
1060

    
1061
        /// <summary>
1062
        /// 전체 컨버터를 가져온다. 비동기로 변경하여야 한다.
1063
        /// </summary>
1064
        /// <returns></returns>
1065
        public List<Interface.ConvertItem> GetConvertItems(StatusCodeType statusCodeType)
1066
        {
1067
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
1068

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

    
1071
            if (items.Count() > 0)
1072
            {
1073
                foreach (var item in items)
1074
                {
1075
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
1076
                    {
1077
                        ReConverter = item.RECONVERTER,
1078
                        ServiceID = item.SERVICE_ID,
1079
                        ConvertState = ((StatusCodeType)item.STATUS),
1080
                        CreateTime = item.CREATE_DATETIME,
1081
                        TotalPage = item.TOTAL_PAGE,
1082
                        CurrentPageNo = item.CURRENT_PAGE,
1083

    
1084
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID)
1085
                    };
1086

    
1087

    
1088
                    convertItems.Add(convertitem);
1089
                }
1090
            }
1091
            return convertItems;
1092
        }
1093

    
1094
        public List<Interface.ConvertItem> GetConvertProjectsStatus(Func<CONVERTER_DOC, bool> @where)
1095
        {
1096
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
1097

    
1098

    
1099
            //var items = entities.CONVERTER_DOC.Where(x => x.STATUS == (int)statusCodeType).Take(takeCount).ToList(); //.Where(x => x.PROJECT_NO == gProjectNo);
1100
            var items = entities.CONVERTER_DOC.Where(x => x.STATUS <= 4);
1101

    
1102
            if (items.Count() > 0)
1103
            {
1104
                foreach (var item in items)
1105
                {
1106
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
1107
                    {
1108
                        ReConverter = item.RECONVERTER,
1109
                        ServiceID = item.SERVICE_ID,
1110
                        //ConvertState = ((StatusCodeType)item.STATUS).ToString(),
1111
                        //ConvertState = (item.STATUS).ToString(),
1112
                        ConvertState = (StatusCodeType)item.STATUS,
1113
                        CreateTime = item.CREATE_DATETIME,
1114
                        TotalPage = item.TOTAL_PAGE,
1115
                        CurrentPageNo = item.CURRENT_PAGE,
1116
                        Exception = item.EXCEPTION,
1117
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID)
1118
                    };
1119

    
1120

    
1121
                    convertItems.Add(convertitem);
1122
                }
1123
            }
1124

    
1125
            return convertItems;
1126
        }
1127

    
1128

    
1129
        public bool SetConvertState(string ServiceID, string UniqueID, int State, int CurrentPage, int TotalPage, string Error)
1130
        {
1131
            bool result = false;
1132

    
1133
            try
1134
            {
1135
                var items = entities.CONVERTER_DOC.SingleOrDefault(f => f.ID == UniqueID);
1136
                //var items = entities.CONVERTER_DOC.SingleOrDefault(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID);
1137

    
1138
                if (items != null)
1139
                {
1140
                    items.SERVICE_ID = ServiceID;
1141
                    items.STATUS = State;
1142
                    items.CURRENT_PAGE = CurrentPage;
1143
                    items.TOTAL_PAGE = TotalPage;
1144

    
1145
                    StatusCodeType statusCode = (StatusCodeType)State;
1146

    
1147
                    if (items.START_DATETIME == null)
1148
                    {
1149
                        items.START_DATETIME = DateTime.Now;
1150
                    }
1151

    
1152
                    switch (statusCode)
1153
                    {
1154
                        case StatusCodeType.None:
1155
                            break;
1156
                        case StatusCodeType.Wait:
1157
                            items.START_DATETIME = DateTime.Now;
1158
                            break;
1159
                        case StatusCodeType.PageLoading:
1160
                            break;
1161
                        case StatusCodeType.Saving:
1162
                            break;
1163
                        case StatusCodeType.Completed:
1164
                            items.CURRENT_PAGE = items.TOTAL_PAGE;
1165
                            items.END_DATETIME = DateTime.Now;
1166
                            break;
1167
                        case StatusCodeType.FileError:
1168
                            Error = $" file Error :" + Error;
1169
                            items.END_DATETIME = DateTime.Now;
1170
                            break;
1171
                        case StatusCodeType.PageError:
1172
                            Error = $" Page No {CurrentPage} Error :" + Error;
1173
                            break;
1174
                        case StatusCodeType.NeedsPassword:
1175
                            break;
1176
                        case StatusCodeType.Error:
1177
                            Error = $" Error :" + Error;
1178
                            items.END_DATETIME = DateTime.Now;
1179
                            break;
1180
                        default:
1181
                            break;
1182
                    }
1183

    
1184
                    if (items.EXCEPTION == null)
1185
                    {
1186
                        items.EXCEPTION = "";
1187
                    }
1188

    
1189
                    if (items.EXCEPTION.Length < 255)
1190
                    {
1191
                        items.EXCEPTION = items.EXCEPTION + Error;
1192
                    }
1193

    
1194
                    entities.SaveChanges();
1195
                    result = true;
1196
                }
1197
            }
1198
            catch (Exception ex)
1199
            {
1200
                throw new Exception("SetConvertState", ex);
1201
            }
1202

    
1203
            return result;
1204
        }
1205

    
1206
        public SERVICE_PROPERTIES GetServiceProperties(string ServiceID)
1207
        {
1208
            SERVICE_PROPERTIES result = null;
1209

    
1210
            var items = entities.SERVICE_PROPERTIES.Where(x => x.ID == ServiceID);
1211

    
1212
            if (items.Count() > 0)
1213
            {
1214
                result = items.First();
1215
            }
1216

    
1217
            return result;
1218
        }
1219

    
1220

    
1221
        /// <summary>
1222
        /// 현재 서비스에서 컨버터중인 아이템.
1223
        /// </summary>
1224
        /// <returns></returns>
1225
        public List<Interface.ConvertItem> GetServiceAliveItems(string ServiceID)
1226
        {
1227
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
1228

    
1229
            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);
1230

    
1231
            if (items.Count() > 0)
1232
            {
1233
                foreach (var item in items)
1234
                {
1235
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL);
1236
                    convertItems.Add(convertitem);
1237
                }
1238
            }
1239
            return convertItems;
1240
        }
1241

    
1242
        #endregion
1243

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