프로젝트

일반

사용자정보

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

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

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

1 ff4b1e6e taeseongkim
using Markus.EntityModel;
2
using Markus.Message;
3 53c9637d taeseongkim
using Markus.Service.Extensions;
4
using System;
5
using System.Collections.Generic;
6
using System.IO;
7
using System.Linq;
8 2decfbdf alzkakdixm
using static Markus.Service.DataBase.ConvertDatabase;
9
using System.Windows;
10
using System.Linq.Expressions;
11
using Markus.Service.Interface;
12 05fd750b alzkakdixm
using Markus.Service.DataBase.Data;
13
using Markus.Service.DataBase.Extensions;
14
15 53c9637d taeseongkim
16
namespace Markus.Service.DataBase
17
{
18
    public class ConvertDatabase : IDisposable
19
    {
20 e6281033 alzkakdixm
        #region Constructor
21
        /// <summary>
22
        ///해당 프로젝트의 데이터베이스 연결
23
        /// </summary>
24
25 ff4b1e6e taeseongkim
        Markus.EntityModel.MarkusModel entities;
26 53c9637d taeseongkim
27
        public ConvertDatabase(string ConnectionString)
28
        {
29
            try
30
            {
31 ff4b1e6e taeseongkim
                entities = new Markus.EntityModel.MarkusModel(ConnectionString);
32 53c9637d taeseongkim
            }
33
            catch (Exception ex)
34
            {
35
                System.Diagnostics.Debug.WriteLine(ex.ToString());
36 06f13e11 taeseongkim
                throw ex;
37 53c9637d taeseongkim
            }
38
        }
39
40
        public void Dispose()
41
        {
42
            entities.Dispose();
43
        }
44
45 e6281033 alzkakdixm
        #endregion
46
47
        #region DataBaseItemsModel Function
48
49
        #region Get WaitConvertItems
50
51 53c9637d taeseongkim
        /// <summary>
52 e6281033 alzkakdixm
        /// service에서 대기중이거나 오류인 아이템을 가져가서 컨버터 프로세스를 호출한다.
53
        /// 컨버터 상태가 에러이거나 2보다 작은 경우 
54
        /// UniqueKey는 각 데이터베이스의 문서 정보에서 유일한 키이며 컨버터저장에서 같은 폴더로의 저장을 방지 한다.
55
        /// 
56 53c9637d taeseongkim
        /// </summary>
57 e6281033 alzkakdixm
        /// <param name="aliveItems"></param>
58
        /// <param name="TakeCount"></param>
59 53c9637d taeseongkim
        /// <returns></returns>
60 e6281033 alzkakdixm
        public IEnumerable<CONVERTER_DOC> GetWaitConvertItems(List<string> projectList, int TakeCount)
61 53c9637d taeseongkim
        {
62 e6281033 alzkakdixm
            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 53c9637d taeseongkim
70 e6281033 alzkakdixm
            return convertWaitingItems;
71
        }
72 53c9637d taeseongkim
73 e6281033 alzkakdixm
        #endregion
74 53c9637d taeseongkim
75 e6281033 alzkakdixm
        #region Get FilterConvertItems
76 53c9637d taeseongkim
77 e6281033 alzkakdixm
        /// <summary>
78
        /// 상단 그리드 선택된 Status에 따라 DB에서 값 가져온다.
79
        /// </summary>
80 3bde451b semi
        public IEnumerable<Interface.ConvertItem> GetConvertProjects(int status,string ProjectNumberFilter, string UniqueKeyFilter, string Document_NameFilter, string Service_IDFilter, string Docuemnt_NOFilter, int? ReconverterFilter
81 b63dcfbb semi
            , 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 3bde451b semi
                         || subpet.DOCUMENT_NAME.Contains(Document_NameFilter)
92 b63dcfbb semi
                         || 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 8c128693 semi
                       // StartTime = (DateTime)item.START_DATETIME,
133
                        //EndTime = (DateTime)item.END_DATETIME,
134 b63dcfbb semi
                        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 8c128693 semi
                    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 b63dcfbb semi
                    convertItems.Add(convertitem);
164
                }
165
            }
166
            return convertItems;
167
168
        }
169
170 3bde451b semi
        /// <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 e6281033 alzkakdixm
        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 b63dcfbb semi
                        orderby items.CREATE_DATETIME descending
268 5a954acc semi
                        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 3bde451b semi
                            GROUP_NO = subpet.GROUP_NO
287 5a954acc semi
                        };
288 53c9637d taeseongkim
289 e6281033 alzkakdixm
            if (query.Count() > 0)//세미
290 53c9637d taeseongkim
            {
291 e6281033 alzkakdixm
                foreach (var item in query)
292 53c9637d taeseongkim
                {
293 e6281033 alzkakdixm
                    Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
294 53c9637d taeseongkim
                    {
295
296 e6281033 alzkakdixm
                        ReConverter = item.RECONVERTER,
297
                        ServiceID = item.SERVICE_ID,
298
                        ConvertState = (StatusCodeType)item.STATUS,
299
                        CreateTime = item.CREATE_DATETIME,
300 344ac7ed alzkakdixm
                        StartTime = (DateTime)item.START_DATETIME,
301
                        EndTime = (DateTime)item.END_DATETIME,
302 e6281033 alzkakdixm
                        TotalPage = item.TOTAL_PAGE,
303
                        CurrentPageNo = item.CURRENT_PAGE,
304
                        Exception = item.EXCEPTION,
305 e78f0871 alzkakdixm
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID),
306 53c9637d taeseongkim
307 e6281033 alzkakdixm
                        Revision = item.REVISION,
308
                        DocumnetNo = item.DOCUMENT_NO,
309
                        DocumnetName = item.DOCUMENT_NAME,
310
                        GroupNo = item.GROUP_NO,
311 05fd750b alzkakdixm
                        DocumentID = item.DOCUMENT_ID,
312
313 3bde451b semi
314 e78f0871 alzkakdixm
                        MarkusLink = "kcom://" + Markus.Service.DataBase.Extensions.MarkusAPI.CreateMarkusParam(item.PROJECT_NO, item.DOCUMENT_ID, "doftech")
315 e6281033 alzkakdixm
                    };
316
                    convertItems.Add(convertitem);
317 53c9637d taeseongkim
                }
318
            }
319 e6281033 alzkakdixm
            return convertItems;
320 53c9637d taeseongkim
321 e6281033 alzkakdixm
        }
322 53c9637d taeseongkim
323 218e5002 semi
        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 e6281033 alzkakdixm
        #endregion
333 53c9637d taeseongkim
334 e6281033 alzkakdixm
        #region Update RealDataSelect 
335 53c9637d taeseongkim
336
        /// <summary>
337 e6281033 alzkakdixm
        /// 상단 그리드에서 선택된 RealDataSelect
338
        /// 용도: 중앙그리드 Items Update
339 53c9637d taeseongkim
        /// </summary>
340 3bde451b semi
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 e6281033 alzkakdixm
        public IEnumerable<Interface.ConvertItem> GetConvertProjects(System.Collections.ObjectModel.ObservableCollection<Interface.ConvertItem> selectedConvert)
410 53c9637d taeseongkim
        {
411 e6281033 alzkakdixm
            List<Interface.ConvertItem> StatusKeep = new List<Interface.ConvertItem>();
412 53c9637d taeseongkim
413 e6281033 alzkakdixm
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
414 53c9637d taeseongkim
415 e6281033 alzkakdixm
            foreach (var selectedConvertItem in selectedConvert)
416 53c9637d taeseongkim
            {
417 e6281033 alzkakdixm
                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 344ac7ed alzkakdixm
                                START_DATETIME  = items.START_DATETIME,
430
                                END_DATETIME = items.END_DATETIME,
431 e6281033 alzkakdixm
                                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 53c9637d taeseongkim
442 41fa3d98 djkim
443 e6281033 alzkakdixm
                if (query.Count() > 0)//세미
444 53c9637d taeseongkim
                {
445 e6281033 alzkakdixm
                    foreach (var item in query)
446 41fa3d98 djkim
                    {
447 e6281033 alzkakdixm
                        Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
448
                        {
449 53c9637d taeseongkim
450 e6281033 alzkakdixm
                            ReConverter = item.RECONVERTER,
451
                            ServiceID = item.SERVICE_ID,
452
                            ConvertState = (StatusCodeType)item.STATUS,
453
                            CreateTime = item.CREATE_DATETIME,
454 344ac7ed alzkakdixm
                            StartTime = item.START_DATETIME,
455
                            EndTime = item.END_DATETIME,
456 e6281033 alzkakdixm
                            TotalPage = item.TOTAL_PAGE,
457
                            CurrentPageNo = item.CURRENT_PAGE,
458
                            Exception = item.EXCEPTION,
459
                            ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID),
460 53c9637d taeseongkim
461 e6281033 alzkakdixm
                            Revision = item.REVISION,
462
                            DocumnetNo = item.DOCUMENT_NO,
463
                            DocumnetName = item.DOCUMENT_NAME,
464 05fd750b alzkakdixm
                            GroupNo = item.GROUP_NO,
465
466 e78f0871 alzkakdixm
                            MarkusLink = "kcom://" + MarkusAPI.CreateMarkusParam(item.PROJECT_NO, item.DOCUMENT_ID, "doftech")
467 e6281033 alzkakdixm
                        };
468 53c9637d taeseongkim
469 e6281033 alzkakdixm
                        StatusKeep.Add(convertitem);
470 53c9637d taeseongkim
471 e6281033 alzkakdixm
                    }
472
                }
473
            }
474
            return StatusKeep;
475 0157b158 taeseongkim
        }
476 53c9637d taeseongkim
477 e6281033 alzkakdixm
        #endregion
478 53c9637d taeseongkim
479 e6281033 alzkakdixm
        #region Data Convert
480 53c9637d taeseongkim
481 e6281033 alzkakdixm
        /// <summary>
482
        /// 상단 그리드에서 선택된 Convert 버튼 
483
        /// 용도: 중앙 그리드로 Convert된 row 값 저장 하기 위해서 입니다.
484
        /// </summary>
485 3bde451b semi
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 e6281033 alzkakdixm
        public IEnumerable<Interface.ConvertItem> GetConvertProjects(Markus.Service.Interface.ConvertItem selectedConvert)
555 53c9637d taeseongkim
        {
556 e6281033 alzkakdixm
            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 344ac7ed alzkakdixm
                            START_DATETIME = items.START_DATETIME,
579
                            END_DATETIME = items.END_DATETIME,
580 e6281033 alzkakdixm
                            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 53c9637d taeseongkim
            {
593 e6281033 alzkakdixm
                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 344ac7ed alzkakdixm
                        StartTime = item.START_DATETIME,
603
                        EndTime = item.END_DATETIME,
604 e6281033 alzkakdixm
                        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 05fd750b alzkakdixm
                        GroupNo = item.GROUP_NO,
612
613 e78f0871 alzkakdixm
                        MarkusLink = "kcom://" + Markus.Service.DataBase.Extensions.MarkusAPI.CreateMarkusParam(item.PROJECT_NO, item.DOCUMENT_ID, "doftech")
614 e6281033 alzkakdixm
                    };
615
                    StatusKeep.Add(convertitem);
616
                }
617 53c9637d taeseongkim
            }
618 e6281033 alzkakdixm
            System.Diagnostics.Debug.WriteLine(new TimeSpan(stopwatch.ElapsedTicks).ToString());
619
            return StatusKeep;
620 53c9637d taeseongkim
621
        }
622
623 3bde451b semi
624 e6281033 alzkakdixm
        #endregion
625 53c9637d taeseongkim
626 e6281033 alzkakdixm
        #region SetCleanUpItem
627 53c9637d taeseongkim
        /// <summary>
628
        /// 오류나 wait으로 남아 있는 데이터베이스의 Item을 StatusCodeType.None으로 복구
629
        /// </summary>
630 2bbea412 taeseongkim
        /// <param name="convertID">StatusCodeType을 변경하고자 하는 ConvertItem의 ID</param>
631
        /// <param name="ReConvert">ReConvert가 2이면 다시 Convert를 시도 안하기 때문에 기존 값으로 유지 하고 계속 시도 할수 있도록 0을 주는 경우가 있다.</param>
632 53c9637d taeseongkim
        /// <returns></returns>
633 2decfbdf alzkakdixm
        /// 
634 3bde451b semi
        public int SetCleanUpFinalPDFItem(ConvertItem _ConvertItem)
635 53c9637d taeseongkim
        {
636
            int result = 0;
637
638 3bde451b semi
            var items = entities.FINAL_PDF.Where(x => x.ID == _ConvertItem.ConvertID);
639 53c9637d taeseongkim
640
            result = items.Count();
641
642
            if (items.Count() > 0)
643
            {
644 0157b158 taeseongkim
                var item = items.First();
645
646 3bde451b semi
                //item.RECONVERTER = item.RECONVERTER - _ConvertItem.ReConverter;
647 508debb1 taeseongkim
648 e6281033 alzkakdixm
                item.CREATE_DATETIME = DateTime.Now;
649
                item.STATUS = (int)StatusCodeType.None;
650 508debb1 taeseongkim
                item.END_DATETIME = null;
651 53c9637d taeseongkim
652 0157b158 taeseongkim
                result = entities.SaveChanges();
653 53c9637d taeseongkim
            }
654
655
            return result;
656
        }
657 2decfbdf alzkakdixm
658 3bde451b semi
        //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 508debb1 taeseongkim
        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 e6281033 alzkakdixm
        #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 2decfbdf alzkakdixm
720 e6281033 alzkakdixm
        }
721 2decfbdf alzkakdixm
722 e6281033 alzkakdixm
        private string BaseStorage(string ProjectNo)
723
        {
724
            string result = "";
725 2decfbdf alzkakdixm
726 e6281033 alzkakdixm
            var properties = entities.PROPERTIES.Where(f => f.PROPERTY == ProjectNo && f.TYPE == PROPERTIES_DEFINE.TILE_SOURCE_STORAGE);
727 2decfbdf alzkakdixm
728 e6281033 alzkakdixm
            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 2decfbdf alzkakdixm
737 e6281033 alzkakdixm
            return result;
738
        }
739 2decfbdf alzkakdixm
740 e6281033 alzkakdixm
        #endregion
741 53c9637d taeseongkim
742 e6281033 alzkakdixm
        #region Remove
743 5d863c06 taeseongkim
744
        /// <summary>
745
        /// Item 삭제
746
        /// </summary>
747
        /// <returns></returns>
748 3bde451b semi
        /// 
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 5d863c06 taeseongkim
        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 e6281033 alzkakdixm
785
        #endregion
786
787 05fd750b alzkakdixm
        #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 e6281033 alzkakdixm
        #endregion
818
819
        #region DataBaseByStatusViewModel Function
820 53c9637d taeseongkim
        /// <summary>
821
        /// 전체 컨버터를 가져온다. 비동기로 변경하여야 한다.
822
        /// </summary>
823
        /// <returns></returns>
824 e6281033 alzkakdixm
        public List<Interface.ConvertItem> GetConvertItems(StatusCodeType statusCodeType, Func<CONVERTER_DOC, bool> @where, int takeCount = 100)
825 53c9637d taeseongkim
        {
826
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
827
828 e6281033 alzkakdixm
829
            var items = entities.CONVERTER_DOC.Where(x => x.STATUS == (int)statusCodeType).Take(takeCount).ToList();
830 53c9637d taeseongkim
831
            if (items.Count() > 0)
832
            {
833
                foreach (var item in items)
834
                {
835 06f13e11 taeseongkim
                    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 2decfbdf alzkakdixm
                        ConvertState = ((StatusCodeType)item.STATUS),
840 06f13e11 taeseongkim
                        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 53c9637d taeseongkim
                    convertItems.Add(convertitem);
848
                }
849
            }
850
            return convertItems;
851
        }
852 e6281033 alzkakdixm
        #endregion
853
854
        #region No 참조 
855 53c9637d taeseongkim
856 0157b158 taeseongkim
        /// <summary>
857 e6281033 alzkakdixm
        /// 컨버터서비스를 이용하는 문서 정보 저장
858
        /// UniqueID
859
        /// using Markus.Service.Extensions;  new Guid().CreateUniqueGuid().ToString();
860 b92f142f taeseongkim
        /// </summary>
861 e6281033 alzkakdixm
        /// <param name="ProjectNo">프로젝트</param>
862
        /// <param name="UniqueID">컨버터 서비스의 아이템 ID</param>
863
        /// <param name="originfilePath"></param>
864
        /// <param name="DocumentID"></param>
865 b92f142f taeseongkim
        /// <returns></returns>
866 e6281033 alzkakdixm
        public bool SetConvertDoc(string ProjectNo, string UniqueID, string originfilePath, string DocumentID)
867 b92f142f taeseongkim
        {
868 e6281033 alzkakdixm
            bool result = false;
869 b92f142f taeseongkim
870 e6281033 alzkakdixm
            if (ProjectNo.IsNullOrEmpty())
871
            {
872
                throw new Exception("ProjectNo is Null");
873
            }
874 60723dc9 taeseongkim
875 e6281033 alzkakdixm
            if (UniqueID.IsNullOrEmpty())
876
            {
877
                throw new Exception("UniqueID is Null");
878
            }
879 b92f142f taeseongkim
880 e6281033 alzkakdixm
            if (originfilePath.IsNullOrEmpty())
881 b92f142f taeseongkim
            {
882 e6281033 alzkakdixm
                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 b92f142f taeseongkim
                {
896 e6281033 alzkakdixm
                    try
897 b92f142f taeseongkim
                    {
898 e6281033 alzkakdixm
                        string qry = @"SELECT * FROM CONVERTER_DOC order by CAST(DOCUMENT_ID as int) desc";
899
                        var _item = entities.CONVERTER_DOC.SqlQuery(qry).FirstOrDefault();
900 b92f142f taeseongkim
901 e6281033 alzkakdixm
                        if (_item != null)
902
                        {
903
                            _lastDocId = Convert.ToInt64(_item.DOCUMENT_ID) + 1;
904
                        }
905
                    }
906
                    catch (Exception)
907
                    {
908 b92f142f taeseongkim
909 e6281033 alzkakdixm
                        throw;
910
                    }
911 b92f142f taeseongkim
                }
912 e6281033 alzkakdixm
913
                DocumentID = _lastDocId.ToString();
914 b92f142f taeseongkim
            }
915
916 e6281033 alzkakdixm
            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 a6e5055d alzkakdixm
932 e6281033 alzkakdixm
            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 2decfbdf alzkakdixm
        {
952 e6281033 alzkakdixm
            bool result = false;
953 2decfbdf alzkakdixm
954 e6281033 alzkakdixm
            var convertDocItems = entities.CONVERTER_DOC.Where(f => f.ID == ConvertID);
955
956
            if (convertDocItems.Count() > 0)
957 a6e5055d alzkakdixm
            {
958 e6281033 alzkakdixm
                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 a6e5055d alzkakdixm
                {
979 e6281033 alzkakdixm
                    DOCINFO instace = new DOCINFO
980 a6e5055d alzkakdixm
                    {
981 e6281033 alzkakdixm
                        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 a6e5055d alzkakdixm
                    };
988
989 e6281033 alzkakdixm
                    entities.DOCINFO.Add(instace);
990
                    var save = entities.SaveChanges();
991
992
                    if (save == pageinfo.Count() + 1)
993
                    {
994
                        result = true;
995
                    }
996 a6e5055d alzkakdixm
                }
997 2decfbdf alzkakdixm
998 e6281033 alzkakdixm
                
999
                
1000
            }
1001 a6e5055d alzkakdixm
1002 e6281033 alzkakdixm
            return result;
1003 2decfbdf alzkakdixm
        }
1004 e6281033 alzkakdixm
1005
        public Interface.ConvertItem GetConvertItem(string ProjectNo, string UniqueID)
1006 a6e5055d alzkakdixm
        {
1007 e6281033 alzkakdixm
            Interface.ConvertItem result = null;
1008 a6e5055d alzkakdixm
1009 e6281033 alzkakdixm
            //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 2decfbdf alzkakdixm
            {
1014 e6281033 alzkakdixm
                var convertItem = items.First();
1015 2decfbdf alzkakdixm
1016 e6281033 alzkakdixm
                string convertPath = Path.Combine(BaseStorage(convertItem.PROJECT_NO), convertItem.PROJECT_NO + "_Tile", (System.Convert.ToInt64(convertItem.DOCUMENT_ID) / 100).ToString(), convertItem.DOCUMENT_ID);
1017 2decfbdf alzkakdixm
1018 e6281033 alzkakdixm
                result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath);
1019
            }
1020 a6e5055d alzkakdixm
1021 e6281033 alzkakdixm
            return result;
1022
        }
1023 2decfbdf alzkakdixm
1024 a6e5055d alzkakdixm
1025 e6281033 alzkakdixm
        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 2decfbdf alzkakdixm
                }
1046
            }
1047
1048 e6281033 alzkakdixm
            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 2decfbdf alzkakdixm
1058 e6281033 alzkakdixm
            return convertWaitingItems.ToList();
1059 2decfbdf alzkakdixm
        }
1060 e6281033 alzkakdixm
1061
        /// <summary>
1062
        /// 전체 컨버터를 가져온다. 비동기로 변경하여야 한다.
1063
        /// </summary>
1064
        /// <returns></returns>
1065
        public List<Interface.ConvertItem> GetConvertItems(StatusCodeType statusCodeType)
1066 2decfbdf alzkakdixm
        {
1067 e6281033 alzkakdixm
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
1068 2decfbdf alzkakdixm
1069 e6281033 alzkakdixm
            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 a6e5055d alzkakdixm
            {
1073 e6281033 alzkakdixm
                foreach (var item in items)
1074 a6e5055d alzkakdixm
                {
1075 e6281033 alzkakdixm
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
1076 a6e5055d alzkakdixm
                    {
1077
                        ReConverter = item.RECONVERTER,
1078
                        ServiceID = item.SERVICE_ID,
1079 e6281033 alzkakdixm
                        ConvertState = ((StatusCodeType)item.STATUS),
1080 a6e5055d alzkakdixm
                        CreateTime = item.CREATE_DATETIME,
1081
                        TotalPage = item.TOTAL_PAGE,
1082
                        CurrentPageNo = item.CURRENT_PAGE,
1083
1084 e6281033 alzkakdixm
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID)
1085 2decfbdf alzkakdixm
                    };
1086 e6281033 alzkakdixm
1087
1088
                    convertItems.Add(convertitem);
1089 a6e5055d alzkakdixm
                }
1090
            }
1091 e6281033 alzkakdixm
            return convertItems;
1092 a6e5055d alzkakdixm
        }
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 e6281033 alzkakdixm
            var items = entities.CONVERTER_DOC.Where(x => x.STATUS <= 4);
1101 a6e5055d alzkakdixm
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 2decfbdf alzkakdixm
                        //ConvertState = (item.STATUS).ToString(),
1112
                        ConvertState = (StatusCodeType)item.STATUS,
1113 a6e5055d alzkakdixm
                        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 b92f142f taeseongkim
1129 e6281033 alzkakdixm
        public bool SetConvertState(string ServiceID, string UniqueID, int State, int CurrentPage, int TotalPage, string Error)
1130 53c9637d taeseongkim
        {
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 0157b158 taeseongkim
                    items.SERVICE_ID = ServiceID;
1141 53c9637d taeseongkim
                    items.STATUS = State;
1142
                    items.CURRENT_PAGE = CurrentPage;
1143
                    items.TOTAL_PAGE = TotalPage;
1144
1145
                    StatusCodeType statusCode = (StatusCodeType)State;
1146
1147 65fbe3cb taeseongkim
                    if (items.START_DATETIME == null)
1148 a8f1a865 taeseongkim
                    {
1149
                        items.START_DATETIME = DateTime.Now;
1150
                    }
1151
1152 53c9637d taeseongkim
                    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 a0341bef taeseongkim
                            items.CURRENT_PAGE = items.TOTAL_PAGE;
1165 e6281033 alzkakdixm
                            items.END_DATETIME = DateTime.Now;
1166 53c9637d taeseongkim
                            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 e6281033 alzkakdixm
                    if (items.EXCEPTION == null)
1185 53c9637d taeseongkim
                    {
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 e6281033 alzkakdixm
                throw new Exception("SetConvertState", ex);
1201 53c9637d taeseongkim
            }
1202
1203
            return result;
1204
        }
1205
1206 e6281033 alzkakdixm
        public SERVICE_PROPERTIES GetServiceProperties(string ServiceID)
1207 53c9637d taeseongkim
        {
1208 e6281033 alzkakdixm
            SERVICE_PROPERTIES result = null;
1209 53c9637d taeseongkim
1210 e6281033 alzkakdixm
            var items = entities.SERVICE_PROPERTIES.Where(x => x.ID == ServiceID);
1211 53c9637d taeseongkim
1212 e6281033 alzkakdixm
            if (items.Count() > 0)
1213 53c9637d taeseongkim
            {
1214 e6281033 alzkakdixm
                result = items.First();
1215 53c9637d taeseongkim
            }
1216
1217
            return result;
1218
        }
1219
1220 e6281033 alzkakdixm
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 53c9637d taeseongkim
    }
1245
}
클립보드 이미지 추가 (최대 크기: 500 MB)