프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.DataBase / ConvertDatabase.cs @ 902f397c

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