프로젝트

일반

사용자정보

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

markus / MarkusLogview / MARKUS_LOGVIEW / Controllers / ConvertAPIController.cs @ 9eb27750

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

1
using IKCOM;
2
using MARKUS_LOGVIEW.Common;
3
using MarkusDataModel.Common;
4
using MarkusDataModel.DataModel;
5
using MarkusDataModel.DTOs;
6
using System;
7
using System.Collections.Generic;
8
using System.IO;
9
using System.Linq;
10
using System.Net;
11
using System.Net.Http;
12
using System.Net.Http.Headers;
13
using System.Threading.Tasks;
14
using System.Web;
15
using System.Web.Http;
16
using System.Web.Services;
17
using static ServiceInterface.LogView_Interface;
18

    
19
namespace MARKUS_LOGVIEW.Controllers
20
{
21
    
22
    public class ConvertAPIController : ApiController
23
    {
24

    
25
        /// <summary>
26
        /// 컨버팅 데이블 데이터 반환 
27
        /// </summary>
28
        /// <param name="filter"></param>
29
        /// <returns></returns>
30
        [HttpPost, Route("~/api/project/GetConvertDocument")]
31
        public async Task<ConvertTableData> GetConvertDocument([FromBody] DataTableParameters filter)
32
        {
33
            #region Convert Table data 반환 
34
            ConvertTableData dto = new ConvertTableData();
35
            List<TableData_Convert> tableData = new List<TableData_Convert>();
36

    
37
            DateTime prjDocStartDate = Convert.ToDateTime(filter.startDate);
38
            DateTime prjDocEndDate = Convert.ToDateTime(filter.endDate).AddHours(23).AddMinutes(59).AddSeconds(59);
39

    
40
            if (!AuthorizationController.UserAuthorization(Request.Headers.Authorization.ToString()))
41
            {
42
                dto.statusCode = 403;
43
                return dto;
44
            }
45
            else
46
            {
47

    
48
                try
49
                {
50

    
51
                    string token = Request.Headers.Authorization.ToString();
52

    
53
                    using (markusEntities ent = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString()))
54
                    {
55

    
56
                        var convDocList = ent.CONVERTER_DOC
57
                               .Where(
58
                            cd => cd.CREATE_DATETIME >= prjDocStartDate &&
59
                            cd.CREATE_DATETIME <= prjDocEndDate &&
60
                            cd.PROJECT_NO == filter.projectNo &&
61
                            (string.IsNullOrEmpty(filter.Search.Value)) ? string.IsNullOrEmpty(filter.Search.Value) : cd.DOCUMENT_ID.Contains(filter.Search.Value)
62
                            )
63
                               .OrderByDescending(t => t.CREATE_DATETIME)
64
                               .ToList();
65

    
66
                        if (convDocList.Count > 0)
67
                        {
68

    
69
                            int count = convDocList.Count;
70
                            int index = filter.start;
71

    
72
                            var limitList = convDocList.Skip(filter.start).Take(filter.Length).ToList();
73

    
74
                            limitList.ForEach(ret =>
75
                            {
76
                                try
77
                                {
78
                                    string deleteDocument = "<input type=\"checkbox\" name=\"deleteDocument[]\" value=\"" + ret.DOCUMENT_ID + "\" />";
79
                                    string openMarkusURL = "<a href=\"kcom://" + CommonController.CreateMarkusParam(ret.PROJECT_NO, ret.DOCUMENT_ID, token) + "\">open</a>";
80
                                    string interfaceID = string.Empty;
81
                                    string documentURL = string.Empty;
82
                                    string message = string.Empty;
83
                                    var dOCUMENT_ITEMs = ent.DOCUMENT_ITEM.Where(d => d.DOCUMENT_ID == ret.DOCUMENT_ID).FirstOrDefault();
84

    
85
                                    if (dOCUMENT_ITEMs != null) {
86
                                        interfaceID = dOCUMENT_ITEMs.DOCUMENT_ID;
87
                                    }
88
                                    else {
89
                                        message = string.Format("{0}의 DOCUMENT_ITEM이 존재하지 않습니다.", ret.DOCUMENT_ID);
90
                                    }
91

    
92
                                    string status = CommonController.GetStatusName(ret.STATUS);
93

    
94
                                    if (ret.DOCUMENT_URL != null) {
95
                                        documentURL = "<a href=\"" + ret.DOCUMENT_URL + "\" target=\"_blank\">PDF</a>";
96
                                    }
97

    
98
                                    tableData.Add(new TableData_Convert()
99
                                    {
100
                                        ID = ret.ID,
101
                                        DeleteDocument = deleteDocument,
102
                                        OpenMarkusURL = openMarkusURL,
103
                                        DocumentID = ret.DOCUMENT_ID,
104
                                        InterfaceID = interfaceID,
105
                                        CurrentPage = ret.CURRENT_PAGE,
106
                                        TotalPage = ret.TOTAL_PAGE,
107
                                        CreateDate = ret.CREATE_DATETIME,
108
                                        StartDateTime = ret.START_DATETIME,
109
                                        EndDateTime = ret.END_DATETIME,
110
                                        ConvertTime = null,
111
                                        Status = status,
112
                                        DocumentURL = documentURL,
113
                                        Message = message
114
                                    });
115

    
116
                                }
117
                                catch (Exception ex)
118
                                {
119

    
120
                                    throw ex;
121
                                }
122
                            });
123

    
124
                            dto.draw = filter.Draw;
125
                            dto.recordsTotal = count;
126
                            dto.recordsFiltered = count;
127
                            dto.length = filter.Length;
128
                            dto.data = tableData;
129

    
130
                            return dto;
131

    
132
                        }
133
                        else
134
                        {
135
                            dto.draw = filter.Draw;
136
                            dto.recordsFiltered = 0;
137
                            dto.recordsTotal = 0;
138
                            dto.length = 0;
139
                            dto.data = new List<TableData_Convert>();
140

    
141
                            return dto;
142

    
143
                        }
144

    
145

    
146
                    }
147

    
148
                }
149
                catch (Exception ex)
150
                {
151
                    dto.statusCode = 500;
152
                    return dto;
153
                }
154

    
155
            }
156
            #endregion
157
        }
158

    
159
        /// <summary>
160
        /// Get Revision Document List 
161
        /// </summary>
162
        /// <param name="param"></param>
163
        /// <returns></returns>
164
        [HttpPost,Route("~/api/GetDocumentItemList")]
165
        public async Task<HttpResponseMessage> GetDocumentItemList(pGetDocumentItemList param)
166
        {
167
            #region 해당 프로젝트의 DocumentItem 가져오기 ( 파일 업로드 시 - 리비전 업 ) 
168
            HttpResponseMessage resp = new HttpResponseMessage();
169
            List<DocumentItemInfoList> docItemList = new List<DocumentItemInfoList>();
170

    
171
            if (!AuthorizationController.UserAuthorization(Request.Headers.Authorization.ToString()))
172
            {
173
                return CommonController.Forbidden(resp);
174
            }
175
            else
176
            {
177
                try
178
                {
179

    
180
                    using (markusEntities entity = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString()))
181
                    {
182

    
183
                        var docItems = entity.DOCUMENT_ITEM
184
                            .Where(doc => doc.PROJECT_NO.Equals(param.ProjectNO))
185
                            .GroupBy(g => g.DOCUMENT_NO, (key, docNO) => docNO.FirstOrDefault())
186
                            .Select(ret => new DocumentItemInfoList()
187
                            {
188
                                DocumentItemNO = ret.DOCUMENT_NO,
189
                                DocumentItemID = ret.DOCUMENT_ID,
190
                                DocumentItemName = ret.DOCUMENT_NAME
191

    
192
                            }).ToList();
193

    
194
                        if (docItems.Count > 0)
195
                        {
196
                            resp = await CommonController.OK<List<DocumentItemInfoList>>(resp, docItems);
197
                        }
198
                        else
199
                        {
200
                            resp = await CommonController.NotFound<pGetDocumentItemList>(resp, new pGetDocumentItemList()
201
                            {
202
                                ProjectNO = param.ProjectNO
203
                            });
204
                        }
205

    
206
                        return resp;
207
                    }
208
                }
209
                catch (Exception ex)
210
                {
211
                    resp = CommonController.InternalServerError(resp, ex.Message);
212
                    return resp;
213
                }
214
            }
215
            #endregion
216
        }
217

    
218
        /// <summary>
219
        /// Get Document Message and Original URL 
220
        /// </summary>
221
        /// <param name="pDocInfo"></param>
222
        /// <returns></returns>
223
        [HttpPost,Route("~/api/convert/GetDocumentMessage")]
224
        public async Task<HttpResponseMessage> GetDocumentItemMessage([FromBody] pDocumentMessage pDocInfo)
225
        {
226
            #region 도큐먼트 Message, Original URL 가져오기 
227
            HttpResponseMessage resp = new HttpResponseMessage();
228

    
229
            if (!AuthorizationController.UserAuthorization(Request.Headers.Authorization.ToString()))
230
            {
231
                return CommonController.Forbidden(resp);
232
            }
233
            else
234
            {
235
                try
236
                {
237

    
238
                    ViewInfo getDocument = CommonController.ParamDecoding(pDocInfo.pDocumentInfo);
239

    
240
                    using (markusEntities ent = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString()))
241
                    {
242

    
243
                        var convMessage = ent.CONVERTER_DOC.Where(cd => cd.DOCUMENT_ID == getDocument.DocumentItemID).Select(ret => ret.EXCEPTION).FirstOrDefault();
244

    
245
                        DocumentMessage docMessage = ent.DOCUMENT_ITEM
246
                            .Where(di => di.DOCUMENT_ID == getDocument.DocumentItemID)
247
                            .Select(ret => new DocumentMessage()
248
                            {
249
                                OriginalURL = ret.ORIGINAL_FILE,
250
                                Message = (convMessage == null) ? "DocumentItemID의 " +getDocument.DocumentItemID + "의 CONVERTER_DOC가 존재하지 않습니다." 
251
                                                    :  (convMessage.Length == 0) ? "No Message" : convMessage
252
                            })
253
                            .FirstOrDefault();
254

    
255
                        return await CommonController.OK<DocumentMessage>(resp, docMessage);
256

    
257

    
258
                    }
259

    
260
                }
261
                catch (Exception ex)
262
                {
263

    
264
                    Console.WriteLine(ex.Message);
265
                    throw ex;
266

    
267
                }
268
            }
269
            #endregion
270
        }
271

    
272
        /// <summary>
273
        /// Upload PDF File 
274
        /// </summary>
275
        private string folder_increaseNumber;
276
        [HttpPost]
277
        [Route("~/api/pdf/upload")]
278
        public async Task<HttpResponseMessage> UploadFile()
279
        {
280
            #region 파일 리비전 메서드
281
            int uploadType = 0;
282
            string initFolderName = "40000000";
283

    
284
            // 파일 저장 경로 
285
            // Web Server 000000_app/VPCS_DOCLIB/
286
            string serverPath = "../../Doc_Manager/";
287
            string originalFileDefaultURL = "/Doc_Manager/";
288

    
289
            // Local Test
290
            //string serverPath = "/pdfUpload/";
291
            //string originalFileDefaultURL = "/pdfUpload/";
292

    
293
            HttpResponseMessage resp = new HttpResponseMessage();
294
            DocumentItemDTO revDoc = new DocumentItemDTO();
295

    
296
            if (!AuthorizationController.UserAuthorization(Request.Headers.Authorization.ToString()))
297
            {
298
                return CommonController.Forbidden(resp);
299
            }
300
            else
301
            {
302

    
303
                if (!Request.Content.IsMimeMultipartContent())
304
                {
305
                    throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
306
                }
307

    
308
                try
309
                {
310

    
311
                    string defaultSaveFilePath = HttpContext.Current.Server.MapPath(serverPath);
312

    
313
                    if (!Directory.Exists(defaultSaveFilePath))
314
                    {
315
                        Directory.CreateDirectory(defaultSaveFilePath);
316
                    }
317

    
318

    
319
                    var provider = new MultipartFormDataStreamProvider(HttpContext.Current.Server.MapPath(serverPath));
320

    
321
                    await Request.Content.ReadAsMultipartAsync(provider);
322

    
323
                    foreach (var key in provider.FormData.AllKeys)
324
                    {
325
                        foreach (var val in provider.FormData.GetValues(key))
326
                        {
327

    
328
                            switch (key)
329
                            {
330
                                case "ProjectNO":
331
                                    revDoc.ProjectNO = val;
332
                                    break;
333
                                case "DocumentID":
334
                                    revDoc.DocumentID = (val != "") ? val : null;
335
                                    break;
336
                                case "DocumentName":
337
                                    revDoc.DocumentName = (val != "") ? val : null;
338
                                    break;
339
                                case "DocumentNO":
340
                                    revDoc.DocumentNO = (val != "") ? val : null;
341
                                    break;
342
                                case "UploadType":
343
                                    uploadType = Convert.ToInt32(val);
344
                                    break;
345

    
346
                            }
347

    
348
                        }
349

    
350
                    }
351

    
352
                    string storagePath = HttpContext.Current.Server.MapPath(serverPath);
353
                    storagePath = storagePath + revDoc.ProjectNO + "_app/VPCS_DOCLIB/";
354
                    // 해당 폴더가 없으면  +  initFolderName
355
                    if (!Directory.Exists(storagePath + initFolderName))
356
                    {
357
                        // 폴더 생성 
358
                        storagePath += initFolderName;
359
                        Directory.CreateDirectory(storagePath);
360

    
361
                    }
362
                    else
363
                    {
364
                        // 폴더 정보를 가져와서 내림차순으로 정렬
365
                        DirectoryInfo[] dicInfo = new DirectoryInfo(storagePath).GetDirectories();
366
                        Array.Sort(dicInfo, (x, y) => y.Name.CompareTo(x.Name));
367

    
368
                        // 저장경로에 폴더명 가져오기 ( 제일 높은 숫자의 폴더명 + 1 하여 폴더 생성 ) 
369
                        folder_increaseNumber = (Convert.ToInt32(dicInfo[0].Name) + 1).ToString();
370
                        storagePath += folder_increaseNumber;
371

    
372
                        Directory.CreateDirectory(storagePath);
373

    
374
                    }
375

    
376
                    // project revision setting 가져오기 
377
                    string strRevision;
378
                    using (markusEntities entity = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString()))
379
                    {
380
                        strRevision = entity.PROJECT_SETTING.Where(ps => ps.PROJECT_NO.Equals(revDoc.ProjectNO)).Select(ret => ret.REVISION).FirstOrDefault();
381

    
382

    
383
                        // 리비전 업을 또는 생성을 위한 로직 
384
                        // GroupNo은 해당 프로젝트의 GroupNo 의 마지막 값에서 증가.
385
                        var grouping = entity.DOCUMENT_ITEM.Where(di => di.PROJECT_NO.Equals(revDoc.ProjectNO)).ToList();
386

    
387
                        if (grouping.Count() > 0)
388
                        {
389

    
390
                            string descGroupNo = entity.DOCUMENT_ITEM.Where(di => di.PROJECT_NO.Equals(revDoc.ProjectNO)).OrderByDescending(x => x.GROUP_NO).Select(ret => ret).ToList().First().GROUP_NO;
391
                            revDoc.GroupNO = (Int32.Parse(descGroupNo) + 1).ToString();
392

    
393
                        }
394
                        else
395
                        {
396
                            revDoc.GroupNO = "1";
397
                        }
398

    
399
                        if (uploadType == (int)UPLOAD_TYPE.NEWDOCUMENT)
400
                        {
401
                            // 새로운 리비전 파라미터 DocumentItemNO, DocumentItemName
402
                            // 해당 이름이 먼저 있는지 체크를 해야함. 
403
                            var checkDocumentItem = entity.DOCUMENT_ITEM.Where(di => di.DOCUMENT_NO.Equals(revDoc.DocumentNO) && di.PROJECT_NO == revDoc.ProjectNO).ToList();
404

    
405
                            if (checkDocumentItem.Count > 0)
406
                            {
407

    
408
                                resp.StatusCode = HttpStatusCode.InternalServerError;
409
                                resp.Content = await CommonController.JsonSerialize<string>("The same document number exists");
410

    
411
                                return resp;
412

    
413
                            }
414
                            else
415
                            {
416
                                revDoc.Revision = strRevision.Split(',')[0].ToString();
417
                            }
418
                        }
419
                        else if (uploadType == (int)UPLOAD_TYPE.REVISIONUP)
420
                        {
421

    
422
                            // 기존 리비전 업 파라미터 DocumentItemNO
423
                            var selectedDocumentItem = entity.DOCUMENT_ITEM
424
                                .Where(di => di.DOCUMENT_ID.Equals(revDoc.DocumentID))
425
                                .OrderByDescending(x => x.REVISION)
426
                                .Select(ret => ret)
427
                                .ToList();
428

    
429
                            if (selectedDocumentItem.Count > 0)
430
                            {
431

    
432
                                var getDocument = selectedDocumentItem.First();
433
                                if (strRevision.Split(',').Last() == getDocument.REVISION)
434
                                {
435
                                    resp.StatusCode = HttpStatusCode.InternalServerError;
436
                                    resp.Content = await CommonController.JsonSerialize<string>("Can not make any more revisions.");
437

    
438
                                    return resp;
439
                                }
440
                                else
441
                                {
442
                                    revDoc.Revision = ((char)(Convert.ToInt32((getDocument.REVISION.ToCharArray()[0])) + 1)).ToString();
443
                                    revDoc.DocumentName = getDocument.DOCUMENT_NAME;
444
                                }
445

    
446
                                revDoc.DocumentNO = getDocument.DOCUMENT_NO;
447

    
448
                            }
449

    
450
                        }
451
                        else
452
                        {
453

    
454
                            resp.StatusCode = HttpStatusCode.InternalServerError;
455
                            resp.Content = await CommonController.JsonSerialize<string>("PDF File Upload Error");
456

    
457
                            return resp;
458

    
459
                        }
460

    
461
                    }
462

    
463
                    MultipartFileData fileData = provider.FileData[0];
464

    
465
                    if (string.IsNullOrEmpty(fileData.Headers.ContentDisposition.FileName))
466
                    {
467
                        // type이 다르다.
468
                    }
469

    
470
                    if (string.IsNullOrEmpty(fileData.Headers.ContentDisposition.FileName))
471
                    {
472
                        return Request.CreateResponse(HttpStatusCode.NotAcceptable, "This request is not properly formatted");
473
                    }
474
                    string fileName = fileData.Headers.ContentDisposition.FileName;
475
                    if (fileName.StartsWith("\"") && fileName.EndsWith("\""))
476
                    {
477
                        fileName = fileName.Trim('"');
478
                    }
479
                    if (fileName.Contains(@"/") || fileName.Contains(@"\"))
480
                    {
481
                        fileName = Path.GetFileName(fileName);
482
                    }
483

    
484
                    // 파일 저장 
485
                    File.Move(fileData.LocalFileName, Path.Combine(storagePath, fileName));
486

    
487
                    // 파일 저장을 성공하면 ConvertWebService 로 전송
488
                    using (ConvertWebService.Conversion convertService = new ConvertWebService.Conversion())
489
                    {
490

    
491

    
492
                        revDoc.DocumentID = (folder_increaseNumber != null) ? folder_increaseNumber : initFolderName;
493
                        revDoc.OriginalFile = "http://" + Request.Headers.Host + originalFileDefaultURL + revDoc.ProjectNO + "_app/VPCS_DOCLIB/" + revDoc.DocumentID + "/" + fileName;
494
                        revDoc.ID = CommonController.shortGuid();
495

    
496
                        // 디비에 저장 
497
                        using (markusEntities entity = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString()))
498
                        {
499

    
500
                            entity.DOCUMENT_ITEM.AddObject(new DOCUMENT_ITEM()
501
                            {
502
                                ID = revDoc.ID,
503
                                REVISION = revDoc.Revision,
504
                                DOCUMENT_NO = revDoc.DocumentNO,
505
                                DOCUMENT_NAME = revDoc.DocumentName,
506
                                GROUP_NO = revDoc.GroupNO,
507
                                ORIGINAL_FILE = revDoc.OriginalFile,
508
                                DOCUMENT_ID = revDoc.DocumentID,
509
                                PROJECT_NO = revDoc.ProjectNO
510
                            });
511

    
512
                            entity.SaveChanges();
513

    
514
                        }
515

    
516

    
517
                        // 웹 서비스 호출 ( 컨버팅 서비스 호출 ) 
518
                        //convertService.Run(revDoc.ProjectNO, revDoc.OriginalFile, revDoc.DocumentID);
519

    
520
                        resp.StatusCode = HttpStatusCode.OK;
521
                        resp.Content = await CommonController.JsonSerialize<string>("Upload Success");
522

    
523
                    }
524

    
525
                    return resp;
526

    
527

    
528

    
529
                }
530
                catch (Exception ex)
531
                {
532

    
533
                    Console.WriteLine(ex.Message);
534
                    resp.StatusCode = HttpStatusCode.InternalServerError;
535
                    resp.Content = await CommonController.JsonSerialize<string>("Upload Failed");
536

    
537
                    return resp;
538

    
539
                }
540

    
541
            }
542
            #endregion
543
        }
544

    
545
        /// <summary>
546
        /// Update Complete Convert Documnet URL, ViewInfo 
547
        /// </summary>
548
        /// <param name="pComplete"></param>
549
        /// <returns></returns>
550
        [HttpPost, Route("~/api/convert/complete")]
551
        public async Task<HttpResponseMessage> Complete(CONVERTER_DOC pComplete)
552
        {
553
            #region 컨버팅이 완료되면 ConvertURL , ViewInfo 데이터 생성
554
            HttpResponseMessage resp = new HttpResponseMessage();
555
            CompleteConvertDTO completeInfo = new CompleteConvertDTO();
556

    
557
            if (!AuthorizationController.UserAuthorization(Request.Headers.Authorization.ToString()))
558
            {
559
                return CommonController.Forbidden(resp);
560
            }
561
            else
562
            {
563

    
564
                using (markusEntities entity = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString()))
565
                {
566

    
567
                    var convertDocument = entity.CONVERTER_DOC.Where(doc => doc.PROJECT_NO == pComplete.PROJECT_NO && doc.ID == pComplete.ID).FirstOrDefault();
568
                    if (convertDocument != null)
569
                    {
570

    
571
                        completeInfo = new CompleteConvertDTO()
572
                        {
573
                            ID = convertDocument.ID,
574
                            ConvertURL = convertDocument.DOCUMENT_URL.ToString(),
575
                            ViewInfo = CommonController.CreateMarkusParam(convertDocument.PROJECT_NO, convertDocument.DOCUMENT_ID, Request.Headers.Authorization.ToString())
576
                        };
577

    
578
                        resp = await CommonController.OK<CompleteConvertDTO>(resp, completeInfo);
579

    
580
                    }
581
                    else
582
                    {
583
                        resp = await CommonController.NotFound<CompleteConvertDTO>(resp, completeInfo);
584
                    }
585

    
586
                }
587

    
588
            }
589

    
590
            return resp;
591

    
592
            #endregion
593
        }
594

    
595
        /// <summary>
596
        /// 컨버팅 재시작
597
        /// </summary>
598
        /// <param name="doc"></param>
599
        /// <returns></returns>
600
        [HttpPost, Route("~/api/retry/convert")]
601
        public async Task<HttpResponseMessage> Reconvert([FromBody] pRetryDocument doc)
602
        {
603
            HttpResponseMessage resp = new HttpResponseMessage();
604

    
605
            if (doc.documentID == null)
606
            {
607
                return await CommonController.NotFound<string>(resp, "호출된 문서의 Id값이  Null 입니다.");
608
            }
609

    
610
            #region 컨버팅 재시작 
611

    
612
            if (!AuthorizationController.UserAuthorization(Request.Headers.Authorization.ToString()))
613
            {
614
                return CommonController.Forbidden(resp);
615
            }
616
            else
617
            {
618
                
619

    
620
                try
621
                {
622
                    using (markusEntities ent = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString()))
623
                    {
624
                        if (!doc.isAllDocuments)
625
                        {
626
                            //Each Convert
627
                            for (int i = 0; i < doc.documentID.Count(); i++)
628
                            {
629
                                string targetDocumentID = doc.documentID[i].ToString();
630

    
631
                                var targetDocument = ent.CONVERTER_DOC.Where(di => di.PROJECT_NO == doc.projectNO && di.DOCUMENT_ID == targetDocumentID).FirstOrDefault();
632

    
633
                                if (targetDocument != null)
634
                                {
635
                                    targetDocument.STATUS = (int)PDFStatus.Insert;
636
                                    targetDocument.RECONVERTER = 0;
637
                                    ent.SaveChanges();
638
                                    //웹 서비스 구문
639
                                    //using (ConvertWebService.Conversion convertService = new ConvertWebService.Conversion())
640
                                    //{
641
                                    //    convertService.ConvertRun(targetDocument.REVISION, targetDocument.DOCUMENT_NO, targetDocument.DOCUMENT_NAME, targetDocument.GROUP_NO, targetDocument.PROJECT_NO, targetDocument.ID, targetDocument.ORIGINAL_FILE);
642
                                    //}                                
643
                                }
644
                                else
645
                                {
646
                                    return await CommonController.NotFound<string>(resp, "Not found");
647
                                }
648

    
649
                            }
650
                        }
651
                        else
652
                        {
653
                            //All Convert
654
                            var targetDocuments = ent.CONVERTER_DOC.Where(di => di.PROJECT_NO == doc.projectNO &&
655
                                                                                    di.CREATE_DATETIME >= doc.startDate &&
656
                                                                                        di.CREATE_DATETIME <= doc.endDate);
657
                            foreach (var item in targetDocuments)
658
                            {
659
                                item.STATUS = (int)PDFStatus.Insert;
660
                                item.RECONVERTER = 0;
661
                                ent.SaveChanges();
662
                            }
663
                        }
664

    
665
                        return await CommonController.OK<bool>(resp, true);
666

    
667
                    }
668

    
669
                }
670
                catch (Exception ex)
671
                {
672
                    Console.WriteLine(ex.Message);
673
                    return CommonController.InternalServerError(resp, "server error");
674
                    throw;
675
                }
676

    
677
            }
678

    
679
            #endregion
680
        }
681

    
682
        /// <summary>
683
        /// 컨버팅 재시작
684
        /// </summary>
685
        /// <param name="doc"></param>
686
        /// <returns></returns>
687
        [HttpPost, Route("~/api/retry/coverconvert")]
688
        public async Task<HttpResponseMessage> Coverconvert([FromBody] pRetryDocument doc)
689
        {
690
            #region 커버컨버팅
691

    
692
            HttpResponseMessage resp = new HttpResponseMessage();
693

    
694
            if (!AuthorizationController.UserAuthorization(Request.Headers.Authorization.ToString()))
695
            {
696
                return CommonController.Forbidden(resp);
697
            }
698
            else
699
            {
700
                try
701
                {
702
                    using (markusEntities ent = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString()))
703
                    {
704
                        // 웹 서비스 호출 ( 컨버팅 서비스 호출 ) 
705
                        var documentCount = doc.documentID.Count();
706

    
707
                        for (int i = 0; i < documentCount; i++)
708
                        {
709

    
710
                            // 선택한 도큐먼트 아이디를 통해 정보 찾기 
711
                            string targetDocumentID = doc.documentID[i].ToString();
712
                            // DOCUMENT_ITEM 에서 찾는 이유는 오리지널 파일 URL 을 찾기 위해서이다.
713
                            var targetDocument = ent.CONVERTER_DOC.Where(di => di.PROJECT_NO == doc.projectNO && di.DOCUMENT_ID == targetDocumentID).FirstOrDefault();
714

    
715
                            if (targetDocument != null)
716
                            {
717
                                using (ConvertWebService.Conversion convertService = new ConvertWebService.Conversion())
718
                                {
719
                                    convertService.CoverConvert(targetDocument.PROJECT_NO, targetDocument.ID);// (targetDocument.REVISION, targetDocument.DOCUMENT_NO, targetDocument.DOCUMENT_NAME, targetDocument.GROUP_NO, targetDocument.PROJECT_NO, targetDocument.ID, targetDocument.ORIGINAL_FILE);
720
                                }
721

    
722
                            }
723
                            else
724
                            {
725
                                return await CommonController.NotFound<string>(resp, "Not found");
726
                            }
727

    
728
                        }
729

    
730
                        return await CommonController.OK<bool>(resp, true);
731

    
732
                    }
733

    
734
                }
735
                catch (Exception ex)
736
                {
737
                    Console.WriteLine(ex.Message);
738
                    return CommonController.InternalServerError(resp, "server error");
739
                    throw;
740
                }
741

    
742
            }
743

    
744
            #endregion
745
        }
746
    }
747

    
748
}
클립보드 이미지 추가 (최대 크기: 500 MB)