프로젝트

일반

사용자정보

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

markus / ConvertService / ConverterService / ConvertionWebService / Conversion.asmx.cs @ 817531e4

이력 | 보기 | 이력해설 | 다운로드 (5.96 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

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

    
25
        RemConverterPDFObject remObj = null;
26

    
27
        public Conversion()
28
        {
29
            try
30
            {
31
                System.Runtime.Remoting.Channels.IChannel _ch = ChannelServices.GetChannel("tcp");
32

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

    
42
            }
43
            catch (Exception ex)
44
            {
45
                SendNotice(ex.ToString());
46
            }
47
        }
48

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

    
62
        [WebMethod]
63
        public string Run(string projNumber, string DocumentUrl, string ItemID)
64
        {
65
            string _result = null;
66
            try
67
            {
68
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
69
                {
70
                    _result = ConnectStringBuilder.DeepViewConnectionString().ToString();
71
                    //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber && DateTime.Parse(r.RUN_DATETIME)<= DateTime.Now);
72
                    //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber);
73
                    var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO != null);
74

    
75
                    if (_RunProjects.Count() > 0)
76
                    {
77
                        _result = SendKcom(projNumber, DocumentUrl, ItemID);
78
                    }
79
                    else
80
                    {
81
                        //_result = client.Run(projNumber, DocumentUrl);
82
                    }
83
                }
84
            }
85
            catch (Exception ex)
86
            {
87
                _result += "error";
88
                SendNotice("Project NO : " + projNumber + "\r\n  DocumentUrl : " + DocumentUrl + "\r\n Error" + ex.ToString());
89
            }
90
            return _result;
91
        }
92

    
93
        private string SendKcom(string projNumber, string DocumentUrl, string ItemID)
94
        {
95
            if (remObj == null)
96
            {
97
                return "Window Service Connection Error";
98
            }
99
            else
100
            {
101
                //string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString();
102
                string _id = shortGuid();
103

    
104
                using (DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
105
                {
106
                    _entity.AddToCONVERTER_DOC(new CONVERTER_DOC
107
                    {
108
                        ID = _id.ToString(),
109
                        CREATE_DATETIME = DateTime.Now,
110
                        DOCUMENT_URL = DocumentUrl,
111
                        PROJECT_NO = projNumber,
112
                        DOCUMENT_ID = ItemID,
113
                    });
114
                    _entity.SaveChanges();
115

    
116

    
117
                    var _result = remObj.SetConverterPDF(projNumber, _id);
118

    
119
                    if (_result.Exception != null)
120
                        return "Window Service Error";
121
                    else
122
                        return true.ToString();
123
                }
124
            }
125
        }
126

    
127
        //private Guid GetGuid(int Count,Guid ID)
128
        //{
129
        //    Guid _ID = ID;
130
        //    string _id = _ID.ToString();
131
        //    DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString());
132

    
133
        //    if (_entity.CONVERTER_DOC.Where(c => c.ID == _id).Count() > 0)
134
        //    {
135
        //        _entity.Dispose();
136

    
137
        //        if (Count > 10)
138
        //        {
139
        //            new Exception("GetGuid : Not Generator");
140
        //        }
141

    
142
        //        if (Count < 3)
143
        //        {
144
        //            System.Threading.Thread.Sleep(3);
145
        //        }
146

    
147
        //        GetGuid(Count++,GuidGenerator.GetUniqueGuid());
148
        //    }
149

    
150
        //    return ID;
151
        //}
152

    
153
        //GUID생성(최민수 사원 수정)
154
        public string shortGuid()
155
        {
156
            byte[] bytes = new byte[16];
157
            using (var provider = System.Security.Cryptography.RandomNumberGenerator.Create())
158
            {
159
                provider.GetBytes(bytes);
160
            }
161

    
162
            var guid = new Guid(bytes);
163

    
164
            return Convert.ToBase64String(guid.ToByteArray())
165
                .Substring(0, 10)
166
                .Replace("/", "")
167
                .Replace("+", "") + DateTime.UtcNow.Ticks.ToString("x");
168
        }
169
    }
170
}
클립보드 이미지 추가 (최대 크기: 500 MB)