프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.DataBase / ConvertDatabase.cs @ 1d79913e

이력 | 보기 | 이력해설 | 다운로드 (52.1 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 System.Windows;
9
using System.Linq.Expressions;
10
using Markus.Service.Interface;
11
using Markus.Service.DataBase.Data;
12
using Markus.Service.DataBase.Extensions;
13

    
14

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

    
24
        Markus.EntityModel.MarkusModel entities;
25

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

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

    
44
        #endregion
45

    
46
        #region DataBaseItemsModel Function
47

    
48
        #region Get WaitConvertItems
49

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

    
69
            return convertWaitingItems;
70
        }
71

    
72
        #endregion
73

    
74
        #region Get FilterConvertItems
75

    
76
        /// <summary>
77
        /// 상단 그리드 선택된 Status에 따라 DB에서 값 가져온다.
78
        /// </summary>
79
        public IEnumerable<Interface.ConvertItem> GetConvertProjects(int status,string ProjectNumberFilter, string UniqueKeyFilter, string Document_NameFilter, string Service_IDFilter, string Docuemnt_NOFilter, int? ReconverterFilter
80
            , string RevisionFilter)
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
                        //
88
                        (
89
                         items.PROJECT_NO.Contains(ProjectNumberFilter)
90
                         || subpet.DOCUMENT_NAME.Contains(Document_NameFilter)
91
                         || items.SERVICE_ID.Contains(Service_IDFilter)
92
                         || subpet.ID.Contains(UniqueKeyFilter)
93
                         || subpet.DOCUMENT_NO.Contains(Docuemnt_NOFilter)
94
                         || items.RECONVERTER == ReconverterFilter
95
                         || subpet.REVISION.Contains(RevisionFilter)
96
                         )
97
                       //
98
                        orderby items.CREATE_DATETIME descending
99
                        select new
100
                        {
101
                            ID = items.ID,
102
                            DOCUMENT_URL = items.DOCUMENT_URL,
103
                            RECONVERTER = items.RECONVERTER,
104
                            SERVICE_ID = items.SERVICE_ID,
105
                            STATUS = items.STATUS,
106
                            CREATE_DATETIME = items.CREATE_DATETIME,
107
                            START_DATETIME = items.START_DATETIME,
108
                            END_DATETIME = items.END_DATETIME,
109
                            TOTAL_PAGE = items.TOTAL_PAGE,
110
                            CURRENT_PAGE = items.CURRENT_PAGE,
111
                            EXCEPTION = items.EXCEPTION,
112
                            PROJECT_NO = items.PROJECT_NO,
113
                            DOCUMENT_ID = items.DOCUMENT_ID,
114
                            REVISION = subpet.REVISION,
115
                            DOCUMENT_NO = subpet.DOCUMENT_NO,
116
                            DOCUMENT_NAME = subpet.DOCUMENT_NAME,
117
                            GROUP_NO = subpet.GROUP_NO,
118
                        };
119

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

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

    
138
                        Revision = item.REVISION,
139
                        DocumentNo = item.DOCUMENT_NO,
140
                        DocumentName = item.DOCUMENT_NAME,
141
                        GroupNo = item.GROUP_NO,
142
                        DocumentID = item.DOCUMENT_ID,
143

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

    
167
        }
168

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

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

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

    
220

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

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

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

    
256
        }
257

    
258

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

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

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

    
306
                        Revision = item.REVISION,
307
                        DocumentNo = item.DOCUMENT_NO,
308
                        DocumentName = item.DOCUMENT_NAME,
309
                        GroupNo = item.GROUP_NO,
310
                        DocumentID = item.DOCUMENT_ID,
311

    
312

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

    
320
        }
321

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

    
328
            return ConvertPath;
329
        }
330

    
331
        #endregion
332

    
333
        #region Update RealDataSelect 
334

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

    
340

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

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

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

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

    
374

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

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

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

    
399
                        StatusKeep.Add(convertitem);
400

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

    
407

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

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

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

    
441

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

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

    
460
                            Revision = item.REVISION,
461
                            DocumentNo = item.DOCUMENT_NO,
462
                            DocumentName = item.DOCUMENT_NAME,
463
                            GroupNo = item.GROUP_NO,
464

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

    
468
                        StatusKeep.Add(convertitem);
469

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

    
476
        #endregion
477

    
478
        #region Data Convert
479

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

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

    
489

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

    
492
            stopwatch.Start();
493

    
494

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

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

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

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

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

    
551
        }
552

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

    
557

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

    
560
            stopwatch.Start();
561

    
562

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

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

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

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

    
620
        }
621

    
622

    
623
        #endregion
624

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

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

    
639
            result = items.Count();
640

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

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

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

    
651

    
652
                var waiter = entities.SaveChangesAsync().GetAwaiter();
653
                result = waiter.GetResult();
654
            }
655

    
656
            return result;
657
        }
658

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

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

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

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

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

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

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

    
680
        //    return result;
681
        //}
682

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

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

    
689
            result = items.Count();
690

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

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

    
701
                var waiter = entities.SaveChangesAsync().GetAwaiter();
702
                result = waiter.GetResult();
703
            }
704

    
705
            return result;
706
        }
707
        #endregion
708

    
709
        #region Convert Path
710

    
711
        private string GetConvertPath(string ProjectNo, string DocumentID)
712
        {
713
            try
714
            {
715
#if XI_C_AND_A
716
                return Path.Combine(BaseStorage(ProjectNo), ProjectNo + "_Tile",DocumentID.Substring(0, 5).ToString(), DocumentID);
717
#else
718
                return Path.Combine(BaseStorage(ProjectNo), ProjectNo + "_Tile", (System.Convert.ToInt64(DocumentID) / 100).ToString(), DocumentID);
719

    
720
            }
721
            catch (Exception)
722
            {
723
                throw new Exception("GetConvertPath Error");
724
            }
725

    
726
        }
727

    
728
        private string BaseStorage(string ProjectNo)
729
        {
730
            string result = "";
731

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

    
734
            if (properties.Count() > 0)
735
            {
736
                result = properties.First().VALUE;
737
            }
738
            else
739
            {
740
                throw new Exception($"Project {ProjectNo} BaseStorage Not Setting.");
741
            }
742

    
743
            return result;
744
        }
745

    
746
        #endregion
747

    
748
        #region Remove
749

    
750
        /// <summary>
751
        /// Item 삭제
752
        /// </summary>
753
        /// <returns></returns>
754
        /// 
755

    
756
        public int RemoveFinalPDFItem(string convertID)
757
        {
758
            int result = 0;
759

    
760
            var items = entities.FINAL_PDF.Where(x => x.ID == convertID);
761

    
762
            if (items.Count() > 0)
763
            {
764
                FINAL_PDF item = items.First();
765
                entities.FINAL_PDF.Remove(item);
766

    
767

    
768
                var waiter = entities.SaveChangesAsync().GetAwaiter();
769
                result = waiter.GetResult();
770
            }
771

    
772
            return result;
773
        } 
774

    
775
        public int RemoveItem(string convertID)
776
        {
777
            int result = 0;
778

    
779
            var items = entities.CONVERTER_DOC.Where(x => x.ID == convertID);
780

    
781
            if (items.Count() > 0)
782
            {
783
                CONVERTER_DOC item = items.First();
784
                entities.CONVERTER_DOC.Remove(item);
785

    
786

    
787
                var waiter = entities.SaveChangesAsync().GetAwaiter();
788
                result = waiter.GetResult();
789
            }
790

    
791
            return result;
792
        }
793

    
794

    
795
        #endregion
796

    
797
        #region MarkusLink
798

    
799

    
800
        ////// userID는 관리자 계정인 doftech
801
        ////string markusLink = "kcom://" + MarkusAPI.CreateMarkusParam(projectNo, documentID, userID);
802
        //public static string CreateMarkusParam(string projectNo, string documentID, string userID)
803
        //{
804
        //    ViewInfo viewInfo = new ViewInfo();
805

    
806
        //    viewInfo.DocumentItemID = documentID;
807
        //    viewInfo.ProjectNO = projectNo;
808
        //    viewInfo.UserID = userID;
809

    
810
        //    return ParamEncoding(JsonConvert.SerializeObject(viewInfo));
811

    
812
        //}
813

    
814
        //public static string ParamEncoding(string EncodingText, System.Text.Encoding oEncoding = null)
815
        //{
816

    
817
        //    if (oEncoding == null)
818
        //        oEncoding = System.Text.Encoding.UTF8;
819

    
820
        //    return Convert.ToBase64String(oEncoding.GetBytes(EncodingText));
821

    
822
        //}
823

    
824

    
825
        #endregion
826

    
827
        #endregion
828

    
829
        #region DataBaseByStatusViewModel Function
830
        /// <summary>
831
        /// 전체 컨버터를 가져온다. 비동기로 변경하여야 한다.
832
        /// </summary>
833
        /// <returns></returns>
834
        public List<Interface.ConvertItem> GetConvertItems(StatusCodeType statusCodeType, Func<CONVERTER_DOC, bool> @where, int takeCount = 100)
835
        {
836
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
837

    
838

    
839
            var items = entities.CONVERTER_DOC.Where(x => x.STATUS == (int)statusCodeType).Where(@where).Take(takeCount).ToList();
840

    
841
            if (items.Count() > 0)
842
            {
843
                foreach (var item in items)
844
                {
845
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
846
                    {
847
                        ReConverter = item.RECONVERTER,
848
                        ServiceID = item.SERVICE_ID,
849
                        ConvertState = ((StatusCodeType)item.STATUS),
850
                        CreateTime = item.CREATE_DATETIME,
851
                        TotalPage = item.TOTAL_PAGE,
852
                        CurrentPageNo = item.CURRENT_PAGE,
853

    
854
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID)
855
                    };
856

    
857
                    convertItems.Add(convertitem);
858
                }
859
            }
860
            return convertItems;
861
        }
862
        #endregion
863

    
864
        #region No 참조 
865

    
866
        /// <summary>
867
        /// 컨버터서비스를 이용하는 문서 정보 저장
868
        /// UniqueID
869
        /// using Markus.Service.Extensions;  new Guid().CreateUniqueGuid().ToString();
870
        /// </summary>
871
        /// <param name="ProjectNo">프로젝트</param>
872
        /// <param name="UniqueID">컨버터 서비스의 아이템 ID</param>
873
        /// <param name="originfilePath"></param>
874
        /// <param name="DocumentID"></param>
875
        /// <returns></returns>
876
        public bool SetConvertDoc(string ProjectNo, string UniqueID, string originfilePath, string DocumentID)
877
        {
878
            bool result = false;
879

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

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

    
890
            if (originfilePath.IsNullOrEmpty())
891
            {
892
                throw new Exception("originfilePath is Null");
893
            }
894

    
895
            if (DocumentID.IsNullOrEmpty())
896
            {
897
                throw new Exception("DocumentID is Null");
898
            }
899

    
900
            if (DocumentID.IsNullOrEmpty())
901
            {
902
                long _lastDocId = 0;
903

    
904
                if (entities.CONVERTER_DOC.Count() > 0)
905
                {
906
                    try
907
                    {
908
                        string qry = @"SELECT * FROM CONVERTER_DOC order by CAST(DOCUMENT_ID as int) desc";
909
                        var _item = entities.CONVERTER_DOC.SqlQuery(qry).FirstOrDefault();
910

    
911
                        if (_item != null)
912
                        {
913
                            _lastDocId = Convert.ToInt64(_item.DOCUMENT_ID) + 1;
914
                        }
915
                    }
916
                    catch (Exception)
917
                    {
918

    
919
                        throw;
920
                    }
921
                }
922

    
923
                DocumentID = _lastDocId.ToString();
924
            }
925

    
926
            CONVERTER_DOC convert_doc = new CONVERTER_DOC
927
            {
928
                ID = UniqueID,
929
                PROJECT_NO = ProjectNo,
930
                DOCUMENT_URL = originfilePath,
931
                DOCUMENT_ID = DocumentID,
932
                CREATE_DATETIME = DateTime.Now,
933
                STATUS = 0,
934
                TOTAL_PAGE = 0,
935
                CURRENT_PAGE = 0,
936
                RECONVERTER = 0
937
            };
938

    
939
            
940
            entities.CONVERTER_DOC.Add(convert_doc);
941

    
942

    
943
            var waiter = entities.SaveChangesAsync().GetAwaiter();
944

    
945
            if (waiter.GetResult() == 1)
946
            {
947
                result = true;
948
            }
949

    
950
            return result;
951
        }
952

    
953
        /// <summary>
954
        /// 컨버터서비스를 이용하는 문서 정보 저장
955
        /// UniqueID
956
        /// using Markus.Service.Extensions;  new Guid().CreateUniqueGuid().ToString();
957
        /// </summary>
958
        /// <param name="ProjectNo">프로젝트</param>
959
        /// <param name="UniqueID">컨버터 서비스의 아이템 ID</param>
960
        /// <param name="originfilePath"></param>
961
        /// <param name="DocumentID"></param>
962
        /// <returns></returns>
963
        public bool SetDocumentInfo(string ConvertID, int totalPage, List<DOCPAGE> pageinfo)
964
        {
965
            bool result = false;
966

    
967
            var convertDocItems = entities.CONVERTER_DOC.Where(f => f.ID == ConvertID);
968

    
969
            if (convertDocItems.Count() > 0)
970
            {
971
                var convertDoc = convertDocItems.First();
972

    
973
                string docId = new Guid().CreateUniqueGuid().ToString();
974

    
975
                var docinfo = entities.DOCINFO.FirstOrDefault(x => x.PROJECT_NO == convertDoc.PROJECT_NO && x.DOCUMENT_ID == convertDoc.DOCUMENT_ID);
976
                
977
                if (docinfo != null)
978
                {
979
                    // 기존 Docpage 삭제.
980
                    entities.DOCPAGE.RemoveRange(docinfo.DOCPAGE);
981

    
982
                    // 기존 코멘트 유지를 위한 Docinfo update                    
983
                    docinfo.PROJECT_NO = convertDoc.PROJECT_NO;
984
                    docinfo.ORIGINAL_FILE = convertDoc.DOCUMENT_URL;
985
                    docinfo.PAGE_COUNT = totalPage;                    
986
                    docinfo.DOCPAGE = pageinfo;
987
                    var waiter = entities.SaveChangesAsync().GetAwaiter();
988
                   
989
                    if(waiter.GetResult() > 0)
990
                    {
991
                        result = true;
992
                    }
993
                }
994
                else
995
                {
996
                    DOCINFO instace = new DOCINFO
997
                    {
998
                        ID = docId,
999
                        PROJECT_NO = convertDoc.PROJECT_NO,
1000
                        ORIGINAL_FILE = convertDoc.DOCUMENT_URL,
1001
                        DOCUMENT_ID = convertDoc.DOCUMENT_ID,
1002
                        PAGE_COUNT = totalPage,
1003
                        DOCPAGE = pageinfo
1004
                    };
1005

    
1006
                    entities.DOCINFO.Add(instace);
1007
                    var waiter = entities.SaveChangesAsync().GetAwaiter();
1008

    
1009
                    var save = waiter.GetResult();
1010

    
1011
                    if (save == pageinfo.Count() + 1)
1012
                    {
1013
                        result = true;
1014
                    }
1015
                }
1016

    
1017
                
1018
                
1019
            }
1020
            else
1021
            {
1022
                throw new Exception($"SetDocumentInfo :{ConvertID} CONVERTER_DOC not found ");
1023
            }
1024

    
1025
            return result;
1026
        }
1027

    
1028
        public Interface.ConvertItem GetConvertItem(string ProjectNo, string UniqueID)
1029
        {
1030
            Interface.ConvertItem result = null;
1031

    
1032
            //var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID);
1033
            var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == ProjectNo && f.ID == UniqueID);
1034

    
1035
            if (items.Count() > 0)
1036
            {
1037
                var convertItem = items.First();
1038

    
1039
#if XI_C_AND_A
1040
                string convertPath = GetConvertPath(convertItem.PROJECT_NO, convertItem.DOCUMENT_ID);
1041
#else
1042

    
1043
                string convertPath = Path.Combine(BaseStorage(convertItem.PROJECT_NO), convertItem.PROJECT_NO + "_Tile", (System.Convert.ToInt64(convertItem.DOCUMENT_ID) / 100).ToString(), convertItem.DOCUMENT_ID);
1044
#endif
1045
                result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath);
1046
            }
1047

    
1048
            return result;
1049
        }
1050

    
1051

    
1052
        public Interface.ConvertItem GetConvertItembyDocumentID(string ProjectNo, string DocumentID)
1053
        {
1054
            Interface.ConvertItem result = null;
1055

    
1056
            //var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID);
1057
            var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == ProjectNo && f.DOCUMENT_ID == DocumentID);
1058

    
1059
            if (items.Count() > 0)
1060
            {
1061
                var convertItem = items.First();
1062

    
1063
#if XI_C_AND_A
1064
                string convertPath = GetConvertPath(convertItem.PROJECT_NO, convertItem.DOCUMENT_ID);
1065
#else
1066
                string convertPath = Path.Combine(BaseStorage(convertItem.PROJECT_NO), convertItem.PROJECT_NO + "_Tile", (System.Convert.ToInt64(convertItem.DOCUMENT_ID) / 100).ToString(), convertItem.DOCUMENT_ID);
1067
#endif
1068
                if (convertItem.STATUS == (int)StatusCodeType.Completed)
1069
                {
1070
                    result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath,
1071
                                                        (StatusCodeType)convertItem.STATUS, convertItem.CURRENT_PAGE, convertItem.TOTAL_PAGE, convertItem.EXCEPTION);
1072
                }
1073
                else
1074
                {
1075
                    result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath);
1076
                }
1077
            }
1078

    
1079
            return result;
1080
        }
1081

    
1082
        public List<CONVERTER_DOC> GetConvertingItems(List<string> projectList)
1083
        {
1084
            var convertWaitingItems = entities.CONVERTER_DOC.OrderBy(x => x.CREATE_DATETIME).Where(
1085
                                        x =>
1086
                                        projectList.Contains(x.PROJECT_NO) &&
1087
                                         ((x.STATUS > (int)StatusCodeType.None && x.STATUS < (int)StatusCodeType.Completed) && x.RECONVERTER < 2));
1088

    
1089
            return convertWaitingItems.ToList();
1090
        }
1091

    
1092
        /// <summary>
1093
        /// 전체 컨버터를 가져온다. 비동기로 변경하여야 한다.
1094
        /// </summary>
1095
        /// <returns></returns>
1096
        public List<Interface.ConvertItem> GetConvertItems(StatusCodeType statusCodeType)
1097
        {
1098
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
1099

    
1100
            var items = entities.CONVERTER_DOC.Where(x => x.STATUS == (int)statusCodeType).ToList(); //.Where(x => x.PROJECT_NO == gProjectNo);
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),
1111
                        CreateTime = item.CREATE_DATETIME,
1112
                        TotalPage = item.TOTAL_PAGE,
1113
                        CurrentPageNo = item.CURRENT_PAGE,
1114

    
1115
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID)
1116
                    };
1117

    
1118

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

    
1125
        public List<Interface.ConvertItem> GetConvertProjectsStatus(Func<CONVERTER_DOC, bool> @where)
1126
        {
1127
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
1128

    
1129

    
1130
            //var items = entities.CONVERTER_DOC.Where(x => x.STATUS == (int)statusCodeType).Take(takeCount).ToList(); //.Where(x => x.PROJECT_NO == gProjectNo);
1131
            var items = entities.CONVERTER_DOC.Where(x => x.STATUS <= 4);
1132

    
1133
            if (items.Count() > 0)
1134
            {
1135
                foreach (var item in items)
1136
                {
1137
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
1138
                    {
1139
                        ReConverter = item.RECONVERTER,
1140
                        ServiceID = item.SERVICE_ID,
1141
                        //ConvertState = ((StatusCodeType)item.STATUS).ToString(),
1142
                        //ConvertState = (item.STATUS).ToString(),
1143
                        ConvertState = (StatusCodeType)item.STATUS,
1144
                        CreateTime = item.CREATE_DATETIME,
1145
                        TotalPage = item.TOTAL_PAGE,
1146
                        CurrentPageNo = item.CURRENT_PAGE,
1147
                        Exception = item.EXCEPTION,
1148
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID)
1149
                    };
1150

    
1151

    
1152
                    convertItems.Add(convertitem);
1153
                }
1154
            }
1155

    
1156
            return convertItems;
1157
        }
1158

    
1159

    
1160
        public bool SetConvertState(string ServiceID, string UniqueID, int State, int CurrentPage, int TotalPage, string Error)
1161
        {
1162
            bool result = false;
1163

    
1164
            try
1165
            {
1166
                var items = entities.CONVERTER_DOC.SingleOrDefault(f => f.ID == UniqueID);
1167
                //var items = entities.CONVERTER_DOC.SingleOrDefault(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID);
1168

    
1169
                if (items != null)
1170
                {
1171
                    items.SERVICE_ID = ServiceID;
1172
                    items.STATUS = State;
1173
                    items.CURRENT_PAGE = CurrentPage;
1174
                    items.TOTAL_PAGE = TotalPage;
1175

    
1176
                    StatusCodeType statusCode = (StatusCodeType)State;
1177

    
1178
                    if (items.START_DATETIME == null)
1179
                    {
1180
                        items.START_DATETIME = DateTime.Now;
1181
                    }
1182

    
1183
                    switch (statusCode)
1184
                    {
1185
                        case StatusCodeType.None:
1186
                            break;
1187
                        case StatusCodeType.Wait:
1188
                            items.START_DATETIME = DateTime.Now;
1189
                            break;
1190
                        case StatusCodeType.PageLoading:
1191
                            break;
1192
                        case StatusCodeType.Saving:
1193
                            break;
1194
                        case StatusCodeType.Completed:
1195
                            items.CURRENT_PAGE = items.TOTAL_PAGE;
1196
                            items.END_DATETIME = DateTime.Now;
1197
                            break;
1198
                        case StatusCodeType.FileError:
1199
                            Error = $" file Error :" + Error;
1200
                            items.END_DATETIME = DateTime.Now;
1201
                            break;
1202
                        case StatusCodeType.PageError:
1203
                            Error = $" Page No {CurrentPage} Error :" + Error;
1204
                            break;
1205
                        case StatusCodeType.NeedsPassword:
1206
                            break;
1207
                        case StatusCodeType.Error:
1208
                            Error = $" Error :" + Error;
1209
                            items.END_DATETIME = DateTime.Now;
1210
                            break;
1211
                        default:
1212
                            break;
1213
                    }
1214

    
1215
                    if (items.EXCEPTION == null)
1216
                    {
1217
                        items.EXCEPTION = "";
1218
                    }
1219

    
1220
                    if (items.EXCEPTION.Length < 255)
1221
                    {
1222
                        if (items.EXCEPTION.Length > 0 && Error?.Length > 0)
1223
                        {
1224
                            items.EXCEPTION = items.EXCEPTION + ";" + Environment.NewLine;
1225
                        }
1226

    
1227
                        items.EXCEPTION = items.EXCEPTION + Error;
1228
                    }
1229

    
1230
                    var waiter = entities.SaveChangesAsync().GetAwaiter();
1231
                    var save = waiter.GetResult();
1232
                    result = true;
1233
                }
1234
            }
1235
            catch (Exception ex)
1236
            {
1237
                throw new Exception("SetConvertState", ex);
1238
            }
1239

    
1240
            return result;
1241
        }
1242

    
1243
        public SERVICE_PROPERTIES GetServiceProperties(string ServiceID)
1244
        {
1245
            SERVICE_PROPERTIES result = null;
1246

    
1247
            var items = entities.SERVICE_PROPERTIES.Where(x => x.ID == ServiceID);
1248

    
1249
            if (items.Count() > 0)
1250
            {
1251
                result = items.First();
1252
            }
1253

    
1254
            return result;
1255
        }
1256

    
1257

    
1258
        /// <summary>
1259
        /// 현재 서비스에서 컨버터중인 아이템.
1260
        /// </summary>
1261
        /// <returns></returns>
1262
        public List<Interface.ConvertItem> GetServiceAliveItems(string ServiceID)
1263
        {
1264
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
1265

    
1266
            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);
1267

    
1268
            if (items.Count() > 0)
1269
            {
1270
                foreach (var item in items)
1271
                {
1272
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL);
1273
                    convertItems.Add(convertitem);
1274
                }
1275
            }
1276
            return convertItems;
1277
        }
1278

    
1279
#endregion
1280

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