프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.DataBase / ConvertDatabase.cs @ 43e1d368

이력 | 보기 | 이력해설 | 다운로드 (52 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 System.Windows;
9
using System.Linq.Expressions;
10
using Markus.Service.Interface;
11 05fd750b alzkakdixm
using Markus.Service.DataBase.Data;
12
using Markus.Service.DataBase.Extensions;
13
14 53c9637d taeseongkim
15
namespace Markus.Service.DataBase
16
{
17
    public class ConvertDatabase : IDisposable
18
    {
19 e6281033 alzkakdixm
        #region Constructor
20
        /// <summary>
21
        ///해당 프로젝트의 데이터베이스 연결
22
        /// </summary>
23
24 ff4b1e6e taeseongkim
        Markus.EntityModel.MarkusModel entities;
25 53c9637d taeseongkim
26
        public ConvertDatabase(string ConnectionString)
27
        {
28
            try
29
            {
30 ff4b1e6e taeseongkim
                entities = new Markus.EntityModel.MarkusModel(ConnectionString);
31 53c9637d taeseongkim
            }
32
            catch (Exception ex)
33
            {
34
                System.Diagnostics.Debug.WriteLine(ex.ToString());
35 06f13e11 taeseongkim
                throw ex;
36 53c9637d taeseongkim
            }
37
        }
38
39
        public void Dispose()
40
        {
41
            entities.Dispose();
42
        }
43
44 e6281033 alzkakdixm
        #endregion
45
46
        #region DataBaseItemsModel Function
47
48
        #region Get WaitConvertItems
49
50 53c9637d taeseongkim
        /// <summary>
51 e6281033 alzkakdixm
        /// service에서 대기중이거나 오류인 아이템을 가져가서 컨버터 프로세스를 호출한다.
52
        /// 컨버터 상태가 에러이거나 2보다 작은 경우 
53
        /// UniqueKey는 각 데이터베이스의 문서 정보에서 유일한 키이며 컨버터저장에서 같은 폴더로의 저장을 방지 한다.
54
        /// 
55 53c9637d taeseongkim
        /// </summary>
56 e6281033 alzkakdixm
        /// <param name="aliveItems"></param>
57
        /// <param name="TakeCount"></param>
58 53c9637d taeseongkim
        /// <returns></returns>
59 e6281033 alzkakdixm
        public IEnumerable<CONVERTER_DOC> GetWaitConvertItems(List<string> projectList, int TakeCount)
60 53c9637d taeseongkim
        {
61 e6281033 alzkakdixm
            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 &&
65 d91efe5c taeseongkim
                                        (x.STATUS == (int)StatusCodeType.None || x.STATUS > (int)StatusCodeType.Completed))
66 e6281033 alzkakdixm
                                    .GroupBy(x => x.DOCUMENT_ID).Select(x => x.FirstOrDefault())
67
                                    .Take(TakeCount);
68 53c9637d taeseongkim
69 e6281033 alzkakdixm
            return convertWaitingItems;
70
        }
71 53c9637d taeseongkim
72 e6281033 alzkakdixm
        #endregion
73 53c9637d taeseongkim
74 e6281033 alzkakdixm
        #region Get FilterConvertItems
75 53c9637d taeseongkim
76 e6281033 alzkakdixm
        /// <summary>
77
        /// 상단 그리드 선택된 Status에 따라 DB에서 값 가져온다.
78
        /// </summary>
79 3bde451b semi
        public IEnumerable<Interface.ConvertItem> GetConvertProjects(int status,string ProjectNumberFilter, string UniqueKeyFilter, string Document_NameFilter, string Service_IDFilter, string Docuemnt_NOFilter, int? ReconverterFilter
80 b63dcfbb semi
            , 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 3bde451b semi
                         || subpet.DOCUMENT_NAME.Contains(Document_NameFilter)
91 b63dcfbb semi
                         || 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 43e1d368 taeseongkim
            if (query.Count() > 0)
121 b63dcfbb semi
            {
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 8c128693 semi
                       // StartTime = (DateTime)item.START_DATETIME,
132
                        //EndTime = (DateTime)item.END_DATETIME,
133 b63dcfbb semi
                        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 af0f18ee taeseongkim
                        DocumentNo = item.DOCUMENT_NO,
140
                        DocumentName = item.DOCUMENT_NAME,
141 b63dcfbb semi
                        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 8c128693 semi
                    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 b63dcfbb semi
                    convertItems.Add(convertitem);
163
                }
164
            }
165
            return convertItems;
166
167
        }
168
169 3bde451b semi
        /// <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 af0f18ee taeseongkim
                        DocumentNo = item.DOCUMENT_NO,
243
                        DocumentName = item.DOCUMENT_NAME,
244 3bde451b semi
                        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 e6281033 alzkakdixm
        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 b63dcfbb semi
                        orderby items.CREATE_DATETIME descending
267 5a954acc semi
                        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 3bde451b semi
                            GROUP_NO = subpet.GROUP_NO
286 5a954acc semi
                        };
287 53c9637d taeseongkim
288 e6281033 alzkakdixm
            if (query.Count() > 0)//세미
289 53c9637d taeseongkim
            {
290 e6281033 alzkakdixm
                foreach (var item in query)
291 53c9637d taeseongkim
                {
292 e6281033 alzkakdixm
                    Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
293 53c9637d taeseongkim
                    {
294
295 e6281033 alzkakdixm
                        ReConverter = item.RECONVERTER,
296
                        ServiceID = item.SERVICE_ID,
297
                        ConvertState = (StatusCodeType)item.STATUS,
298
                        CreateTime = item.CREATE_DATETIME,
299 344ac7ed alzkakdixm
                        StartTime = (DateTime)item.START_DATETIME,
300
                        EndTime = (DateTime)item.END_DATETIME,
301 e6281033 alzkakdixm
                        TotalPage = item.TOTAL_PAGE,
302
                        CurrentPageNo = item.CURRENT_PAGE,
303
                        Exception = item.EXCEPTION,
304 e78f0871 alzkakdixm
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID),
305 53c9637d taeseongkim
306 e6281033 alzkakdixm
                        Revision = item.REVISION,
307 af0f18ee taeseongkim
                        DocumentNo = item.DOCUMENT_NO,
308
                        DocumentName = item.DOCUMENT_NAME,
309 e6281033 alzkakdixm
                        GroupNo = item.GROUP_NO,
310 05fd750b alzkakdixm
                        DocumentID = item.DOCUMENT_ID,
311
312 3bde451b semi
313 e78f0871 alzkakdixm
                        MarkusLink = "kcom://" + Markus.Service.DataBase.Extensions.MarkusAPI.CreateMarkusParam(item.PROJECT_NO, item.DOCUMENT_ID, "doftech")
314 e6281033 alzkakdixm
                    };
315
                    convertItems.Add(convertitem);
316 53c9637d taeseongkim
                }
317
            }
318 e6281033 alzkakdixm
            return convertItems;
319 53c9637d taeseongkim
320 e6281033 alzkakdixm
        }
321 53c9637d taeseongkim
322 218e5002 semi
        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 e6281033 alzkakdixm
        #endregion
332 53c9637d taeseongkim
333 e6281033 alzkakdixm
        #region Update RealDataSelect 
334 53c9637d taeseongkim
335
        /// <summary>
336 e6281033 alzkakdixm
        /// 상단 그리드에서 선택된 RealDataSelect
337
        /// 용도: 중앙그리드 Items Update
338 53c9637d taeseongkim
        /// </summary>
339 3bde451b semi
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 af0f18ee taeseongkim
                            DocumentNo = item.DOCUMENT_NO,
393
                            DocumentName = item.DOCUMENT_NAME,
394 3bde451b semi
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 e6281033 alzkakdixm
        public IEnumerable<Interface.ConvertItem> GetConvertProjects(System.Collections.ObjectModel.ObservableCollection<Interface.ConvertItem> selectedConvert)
409 53c9637d taeseongkim
        {
410 e6281033 alzkakdixm
            List<Interface.ConvertItem> StatusKeep = new List<Interface.ConvertItem>();
411 53c9637d taeseongkim
412 e6281033 alzkakdixm
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
413 53c9637d taeseongkim
414 e6281033 alzkakdixm
            foreach (var selectedConvertItem in selectedConvert)
415 53c9637d taeseongkim
            {
416 e6281033 alzkakdixm
                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 344ac7ed alzkakdixm
                                START_DATETIME  = items.START_DATETIME,
429
                                END_DATETIME = items.END_DATETIME,
430 e6281033 alzkakdixm
                                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 53c9637d taeseongkim
441 41fa3d98 djkim
442 e6281033 alzkakdixm
                if (query.Count() > 0)//세미
443 53c9637d taeseongkim
                {
444 e6281033 alzkakdixm
                    foreach (var item in query)
445 41fa3d98 djkim
                    {
446 e6281033 alzkakdixm
                        Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
447
                        {
448 53c9637d taeseongkim
449 e6281033 alzkakdixm
                            ReConverter = item.RECONVERTER,
450
                            ServiceID = item.SERVICE_ID,
451
                            ConvertState = (StatusCodeType)item.STATUS,
452
                            CreateTime = item.CREATE_DATETIME,
453 344ac7ed alzkakdixm
                            StartTime = item.START_DATETIME,
454
                            EndTime = item.END_DATETIME,
455 e6281033 alzkakdixm
                            TotalPage = item.TOTAL_PAGE,
456
                            CurrentPageNo = item.CURRENT_PAGE,
457
                            Exception = item.EXCEPTION,
458
                            ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID),
459 53c9637d taeseongkim
460 e6281033 alzkakdixm
                            Revision = item.REVISION,
461 af0f18ee taeseongkim
                            DocumentNo = item.DOCUMENT_NO,
462
                            DocumentName = item.DOCUMENT_NAME,
463 05fd750b alzkakdixm
                            GroupNo = item.GROUP_NO,
464
465 e78f0871 alzkakdixm
                            MarkusLink = "kcom://" + MarkusAPI.CreateMarkusParam(item.PROJECT_NO, item.DOCUMENT_ID, "doftech")
466 e6281033 alzkakdixm
                        };
467 53c9637d taeseongkim
468 e6281033 alzkakdixm
                        StatusKeep.Add(convertitem);
469 53c9637d taeseongkim
470 e6281033 alzkakdixm
                    }
471
                }
472
            }
473
            return StatusKeep;
474 0157b158 taeseongkim
        }
475 53c9637d taeseongkim
476 e6281033 alzkakdixm
        #endregion
477 53c9637d taeseongkim
478 e6281033 alzkakdixm
        #region Data Convert
479 53c9637d taeseongkim
480 e6281033 alzkakdixm
        /// <summary>
481
        /// 상단 그리드에서 선택된 Convert 버튼 
482
        /// 용도: 중앙 그리드로 Convert된 row 값 저장 하기 위해서 입니다.
483
        /// </summary>
484 3bde451b semi
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 af0f18ee taeseongkim
                        DocumentNo = item.DOCUMENT_NO,
540
                        DocumentName = item.DOCUMENT_NAME,
541 3bde451b semi
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 e6281033 alzkakdixm
        public IEnumerable<Interface.ConvertItem> GetConvertProjects(Markus.Service.Interface.ConvertItem selectedConvert)
554 53c9637d taeseongkim
        {
555 e6281033 alzkakdixm
            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 344ac7ed alzkakdixm
                            START_DATETIME = items.START_DATETIME,
578
                            END_DATETIME = items.END_DATETIME,
579 e6281033 alzkakdixm
                            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 53c9637d taeseongkim
            {
592 e6281033 alzkakdixm
                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 344ac7ed alzkakdixm
                        StartTime = item.START_DATETIME,
602
                        EndTime = item.END_DATETIME,
603 e6281033 alzkakdixm
                        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 af0f18ee taeseongkim
                        DocumentNo = item.DOCUMENT_NO,
609
                        DocumentName = item.DOCUMENT_NAME,
610 05fd750b alzkakdixm
                        GroupNo = item.GROUP_NO,
611
612 e78f0871 alzkakdixm
                        MarkusLink = "kcom://" + Markus.Service.DataBase.Extensions.MarkusAPI.CreateMarkusParam(item.PROJECT_NO, item.DOCUMENT_ID, "doftech")
613 e6281033 alzkakdixm
                    };
614
                    StatusKeep.Add(convertitem);
615
                }
616 53c9637d taeseongkim
            }
617 e6281033 alzkakdixm
            System.Diagnostics.Debug.WriteLine(new TimeSpan(stopwatch.ElapsedTicks).ToString());
618
            return StatusKeep;
619 53c9637d taeseongkim
620
        }
621
622 3bde451b semi
623 e6281033 alzkakdixm
        #endregion
624 53c9637d taeseongkim
625 e6281033 alzkakdixm
        #region SetCleanUpItem
626 53c9637d taeseongkim
        /// <summary>
627
        /// 오류나 wait으로 남아 있는 데이터베이스의 Item을 StatusCodeType.None으로 복구
628
        /// </summary>
629 2bbea412 taeseongkim
        /// <param name="convertID">StatusCodeType을 변경하고자 하는 ConvertItem의 ID</param>
630
        /// <param name="ReConvert">ReConvert가 2이면 다시 Convert를 시도 안하기 때문에 기존 값으로 유지 하고 계속 시도 할수 있도록 0을 주는 경우가 있다.</param>
631 53c9637d taeseongkim
        /// <returns></returns>
632 2decfbdf alzkakdixm
        /// 
633 3bde451b semi
        public int SetCleanUpFinalPDFItem(ConvertItem _ConvertItem)
634 53c9637d taeseongkim
        {
635
            int result = 0;
636
637 3bde451b semi
            var items = entities.FINAL_PDF.Where(x => x.ID == _ConvertItem.ConvertID);
638 53c9637d taeseongkim
639
            result = items.Count();
640
641
            if (items.Count() > 0)
642
            {
643 0157b158 taeseongkim
                var item = items.First();
644
645 3bde451b semi
                //item.RECONVERTER = item.RECONVERTER - _ConvertItem.ReConverter;
646 508debb1 taeseongkim
647 e6281033 alzkakdixm
                item.CREATE_DATETIME = DateTime.Now;
648
                item.STATUS = (int)StatusCodeType.None;
649 508debb1 taeseongkim
                item.END_DATETIME = null;
650 53c9637d taeseongkim
651 43e1d368 taeseongkim
652
                var waiter = entities.SaveChangesAsync().GetAwaiter();
653
                result = waiter.GetResult();
654 53c9637d taeseongkim
            }
655
656
            return result;
657
        }
658 2decfbdf alzkakdixm
659 3bde451b semi
        //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 508debb1 taeseongkim
        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 43e1d368 taeseongkim
                var waiter = entities.SaveChangesAsync().GetAwaiter();
702
                result = waiter.GetResult();
703 508debb1 taeseongkim
            }
704
705
            return result;
706
        }
707 e6281033 alzkakdixm
        #endregion
708
709
        #region Convert Path
710
711
        private string GetConvertPath(string ProjectNo, string DocumentID)
712
        {
713
            try
714
            {
715 43e1d368 taeseongkim
716 e6281033 alzkakdixm
                return Path.Combine(BaseStorage(ProjectNo), ProjectNo + "_Tile", (System.Convert.ToInt64(DocumentID) / 100).ToString(), DocumentID);
717 43e1d368 taeseongkim
                return Path.Combine(BaseStorage(ProjectNo), ProjectNo + "_Tile",DocumentID.Substring(0, 5).ToString(), DocumentID);
718 e6281033 alzkakdixm
            }
719
            catch (Exception)
720
            {
721
                throw new Exception("GetConvertPath Error");
722
            }
723 2decfbdf alzkakdixm
724 e6281033 alzkakdixm
        }
725 2decfbdf alzkakdixm
726 e6281033 alzkakdixm
        private string BaseStorage(string ProjectNo)
727
        {
728
            string result = "";
729 2decfbdf alzkakdixm
730 e6281033 alzkakdixm
            var properties = entities.PROPERTIES.Where(f => f.PROPERTY == ProjectNo && f.TYPE == PROPERTIES_DEFINE.TILE_SOURCE_STORAGE);
731 2decfbdf alzkakdixm
732 e6281033 alzkakdixm
            if (properties.Count() > 0)
733
            {
734
                result = properties.First().VALUE;
735
            }
736
            else
737
            {
738
                throw new Exception($"Project {ProjectNo} BaseStorage Not Setting.");
739
            }
740 2decfbdf alzkakdixm
741 e6281033 alzkakdixm
            return result;
742
        }
743 2decfbdf alzkakdixm
744 e6281033 alzkakdixm
        #endregion
745 53c9637d taeseongkim
746 e6281033 alzkakdixm
        #region Remove
747 5d863c06 taeseongkim
748
        /// <summary>
749
        /// Item 삭제
750
        /// </summary>
751
        /// <returns></returns>
752 3bde451b semi
        /// 
753
754
        public int RemoveFinalPDFItem(string convertID)
755
        {
756
            int result = 0;
757
758
            var items = entities.FINAL_PDF.Where(x => x.ID == convertID);
759
760
            if (items.Count() > 0)
761
            {
762
                FINAL_PDF item = items.First();
763
                entities.FINAL_PDF.Remove(item);
764
765 43e1d368 taeseongkim
766
                var waiter = entities.SaveChangesAsync().GetAwaiter();
767
                result = waiter.GetResult();
768 3bde451b semi
            }
769
770
            return result;
771
        } 
772
773 5d863c06 taeseongkim
        public int RemoveItem(string convertID)
774
        {
775
            int result = 0;
776
777
            var items = entities.CONVERTER_DOC.Where(x => x.ID == convertID);
778
779
            if (items.Count() > 0)
780
            {
781
                CONVERTER_DOC item = items.First();
782
                entities.CONVERTER_DOC.Remove(item);
783
784 43e1d368 taeseongkim
785
                var waiter = entities.SaveChangesAsync().GetAwaiter();
786
                result = waiter.GetResult();
787 5d863c06 taeseongkim
            }
788
789
            return result;
790
        }
791
792 e6281033 alzkakdixm
793
        #endregion
794
795 05fd750b alzkakdixm
        #region MarkusLink
796
797
798
        ////// userID는 관리자 계정인 doftech
799
        ////string markusLink = "kcom://" + MarkusAPI.CreateMarkusParam(projectNo, documentID, userID);
800
        //public static string CreateMarkusParam(string projectNo, string documentID, string userID)
801
        //{
802
        //    ViewInfo viewInfo = new ViewInfo();
803
804
        //    viewInfo.DocumentItemID = documentID;
805
        //    viewInfo.ProjectNO = projectNo;
806
        //    viewInfo.UserID = userID;
807
808
        //    return ParamEncoding(JsonConvert.SerializeObject(viewInfo));
809
810
        //}
811
812
        //public static string ParamEncoding(string EncodingText, System.Text.Encoding oEncoding = null)
813
        //{
814
815
        //    if (oEncoding == null)
816
        //        oEncoding = System.Text.Encoding.UTF8;
817
818
        //    return Convert.ToBase64String(oEncoding.GetBytes(EncodingText));
819
820
        //}
821
822
823
        #endregion
824
825 e6281033 alzkakdixm
        #endregion
826
827
        #region DataBaseByStatusViewModel Function
828 53c9637d taeseongkim
        /// <summary>
829
        /// 전체 컨버터를 가져온다. 비동기로 변경하여야 한다.
830
        /// </summary>
831
        /// <returns></returns>
832 e6281033 alzkakdixm
        public List<Interface.ConvertItem> GetConvertItems(StatusCodeType statusCodeType, Func<CONVERTER_DOC, bool> @where, int takeCount = 100)
833 53c9637d taeseongkim
        {
834
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
835
836 e6281033 alzkakdixm
837
            var items = entities.CONVERTER_DOC.Where(x => x.STATUS == (int)statusCodeType).Take(takeCount).ToList();
838 53c9637d taeseongkim
839
            if (items.Count() > 0)
840
            {
841
                foreach (var item in items)
842
                {
843 06f13e11 taeseongkim
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
844
                    {
845
                        ReConverter = item.RECONVERTER,
846
                        ServiceID = item.SERVICE_ID,
847 2decfbdf alzkakdixm
                        ConvertState = ((StatusCodeType)item.STATUS),
848 06f13e11 taeseongkim
                        CreateTime = item.CREATE_DATETIME,
849
                        TotalPage = item.TOTAL_PAGE,
850
                        CurrentPageNo = item.CURRENT_PAGE,
851
852
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID)
853
                    };
854
855 53c9637d taeseongkim
                    convertItems.Add(convertitem);
856
                }
857
            }
858
            return convertItems;
859
        }
860 e6281033 alzkakdixm
        #endregion
861
862
        #region No 참조 
863 53c9637d taeseongkim
864 0157b158 taeseongkim
        /// <summary>
865 e6281033 alzkakdixm
        /// 컨버터서비스를 이용하는 문서 정보 저장
866
        /// UniqueID
867
        /// using Markus.Service.Extensions;  new Guid().CreateUniqueGuid().ToString();
868 b92f142f taeseongkim
        /// </summary>
869 e6281033 alzkakdixm
        /// <param name="ProjectNo">프로젝트</param>
870
        /// <param name="UniqueID">컨버터 서비스의 아이템 ID</param>
871
        /// <param name="originfilePath"></param>
872
        /// <param name="DocumentID"></param>
873 b92f142f taeseongkim
        /// <returns></returns>
874 e6281033 alzkakdixm
        public bool SetConvertDoc(string ProjectNo, string UniqueID, string originfilePath, string DocumentID)
875 b92f142f taeseongkim
        {
876 e6281033 alzkakdixm
            bool result = false;
877 b92f142f taeseongkim
878 e6281033 alzkakdixm
            if (ProjectNo.IsNullOrEmpty())
879
            {
880
                throw new Exception("ProjectNo is Null");
881
            }
882 60723dc9 taeseongkim
883 e6281033 alzkakdixm
            if (UniqueID.IsNullOrEmpty())
884
            {
885
                throw new Exception("UniqueID is Null");
886
            }
887 b92f142f taeseongkim
888 e6281033 alzkakdixm
            if (originfilePath.IsNullOrEmpty())
889 b92f142f taeseongkim
            {
890 e6281033 alzkakdixm
                throw new Exception("originfilePath is Null");
891
            }
892
893
            if (DocumentID.IsNullOrEmpty())
894
            {
895
                throw new Exception("DocumentID is Null");
896
            }
897
898
            if (DocumentID.IsNullOrEmpty())
899
            {
900
                long _lastDocId = 0;
901
902
                if (entities.CONVERTER_DOC.Count() > 0)
903 b92f142f taeseongkim
                {
904 e6281033 alzkakdixm
                    try
905 b92f142f taeseongkim
                    {
906 e6281033 alzkakdixm
                        string qry = @"SELECT * FROM CONVERTER_DOC order by CAST(DOCUMENT_ID as int) desc";
907
                        var _item = entities.CONVERTER_DOC.SqlQuery(qry).FirstOrDefault();
908 b92f142f taeseongkim
909 e6281033 alzkakdixm
                        if (_item != null)
910
                        {
911
                            _lastDocId = Convert.ToInt64(_item.DOCUMENT_ID) + 1;
912
                        }
913
                    }
914
                    catch (Exception)
915
                    {
916 b92f142f taeseongkim
917 e6281033 alzkakdixm
                        throw;
918
                    }
919 b92f142f taeseongkim
                }
920 e6281033 alzkakdixm
921
                DocumentID = _lastDocId.ToString();
922 b92f142f taeseongkim
            }
923
924 e6281033 alzkakdixm
            CONVERTER_DOC convert_doc = new CONVERTER_DOC
925
            {
926
                ID = UniqueID,
927
                PROJECT_NO = ProjectNo,
928
                DOCUMENT_URL = originfilePath,
929
                DOCUMENT_ID = DocumentID,
930
                CREATE_DATETIME = DateTime.Now,
931
                STATUS = 0,
932
                TOTAL_PAGE = 0,
933
                CURRENT_PAGE = 0,
934
                RECONVERTER = 0
935
            };
936
937
            
938
            entities.CONVERTER_DOC.Add(convert_doc);
939 a6e5055d alzkakdixm
940 43e1d368 taeseongkim
941
            var waiter = entities.SaveChangesAsync().GetAwaiter();
942
943
            if (waiter.GetResult() == 1)
944 e6281033 alzkakdixm
            {
945
                result = true;
946
            }
947
948
            return result;
949
        }
950
951
        /// <summary>
952
        /// 컨버터서비스를 이용하는 문서 정보 저장
953
        /// UniqueID
954
        /// using Markus.Service.Extensions;  new Guid().CreateUniqueGuid().ToString();
955
        /// </summary>
956
        /// <param name="ProjectNo">프로젝트</param>
957
        /// <param name="UniqueID">컨버터 서비스의 아이템 ID</param>
958
        /// <param name="originfilePath"></param>
959
        /// <param name="DocumentID"></param>
960
        /// <returns></returns>
961
        public bool SetDocumentInfo(string ConvertID, int totalPage, List<DOCPAGE> pageinfo)
962 2decfbdf alzkakdixm
        {
963 e6281033 alzkakdixm
            bool result = false;
964 2decfbdf alzkakdixm
965 e6281033 alzkakdixm
            var convertDocItems = entities.CONVERTER_DOC.Where(f => f.ID == ConvertID);
966
967
            if (convertDocItems.Count() > 0)
968 a6e5055d alzkakdixm
            {
969 e6281033 alzkakdixm
                var convertDoc = convertDocItems.First();
970
971
                string docId = new Guid().CreateUniqueGuid().ToString();
972
973
                var docinfo = entities.DOCINFO.FirstOrDefault(x => x.PROJECT_NO == convertDoc.PROJECT_NO && x.DOCUMENT_ID == convertDoc.DOCUMENT_ID);
974
                
975
                if (docinfo != null)
976
                {
977
                    // 기존 Docpage 삭제.
978
                    entities.DOCPAGE.RemoveRange(docinfo.DOCPAGE);
979
980
                    // 기존 코멘트 유지를 위한 Docinfo update                    
981
                    docinfo.PROJECT_NO = convertDoc.PROJECT_NO;
982
                    docinfo.ORIGINAL_FILE = convertDoc.DOCUMENT_URL;
983
                    docinfo.PAGE_COUNT = totalPage;                    
984 43e1d368 taeseongkim
                    docinfo.DOCPAGE = pageinfo;
985
                    var waiter = entities.SaveChangesAsync().GetAwaiter();
986
                   
987
                    if(waiter.GetResult() > 0)
988
                    {
989
                        result = true;
990
                    }
991 e6281033 alzkakdixm
                }
992
                else
993 a6e5055d alzkakdixm
                {
994 e6281033 alzkakdixm
                    DOCINFO instace = new DOCINFO
995 a6e5055d alzkakdixm
                    {
996 e6281033 alzkakdixm
                        ID = docId,
997
                        PROJECT_NO = convertDoc.PROJECT_NO,
998
                        ORIGINAL_FILE = convertDoc.DOCUMENT_URL,
999
                        DOCUMENT_ID = convertDoc.DOCUMENT_ID,
1000
                        PAGE_COUNT = totalPage,
1001
                        DOCPAGE = pageinfo
1002 a6e5055d alzkakdixm
                    };
1003
1004 e6281033 alzkakdixm
                    entities.DOCINFO.Add(instace);
1005 43e1d368 taeseongkim
                    var waiter = entities.SaveChangesAsync().GetAwaiter();
1006
1007
                    var save = waiter.GetResult();
1008 e6281033 alzkakdixm
1009
                    if (save == pageinfo.Count() + 1)
1010
                    {
1011
                        result = true;
1012
                    }
1013 a6e5055d alzkakdixm
                }
1014 2decfbdf alzkakdixm
1015 e6281033 alzkakdixm
                
1016
                
1017
            }
1018 d91efe5c taeseongkim
            else
1019
            {
1020
                throw new Exception($"SetDocumentInfo :{ConvertID} CONVERTER_DOC not found ");
1021
            }
1022 a6e5055d alzkakdixm
1023 e6281033 alzkakdixm
            return result;
1024 2decfbdf alzkakdixm
        }
1025 e6281033 alzkakdixm
1026
        public Interface.ConvertItem GetConvertItem(string ProjectNo, string UniqueID)
1027 a6e5055d alzkakdixm
        {
1028 e6281033 alzkakdixm
            Interface.ConvertItem result = null;
1029 a6e5055d alzkakdixm
1030 e6281033 alzkakdixm
            //var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID);
1031
            var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == ProjectNo && f.ID == UniqueID);
1032
1033
            if (items.Count() > 0)
1034 2decfbdf alzkakdixm
            {
1035 e6281033 alzkakdixm
                var convertItem = items.First();
1036 2decfbdf alzkakdixm
1037 43e1d368 taeseongkim
#if XI_C_AND_A
1038
                string convertPath = GetConvertPath(convertItem.PROJECT_NO, convertItem.DOCUMENT_ID);
1039
#else
1040 2decfbdf alzkakdixm
1041 43e1d368 taeseongkim
                string convertPath = Path.Combine(BaseStorage(convertItem.PROJECT_NO), convertItem.PROJECT_NO + "_Tile", (System.Convert.ToInt64(convertItem.DOCUMENT_ID) / 100).ToString(), convertItem.DOCUMENT_ID);
1042
#endif
1043 e6281033 alzkakdixm
                result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath);
1044
            }
1045 a6e5055d alzkakdixm
1046 e6281033 alzkakdixm
            return result;
1047
        }
1048 2decfbdf alzkakdixm
1049 a6e5055d alzkakdixm
1050 e6281033 alzkakdixm
        public Interface.ConvertItem GetConvertItembyDocumentID(string ProjectNo, string DocumentID)
1051
        {
1052
            Interface.ConvertItem result = null;
1053
1054
            //var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID);
1055
            var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == ProjectNo && f.DOCUMENT_ID == DocumentID);
1056
1057
            if (items.Count() > 0)
1058
            {
1059
                var convertItem = items.First();
1060
1061 43e1d368 taeseongkim
#if XI_C_AND_A
1062
                string convertPath = GetConvertPath(convertItem.PROJECT_NO, convertItem.DOCUMENT_ID);
1063
#else
1064
                string convertPath = Path.Combine(BaseStorage(convertItem.PROJECT_NO), convertItem.PROJECT_NO + "_Tile", (System.Convert.ToInt64(convertItem.DOCUMENT_ID) / 100).ToString(), convertItem.DOCUMENT_ID);
1065
#endif
1066 e6281033 alzkakdixm
                if (convertItem.STATUS == (int)StatusCodeType.Completed)
1067
                {
1068
                    result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath,
1069
                                                        (StatusCodeType)convertItem.STATUS, convertItem.CURRENT_PAGE, convertItem.TOTAL_PAGE, convertItem.EXCEPTION);
1070
                }
1071
                else
1072
                {
1073
                    result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath);
1074 2decfbdf alzkakdixm
                }
1075
            }
1076
1077 e6281033 alzkakdixm
            return result;
1078
        }
1079
1080
        public List<CONVERTER_DOC> GetConvertingItems(List<string> projectList)
1081
        {
1082
            var convertWaitingItems = entities.CONVERTER_DOC.OrderBy(x => x.CREATE_DATETIME).Where(
1083
                                        x =>
1084
                                        projectList.Contains(x.PROJECT_NO) &&
1085
                                         (x.STATUS > (int)StatusCodeType.None && x.STATUS < (int)StatusCodeType.Completed) && x.RECONVERTER < 2);
1086 2decfbdf alzkakdixm
1087 e6281033 alzkakdixm
            return convertWaitingItems.ToList();
1088 2decfbdf alzkakdixm
        }
1089 e6281033 alzkakdixm
1090
        /// <summary>
1091
        /// 전체 컨버터를 가져온다. 비동기로 변경하여야 한다.
1092
        /// </summary>
1093
        /// <returns></returns>
1094
        public List<Interface.ConvertItem> GetConvertItems(StatusCodeType statusCodeType)
1095 2decfbdf alzkakdixm
        {
1096 e6281033 alzkakdixm
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
1097 2decfbdf alzkakdixm
1098 e6281033 alzkakdixm
            var items = entities.CONVERTER_DOC.Where(x => x.STATUS == (int)statusCodeType).ToList(); //.Where(x => x.PROJECT_NO == gProjectNo);
1099
1100
            if (items.Count() > 0)
1101 a6e5055d alzkakdixm
            {
1102 e6281033 alzkakdixm
                foreach (var item in items)
1103 a6e5055d alzkakdixm
                {
1104 e6281033 alzkakdixm
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
1105 a6e5055d alzkakdixm
                    {
1106
                        ReConverter = item.RECONVERTER,
1107
                        ServiceID = item.SERVICE_ID,
1108 e6281033 alzkakdixm
                        ConvertState = ((StatusCodeType)item.STATUS),
1109 a6e5055d alzkakdixm
                        CreateTime = item.CREATE_DATETIME,
1110
                        TotalPage = item.TOTAL_PAGE,
1111
                        CurrentPageNo = item.CURRENT_PAGE,
1112
1113 e6281033 alzkakdixm
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID)
1114 2decfbdf alzkakdixm
                    };
1115 e6281033 alzkakdixm
1116
1117
                    convertItems.Add(convertitem);
1118 a6e5055d alzkakdixm
                }
1119
            }
1120 e6281033 alzkakdixm
            return convertItems;
1121 a6e5055d alzkakdixm
        }
1122
1123
        public List<Interface.ConvertItem> GetConvertProjectsStatus(Func<CONVERTER_DOC, bool> @where)
1124
        {
1125
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
1126
1127
1128
            //var items = entities.CONVERTER_DOC.Where(x => x.STATUS == (int)statusCodeType).Take(takeCount).ToList(); //.Where(x => x.PROJECT_NO == gProjectNo);
1129 e6281033 alzkakdixm
            var items = entities.CONVERTER_DOC.Where(x => x.STATUS <= 4);
1130 a6e5055d alzkakdixm
1131
            if (items.Count() > 0)
1132
            {
1133
                foreach (var item in items)
1134
                {
1135
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
1136
                    {
1137
                        ReConverter = item.RECONVERTER,
1138
                        ServiceID = item.SERVICE_ID,
1139
                        //ConvertState = ((StatusCodeType)item.STATUS).ToString(),
1140 2decfbdf alzkakdixm
                        //ConvertState = (item.STATUS).ToString(),
1141
                        ConvertState = (StatusCodeType)item.STATUS,
1142 a6e5055d alzkakdixm
                        CreateTime = item.CREATE_DATETIME,
1143
                        TotalPage = item.TOTAL_PAGE,
1144
                        CurrentPageNo = item.CURRENT_PAGE,
1145
                        Exception = item.EXCEPTION,
1146
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID)
1147
                    };
1148
1149
1150
                    convertItems.Add(convertitem);
1151
                }
1152
            }
1153
1154
            return convertItems;
1155
        }
1156
1157 b92f142f taeseongkim
1158 e6281033 alzkakdixm
        public bool SetConvertState(string ServiceID, string UniqueID, int State, int CurrentPage, int TotalPage, string Error)
1159 53c9637d taeseongkim
        {
1160
            bool result = false;
1161
1162
            try
1163
            {
1164
                var items = entities.CONVERTER_DOC.SingleOrDefault(f => f.ID == UniqueID);
1165
                //var items = entities.CONVERTER_DOC.SingleOrDefault(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID);
1166
1167
                if (items != null)
1168
                {
1169 0157b158 taeseongkim
                    items.SERVICE_ID = ServiceID;
1170 53c9637d taeseongkim
                    items.STATUS = State;
1171
                    items.CURRENT_PAGE = CurrentPage;
1172
                    items.TOTAL_PAGE = TotalPage;
1173
1174
                    StatusCodeType statusCode = (StatusCodeType)State;
1175
1176 65fbe3cb taeseongkim
                    if (items.START_DATETIME == null)
1177 a8f1a865 taeseongkim
                    {
1178
                        items.START_DATETIME = DateTime.Now;
1179
                    }
1180
1181 53c9637d taeseongkim
                    switch (statusCode)
1182
                    {
1183
                        case StatusCodeType.None:
1184
                            break;
1185
                        case StatusCodeType.Wait:
1186
                            items.START_DATETIME = DateTime.Now;
1187
                            break;
1188
                        case StatusCodeType.PageLoading:
1189
                            break;
1190
                        case StatusCodeType.Saving:
1191
                            break;
1192
                        case StatusCodeType.Completed:
1193 a0341bef taeseongkim
                            items.CURRENT_PAGE = items.TOTAL_PAGE;
1194 e6281033 alzkakdixm
                            items.END_DATETIME = DateTime.Now;
1195 53c9637d taeseongkim
                            break;
1196
                        case StatusCodeType.FileError:
1197
                            Error = $" file Error :" + Error;
1198
                            items.END_DATETIME = DateTime.Now;
1199
                            break;
1200
                        case StatusCodeType.PageError:
1201
                            Error = $" Page No {CurrentPage} Error :" + Error;
1202
                            break;
1203
                        case StatusCodeType.NeedsPassword:
1204
                            break;
1205
                        case StatusCodeType.Error:
1206
                            Error = $" Error :" + Error;
1207
                            items.END_DATETIME = DateTime.Now;
1208
                            break;
1209
                        default:
1210
                            break;
1211
                    }
1212
1213 e6281033 alzkakdixm
                    if (items.EXCEPTION == null)
1214 53c9637d taeseongkim
                    {
1215
                        items.EXCEPTION = "";
1216
                    }
1217
1218
                    if (items.EXCEPTION.Length < 255)
1219
                    {
1220 43e1d368 taeseongkim
                        if (items.EXCEPTION.Length > 0 && Error?.Length > 0)
1221
                        {
1222
                            items.EXCEPTION = items.EXCEPTION + ";" + Environment.NewLine;
1223
                        }
1224
1225 53c9637d taeseongkim
                        items.EXCEPTION = items.EXCEPTION + Error;
1226
                    }
1227
1228 43e1d368 taeseongkim
                    var waiter = entities.SaveChangesAsync().GetAwaiter();
1229
                    var save = waiter.GetResult();
1230 53c9637d taeseongkim
                    result = true;
1231
                }
1232
            }
1233
            catch (Exception ex)
1234
            {
1235 e6281033 alzkakdixm
                throw new Exception("SetConvertState", ex);
1236 53c9637d taeseongkim
            }
1237
1238
            return result;
1239
        }
1240
1241 e6281033 alzkakdixm
        public SERVICE_PROPERTIES GetServiceProperties(string ServiceID)
1242 53c9637d taeseongkim
        {
1243 e6281033 alzkakdixm
            SERVICE_PROPERTIES result = null;
1244 53c9637d taeseongkim
1245 e6281033 alzkakdixm
            var items = entities.SERVICE_PROPERTIES.Where(x => x.ID == ServiceID);
1246 53c9637d taeseongkim
1247 e6281033 alzkakdixm
            if (items.Count() > 0)
1248 53c9637d taeseongkim
            {
1249 e6281033 alzkakdixm
                result = items.First();
1250 53c9637d taeseongkim
            }
1251
1252
            return result;
1253
        }
1254
1255 e6281033 alzkakdixm
1256
        /// <summary>
1257
        /// 현재 서비스에서 컨버터중인 아이템.
1258
        /// </summary>
1259
        /// <returns></returns>
1260
        public List<Interface.ConvertItem> GetServiceAliveItems(string ServiceID)
1261
        {
1262
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
1263
1264
            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);
1265
1266
            if (items.Count() > 0)
1267
            {
1268
                foreach (var item in items)
1269
                {
1270
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL);
1271
                    convertItems.Add(convertitem);
1272
                }
1273
            }
1274
            return convertItems;
1275
        }
1276
1277 43e1d368 taeseongkim
#endregion
1278 e6281033 alzkakdixm
1279 53c9637d taeseongkim
    }
1280
}
클립보드 이미지 추가 (최대 크기: 500 MB)