markus / ConvertService / ConverterService / ConvertionWebService / Conversion.asmx.cs @ 2a23dc85
이력 | 보기 | 이력해설 | 다운로드 (5.96 KB)
1 | 7ca218b3 | KangIngu | 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 | 53393bae | KangIngu | //_result = ConnectStringBuilder.DeepViewConnectionString().ToString(); |
71 | 7ca218b3 | KangIngu | //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 | 817531e4 | KangIngu | //string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString(); |
102 | string _id = shortGuid(); |
||
103 | 7ca218b3 | KangIngu | |
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 | 817531e4 | KangIngu | //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 | 7ca218b3 | KangIngu | |
133 | 817531e4 | KangIngu | // if (_entity.CONVERTER_DOC.Where(c => c.ID == _id).Count() > 0) |
134 | // { |
||
135 | // _entity.Dispose(); |
||
136 | 7ca218b3 | KangIngu | |
137 | 817531e4 | KangIngu | // if (Count > 10) |
138 | // { |
||
139 | // new Exception("GetGuid : Not Generator"); |
||
140 | // } |
||
141 | 7ca218b3 | KangIngu | |
142 | 817531e4 | KangIngu | // if (Count < 3) |
143 | // { |
||
144 | // System.Threading.Thread.Sleep(3); |
||
145 | // } |
||
146 | 7ca218b3 | KangIngu | |
147 | 817531e4 | KangIngu | // 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 | 7ca218b3 | KangIngu | } |
161 | |||
162 | 817531e4 | KangIngu | 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 | 7ca218b3 | KangIngu | } |
169 | } |
||
170 | } |