프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.DataBase / ConvertDatabase.cs @ b63dcfbb

이력 | 보기 | 이력해설 | 다운로드 (37.3 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 b63dcfbb semi
        public IEnumerable<Interface.ConvertItem> GetConvertProjects(int status,string ProjectNumberFilter, string UniqueKeyFilter, string Docuemnt_NameFilter, string Service_IDFilter, string Docuemnt_NOFilter, int? ReconverterFilter
81
            , string RevisionFilter)
82
        {
83
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
84
            var query = from items in entities.CONVERTER_DOC
85
                        join documents in entities.DOCUMENT_ITEM on items.DOCUMENT_ID equals documents.DOCUMENT_ID into GroupItems
86
                        from subpet in GroupItems.DefaultIfEmpty()
87
                        where items.STATUS == status &&
88
                        //
89
                        (
90
                         items.PROJECT_NO.Contains(ProjectNumberFilter)
91
                         || subpet.DOCUMENT_NAME.Contains(Docuemnt_NameFilter)
92
                         || items.SERVICE_ID.Contains(Service_IDFilter)
93
                         || subpet.ID.Contains(UniqueKeyFilter)
94
                         || subpet.DOCUMENT_NO.Contains(Docuemnt_NOFilter)
95
                         || items.RECONVERTER == ReconverterFilter
96
                         || subpet.REVISION.Contains(RevisionFilter)
97
                         )
98
                       //
99
                        orderby items.CREATE_DATETIME descending
100
                        select new
101
                        {
102
                            ID = items.ID,
103
                            DOCUMENT_URL = items.DOCUMENT_URL,
104
                            RECONVERTER = items.RECONVERTER,
105
                            SERVICE_ID = items.SERVICE_ID,
106
                            STATUS = items.STATUS,
107
                            CREATE_DATETIME = items.CREATE_DATETIME,
108
                            START_DATETIME = items.START_DATETIME,
109
                            END_DATETIME = items.END_DATETIME,
110
                            TOTAL_PAGE = items.TOTAL_PAGE,
111
                            CURRENT_PAGE = items.CURRENT_PAGE,
112
                            EXCEPTION = items.EXCEPTION,
113
                            PROJECT_NO = items.PROJECT_NO,
114
                            DOCUMENT_ID = items.DOCUMENT_ID,
115
                            REVISION = subpet.REVISION,
116
                            DOCUMENT_NO = subpet.DOCUMENT_NO,
117
                            DOCUMENT_NAME = subpet.DOCUMENT_NAME,
118
                            GROUP_NO = subpet.GROUP_NO,
119
                        };
120
121
            if (query.Count() > 0)//세미
122
            {
123
                foreach (var item in query)
124
                {
125
                    Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
126
                    {
127
128
                        ReConverter = item.RECONVERTER,
129
                        ServiceID = item.SERVICE_ID,
130
                        ConvertState = (StatusCodeType)item.STATUS,
131
                        CreateTime = item.CREATE_DATETIME,
132
                        StartTime = (DateTime)item.START_DATETIME,
133
                        EndTime = (DateTime)item.END_DATETIME,
134
                        TotalPage = item.TOTAL_PAGE,
135
                        CurrentPageNo = item.CURRENT_PAGE,
136
                        Exception = item.EXCEPTION,
137
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID),
138
139
                        Revision = item.REVISION,
140
                        DocumnetNo = item.DOCUMENT_NO,
141
                        DocumnetName = item.DOCUMENT_NAME,
142
                        GroupNo = item.GROUP_NO,
143
                        DocumentID = item.DOCUMENT_ID,
144
145
                        MarkusLink = "kcom://" + Markus.Service.DataBase.Extensions.MarkusAPI.CreateMarkusParam(item.PROJECT_NO, item.DOCUMENT_ID, "doftech")
146
                    };
147
                    convertItems.Add(convertitem);
148
                }
149
            }
150
            return convertItems;
151
152
        }
153
154 e6281033 alzkakdixm
        public IEnumerable<Interface.ConvertItem> GetConvertProjects(int status)
155
        {
156
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
157
            var query = from items in entities.CONVERTER_DOC
158
                        join documents in entities.DOCUMENT_ITEM on items.DOCUMENT_ID equals documents.DOCUMENT_ID into GroupItems
159
                        from subpet in GroupItems.DefaultIfEmpty()
160
                        where items.STATUS == status
161 b63dcfbb semi
                        orderby items.CREATE_DATETIME descending
162 5a954acc semi
                        select new
163
                        {
164
                            ID = items.ID,
165
                            DOCUMENT_URL = items.DOCUMENT_URL,
166
                            RECONVERTER = items.RECONVERTER,
167
                            SERVICE_ID = items.SERVICE_ID,
168
                            STATUS = items.STATUS,
169
                            CREATE_DATETIME = items.CREATE_DATETIME,
170
                            START_DATETIME = items.START_DATETIME,
171
                            END_DATETIME = items.END_DATETIME,
172
                            TOTAL_PAGE = items.TOTAL_PAGE,
173
                            CURRENT_PAGE = items.CURRENT_PAGE,
174
                            EXCEPTION = items.EXCEPTION,
175
                            PROJECT_NO = items.PROJECT_NO,
176
                            DOCUMENT_ID = items.DOCUMENT_ID,
177
                            REVISION = subpet.REVISION,
178
                            DOCUMENT_NO = subpet.DOCUMENT_NO,
179
                            DOCUMENT_NAME = subpet.DOCUMENT_NAME,
180
                            GROUP_NO = subpet.GROUP_NO,
181
                        };
182 53c9637d taeseongkim
183 e6281033 alzkakdixm
            if (query.Count() > 0)//세미
184 53c9637d taeseongkim
            {
185 e6281033 alzkakdixm
                foreach (var item in query)
186 53c9637d taeseongkim
                {
187 e6281033 alzkakdixm
                    Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
188 53c9637d taeseongkim
                    {
189
190 e6281033 alzkakdixm
                        ReConverter = item.RECONVERTER,
191
                        ServiceID = item.SERVICE_ID,
192
                        ConvertState = (StatusCodeType)item.STATUS,
193
                        CreateTime = item.CREATE_DATETIME,
194 344ac7ed alzkakdixm
                        StartTime = (DateTime)item.START_DATETIME,
195
                        EndTime = (DateTime)item.END_DATETIME,
196 e6281033 alzkakdixm
                        TotalPage = item.TOTAL_PAGE,
197
                        CurrentPageNo = item.CURRENT_PAGE,
198
                        Exception = item.EXCEPTION,
199 e78f0871 alzkakdixm
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID),
200 53c9637d taeseongkim
201 e6281033 alzkakdixm
                        Revision = item.REVISION,
202
                        DocumnetNo = item.DOCUMENT_NO,
203
                        DocumnetName = item.DOCUMENT_NAME,
204
                        GroupNo = item.GROUP_NO,
205 05fd750b alzkakdixm
                        DocumentID = item.DOCUMENT_ID,
206
207 e78f0871 alzkakdixm
                        MarkusLink = "kcom://" + Markus.Service.DataBase.Extensions.MarkusAPI.CreateMarkusParam(item.PROJECT_NO, item.DOCUMENT_ID, "doftech")
208 e6281033 alzkakdixm
                    };
209
                    convertItems.Add(convertitem);
210 53c9637d taeseongkim
                }
211
            }
212 e6281033 alzkakdixm
            return convertItems;
213 53c9637d taeseongkim
214 e6281033 alzkakdixm
        }
215 53c9637d taeseongkim
216 e6281033 alzkakdixm
        #endregion
217 53c9637d taeseongkim
218 e6281033 alzkakdixm
        #region Update RealDataSelect 
219 53c9637d taeseongkim
220
        /// <summary>
221 e6281033 alzkakdixm
        /// 상단 그리드에서 선택된 RealDataSelect
222
        /// 용도: 중앙그리드 Items Update
223 53c9637d taeseongkim
        /// </summary>
224 e6281033 alzkakdixm
        public IEnumerable<Interface.ConvertItem> GetConvertProjects(System.Collections.ObjectModel.ObservableCollection<Interface.ConvertItem> selectedConvert)
225 53c9637d taeseongkim
        {
226 e6281033 alzkakdixm
            List<Interface.ConvertItem> StatusKeep = new List<Interface.ConvertItem>();
227 53c9637d taeseongkim
228 e6281033 alzkakdixm
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
229 53c9637d taeseongkim
230 e6281033 alzkakdixm
            foreach (var selectedConvertItem in selectedConvert)
231 53c9637d taeseongkim
            {
232 e6281033 alzkakdixm
                var query = from items in entities.CONVERTER_DOC //세미
233
                            join documents in entities.DOCUMENT_ITEM on items.DOCUMENT_ID equals documents.DOCUMENT_ID into GroupItems
234
                            from subpet in GroupItems.DefaultIfEmpty()
235
                            where items.PROJECT_NO == selectedConvertItem.ProjectNumber && items.ID == selectedConvertItem.ConvertID
236
                            select new
237
                            {
238
                                ID = items.ID,
239
                                DOCUMENT_URL = items.DOCUMENT_URL,
240
                                RECONVERTER = items.RECONVERTER,
241
                                SERVICE_ID = items.SERVICE_ID,
242
                                STATUS = items.STATUS,
243
                                CREATE_DATETIME = items.CREATE_DATETIME,
244 344ac7ed alzkakdixm
                                START_DATETIME  = items.START_DATETIME,
245
                                END_DATETIME = items.END_DATETIME,
246 e6281033 alzkakdixm
                                TOTAL_PAGE = items.TOTAL_PAGE,
247
                                CURRENT_PAGE = items.CURRENT_PAGE,
248
                                EXCEPTION = items.EXCEPTION,
249
                                PROJECT_NO = items.PROJECT_NO,
250
                                DOCUMENT_ID = items.DOCUMENT_ID,
251
                                REVISION = subpet.REVISION,
252
                                DOCUMENT_NO = subpet.DOCUMENT_NO,
253
                                DOCUMENT_NAME = subpet.DOCUMENT_NAME,
254
                                GROUP_NO = subpet.GROUP_NO
255
                            };
256 53c9637d taeseongkim
257 41fa3d98 djkim
258 e6281033 alzkakdixm
                if (query.Count() > 0)//세미
259 53c9637d taeseongkim
                {
260 e6281033 alzkakdixm
                    foreach (var item in query)
261 41fa3d98 djkim
                    {
262 e6281033 alzkakdixm
                        Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
263
                        {
264 53c9637d taeseongkim
265 e6281033 alzkakdixm
                            ReConverter = item.RECONVERTER,
266
                            ServiceID = item.SERVICE_ID,
267
                            ConvertState = (StatusCodeType)item.STATUS,
268
                            CreateTime = item.CREATE_DATETIME,
269 344ac7ed alzkakdixm
                            StartTime = item.START_DATETIME,
270
                            EndTime = item.END_DATETIME,
271 e6281033 alzkakdixm
                            TotalPage = item.TOTAL_PAGE,
272
                            CurrentPageNo = item.CURRENT_PAGE,
273
                            Exception = item.EXCEPTION,
274
                            ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID),
275 53c9637d taeseongkim
276 e6281033 alzkakdixm
                            Revision = item.REVISION,
277
                            DocumnetNo = item.DOCUMENT_NO,
278
                            DocumnetName = item.DOCUMENT_NAME,
279 05fd750b alzkakdixm
                            GroupNo = item.GROUP_NO,
280
281 e78f0871 alzkakdixm
                            MarkusLink = "kcom://" + MarkusAPI.CreateMarkusParam(item.PROJECT_NO, item.DOCUMENT_ID, "doftech")
282 e6281033 alzkakdixm
                        };
283 53c9637d taeseongkim
284 e6281033 alzkakdixm
                        StatusKeep.Add(convertitem);
285 53c9637d taeseongkim
286 e6281033 alzkakdixm
                    }
287
                }
288
            }
289
            return StatusKeep;
290 0157b158 taeseongkim
        }
291 53c9637d taeseongkim
292 e6281033 alzkakdixm
        #endregion
293 53c9637d taeseongkim
294 e6281033 alzkakdixm
        #region Data Convert
295 53c9637d taeseongkim
296 e6281033 alzkakdixm
        /// <summary>
297
        /// 상단 그리드에서 선택된 Convert 버튼 
298
        /// 용도: 중앙 그리드로 Convert된 row 값 저장 하기 위해서 입니다.
299
        /// </summary>
300
        public IEnumerable<Interface.ConvertItem> GetConvertProjects(Markus.Service.Interface.ConvertItem selectedConvert)
301 53c9637d taeseongkim
        {
302 e6281033 alzkakdixm
            List<Interface.ConvertItem> StatusKeep = new List<Interface.ConvertItem>();
303
304
305
            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
306
307
            stopwatch.Start();
308
309
310
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();//디비 다 조인 후 조건 비교 후 그리드 출력
311
            var query = from items in entities.CONVERTER_DOC //세미
312
                        join documents in entities.DOCUMENT_ITEM on items.DOCUMENT_ID equals documents.DOCUMENT_ID into GroupItems
313
                        from subpet in GroupItems.DefaultIfEmpty()
314
                        where items.PROJECT_NO == selectedConvert.ProjectNumber && items.DOCUMENT_ID == selectedConvert.DocumentID
315
                        orderby items.CREATE_DATETIME descending
316
                        select new
317
                        {
318
                            ID = items.ID,
319
                            DOCUMENT_URL = items.DOCUMENT_URL,
320
                            RECONVERTER = items.RECONVERTER,
321
                            SERVICE_ID = items.SERVICE_ID,
322
                            STATUS = items.STATUS,
323
                            CREATE_DATETIME = items.CREATE_DATETIME,
324 344ac7ed alzkakdixm
                            START_DATETIME = items.START_DATETIME,
325
                            END_DATETIME = items.END_DATETIME,
326 e6281033 alzkakdixm
                            TOTAL_PAGE = items.TOTAL_PAGE,
327
                            CURRENT_PAGE = items.CURRENT_PAGE,
328
                            EXCEPTION = items.EXCEPTION,
329
                            PROJECT_NO = items.PROJECT_NO,
330
                            DOCUMENT_ID = items.DOCUMENT_ID,
331
                            REVISION = subpet.REVISION,
332
                            DOCUMENT_NO = subpet.DOCUMENT_NO,
333
                            DOCUMENT_NAME = subpet.DOCUMENT_NAME,
334
                            GROUP_NO = subpet.GROUP_NO
335
                        };
336
337
            if (query.Count() > 0)//세미
338 53c9637d taeseongkim
            {
339 e6281033 alzkakdixm
                foreach (var item in query)
340
                {
341
                    Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
342
                    {
343
344
                        ReConverter = item.RECONVERTER,
345
                        ServiceID = item.SERVICE_ID,
346
                        ConvertState = (StatusCodeType)item.STATUS,
347
                        CreateTime = item.CREATE_DATETIME,
348 344ac7ed alzkakdixm
                        StartTime = item.START_DATETIME,
349
                        EndTime = item.END_DATETIME,
350 e6281033 alzkakdixm
                        TotalPage = item.TOTAL_PAGE,
351
                        CurrentPageNo = item.CURRENT_PAGE,
352
                        Exception = item.EXCEPTION,
353
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID),
354
                        Revision = item.REVISION,
355
                        DocumnetNo = item.DOCUMENT_NO,
356
                        DocumnetName = item.DOCUMENT_NAME,
357 05fd750b alzkakdixm
                        GroupNo = item.GROUP_NO,
358
359 e78f0871 alzkakdixm
                        MarkusLink = "kcom://" + Markus.Service.DataBase.Extensions.MarkusAPI.CreateMarkusParam(item.PROJECT_NO, item.DOCUMENT_ID, "doftech")
360 e6281033 alzkakdixm
                    };
361
                    StatusKeep.Add(convertitem);
362
                }
363 53c9637d taeseongkim
            }
364 e6281033 alzkakdixm
            System.Diagnostics.Debug.WriteLine(new TimeSpan(stopwatch.ElapsedTicks).ToString());
365
            return StatusKeep;
366 53c9637d taeseongkim
367
        }
368
369 e6281033 alzkakdixm
        #endregion
370 53c9637d taeseongkim
371 e6281033 alzkakdixm
        #region SetCleanUpItem
372 53c9637d taeseongkim
        /// <summary>
373
        /// 오류나 wait으로 남아 있는 데이터베이스의 Item을 StatusCodeType.None으로 복구
374
        /// </summary>
375 2bbea412 taeseongkim
        /// <param name="convertID">StatusCodeType을 변경하고자 하는 ConvertItem의 ID</param>
376
        /// <param name="ReConvert">ReConvert가 2이면 다시 Convert를 시도 안하기 때문에 기존 값으로 유지 하고 계속 시도 할수 있도록 0을 주는 경우가 있다.</param>
377 53c9637d taeseongkim
        /// <returns></returns>
378 2decfbdf alzkakdixm
        /// 
379
        public int SetCleanUpItem(ConvertItem _ConvertItem)
380 53c9637d taeseongkim
        {
381
            int result = 0;
382
383 2decfbdf alzkakdixm
            var items = entities.CONVERTER_DOC.Where(x => x.ID == _ConvertItem.ConvertID);
384 53c9637d taeseongkim
385
            result = items.Count();
386
387
            if (items.Count() > 0)
388
            {
389 0157b158 taeseongkim
                var item = items.First();
390
391 2decfbdf alzkakdixm
                item.RECONVERTER = item.RECONVERTER - _ConvertItem.ReConverter;
392 508debb1 taeseongkim
393 e6281033 alzkakdixm
                item.CREATE_DATETIME = DateTime.Now;
394
                item.STATUS = (int)StatusCodeType.None;
395 508debb1 taeseongkim
                item.END_DATETIME = null;
396 53c9637d taeseongkim
397 0157b158 taeseongkim
                result = entities.SaveChanges();
398 53c9637d taeseongkim
            }
399
400
            return result;
401
        }
402 2decfbdf alzkakdixm
403 508debb1 taeseongkim
        public int SetCleanUpItem(string convertID, int ReConvert)
404
        {
405
            int result = 0;
406
407
            var items = entities.CONVERTER_DOC.Where(x => x.ID == convertID);
408
409
            result = items.Count();
410
411
            if (items.Count() > 0)
412
            {
413
                var item = items.First();
414
415
                item.RECONVERTER = item.RECONVERTER + ReConvert;
416
                item.CREATE_DATETIME = DateTime.Now;
417
                //item.START_DATETIME = null;
418
                item.END_DATETIME = null;
419
                item.STATUS = (int)StatusCodeType.None;
420
421
                result = entities.SaveChanges();
422
            }
423
424
            return result;
425
        }
426 e6281033 alzkakdixm
        #endregion
427
428
        #region Convert Path
429
430
        private string GetConvertPath(string ProjectNo, string DocumentID)
431
        {
432
            try
433
            {
434
                return Path.Combine(BaseStorage(ProjectNo), ProjectNo + "_Tile", (System.Convert.ToInt64(DocumentID) / 100).ToString(), DocumentID);
435
            }
436
            catch (Exception)
437
            {
438
                throw new Exception("GetConvertPath Error");
439
            }
440 2decfbdf alzkakdixm
441 e6281033 alzkakdixm
        }
442 2decfbdf alzkakdixm
443 e6281033 alzkakdixm
        private string BaseStorage(string ProjectNo)
444
        {
445
            string result = "";
446 2decfbdf alzkakdixm
447 e6281033 alzkakdixm
            var properties = entities.PROPERTIES.Where(f => f.PROPERTY == ProjectNo && f.TYPE == PROPERTIES_DEFINE.TILE_SOURCE_STORAGE);
448 2decfbdf alzkakdixm
449 e6281033 alzkakdixm
            if (properties.Count() > 0)
450
            {
451
                result = properties.First().VALUE;
452
            }
453
            else
454
            {
455
                throw new Exception($"Project {ProjectNo} BaseStorage Not Setting.");
456
            }
457 2decfbdf alzkakdixm
458 e6281033 alzkakdixm
            return result;
459
        }
460 2decfbdf alzkakdixm
461 e6281033 alzkakdixm
        #endregion
462 53c9637d taeseongkim
463 e6281033 alzkakdixm
        #region Remove
464 5d863c06 taeseongkim
465
        /// <summary>
466
        /// Item 삭제
467
        /// </summary>
468
        /// <returns></returns>
469
        public int RemoveItem(string convertID)
470
        {
471
            int result = 0;
472
473
            var items = entities.CONVERTER_DOC.Where(x => x.ID == convertID);
474
475
            if (items.Count() > 0)
476
            {
477
                CONVERTER_DOC item = items.First();
478
                entities.CONVERTER_DOC.Remove(item);
479
480
                result = entities.SaveChanges();
481
            }
482
483
            return result;
484
        }
485
486 e6281033 alzkakdixm
487
        #endregion
488
489 05fd750b alzkakdixm
        #region MarkusLink
490
491
492
        ////// userID는 관리자 계정인 doftech
493
        ////string markusLink = "kcom://" + MarkusAPI.CreateMarkusParam(projectNo, documentID, userID);
494
        //public static string CreateMarkusParam(string projectNo, string documentID, string userID)
495
        //{
496
        //    ViewInfo viewInfo = new ViewInfo();
497
498
        //    viewInfo.DocumentItemID = documentID;
499
        //    viewInfo.ProjectNO = projectNo;
500
        //    viewInfo.UserID = userID;
501
502
        //    return ParamEncoding(JsonConvert.SerializeObject(viewInfo));
503
504
        //}
505
506
        //public static string ParamEncoding(string EncodingText, System.Text.Encoding oEncoding = null)
507
        //{
508
509
        //    if (oEncoding == null)
510
        //        oEncoding = System.Text.Encoding.UTF8;
511
512
        //    return Convert.ToBase64String(oEncoding.GetBytes(EncodingText));
513
514
        //}
515
516
517
        #endregion
518
519 e6281033 alzkakdixm
        #endregion
520
521
        #region DataBaseByStatusViewModel Function
522 53c9637d taeseongkim
        /// <summary>
523
        /// 전체 컨버터를 가져온다. 비동기로 변경하여야 한다.
524
        /// </summary>
525
        /// <returns></returns>
526 e6281033 alzkakdixm
        public List<Interface.ConvertItem> GetConvertItems(StatusCodeType statusCodeType, Func<CONVERTER_DOC, bool> @where, int takeCount = 100)
527 53c9637d taeseongkim
        {
528
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
529
530 e6281033 alzkakdixm
531
            var items = entities.CONVERTER_DOC.Where(x => x.STATUS == (int)statusCodeType).Take(takeCount).ToList();
532 53c9637d taeseongkim
533
            if (items.Count() > 0)
534
            {
535
                foreach (var item in items)
536
                {
537 06f13e11 taeseongkim
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
538
                    {
539
                        ReConverter = item.RECONVERTER,
540
                        ServiceID = item.SERVICE_ID,
541 2decfbdf alzkakdixm
                        ConvertState = ((StatusCodeType)item.STATUS),
542 06f13e11 taeseongkim
                        CreateTime = item.CREATE_DATETIME,
543
                        TotalPage = item.TOTAL_PAGE,
544
                        CurrentPageNo = item.CURRENT_PAGE,
545
546
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID)
547
                    };
548
549 53c9637d taeseongkim
                    convertItems.Add(convertitem);
550
                }
551
            }
552
            return convertItems;
553
        }
554 e6281033 alzkakdixm
        #endregion
555
556
        #region No 참조 
557 53c9637d taeseongkim
558 0157b158 taeseongkim
        /// <summary>
559 e6281033 alzkakdixm
        /// 컨버터서비스를 이용하는 문서 정보 저장
560
        /// UniqueID
561
        /// using Markus.Service.Extensions;  new Guid().CreateUniqueGuid().ToString();
562 b92f142f taeseongkim
        /// </summary>
563 e6281033 alzkakdixm
        /// <param name="ProjectNo">프로젝트</param>
564
        /// <param name="UniqueID">컨버터 서비스의 아이템 ID</param>
565
        /// <param name="originfilePath"></param>
566
        /// <param name="DocumentID"></param>
567 b92f142f taeseongkim
        /// <returns></returns>
568 e6281033 alzkakdixm
        public bool SetConvertDoc(string ProjectNo, string UniqueID, string originfilePath, string DocumentID)
569 b92f142f taeseongkim
        {
570 e6281033 alzkakdixm
            bool result = false;
571 b92f142f taeseongkim
572 e6281033 alzkakdixm
            if (ProjectNo.IsNullOrEmpty())
573
            {
574
                throw new Exception("ProjectNo is Null");
575
            }
576 60723dc9 taeseongkim
577 e6281033 alzkakdixm
            if (UniqueID.IsNullOrEmpty())
578
            {
579
                throw new Exception("UniqueID is Null");
580
            }
581 b92f142f taeseongkim
582 e6281033 alzkakdixm
            if (originfilePath.IsNullOrEmpty())
583 b92f142f taeseongkim
            {
584 e6281033 alzkakdixm
                throw new Exception("originfilePath is Null");
585
            }
586
587
            if (DocumentID.IsNullOrEmpty())
588
            {
589
                throw new Exception("DocumentID is Null");
590
            }
591
592
            if (DocumentID.IsNullOrEmpty())
593
            {
594
                long _lastDocId = 0;
595
596
                if (entities.CONVERTER_DOC.Count() > 0)
597 b92f142f taeseongkim
                {
598 e6281033 alzkakdixm
                    try
599 b92f142f taeseongkim
                    {
600 e6281033 alzkakdixm
                        string qry = @"SELECT * FROM CONVERTER_DOC order by CAST(DOCUMENT_ID as int) desc";
601
                        var _item = entities.CONVERTER_DOC.SqlQuery(qry).FirstOrDefault();
602 b92f142f taeseongkim
603 e6281033 alzkakdixm
                        if (_item != null)
604
                        {
605
                            _lastDocId = Convert.ToInt64(_item.DOCUMENT_ID) + 1;
606
                        }
607
                    }
608
                    catch (Exception)
609
                    {
610 b92f142f taeseongkim
611 e6281033 alzkakdixm
                        throw;
612
                    }
613 b92f142f taeseongkim
                }
614 e6281033 alzkakdixm
615
                DocumentID = _lastDocId.ToString();
616 b92f142f taeseongkim
            }
617
618 e6281033 alzkakdixm
            CONVERTER_DOC convert_doc = new CONVERTER_DOC
619
            {
620
                ID = UniqueID,
621
                PROJECT_NO = ProjectNo,
622
                DOCUMENT_URL = originfilePath,
623
                DOCUMENT_ID = DocumentID,
624
                CREATE_DATETIME = DateTime.Now,
625
                STATUS = 0,
626
                TOTAL_PAGE = 0,
627
                CURRENT_PAGE = 0,
628
                RECONVERTER = 0
629
            };
630
631
            
632
            entities.CONVERTER_DOC.Add(convert_doc);
633 a6e5055d alzkakdixm
634 e6281033 alzkakdixm
            if (entities.SaveChanges() == 1)
635
            {
636
                result = true;
637
            }
638
639
            return result;
640
        }
641
642
        /// <summary>
643
        /// 컨버터서비스를 이용하는 문서 정보 저장
644
        /// UniqueID
645
        /// using Markus.Service.Extensions;  new Guid().CreateUniqueGuid().ToString();
646
        /// </summary>
647
        /// <param name="ProjectNo">프로젝트</param>
648
        /// <param name="UniqueID">컨버터 서비스의 아이템 ID</param>
649
        /// <param name="originfilePath"></param>
650
        /// <param name="DocumentID"></param>
651
        /// <returns></returns>
652
        public bool SetDocumentInfo(string ConvertID, int totalPage, List<DOCPAGE> pageinfo)
653 2decfbdf alzkakdixm
        {
654 e6281033 alzkakdixm
            bool result = false;
655 2decfbdf alzkakdixm
656 e6281033 alzkakdixm
            var convertDocItems = entities.CONVERTER_DOC.Where(f => f.ID == ConvertID);
657
658
            if (convertDocItems.Count() > 0)
659 a6e5055d alzkakdixm
            {
660 e6281033 alzkakdixm
                var convertDoc = convertDocItems.First();
661
662
                string docId = new Guid().CreateUniqueGuid().ToString();
663
664
                var docinfo = entities.DOCINFO.FirstOrDefault(x => x.PROJECT_NO == convertDoc.PROJECT_NO && x.DOCUMENT_ID == convertDoc.DOCUMENT_ID);
665
                
666
                if (docinfo != null)
667
                {
668
                    // 기존 Docpage 삭제.
669
                    entities.DOCPAGE.RemoveRange(docinfo.DOCPAGE);
670
671
                    // 기존 코멘트 유지를 위한 Docinfo update                    
672
                    docinfo.PROJECT_NO = convertDoc.PROJECT_NO;
673
                    docinfo.ORIGINAL_FILE = convertDoc.DOCUMENT_URL;
674
                    docinfo.PAGE_COUNT = totalPage;                    
675
                    docinfo.DOCPAGE = pageinfo;                    
676
                    entities.SaveChanges();
677
                    result = true;
678
                }
679
                else
680 a6e5055d alzkakdixm
                {
681 e6281033 alzkakdixm
                    DOCINFO instace = new DOCINFO
682 a6e5055d alzkakdixm
                    {
683 e6281033 alzkakdixm
                        ID = docId,
684
                        PROJECT_NO = convertDoc.PROJECT_NO,
685
                        ORIGINAL_FILE = convertDoc.DOCUMENT_URL,
686
                        DOCUMENT_ID = convertDoc.DOCUMENT_ID,
687
                        PAGE_COUNT = totalPage,
688
                        DOCPAGE = pageinfo
689 a6e5055d alzkakdixm
                    };
690
691 e6281033 alzkakdixm
                    entities.DOCINFO.Add(instace);
692
                    var save = entities.SaveChanges();
693
694
                    if (save == pageinfo.Count() + 1)
695
                    {
696
                        result = true;
697
                    }
698 a6e5055d alzkakdixm
                }
699 2decfbdf alzkakdixm
700 e6281033 alzkakdixm
                
701
                
702
            }
703 a6e5055d alzkakdixm
704 e6281033 alzkakdixm
            return result;
705 2decfbdf alzkakdixm
        }
706 e6281033 alzkakdixm
707
        public Interface.ConvertItem GetConvertItem(string ProjectNo, string UniqueID)
708 a6e5055d alzkakdixm
        {
709 e6281033 alzkakdixm
            Interface.ConvertItem result = null;
710 a6e5055d alzkakdixm
711 e6281033 alzkakdixm
            //var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID);
712
            var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == ProjectNo && f.ID == UniqueID);
713
714
            if (items.Count() > 0)
715 2decfbdf alzkakdixm
            {
716 e6281033 alzkakdixm
                var convertItem = items.First();
717 2decfbdf alzkakdixm
718 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);
719 2decfbdf alzkakdixm
720 e6281033 alzkakdixm
                result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath);
721
            }
722 a6e5055d alzkakdixm
723 e6281033 alzkakdixm
            return result;
724
        }
725 2decfbdf alzkakdixm
726 a6e5055d alzkakdixm
727 e6281033 alzkakdixm
        public Interface.ConvertItem GetConvertItembyDocumentID(string ProjectNo, string DocumentID)
728
        {
729
            Interface.ConvertItem result = null;
730
731
            //var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID);
732
            var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == ProjectNo && f.DOCUMENT_ID == DocumentID);
733
734
            if (items.Count() > 0)
735
            {
736
                var convertItem = items.First();
737
                string convertPath = Path.Combine(BaseStorage(convertItem.PROJECT_NO), convertItem.PROJECT_NO + "_Tile", (System.Convert.ToInt64(convertItem.DOCUMENT_ID) / 100).ToString(), convertItem.DOCUMENT_ID);
738
739
                if (convertItem.STATUS == (int)StatusCodeType.Completed)
740
                {
741
                    result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath,
742
                                                        (StatusCodeType)convertItem.STATUS, convertItem.CURRENT_PAGE, convertItem.TOTAL_PAGE, convertItem.EXCEPTION);
743
                }
744
                else
745
                {
746
                    result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath);
747 2decfbdf alzkakdixm
                }
748
            }
749
750 e6281033 alzkakdixm
            return result;
751
        }
752
753
        public List<CONVERTER_DOC> GetConvertingItems(List<string> projectList)
754
        {
755
            var convertWaitingItems = entities.CONVERTER_DOC.OrderBy(x => x.CREATE_DATETIME).Where(
756
                                        x =>
757
                                        projectList.Contains(x.PROJECT_NO) &&
758
                                         (x.STATUS > (int)StatusCodeType.None && x.STATUS < (int)StatusCodeType.Completed) && x.RECONVERTER < 2);
759 2decfbdf alzkakdixm
760 e6281033 alzkakdixm
            return convertWaitingItems.ToList();
761 2decfbdf alzkakdixm
        }
762 e6281033 alzkakdixm
763
        /// <summary>
764
        /// 전체 컨버터를 가져온다. 비동기로 변경하여야 한다.
765
        /// </summary>
766
        /// <returns></returns>
767
        public List<Interface.ConvertItem> GetConvertItems(StatusCodeType statusCodeType)
768 2decfbdf alzkakdixm
        {
769 e6281033 alzkakdixm
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
770 2decfbdf alzkakdixm
771 e6281033 alzkakdixm
            var items = entities.CONVERTER_DOC.Where(x => x.STATUS == (int)statusCodeType).ToList(); //.Where(x => x.PROJECT_NO == gProjectNo);
772
773
            if (items.Count() > 0)
774 a6e5055d alzkakdixm
            {
775 e6281033 alzkakdixm
                foreach (var item in items)
776 a6e5055d alzkakdixm
                {
777 e6281033 alzkakdixm
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
778 a6e5055d alzkakdixm
                    {
779
                        ReConverter = item.RECONVERTER,
780
                        ServiceID = item.SERVICE_ID,
781 e6281033 alzkakdixm
                        ConvertState = ((StatusCodeType)item.STATUS),
782 a6e5055d alzkakdixm
                        CreateTime = item.CREATE_DATETIME,
783
                        TotalPage = item.TOTAL_PAGE,
784
                        CurrentPageNo = item.CURRENT_PAGE,
785
786 e6281033 alzkakdixm
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID)
787 2decfbdf alzkakdixm
                    };
788 e6281033 alzkakdixm
789
790
                    convertItems.Add(convertitem);
791 a6e5055d alzkakdixm
                }
792
            }
793 e6281033 alzkakdixm
            return convertItems;
794 a6e5055d alzkakdixm
        }
795
796
        public List<Interface.ConvertItem> GetConvertProjectsStatus(Func<CONVERTER_DOC, bool> @where)
797
        {
798
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
799
800
801
            //var items = entities.CONVERTER_DOC.Where(x => x.STATUS == (int)statusCodeType).Take(takeCount).ToList(); //.Where(x => x.PROJECT_NO == gProjectNo);
802 e6281033 alzkakdixm
            var items = entities.CONVERTER_DOC.Where(x => x.STATUS <= 4);
803 a6e5055d alzkakdixm
804
            if (items.Count() > 0)
805
            {
806
                foreach (var item in items)
807
                {
808
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL)
809
                    {
810
                        ReConverter = item.RECONVERTER,
811
                        ServiceID = item.SERVICE_ID,
812
                        //ConvertState = ((StatusCodeType)item.STATUS).ToString(),
813 2decfbdf alzkakdixm
                        //ConvertState = (item.STATUS).ToString(),
814
                        ConvertState = (StatusCodeType)item.STATUS,
815 a6e5055d alzkakdixm
                        CreateTime = item.CREATE_DATETIME,
816
                        TotalPage = item.TOTAL_PAGE,
817
                        CurrentPageNo = item.CURRENT_PAGE,
818
                        Exception = item.EXCEPTION,
819
                        ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID)
820
                    };
821
822
823
                    convertItems.Add(convertitem);
824
                }
825
            }
826
827
            return convertItems;
828
        }
829
830 b92f142f taeseongkim
831 e6281033 alzkakdixm
        public bool SetConvertState(string ServiceID, string UniqueID, int State, int CurrentPage, int TotalPage, string Error)
832 53c9637d taeseongkim
        {
833
            bool result = false;
834
835
            try
836
            {
837
                var items = entities.CONVERTER_DOC.SingleOrDefault(f => f.ID == UniqueID);
838
                //var items = entities.CONVERTER_DOC.SingleOrDefault(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID);
839
840
                if (items != null)
841
                {
842 0157b158 taeseongkim
                    items.SERVICE_ID = ServiceID;
843 53c9637d taeseongkim
                    items.STATUS = State;
844
                    items.CURRENT_PAGE = CurrentPage;
845
                    items.TOTAL_PAGE = TotalPage;
846
847
                    StatusCodeType statusCode = (StatusCodeType)State;
848
849 65fbe3cb taeseongkim
                    if (items.START_DATETIME == null)
850 a8f1a865 taeseongkim
                    {
851
                        items.START_DATETIME = DateTime.Now;
852
                    }
853
854 53c9637d taeseongkim
                    switch (statusCode)
855
                    {
856
                        case StatusCodeType.None:
857
                            break;
858
                        case StatusCodeType.Wait:
859
                            items.START_DATETIME = DateTime.Now;
860
                            break;
861
                        case StatusCodeType.PageLoading:
862
                            break;
863
                        case StatusCodeType.Saving:
864
                            break;
865
                        case StatusCodeType.Completed:
866 a0341bef taeseongkim
                            items.CURRENT_PAGE = items.TOTAL_PAGE;
867 e6281033 alzkakdixm
                            items.END_DATETIME = DateTime.Now;
868 53c9637d taeseongkim
                            break;
869
                        case StatusCodeType.FileError:
870
                            Error = $" file Error :" + Error;
871
                            items.END_DATETIME = DateTime.Now;
872
                            break;
873
                        case StatusCodeType.PageError:
874
                            Error = $" Page No {CurrentPage} Error :" + Error;
875
                            break;
876
                        case StatusCodeType.NeedsPassword:
877
                            break;
878
                        case StatusCodeType.Error:
879
                            Error = $" Error :" + Error;
880
                            items.END_DATETIME = DateTime.Now;
881
                            break;
882
                        default:
883
                            break;
884
                    }
885
886 e6281033 alzkakdixm
                    if (items.EXCEPTION == null)
887 53c9637d taeseongkim
                    {
888
                        items.EXCEPTION = "";
889
                    }
890
891
                    if (items.EXCEPTION.Length < 255)
892
                    {
893
                        items.EXCEPTION = items.EXCEPTION + Error;
894
                    }
895
896
                    entities.SaveChanges();
897
                    result = true;
898
                }
899
            }
900
            catch (Exception ex)
901
            {
902 e6281033 alzkakdixm
                throw new Exception("SetConvertState", ex);
903 53c9637d taeseongkim
            }
904
905
            return result;
906
        }
907
908 e6281033 alzkakdixm
        public SERVICE_PROPERTIES GetServiceProperties(string ServiceID)
909 53c9637d taeseongkim
        {
910 e6281033 alzkakdixm
            SERVICE_PROPERTIES result = null;
911 53c9637d taeseongkim
912 e6281033 alzkakdixm
            var items = entities.SERVICE_PROPERTIES.Where(x => x.ID == ServiceID);
913 53c9637d taeseongkim
914 e6281033 alzkakdixm
            if (items.Count() > 0)
915 53c9637d taeseongkim
            {
916 e6281033 alzkakdixm
                result = items.First();
917 53c9637d taeseongkim
            }
918
919
            return result;
920
        }
921
922 e6281033 alzkakdixm
923
        /// <summary>
924
        /// 현재 서비스에서 컨버터중인 아이템.
925
        /// </summary>
926
        /// <returns></returns>
927
        public List<Interface.ConvertItem> GetServiceAliveItems(string ServiceID)
928
        {
929
            List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();
930
931
            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);
932
933
            if (items.Count() > 0)
934
            {
935
                foreach (var item in items)
936
                {
937
                    var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL);
938
                    convertItems.Add(convertitem);
939
                }
940
            }
941
            return convertItems;
942
        }
943
944
        #endregion
945
946 53c9637d taeseongkim
    }
947
}
클립보드 이미지 추가 (최대 크기: 500 MB)