프로젝트

일반

사용자정보

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

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

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