프로젝트

일반

사용자정보

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

markus / ConvertionWebServiceDefault / Conversion.asmx.cs @ d21e9c15

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

1
using IConverterPDF;
2
using KCOMDataModel.DataModel;
3
using KCOMDataModel.Common;
4
using log4net;
5
using Newtonsoft.Json.Linq;
6
using System;
7
using System.IO;
8
using System.Linq;
9
using System.Runtime.Remoting.Channels;
10
using System.Runtime.Remoting.Channels.Tcp;
11
using System.Text;
12
using System.Web;
13
using System.Web.Services;
14

    
15
namespace ConvertionWebService
16
{
17
    /// <summary>
18
    /// Summary description for Conversio
19
    /// </summary>
20
    [WebService(Namespace = "http://tempuri.org/")]
21
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
22
    [System.ComponentModel.ToolboxItem(false)]
23
    public class Conversion : System.Web.Services.WebService
24
    {
25

    
26
        RemConverterPDFObject remObj = null;
27
        protected ILog logger = LogManager.GetLogger(typeof(Conversion));
28
        public Conversion()
29
        {
30
            try
31
            {
32
                System.Runtime.Remoting.Channels.IChannel _ch = ChannelServices.GetChannel("tcp");
33

    
34
                if(_ch == null)
35
                {
36
                    TcpChannel chan = new TcpChannel();
37
                    ChannelServices.RegisterChannel(chan, false);
38
                }
39
                // Create an instance of the remote object
40
                remObj = (RemConverterPDFObject)Activator.GetObject(typeof(RemConverterPDFObject),
41
                                                            Properties.Settings.Default.ConverterRemotingUrl);
42

    
43
            }
44
            catch (Exception ex)
45
            {
46
                logger.Error("Conversion Web Service Conversion Error", ex);
47
                SendNotice(ex.ToString());
48
            }
49
        }
50

    
51
        private void SendNotice(string ex)
52
        {
53
            if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.ErrorNoticeID))
54
            {
55
                var _lstID = Properties.Settings.Default.ErrorNoticeID.Split(';').ToList();
56
                //EmailClient.EmailClient _client = new EmailClient.EmailClient(_lstID.First());
57
                StringBuilder _bl = new StringBuilder();
58
                _bl.AppendLine("Conversion Web Service Error");
59
                _bl.AppendLine(ex);
60
                //var _emailResult = _client.SendEmail(_lstID, _lstID, "<Conversion Web Service Error>", _bl.ToString(), false);
61
            }
62
            else
63
            {
64
                logger.Error("Conversion Web Service Error",new Exception(ex));
65
            }
66
        }
67

    
68
        [WebMethod]
69
        public string ConvertRun(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url)
70
        {
71
            string _result = null;
72
            try
73
            {
74
                logger.Info($"Conversion Web Service ConvertRun call rev_No :{rev_No} document_No : {document_No}  document_Name : {document_Name}  group_No : {group_No}  prj_No : {prj_No}  document_Id : {document_Id}  document_Url : {document_Url}");
75

    
76
                using (KCOMEntities deepViewEntity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
77
                {
78
                    //_result = ConnectStringBuilder.DeepViewConnectionString().ToString();
79
                    //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber && DateTime.Parse(r.RUN_DATETIME)<= DateTime.Now);
80
                    //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber);
81
                    var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO != null);
82

    
83
                    if (_RunProjects.Count() > 0)
84
                    {
85
                        _result = SendKcom(rev_No, document_No, document_Name, group_No, prj_No, document_Id, document_Url);
86
                    }
87
                    else
88
                    {
89
                        _result = false.ToString();
90
                    }
91
                }
92
            }
93
            catch (Exception ex)
94
            {
95
                logger.Error($"Conversion Web Service ConvertRun Error rev_No :{rev_No} document_No : {document_No}  document_Name : {document_Name}  group_No : {group_No}  prj_No : {prj_No}  document_Id : {document_Id}  document_Url : {document_Url}", ex);
96
                _result = ex.Message.ToString();
97
                SendNotice("Project NO : " + prj_No + "\r\n  DocumentUrl : " + document_Url + "\r\n Error" + ex.ToString());
98
            }
99
            return _result;
100
        }
101

    
102
        [WebMethod]
103
        public string ConvertRunIgnoreComment(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url, string ignoreComment)
104
        {
105
            string _result = null;
106
            try
107
            {
108
                using (KCOMEntities deepViewEntity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
109
                {
110
                    //_result = ConnectStringBuilder.DeepViewConnectionString().ToString();
111
                    //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber && DateTime.Parse(r.RUN_DATETIME)<= DateTime.Now);
112
                    //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber);
113
                    var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO != null);
114

    
115
                    if (_RunProjects.Count() > 0)
116
                    {
117
                        _result = SendKcom(rev_No, document_No, document_Name, group_No, prj_No, document_Id, document_Url,ignoreComment);
118
                    }
119
                    else
120
                    {
121
                        _result = false.ToString();
122
                    }
123
                }
124
            }
125
            catch (Exception ex)
126
            {
127
                _result = ex.Message.ToString();
128
                SendNotice("Project NO : " + prj_No + "\r\n  DocumentUrl : " + document_Url + "\r\n Error" + ex.ToString());
129
            }
130
            return _result;
131
        }
132

    
133
        private string SendKcom(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url, string ignoreComment)
134
        {
135
            string result = false.ToString();
136

    
137
            if (remObj == null)
138
            {
139
                result = "Window Service Connection Error";
140
            }
141
            else
142
            {
143
                //string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString();
144
                string _id = shortGuid();
145
                string _doc_id = ((UInt32)document_Id.GetHashCode()).ToString();
146

    
147
                using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString("").ToString()))
148
                {
149
                    if (string.IsNullOrEmpty(group_No))
150
                    {
151
                        group_No = "0";
152
                    }
153
                    if (!document_Url.Contains("http%3a%2f%2f"))
154
                    {
155
                        document_Url = Base64Decode(document_Url);
156
                        document_Url = HttpUtility.UrlEncodeUnicode(document_Url);
157
                    }
158
                    document_Name = Base64DecodeFromStr(document_Name);
159
                    var doc = _entity.DOCUMENT_ITEM.Where(d => d.ID == document_Id).FirstOrDefault();
160
                    if (doc != null)
161
                    {
162
                        if (bool.Parse(ignoreComment))
163
                        {
164
                            try
165
                            {
166
                                var docinfo = _entity.DOCINFO.Where(x => x.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault();
167
                                var markupinfos = _entity.MARKUP_INFO.Where(x => x.DOCINFO_ID == docinfo.ID).ToList();
168
                                foreach (var markupinfo in markupinfos)
169
                                {
170
                                    var markupinfoversions = _entity.MARKUP_INFO_VERSION.Where(x => x.MARKUPINFO_ID == markupinfo.ID).ToList();
171
                                    foreach (var markupinfoversion in markupinfoversions)
172
                                    {
173
                                        var markupdatas = _entity.MARKUP_DATA.Where(x => x.MARKUPINFO_VERSION_ID == markupinfoversion.ID).ToList();
174
                                        foreach (var markupdata in markupdatas)
175
                                        {
176
                                            _entity.DeleteObject(markupdata);
177
                                        }
178
                                        _entity.DeleteObject(markupinfoversion);
179
                                    }
180
                                    _entity.DeleteObject(markupinfo);
181
                                }
182
                                _entity.SaveChanges();
183
                            }
184
                            catch (Exception ex)
185
                            {
186
                                result = "deleteobject error:"+ex.ToString();
187
                            }
188
                                                    
189
                        }else
190
                        {
191
                            doc.REVISION = rev_No;
192
                            doc.ORIGINAL_FILE = document_Url;
193
                            doc.GROUP_NO = group_No;
194
                            doc.DOCUMENT_NO = document_No;
195
                            doc.DOCUMENT_NAME = document_Name;
196
                        }                        
197
                    }else
198
                    {
199
                        _entity.AddToDOCUMENT_ITEM(new DOCUMENT_ITEM
200
                        {
201
                            ID = document_Id,
202
                            REVISION = rev_No,
203
                            DOCUMENT_NO = document_No,
204
                            DOCUMENT_NAME = document_Name,
205
                            GROUP_NO = group_No,
206
                            ORIGINAL_FILE = document_Url,
207
                            DOCUMENT_ID = _doc_id,
208
                            PROJECT_NO = prj_No,
209
                        });                        
210
                    }
211

    
212
                    _entity.SaveChanges();
213

    
214
                    using (KCOMEntities _kcomEntity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
215
                    {
216
                        _kcomEntity.AddToCONVERTER_DOC(new CONVERTER_DOC
217
                        {
218
                            ID = _id,
219
                            CREATE_DATETIME = DateTime.Now,
220
                            DOCUMENT_URL = document_Url,
221
                            PROJECT_NO = prj_No,
222
                            DOCUMENT_ID = _doc_id,
223
                        });
224
                        _kcomEntity.SaveChanges();
225
                    }
226
                }
227

    
228
                if (Properties.Settings.Default.MARKUS_V3_PROJECTS.Split(',').Contains(prj_No))
229
                {
230
                    try
231
                    {
232
                        System.Net.WebClient client = new System.Net.WebClient();
233
                        var convertResult = client.DownloadString($"{Properties.Settings.Default.MARKUS_V3_ADDRESS}/Rest/ConvertAdd?ProjectNo={prj_No}&ConvertID={_id}");
234

    
235
                        JObject jObject = JObject.Parse(convertResult, new JsonLoadSettings());
236
                        result = jObject["ConvertAddResult"].ToString();
237
                    }
238
                    catch (Exception ex)
239
                    {
240
                        result = $"Markus V3 Connect Error {ex.Message}";
241
                    }
242
                }
243
                else
244
                {
245
                    var convertResult = remObj.SetConverterPDF(prj_No, _id);
246

    
247
                    if (convertResult.Exception != null)
248
                    {
249
                        result = false.ToString();
250
                    }
251
                    else
252
                    {
253
                        result = true.ToString();
254
                    }
255
                }
256

    
257
            }
258

    
259
            return result;
260
        }
261
        [WebMethod]
262
        public string ManualConvert(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url)
263
        {
264
            string _result = null;
265
            try
266
            {
267
                using (KCOMEntities deepViewEntity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
268
                {
269
                    //_result = ConnectStringBuilder.DeepViewConnectionString().ToString();
270
                    //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber && DateTime.Parse(r.RUN_DATETIME)<= DateTime.Now);
271
                    //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber);
272
                    var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO != null);
273

    
274
                    if (_RunProjects.Count() > 0)
275
                    {
276
                        _result = ManualSendKcom(rev_No, document_No, document_Name, group_No, prj_No, document_Id, document_Url);
277
                    }
278
                    else
279
                    {
280
                        _result = false.ToString();
281
                    }
282
                }
283
            }
284
            catch (Exception ex)
285
            {
286
                logger.Error("Conversion Web Service ManualConvert Error", ex);
287
                _result = ex.Message.ToString();
288
                SendNotice("Project NO : " + prj_No + "\r\n  DocumentUrl : " + document_Url + "\r\n Error" + ex.ToString());
289
            }
290
            return _result;
291
        }
292
        [WebMethod]
293
        public string UpdateUrlEncode(string EnsembleId)
294
        {
295
            string _result = null;
296
            try
297
            {
298
                using (CIEntities deepViewEntity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString("").ToString()))
299
                {
300
                    var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault();
301
                    string url = doc.ORIGINAL_FILE;
302
                    if (url.Contains("http://"))
303
                    {
304
                        //기존 url 이 인코딩 안되 있으면 인코딩 작업.
305
                        url = HttpUtility.UrlEncodeUnicode(url);
306
                        doc.ORIGINAL_FILE = url;
307
                        using (KCOMEntities kcomEntity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
308
                        {
309
                            var convertdoc = kcomEntity.CONVERTER_DOC.Where(d => d.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault();
310

    
311
                            if (convertdoc != null)
312
                                convertdoc.DOCUMENT_URL = url;
313

    
314
                            var docinfo = deepViewEntity.DOCINFO.Where(d => d.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault();
315
                            if (docinfo != null)
316
                                docinfo.ORIGINAL_FILE = url;
317

    
318
                        }
319
                    }
320
                        
321
                    deepViewEntity.SaveChanges();
322
                }
323
            }
324
            catch (Exception ex)
325
            {
326
                logger.Error("Conversion Web Service UpdateUrlEncode Error", ex);
327
                _result = ex.Message.ToString();
328
            }
329
            return _result;
330
        }
331
        public string Base64DecodeFromStr(string data)
332
        {
333
            try
334
            {
335
                System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
336
                System.Text.Decoder utf8Decode = encoder.GetDecoder();
337

    
338
                byte[] todecode_byte = Convert.FromBase64String(data);
339

    
340
                int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
341

    
342
                char[] decoded_char = new char[charCount];
343

    
344
                utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
345

    
346
                string result = new String(decoded_char);
347

    
348
                return result;
349
            }
350
            catch (Exception)
351
            {
352
                return data;
353
            }
354
        }
355
        public string Base64Decode(string data)
356
        {
357
            try
358
            {
359
                if(data.Contains("http://"))
360
                {
361
                    return data;
362
                }else
363
                {
364
                    System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
365
                    System.Text.Decoder utf8Decode = encoder.GetDecoder();
366

    
367
                    byte[] todecode_byte = Convert.FromBase64String(data);
368

    
369
                    int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
370

    
371
                    char[] decoded_char = new char[charCount];
372

    
373
                    utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
374

    
375
                    string result = new String(decoded_char);
376

    
377
                    return result;
378
                }
379
                
380

    
381
            }
382

    
383
            catch (Exception e)
384
            {
385
                throw new Exception("Error in Base64Decode: " + e.Message);
386
            }
387
        }
388
        [WebMethod]
389
        public string UpdateSlip(string EnsembleId, string SlipNo, string slipLink)
390
        {
391
            string _result = null;
392
            try
393
            {
394
                using (CIEntities deepViewEntity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString("").ToString()))
395
                {
396
                    var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault();
397
                    if(!string.IsNullOrEmpty(slipLink))
398
                        doc.GROUP_NO = SlipNo;
399
                    if(!string.IsNullOrEmpty(slipLink))
400
                    {
401
                        if (!slipLink.Contains("http://"))
402
                            slipLink = Base64Decode(slipLink);
403
                        throw new Exception("doc.ENSEMBLEINFO_URL not support");
404
                        //doc.ENSEMBLEINFO_URL = slipLink;
405
                    }
406
                    
407
                    deepViewEntity.SaveChanges();
408
                }
409
            }
410
            catch (Exception ex)
411
            {
412
                logger.Error($"Conversion Web Service UpdateSlip Error EnsembleId : {EnsembleId} SlipNo : {SlipNo}   slipLink: {slipLink}", ex);
413
                _result = ex.Message.ToString();                
414
            }
415
            return _result;
416
        }
417
        [WebMethod]
418
        public string UpdateResult(string EnsembleId, string Result, string FinalPDFUrl)
419
        {
420
            string _result = null;
421
            try
422
            {
423
                using (CIEntities deepViewEntity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString("").ToString()))
424
                {
425
                    var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault();
426
                    doc.RESULT = Result;
427
                    doc.RESULT_FILE = FinalPDFUrl;
428
                    deepViewEntity.SaveChanges();
429
                }
430
            }
431
            catch (Exception ex)
432
            {
433
                logger.Error("Conversion Web Service UpdateResult Error", ex);
434
                _result = ex.Message.ToString();
435
            }
436
            return _result;
437
        }
438
        [WebMethod]
439
        public string UpdateVP(string EnsembleId, string rev_No, string document_No, string document_Name, string pdf_url)
440
        {
441
            string _result = null;
442
            try
443
            {
444
                using (CIEntities deepViewEntity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString("").ToString()))
445
                {
446
                    var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault();
447
                    if(!string.IsNullOrEmpty(rev_No))
448
                        doc.REVISION = rev_No;
449
                    if (!string.IsNullOrEmpty(document_No))
450
                        doc.DOCUMENT_NO = document_No;
451
                    if (!string.IsNullOrEmpty(document_Name))
452
                        doc.DOCUMENT_NAME = document_Name;
453
                    if (!string.IsNullOrEmpty(pdf_url))
454
                    {
455
                        string url = pdf_url;
456
                        if (!doc.PROJECT_NO.Equals("150128"))
457
                        {   
458
                            url = HttpUtility.UrlEncodeUnicode(url);
459
                        }
460
                        doc.ORIGINAL_FILE = url;
461
                    }                        
462
                    deepViewEntity.SaveChanges();
463
                }
464
            }
465
            catch (Exception ex)
466
            {
467
                logger.Error("Conversion Web Service UpdateVP Error", ex);
468
                _result = ex.Message.ToString();
469
            }
470
            return _result;
471
        }
472
        [WebMethod]
473
		public string UpdatePDFUrl(string EnsembleId, string original_url, string result_url)
474
        {
475
            string _result = null;
476
            try
477
            {
478
                using (CIEntities _kcomEntity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString("").ToString()))
479
                {
480
                    var doc = _kcomEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault();
481
                    
482
                    if (!string.IsNullOrEmpty(original_url))
483
                    {
484
                        string url = original_url;
485
                        url = Base64Decode(url);
486
                        url = HttpUtility.UrlEncodeUnicode(url);
487
                        doc.ORIGINAL_FILE = url;
488
                    }
489
                    if (!string.IsNullOrEmpty(result_url))
490
                    {
491
                        doc.RESULT_FILE = result_url;
492
                    }
493
                    _kcomEntity.SaveChanges();
494
                    _result = true.ToString();
495
                }
496
            }
497
            catch (Exception ex)
498
            {
499
                logger.Error("Conversion Web Service UpdateVP Error", ex);
500
                _result = ex.Message.ToString();
501
            }
502
            return _result;
503
        }
504

    
505
        [WebMethod]
506
        public string DeleteVP(string id)
507
        {
508
            string _result = null;
509
            try
510
            {
511
                using (CIEntities _kcomEntity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString("").ToString()))
512
                {
513
                    var doc = _kcomEntity.DOCUMENT_ITEM.Where(data => data.ID == id).FirstOrDefault();
514

    
515
                    if (doc != null)
516
                    {
517
                        doc.DOCUMENT_NO = "VOID_" + doc.DOCUMENT_NO;
518
                        doc.GROUP_NO = "VOID_" + doc.GROUP_NO;
519
                        //deepViewEntity.DeleteObject(doc);
520
                        _kcomEntity.SaveChanges();
521
                        _result = true.ToString();
522
                    }
523
                    else
524
                        _result = "document not found.";
525
                }
526
            }
527
            catch (Exception ex)
528
            {
529
                logger.Error("Conversion Web Service DeleteVP Error", ex);
530
                _result = ex.Message.ToString();
531
            }
532
            return _result;
533
        }
534
        public string getDocumentID(string id)
535
        {
536
            string _doc_id = ((UInt32)id.GetHashCode()).ToString();
537
            return _doc_id;
538
        }
539
        [WebMethod]
540
        public string CoverConvert(string prj_No, string _id)
541
        {
542
            string _result = null;
543
            try
544
            {
545
                SendCoverConvert(prj_No, _id);
546
            }
547
            catch (Exception ex)
548
            {
549
                logger.Error("Conversion Web Service CoverConvert Error", ex);
550
                _result = ex.Message.ToString();
551
            }
552
            return _result;
553
        }
554
        private string SendCoverConvert(string prj_No, string _id)
555
        {
556
            if (remObj == null)
557
            {
558
                return "Window Service Connection Error";
559
            }
560
            else
561
            {
562
                var _result = remObj.SetConverterCoverPDF(prj_No, _id);
563

    
564
                if (_result.Exception != null)
565
                {
566
                    return false.ToString();
567
                }
568
                else
569
                {
570
                    return true.ToString();
571
                }
572
            }
573
        }
574
        private string SendKcom(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url)
575
        {
576
            string result = false.ToString();
577

    
578
            if (remObj == null)
579
            {
580
                result  = "Window Service Connection Error";
581
            }
582
            else
583
            {
584
                //string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString();
585
                string _id = shortGuid();
586
                string _doc_id = ((UInt32)document_Id.GetHashCode()).ToString();
587
                using (CIEntities _kcomEntity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString("").ToString()))
588
                {
589
                    if (string.IsNullOrEmpty(group_No))
590
                    {
591
                        group_No = "0";
592
                    }
593
                    if (!document_Url.Contains("http%3a%2f%2f"))
594
                    {
595
                        document_Url = Base64Decode(document_Url);
596
                        document_Url = System.Net.WebUtility.UrlEncode(document_Url);
597
                    }
598
                    document_Name = Base64DecodeFromStr(document_Name);
599

    
600
                    var doc = _kcomEntity.DOCUMENT_ITEM.Where(d => d.PROJECT_NO == prj_No && d.ID == document_Id).FirstOrDefault();
601
                    if(doc != null)
602
                    {
603
                        doc.DOCUMENT_ID = _doc_id;
604
                        doc.REVISION = rev_No;                        
605
                        doc.GROUP_NO = group_No;
606
                        doc.DOCUMENT_NO = document_No;
607
                        doc.DOCUMENT_NAME = document_Name;
608
                        doc.ORIGINAL_FILE = document_Url;
609
                    }
610
                    else
611
                    {
612
                        _kcomEntity.AddToDOCUMENT_ITEM(new DOCUMENT_ITEM
613
                        {
614
                            ID = document_Id,
615
                            REVISION = rev_No,
616
                            DOCUMENT_NO = document_No,
617
                            DOCUMENT_NAME = document_Name,
618
                            GROUP_NO = group_No,
619
                            ORIGINAL_FILE = document_Url,
620
                            DOCUMENT_ID = _doc_id,
621
                            PROJECT_NO = prj_No,
622
                        });
623
                    }
624

    
625
                    _kcomEntity.SaveChanges();
626

    
627
                    using (KCOMEntities _entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
628
                    {
629
                        _entity.AddToCONVERTER_DOC(new CONVERTER_DOC
630
                        {
631
                            ID = _id,
632
                            CREATE_DATETIME = DateTime.Now,
633
                            DOCUMENT_URL = document_Url,
634
                            PROJECT_NO = prj_No,
635
                            DOCUMENT_ID = _doc_id,
636
                        });
637

    
638
                        _entity.SaveChanges();
639
                    }
640
                }
641

    
642
                if (Properties.Settings.Default.MARKUS_V3_PROJECTS.Split(',').Contains(prj_No))
643
                {
644
                    try
645
                    {
646
                        System.Net.WebClient client = new System.Net.WebClient();
647
                        var convertResult = client.DownloadString($"{Properties.Settings.Default.MARKUS_V3_ADDRESS}/Rest/ConvertAdd?ProjectNo={prj_No}&ConvertID={_id}");
648

    
649
                        JObject jObject = JObject.Parse(convertResult, new JsonLoadSettings());
650
                        result = jObject["ConvertAddResult"].ToString();
651
                    }
652
                    catch (Exception ex)
653
                    {
654
                        logger.Error("Conversion Web Service SendKcom Error", ex);
655
                        result = $"Markus V3 Connect Error {ex.Message}";
656
                    }
657
                }
658
                else
659
                {
660
                    var convertResult = remObj.SetConverterPDF(prj_No, _id);
661

    
662
                    if (convertResult.Exception != null)
663
                    {
664
                        result = false.ToString();
665
                    }
666
                    else
667
                    {
668
                        result = true.ToString();
669
                    }
670
                }
671

    
672
            }
673

    
674
            return result;
675
        }
676
                
677
        private string ManualSendKcom(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url)
678
        {
679
            if (remObj == null)
680
            {
681
                return "Window Service Connection Error";
682
            }
683
            else
684
            {
685
                //string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString();
686
                string _id = shortGuid();
687
                string _doc_id = ((UInt32)document_Id.GetHashCode()).ToString();
688
                using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString("").ToString()))
689
                {
690
                    var doc = _entity.DOCUMENT_ITEM.Where(d =>d.PROJECT_NO ==  prj_No && d.ID == document_Id).FirstOrDefault();
691

    
692
                    if (doc != null)
693
                    {
694
                        using (KCOMEntities kCOMEntities = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
695
                        {
696
                            var converterdoc = kCOMEntities.CONVERTER_DOC.Where(c => c.PROJECT_NO == doc.PROJECT_NO && c.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault();
697
                            _entity.DeleteObject(converterdoc);
698
                            _entity.DeleteObject(doc);
699
                            _entity.SaveChanges();
700
                        }
701

    
702
                        document_Url = HttpUtility.UrlDecode(document_Url);
703
                    }
704

    
705
                    int cnt = _entity.DOCUMENT_ITEM.ToList().Count;
706
                    if (string.IsNullOrEmpty(group_No))
707
                    {
708
                        group_No = "0";
709
                    }
710
                    
711
                    _entity.AddToDOCUMENT_ITEM(new DOCUMENT_ITEM
712
                    {
713
                        ID = document_Id,
714
                        REVISION = rev_No,
715
                        DOCUMENT_NO = document_No,
716
                        DOCUMENT_NAME = document_Name,
717
                        GROUP_NO = group_No,
718
                        ORIGINAL_FILE = HttpUtility.UrlEncodeUnicode(document_Url),
719
                        DOCUMENT_ID = _doc_id,
720
                        PROJECT_NO = prj_No,
721
                    });
722

    
723
                    _entity.SaveChanges();
724

    
725
                    using (KCOMEntities kCOMEntities = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
726
                    {
727
                        kCOMEntities.AddToCONVERTER_DOC(new CONVERTER_DOC
728
                        {
729
                            ID = _id,
730
                            CREATE_DATETIME = DateTime.Now,
731
                            DOCUMENT_URL = HttpUtility.UrlEncodeUnicode(document_Url),
732
                            PROJECT_NO = prj_No,
733
                            DOCUMENT_ID = _doc_id,
734
                        });
735

    
736
                        kCOMEntities.SaveChanges();
737
                    }
738
                }
739
                var _result = remObj.SetConverterPDF(prj_No, _id);
740

    
741
                if (_result.Exception != null)
742
                {
743
                    return false.ToString();
744
                }
745
                else
746
                {
747
                    return true.ToString();
748
                }
749
            }
750
        }
751

    
752
        //private Guid GetGuid(int Count,Guid ID)
753
        //{
754
        //    Guid _ID = ID;
755
        //    string _id = _ID.ToString();
756
        //    DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString());
757

    
758
        //    if (_entity.CONVERTER_DOC.Where(c => c.ID == _id).Count() > 0)
759
        //    {
760
        //        _entity.Dispose();
761

    
762
        //        if (Count > 10)
763
        //        {
764
        //            new Exception("GetGuid : Not Generator");
765
        //        }
766

    
767
        //        if (Count < 3)
768
        //        {
769
        //            System.Threading.Thread.Sleep(3);
770
        //        }
771

    
772
        //        GetGuid(Count++,GuidGenerator.GetUniqueGuid());
773
        //    }
774

    
775
        //    return ID;
776
        //}
777

    
778
        //GUID생성(최민수 사원 수정)
779
        public string shortGuid()
780
        {
781
            byte[] bytes = new byte[16];
782
            using (var provider = System.Security.Cryptography.RandomNumberGenerator.Create())
783
            {
784
                provider.GetBytes(bytes);
785
            }
786

    
787
            var guid = new Guid(bytes);
788

    
789
            return Convert.ToBase64String(guid.ToByteArray())
790
                .Substring(0, 10)
791
                .Replace("/", "")
792
                .Replace("+", "") + DateTime.UtcNow.Ticks.ToString("x");
793
        }
794

    
795
        [WebMethod]
796
        public string ExcelExport(string project_no, string slip_no)
797
        {
798
            string _result = "false";
799
            //FileInfo fileInfo2 = new FileInfo(Path.GetTempFileName());
800
            //fileInfo2.FullName
801
            try
802
            {
803
                // Excel 첫번째 워크시트 가져오기                
804
                //application = new Excel.Application();
805
                //workbook = application.Workbooks.Open(xlsxfilepath);
806
                //worksheet = (Excel.Worksheet)workbook.Worksheets.get_Item("Sheet1");
807
                string xlsxfilepath = @"C:\WebSite\LogView\Doc_Manager\sample.xlsx";
808
                GemBox.Spreadsheet.SpreadsheetInfo.SetLicense("EXK0-W4HZ-N518-IMEW");
809
                GemBox.Spreadsheet.ExcelFile excelFile = new GemBox.Spreadsheet.ExcelFile();
810
                excelFile.LoadXlsx(xlsxfilepath, GemBox.Spreadsheet.XlsxOptions.PreserveMakeCopy);
811
                GemBox.Spreadsheet.ExcelWorksheet ws = excelFile.Worksheets[0];
812
                FileInfo fileInfo2 = new FileInfo(Path.GetTempFileName().Replace(".tmp", ".xlsx"));
813

    
814
                string fileout = @"C:\WebSite\LogView\Doc_Manager\commentexcel_" + DateTime.Now.ToString() + ".xlsx";
815
                string naspath = Properties.Settings.Default.Excelfilepath;
816
                    //@"\\172.20.121.220\comment3\TileSource\Excelexport";
817

    
818
                // 데이타 넣기
819
                int h = 6;
820
                int w = 1;
821

    
822

    
823
                //필터 기능 추가
824
                //Excel.Range Filter_Range = worksheet.Range["B9:" + Ran + "9"];
825
                //Filter_Range.AutoFilter(1, Type.Missing, Excel.XlAutoFilterOperator.xlAnd, Type.Missing, true);
826

    
827
                using (CIEntities deepViewEntity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString("").ToString()))
828
                {
829
                    var docs = deepViewEntity.DOCUMENT_ITEM.Where(doc => doc.GROUP_NO == slip_no && doc.PROJECT_NO == project_no).ToList();
830
                    if (docs.Count > 0)
831
                    {
832
                        foreach (var doc in docs)
833
                        {
834
                            var commentlist = deepViewEntity.MARKUP_DATA.Where(d => d.MARKUP_INFO_VERSION.MARKUP_INFO.DOCINFO.DOCUMENT_ID == doc.DOCUMENT_ID
835
                            && d.MARKUP_INFO_VERSION.MARKUP_INFO.CONSOLIDATE == 1).ToList();
836

    
837
                            string docNo = doc.DOCUMENT_NO;
838
                            string docDesc = doc.DOCUMENT_NAME;
839
                            string docRev = doc.REVISION;
840
                            foreach (var comment in commentlist)
841
                            {
842
                                var member = deepViewEntity.MEMBER.Where(m => m.ID == comment.MARKUP_INFO_VERSION.MARKUP_INFO.USER_ID).FirstOrDefault();
843
                                string docdept = member.DEPARTMENT;
844
                                string doccomment = string.Empty;
845
                                var data = MarkupToPDF.Serialize.Core.JsonSerializerHelper.UnCompressStringAsync(comment.DATA.ToString(),null).ConfigureAwait(false).GetAwaiter().GetResult();
846
                                switch (Enum.Parse(typeof(MarkupToPDF.Controls.Common.ControlType), comment.DATA_TYPE.ToString()))
847
                                {
848
                                    case MarkupToPDF.Controls.Common.ControlType.TextControl:
849
                                    case MarkupToPDF.Controls.Common.ControlType.TextBorder:
850
                                    case MarkupToPDF.Controls.Common.ControlType.TextCloud:
851
                                        {
852
                                            MarkupToPDF.Serialize.S_Control.S_TextControl instance = MarkupToPDF.Serialize.Core.JsonSerializerHelper.JsonDeserialize<MarkupToPDF.Serialize.S_Control.S_TextControl>(data);
853
                                            doccomment = instance.Text;
854
                                        }
855
                                        break;
856
                                    case MarkupToPDF.Controls.Common.ControlType.ArrowTextBorderControl:
857
                                    case MarkupToPDF.Controls.Common.ControlType.ArrowTextCloudControl:
858
                                    case MarkupToPDF.Controls.Common.ControlType.ArrowTextControl:
859
                                    case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextBorderControl:
860
                                    case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextCloudControl:
861
                                    case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextControl:
862
                                        {
863
                                            MarkupToPDF.Serialize.S_Control.S_ArrowTextControl instance = MarkupToPDF.Serialize.Core.JsonSerializerHelper.JsonDeserialize<MarkupToPDF.Serialize.S_Control.S_ArrowTextControl>(data);
864
                                            doccomment = instance.ArrowText;
865
                                        }
866
                                        break;
867
                                }
868
                                ws.Cells[h, w].Value = string.Format("{0}\n({1})", docNo, docDesc);
869
                                ws.Cells[h, w + 1].Value = docRev;
870
                                ws.Cells[h, w + 2].Value = docdept;
871
                                ws.Cells[h, w + 3].Value = doccomment;
872
                                h++;
873
                            }
874
                        }
875
                    }
876
                    else
877
                    {
878
                        _result = "ERROR : 해당 Slip 의 데이터가 없습니다.";
879
                    }
880

    
881

    
882
                }
883

    
884
                int columnCount = ws.CalculateMaxUsedColumns();
885
                for (int i = 0; i < columnCount; i++)
886
                    ws.Columns[i].AutoFit();
887
                //worksheet.Columns.AutoFit();
888
                // 엑셀파일 저장
889

    
890
                excelFile.Save(fileInfo2.FullName);
891
                fileInfo2.MoveTo(naspath + "\\" + fileInfo2.Name);
892
                //workbook.SaveAs(fileout);
893
                ////workbook.Save();
894
                //workbook.Close(true);
895
                //application.Quit();
896
                _result = Properties.Settings.Default.Excelresulturl + fileInfo2.Name;
897
            }
898
            catch (Exception e)
899
            {
900
                _result = "ERROR : " + e.ToString();
901
            }
902
            return _result;
903
        }
904

    
905
        private static void ReleaseExcelObject(object obj)
906
        {
907
            try
908
            {
909
                if (obj != null)
910
                {
911
                    obj = null;
912
                }
913
            }
914
            catch (Exception ex)
915
            {
916
                obj = null;
917
                throw ex;
918
            }
919
            finally
920
            {
921
                GC.Collect();
922
            }
923
        }
924
    }
925
}
클립보드 이미지 추가 (최대 크기: 500 MB)