프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.DataBase / ConvertDatabase.cs @ 8c7d1ea1

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

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