프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / ConvertionWebService / Conversion.asmx.cs @ f09d5acb

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

1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Web;
5
using System.Web.Services;
6
using System.Runtime.Remoting.Channels;
7
using System.Runtime.Remoting.Channels.Tcp;
8
using IConverterPDF;
9
using System.Text;
10
using DeepViewDataModel.DataModel;
11
using DeepViewDataModel.Common;
12
using DeepView.Toolkit.GuidGenerator;
13
using MarkupToPDF;
14
using System.IO;
15
using Newtonsoft.Json;
16
using Newtonsoft.Json.Linq;
17
using log4net;
18

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

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

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

    
47
            }
48
            catch (Exception ex)
49
            {
50
                logger.Error("Conversion Web Service Conversion Error", ex);
51
                SendNotice(ex.ToString());
52
            }
53
        }
54

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

    
72
        [WebMethod]
73
        public string ConvertRun(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url)
74
        {
75
            string _result = null;
76
            try
77
            {
78
                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}");
79

    
80
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
81
                {
82
                    //_result = ConnectStringBuilder.DeepViewConnectionString().ToString();
83
                    //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber && DateTime.Parse(r.RUN_DATETIME)<= DateTime.Now);
84
                    //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber);
85
                    var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO != null);
86

    
87
                    if (_RunProjects.Count() > 0)
88
                    {
89
                        _result = SendKcom(rev_No, document_No, document_Name, group_No, prj_No, document_Id, document_Url);
90
                    }
91
                    else
92
                    {
93
                        _result = false.ToString();
94
                    }
95
                }
96
            }
97
            catch (Exception ex)
98
            {
99
                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);
100
                _result = ex.Message.ToString();
101
                SendNotice("Project NO : " + prj_No + "\r\n  DocumentUrl : " + document_Url + "\r\n Error" + ex.ToString());
102
            }
103
            return _result;
104
        }
105

    
106
        [WebMethod]
107
        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)
108
        {
109
            string _result = null;
110
            try
111
            {
112
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
113
                {
114
                    //_result = ConnectStringBuilder.DeepViewConnectionString().ToString();
115
                    //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber && DateTime.Parse(r.RUN_DATETIME)<= DateTime.Now);
116
                    //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber);
117
                    var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO != null);
118

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

    
137
        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)
138
        {
139
            string result = false.ToString();
140

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

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

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

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

    
256
            }
257

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

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

    
307
                        var convertdoc = deepViewEntity.CONVERTER_DOC.Where(d => d.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault();
308
                        if(convertdoc != null)
309
                            convertdoc.DOCUMENT_URL = url;
310
                        var docinfo = deepViewEntity.DOCINFO.Where(d => d.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault();
311
                        if(docinfo != null)
312
                            docinfo.ORIGINAL_FILE = url;
313
                    }
314
                        
315
                    deepViewEntity.SaveChanges();
316
                }
317
            }
318
            catch (Exception ex)
319
            {
320
                logger.Error("Conversion Web Service UpdateUrlEncode Error", ex);
321
                _result = ex.Message.ToString();
322
            }
323
            return _result;
324
        }
325
        public string Base64DecodeFromStr(string data)
326
        {
327
            try
328
            {
329
                System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
330
                System.Text.Decoder utf8Decode = encoder.GetDecoder();
331

    
332
                byte[] todecode_byte = Convert.FromBase64String(data);
333

    
334
                int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
335

    
336
                char[] decoded_char = new char[charCount];
337

    
338
                utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
339

    
340
                string result = new String(decoded_char);
341

    
342
                return result;
343
            }
344
            catch (Exception)
345
            {
346
                return data;
347
            }
348
        }
349
        public string Base64Decode(string data)
350
        {
351
            try
352
            {
353
                if(data.Contains("http://"))
354
                {
355
                    return data;
356
                }else
357
                {
358
                    System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
359
                    System.Text.Decoder utf8Decode = encoder.GetDecoder();
360

    
361
                    byte[] todecode_byte = Convert.FromBase64String(data);
362

    
363
                    int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
364

    
365
                    char[] decoded_char = new char[charCount];
366

    
367
                    utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
368

    
369
                    string result = new String(decoded_char);
370

    
371
                    return result;
372
                }
373
                
374

    
375
            }
376

    
377
            catch (Exception e)
378
            {
379
                throw new Exception("Error in Base64Decode: " + e.Message);
380
            }
381
        }
382
        [WebMethod]
383
        public string UpdateSlip(string EnsembleId, string SlipNo, string slipLink)
384
        {
385
            string _result = null;
386
            try
387
            {
388
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
389
                {
390
                    var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault();
391
                    if(!string.IsNullOrEmpty(SlipNo))
392
                        doc.GROUP_NO = SlipNo;
393
                    if(!string.IsNullOrEmpty(slipLink))
394
                    {
395
                        if (!slipLink.Contains("http://"))
396
                            slipLink = Base64Decode(slipLink);
397
                        //throw new Exception("doc.ENSEMBLEINFO_URL not support");
398
                        doc.ENSEMBLEINFO_URL = slipLink;
399
                    }
400
                    
401
                    deepViewEntity.SaveChanges();
402
                }
403
            }
404
            catch (Exception ex)
405
            {
406
                logger.Error($"Conversion Web Service UpdateSlip Error EnsembleId : {EnsembleId} SlipNo : {SlipNo}   slipLink: {slipLink}", ex);
407
                _result = ex.Message.ToString();                
408
            }
409
            return _result;
410
        }
411
        [WebMethod]
412
        public string UpdateResult(string EnsembleId, string Result, string FinalPDFUrl)
413
        {
414
            string _result = null;
415
            try
416
            {
417
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
418
                {
419
                    var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault();
420
                    doc.RESULT = Result;
421
                    doc.RESULT_FILE = FinalPDFUrl;
422
                    deepViewEntity.SaveChanges();
423
                }
424
            }
425
            catch (Exception ex)
426
            {
427
                logger.Error("Conversion Web Service UpdateResult Error", ex);
428
                _result = ex.Message.ToString();
429
            }
430
            return _result;
431
        }
432
        [WebMethod]
433
        public string UpdateVP(string EnsembleId, string rev_No, string document_No, string document_Name, string pdf_url)
434
        {
435
            string _result = null;
436
            try
437
            {
438
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
439
                {
440
                    var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault();
441
                    if(!string.IsNullOrEmpty(rev_No))
442
                        doc.REVISION = rev_No;
443
                    if (!string.IsNullOrEmpty(document_No))
444
                        doc.DOCUMENT_NO = document_No;
445
                    if (!string.IsNullOrEmpty(document_Name))
446
                        doc.DOCUMENT_NAME = document_Name;
447
                    if (!string.IsNullOrEmpty(pdf_url))
448
                    {
449
                        string url = pdf_url;
450
                        if (!doc.PROJECT_NO.Equals("150128"))
451
                        {   
452
                            url = HttpUtility.UrlEncodeUnicode(url);
453
                        }
454
                        doc.ORIGINAL_FILE = url;
455
                    }                        
456
                    deepViewEntity.SaveChanges();
457
                }
458
            }
459
            catch (Exception ex)
460
            {
461
                logger.Error("Conversion Web Service UpdateVP Error", ex);
462
                _result = ex.Message.ToString();
463
            }
464
            return _result;
465
        }
466

    
467
        [WebMethod]
468
        public string UpdatePDFUrl(string EnsembleId, string original_url, string result_url)
469
        {
470
            string _result = null;
471
            try
472
            {
473
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
474
                {
475
                    var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault();
476
                    
477
                    if (!string.IsNullOrEmpty(original_url))
478
                    {
479
                        string url = original_url;
480
                        url = Base64Decode(url);
481
                        url = HttpUtility.UrlEncodeUnicode(url);
482
                        doc.ORIGINAL_FILE = url;
483
                    }
484
                    if (!string.IsNullOrEmpty(result_url))
485
                    {
486
                        doc.RESULT_FILE = result_url;
487
                    }                    
488
                    deepViewEntity.SaveChanges();
489
                    _result = true.ToString();
490
                }
491
            }
492
            catch (Exception ex)
493
            {
494
                logger.Error("Conversion Web Service UpdateVP Error", ex);
495
                _result = ex.Message.ToString();
496
            }
497
            return _result;
498
        }
499

    
500
        [WebMethod]
501
        public string DeleteVP(string id)
502
        {
503
            string _result = null;
504
            try
505
            {
506
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
507
                {
508
                    var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == id).FirstOrDefault();
509

    
510
                    if (doc != null)
511
                    {
512
                        deepViewEntity.DeleteObject(doc);
513
                        deepViewEntity.SaveChanges();
514
                        _result = true.ToString();
515
                    }
516
                    else
517
                        _result = true.ToString();
518
                }
519
            }
520
            catch (Exception ex)
521
            {
522
                logger.Error("Conversion Web Service DeleteVP Error", ex);
523
                _result = true.ToString();
524
            }
525
            return _result;
526
        }
527

    
528
        [WebMethod]
529
        public string CoverConvert(string prj_No, string _id)
530
        {
531
            string _result = null;
532
            try
533
            {
534
                SendCoverConvert(prj_No, _id);
535
            }
536
            catch (Exception ex)
537
            {
538
                logger.Error("Conversion Web Service CoverConvert Error", ex);
539
                _result = ex.Message.ToString();
540
            }
541
            return _result;
542
        }
543
        private string SendCoverConvert(string prj_No, string _id)
544
        {
545
            if (remObj == null)
546
            {
547
                return "Window Service Connection Error";
548
            }
549
            else
550
            {
551
                var _result = remObj.SetConverterCoverPDF(prj_No, _id);
552

    
553
                if (_result.Exception != null)
554
                {
555
                    return false.ToString();
556
                }
557
                else
558
                {
559
                    return true.ToString();
560
                }
561
            }
562
        }
563
        private string SendKcom(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url)
564
        {
565
            string result = false.ToString();
566

    
567
            if (remObj == null)
568
            {
569
                result  = "Window Service Connection Error";
570
            }
571
            else
572
            {
573
                //string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString();
574
                string _id = shortGuid();
575
                string _doc_id = ((UInt32)document_Id.GetHashCode()).ToString();
576
                using (DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
577
                {
578
                    if (string.IsNullOrEmpty(group_No))
579
                    {
580
                        group_No = "0";
581
                    }
582
                    if (!document_Url.Contains("http%3a%2f%2f"))
583
                    {
584
                        document_Url = Base64Decode(document_Url);
585
                        document_Url = HttpUtility.UrlEncodeUnicode(document_Url);
586
                    }
587
                    document_Name = Base64DecodeFromStr(document_Name);
588
                    var doc = _entity.DOCUMENT_ITEM.Where(d => d.ID == document_Id).FirstOrDefault();
589
                    if(doc != null)
590
                    {
591
                        doc.REVISION = rev_No;                        
592
                        doc.GROUP_NO = group_No;
593
                        doc.DOCUMENT_NO = document_No;
594
                        doc.DOCUMENT_NAME = document_Name;
595
                        doc.ORIGINAL_FILE = document_Url;
596
                    }
597
                    else
598
                    {                        
599
                        _entity.AddToDOCUMENT_ITEM(new DOCUMENT_ITEM
600
                        {
601
                            ID = document_Id,
602
                            REVISION = rev_No,
603
                            DOCUMENT_NO = document_No,
604
                            DOCUMENT_NAME = document_Name,
605
                            GROUP_NO = group_No,
606
                            ORIGINAL_FILE = document_Url,
607
                            DOCUMENT_ID = _doc_id,
608
                            PROJECT_NO = prj_No,
609
                        });
610
                    }
611
                    
612
                    _entity.AddToCONVERTER_DOC(new CONVERTER_DOC
613
                    {
614
                        ID = _id,
615
                        CREATE_DATETIME = DateTime.Now,
616
                        DOCUMENT_URL = document_Url,
617
                        PROJECT_NO = prj_No,
618
                        DOCUMENT_ID = _doc_id,
619
                    });
620
                    _entity.SaveChanges();
621
                }
622

    
623
                if (Properties.Settings.Default.MARKUS_V3_PROJECTS.Split(',').Contains(prj_No))
624
                {
625
                    try
626
                    {
627
                        System.Net.WebClient client = new System.Net.WebClient();
628
                        var convertResult = client.DownloadString($"{Properties.Settings.Default.MARKUS_V3_ADDRESS}/Rest/ConvertAdd?ProjectNo={prj_No}&DocumentID={_id}");
629

    
630
                        JObject jObject = JObject.Parse(convertResult, new JsonLoadSettings());
631
                        result = jObject["ConvertAddResult"].ToString();
632
                    }
633
                    catch (Exception ex)
634
                    {
635
                        logger.Error("Conversion Web Service SendKcom Error", ex);
636
                        result = $"Markus V3 Connect Error {ex.Message}";
637
                    }
638
                }
639
                else
640
                {
641
                    var convertResult = remObj.SetConverterPDF(prj_No, _id);
642

    
643
                    if (convertResult.Exception != null)
644
                    {
645
                        result = false.ToString();
646
                    }
647
                    else
648
                    {
649
                        result = true.ToString();
650
                    }
651
                }
652

    
653
            }
654

    
655
            return result;
656
        }
657
                
658
        private string ManualSendKcom(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url)
659
        {
660
            if (remObj == null)
661
            {
662
                return "Window Service Connection Error";
663
            }
664
            else
665
            {
666
                //string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString();
667
                string _id = shortGuid();
668
                string _doc_id = ((UInt32)document_Id.GetHashCode()).ToString();
669
                using (DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
670
                {
671
                    var doc = _entity.DOCUMENT_ITEM.Where(d => d.ID == document_Id).FirstOrDefault();
672
                    if (doc != null)
673
                    {
674
                        var converterdoc = _entity.CONVERTER_DOC.Where(c => c.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault();
675
                        _entity.DeleteObject(converterdoc);
676
                        _entity.DeleteObject(doc);
677
                        _entity.SaveChanges();
678
                        document_Url = HttpUtility.UrlDecode(document_Url);
679
                    }
680
                    int cnt = _entity.DOCUMENT_ITEM.ToList().Count;
681
                    if (string.IsNullOrEmpty(group_No))
682
                    {
683
                        group_No = "0";
684
                    }
685
                    
686
                    _entity.AddToDOCUMENT_ITEM(new DOCUMENT_ITEM
687
                    {
688
                        ID = document_Id,
689
                        REVISION = rev_No,
690
                        DOCUMENT_NO = document_No,
691
                        DOCUMENT_NAME = document_Name,
692
                        GROUP_NO = group_No,
693
                        ORIGINAL_FILE = HttpUtility.UrlEncodeUnicode(document_Url),
694
                        DOCUMENT_ID = _doc_id,
695
                        PROJECT_NO = prj_No,
696
                    });
697
                    _entity.AddToCONVERTER_DOC(new CONVERTER_DOC
698
                    {
699
                        ID = _id,
700
                        CREATE_DATETIME = DateTime.Now,
701
                        DOCUMENT_URL = HttpUtility.UrlEncodeUnicode(document_Url),
702
                        PROJECT_NO = prj_No,
703
                        DOCUMENT_ID = _doc_id,
704
                    });
705
                    _entity.SaveChanges();
706
                }
707
                var _result = remObj.SetConverterPDF(prj_No, _id);
708

    
709
                if (_result.Exception != null)
710
                {
711
                    return false.ToString();
712
                }
713
                else
714
                {
715
                    return true.ToString();
716
                }
717
            }
718
        }
719

    
720
        //private Guid GetGuid(int Count,Guid ID)
721
        //{
722
        //    Guid _ID = ID;
723
        //    string _id = _ID.ToString();
724
        //    DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString());
725

    
726
        //    if (_entity.CONVERTER_DOC.Where(c => c.ID == _id).Count() > 0)
727
        //    {
728
        //        _entity.Dispose();
729

    
730
        //        if (Count > 10)
731
        //        {
732
        //            new Exception("GetGuid : Not Generator");
733
        //        }
734

    
735
        //        if (Count < 3)
736
        //        {
737
        //            System.Threading.Thread.Sleep(3);
738
        //        }
739

    
740
        //        GetGuid(Count++,GuidGenerator.GetUniqueGuid());
741
        //    }
742

    
743
        //    return ID;
744
        //}
745

    
746
        //GUID생성(최민수 사원 수정)
747
        public string shortGuid()
748
        {
749
            byte[] bytes = new byte[16];
750
            using (var provider = System.Security.Cryptography.RandomNumberGenerator.Create())
751
            {
752
                provider.GetBytes(bytes);
753
            }
754

    
755
            var guid = new Guid(bytes);
756

    
757
            return Convert.ToBase64String(guid.ToByteArray())
758
                .Substring(0, 10)
759
                .Replace("/", "")
760
                .Replace("+", "") + DateTime.UtcNow.Ticks.ToString("x");
761
        }
762

    
763
        [WebMethod]
764
        public string ExcelExport(string project_no, string slip_no)
765
        {
766
            string _result = "false";
767
            //FileInfo fileInfo2 = new FileInfo(Path.GetTempFileName());
768
            //fileInfo2.FullName
769
            try
770
            {
771
                // Excel 첫번째 워크시트 가져오기                
772
                //application = new Excel.Application();
773
                //workbook = application.Workbooks.Open(xlsxfilepath);
774
                //worksheet = (Excel.Worksheet)workbook.Worksheets.get_Item("Sheet1");
775
                string xlsxfilepath = @"C:\WebSite\LogView\Doc_Manager\sample.xlsx";
776
                GemBox.Spreadsheet.SpreadsheetInfo.SetLicense("EXK0-W4HZ-N518-IMEW");
777
                GemBox.Spreadsheet.ExcelFile excelFile = new GemBox.Spreadsheet.ExcelFile();
778
                excelFile.LoadXlsx(xlsxfilepath, GemBox.Spreadsheet.XlsxOptions.PreserveMakeCopy);
779
                GemBox.Spreadsheet.ExcelWorksheet ws = excelFile.Worksheets[0];
780
                FileInfo fileInfo2 = new FileInfo(Path.GetTempFileName().Replace(".tmp", ".xlsx"));
781

    
782
                string fileout = @"C:\WebSite\LogView\Doc_Manager\commentexcel_" + DateTime.Now.ToString() + ".xlsx";
783
                string naspath = Properties.Settings.Default.Excelfilepath;
784
                    //@"\\172.20.121.220\comment3\TileSource\Excelexport";
785

    
786
                // 데이타 넣기
787
                int h = 6;
788
                int w = 1;
789

    
790

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

    
795

    
796
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
797
                {
798
                    var docs = deepViewEntity.DOCUMENT_ITEM.Where(doc => doc.GROUP_NO == slip_no && doc.PROJECT_NO == project_no).ToList();
799
                    if (docs.Count > 0)
800
                    {
801
                        foreach (var doc in docs)
802
                        {
803
                            var commentlist = deepViewEntity.MARKUP_DATA.Where(d => d.MARKUP_INFO_VERSION.MARKUP_INFO.DOCINFO.DOCUMENT_ID == doc.DOCUMENT_ID
804
                            && d.MARKUP_INFO_VERSION.MARKUP_INFO.CONSOLIDATE == 1).ToList();
805

    
806
                            string docNo = doc.DOCUMENT_NO;
807
                            string docDesc = doc.DOCUMENT_NAME;
808
                            string docRev = doc.REVISION;
809
                            foreach (var comment in commentlist)
810
                            {
811
                                var member = deepViewEntity.MEMBER.Where(m => m.ID == comment.MARKUP_INFO_VERSION.MARKUP_INFO.USER_ID).FirstOrDefault();
812
                                string docdept = member.DEPARTMENT;
813
                                string doccomment = string.Empty;
814
                                var data = MarkupToPDF.Serialize.Core.JsonSerializerHelper.UnCompressString(comment.DATA.ToString());
815
                                switch (Enum.Parse(typeof(MarkupToPDF.Controls.Common.ControlType), comment.DATA_TYPE.ToString()))
816
                                {
817
                                    case MarkupToPDF.Controls.Common.ControlType.TextControl:
818
                                    case MarkupToPDF.Controls.Common.ControlType.TextBorder:
819
                                    case MarkupToPDF.Controls.Common.ControlType.TextCloud:
820
                                        {
821
                                            MarkupToPDF.Serialize.S_Control.S_TextControl instance = MarkupToPDF.Serialize.Core.JsonSerializerHelper.JsonDeserialize<MarkupToPDF.Serialize.S_Control.S_TextControl>(data);
822
                                            doccomment = instance.Text;
823
                                        }
824
                                        break;
825
                                    case MarkupToPDF.Controls.Common.ControlType.ArrowTextBorderControl:
826
                                    case MarkupToPDF.Controls.Common.ControlType.ArrowTextCloudControl:
827
                                    case MarkupToPDF.Controls.Common.ControlType.ArrowTextControl:
828
                                    case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextBorderControl:
829
                                    case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextCloudControl:
830
                                    case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextControl:
831
                                        {
832
                                            MarkupToPDF.Serialize.S_Control.S_ArrowTextControl instance = MarkupToPDF.Serialize.Core.JsonSerializerHelper.JsonDeserialize<MarkupToPDF.Serialize.S_Control.S_ArrowTextControl>(data);
833
                                            doccomment = instance.ArrowText;
834
                                        }
835
                                        break;
836
                                }
837
                                ws.Cells[h, w].Value = string.Format("{0}\n({1})", docNo, docDesc);
838
                                ws.Cells[h, w + 1].Value = docRev;
839
                                ws.Cells[h, w + 2].Value = docdept;
840
                                ws.Cells[h, w + 3].Value = doccomment;
841
                                h++;
842
                            }
843
                        }
844
                    }
845
                    else
846
                    {
847
                        _result = "ERROR : 해당 Slip 의 데이터가 없습니다.";
848
                    }
849

    
850

    
851
                }
852

    
853
                int columnCount = ws.CalculateMaxUsedColumns();
854
                for (int i = 0; i < columnCount; i++)
855
                    ws.Columns[i].AutoFit();
856
                //worksheet.Columns.AutoFit();
857
                // 엑셀파일 저장
858

    
859
                excelFile.Save(fileInfo2.FullName);
860
                fileInfo2.MoveTo(naspath + "\\" + fileInfo2.Name);
861
                //workbook.SaveAs(fileout);
862
                ////workbook.Save();
863
                //workbook.Close(true);
864
                //application.Quit();
865
                _result = Properties.Settings.Default.Excelresulturl + fileInfo2.Name;
866
            }
867
            catch (Exception e)
868
            {
869
                _result = "ERROR : " + e.ToString();
870
            }
871
            return _result;
872
        }
873

    
874
        private static void ReleaseExcelObject(object obj)
875
        {
876
            try
877
            {
878
                if (obj != null)
879
                {
880
                    obj = null;
881
                }
882
            }
883
            catch (Exception ex)
884
            {
885
                obj = null;
886
                throw ex;
887
            }
888
            finally
889
            {
890
                GC.Collect();
891
            }
892
        }
893
    }
894
}
클립보드 이미지 추가 (최대 크기: 500 MB)