markus / ConvertService / ServiceBase / ConvertionWebServiceDefault / Conversion.asmx.cs @ d21e9c15
이력 | 보기 | 이력해설 | 다운로드 (38.4 KB)
1 | d21e9c15 | taeseongkim | 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 DeepView.Toolkit.GuidGenerator; |
||
11 | using MarkupToPDF; |
||
12 | using System.IO; |
||
13 | using Newtonsoft.Json; |
||
14 | using Newtonsoft.Json.Linq; |
||
15 | using log4net; |
||
16 | using DeepViewDataModel.DataModel; |
||
17 | using DeepViewDataModel.Common; |
||
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}&ConvertID={_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(slipLink)) |
||
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 | [WebMethod] |
||
467 | public string UpdatePDFUrl(string EnsembleId, string original_url, string result_url) |
||
468 | { |
||
469 | string _result = null; |
||
470 | try |
||
471 | { |
||
472 | using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
||
473 | { |
||
474 | var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault(); |
||
475 | |||
476 | if (!string.IsNullOrEmpty(original_url)) |
||
477 | { |
||
478 | string url = original_url; |
||
479 | url = Base64Decode(url); |
||
480 | url = HttpUtility.UrlEncodeUnicode(url); |
||
481 | doc.ORIGINAL_FILE = url; |
||
482 | } |
||
483 | if (!string.IsNullOrEmpty(result_url)) |
||
484 | { |
||
485 | doc.RESULT_FILE = result_url; |
||
486 | } |
||
487 | deepViewEntity.SaveChanges(); |
||
488 | _result = true.ToString(); |
||
489 | } |
||
490 | } |
||
491 | catch (Exception ex) |
||
492 | { |
||
493 | logger.Error("Conversion Web Service UpdateVP Error", ex); |
||
494 | _result = ex.Message.ToString(); |
||
495 | } |
||
496 | return _result; |
||
497 | } |
||
498 | |||
499 | [WebMethod] |
||
500 | public string DeleteVP(string id) |
||
501 | { |
||
502 | string _result = null; |
||
503 | try |
||
504 | { |
||
505 | using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
||
506 | { |
||
507 | var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == id).FirstOrDefault(); |
||
508 | |||
509 | if (doc != null) |
||
510 | { |
||
511 | doc.DOCUMENT_NO = "VOID_" + doc.DOCUMENT_NO; |
||
512 | doc.GROUP_NO = "VOID_" + doc.GROUP_NO; |
||
513 | //deepViewEntity.DeleteObject(doc); |
||
514 | deepViewEntity.SaveChanges(); |
||
515 | _result = true.ToString(); |
||
516 | } |
||
517 | else |
||
518 | _result = "document not found."; |
||
519 | } |
||
520 | } |
||
521 | catch (Exception ex) |
||
522 | { |
||
523 | logger.Error("Conversion Web Service DeleteVP Error", ex); |
||
524 | _result = ex.Message.ToString(); |
||
525 | } |
||
526 | return _result; |
||
527 | } |
||
528 | public string getDocumentID(string id) |
||
529 | { |
||
530 | string _doc_id = ((UInt32)id.GetHashCode()).ToString(); |
||
531 | return _doc_id; |
||
532 | } |
||
533 | [WebMethod] |
||
534 | public string CoverConvert(string prj_No, string _id) |
||
535 | { |
||
536 | string _result = null; |
||
537 | try |
||
538 | { |
||
539 | SendCoverConvert(prj_No, _id); |
||
540 | } |
||
541 | catch (Exception ex) |
||
542 | { |
||
543 | logger.Error("Conversion Web Service CoverConvert Error", ex); |
||
544 | _result = ex.Message.ToString(); |
||
545 | } |
||
546 | return _result; |
||
547 | } |
||
548 | private string SendCoverConvert(string prj_No, string _id) |
||
549 | { |
||
550 | if (remObj == null) |
||
551 | { |
||
552 | return "Window Service Connection Error"; |
||
553 | } |
||
554 | else |
||
555 | { |
||
556 | var _result = remObj.SetConverterCoverPDF(prj_No, _id); |
||
557 | |||
558 | if (_result.Exception != null) |
||
559 | { |
||
560 | return false.ToString(); |
||
561 | } |
||
562 | else |
||
563 | { |
||
564 | return true.ToString(); |
||
565 | } |
||
566 | } |
||
567 | } |
||
568 | private string SendKcom(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url) |
||
569 | { |
||
570 | string result = false.ToString(); |
||
571 | |||
572 | if (remObj == null) |
||
573 | { |
||
574 | result = "Window Service Connection Error"; |
||
575 | } |
||
576 | else |
||
577 | { |
||
578 | //string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString(); |
||
579 | string _id = shortGuid(); |
||
580 | string _doc_id = ((UInt32)document_Id.GetHashCode()).ToString(); |
||
581 | using (DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
||
582 | { |
||
583 | if (string.IsNullOrEmpty(group_No)) |
||
584 | { |
||
585 | group_No = "0"; |
||
586 | } |
||
587 | if (!document_Url.Contains("http%3a%2f%2f")) |
||
588 | { |
||
589 | document_Url = Base64Decode(document_Url); |
||
590 | document_Url = System.Net.WebUtility.UrlEncode(document_Url); |
||
591 | } |
||
592 | document_Name = Base64DecodeFromStr(document_Name); |
||
593 | |||
594 | var doc = _entity.DOCUMENT_ITEM.Where(d => d.PROJECT_NO == prj_No && d.ID == document_Id).FirstOrDefault(); |
||
595 | if(doc != null) |
||
596 | { |
||
597 | doc.DOCUMENT_ID = _doc_id; |
||
598 | doc.REVISION = rev_No; |
||
599 | doc.GROUP_NO = group_No; |
||
600 | doc.DOCUMENT_NO = document_No; |
||
601 | doc.DOCUMENT_NAME = document_Name; |
||
602 | doc.ORIGINAL_FILE = document_Url; |
||
603 | } |
||
604 | else |
||
605 | { |
||
606 | _entity.AddToDOCUMENT_ITEM(new DOCUMENT_ITEM |
||
607 | { |
||
608 | ID = document_Id, |
||
609 | REVISION = rev_No, |
||
610 | DOCUMENT_NO = document_No, |
||
611 | DOCUMENT_NAME = document_Name, |
||
612 | GROUP_NO = group_No, |
||
613 | ORIGINAL_FILE = document_Url, |
||
614 | DOCUMENT_ID = _doc_id, |
||
615 | PROJECT_NO = prj_No, |
||
616 | }); |
||
617 | } |
||
618 | |||
619 | _entity.AddToCONVERTER_DOC(new CONVERTER_DOC |
||
620 | { |
||
621 | ID = _id, |
||
622 | CREATE_DATETIME = DateTime.Now, |
||
623 | DOCUMENT_URL = document_Url, |
||
624 | PROJECT_NO = prj_No, |
||
625 | DOCUMENT_ID = _doc_id, |
||
626 | }); |
||
627 | _entity.SaveChanges(); |
||
628 | } |
||
629 | |||
630 | if (Properties.Settings.Default.MARKUS_V3_PROJECTS.Split(',').Contains(prj_No)) |
||
631 | { |
||
632 | try |
||
633 | { |
||
634 | System.Net.WebClient client = new System.Net.WebClient(); |
||
635 | var convertResult = client.DownloadString($"{Properties.Settings.Default.MARKUS_V3_ADDRESS}/Rest/ConvertAdd?ProjectNo={prj_No}&ConvertID={_id}"); |
||
636 | |||
637 | JObject jObject = JObject.Parse(convertResult, new JsonLoadSettings()); |
||
638 | result = jObject["ConvertAddResult"].ToString(); |
||
639 | } |
||
640 | catch (Exception ex) |
||
641 | { |
||
642 | logger.Error("Conversion Web Service SendKcom Error", ex); |
||
643 | result = $"Markus V3 Connect Error {ex.Message}"; |
||
644 | } |
||
645 | } |
||
646 | else |
||
647 | { |
||
648 | var convertResult = remObj.SetConverterPDF(prj_No, _id); |
||
649 | |||
650 | if (convertResult.Exception != null) |
||
651 | { |
||
652 | result = false.ToString(); |
||
653 | } |
||
654 | else |
||
655 | { |
||
656 | result = true.ToString(); |
||
657 | } |
||
658 | } |
||
659 | |||
660 | } |
||
661 | |||
662 | return result; |
||
663 | } |
||
664 | |||
665 | private string ManualSendKcom(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url) |
||
666 | { |
||
667 | if (remObj == null) |
||
668 | { |
||
669 | return "Window Service Connection Error"; |
||
670 | } |
||
671 | else |
||
672 | { |
||
673 | //string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString(); |
||
674 | string _id = shortGuid(); |
||
675 | string _doc_id = ((UInt32)document_Id.GetHashCode()).ToString(); |
||
676 | using (DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
||
677 | { |
||
678 | var doc = _entity.DOCUMENT_ITEM.Where(d =>d.PROJECT_NO == prj_No && d.ID == document_Id).FirstOrDefault(); |
||
679 | |||
680 | if (doc != null) |
||
681 | { |
||
682 | var converterdoc = _entity.CONVERTER_DOC.Where(c =>c.PROJECT_NO == doc.PROJECT_NO && c.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault(); |
||
683 | _entity.DeleteObject(converterdoc); |
||
684 | _entity.DeleteObject(doc); |
||
685 | _entity.SaveChanges(); |
||
686 | |||
687 | document_Url = HttpUtility.UrlDecode(document_Url); |
||
688 | } |
||
689 | |||
690 | int cnt = _entity.DOCUMENT_ITEM.ToList().Count; |
||
691 | if (string.IsNullOrEmpty(group_No)) |
||
692 | { |
||
693 | group_No = "0"; |
||
694 | } |
||
695 | |||
696 | _entity.AddToDOCUMENT_ITEM(new DOCUMENT_ITEM |
||
697 | { |
||
698 | ID = document_Id, |
||
699 | REVISION = rev_No, |
||
700 | DOCUMENT_NO = document_No, |
||
701 | DOCUMENT_NAME = document_Name, |
||
702 | GROUP_NO = group_No, |
||
703 | ORIGINAL_FILE = HttpUtility.UrlEncodeUnicode(document_Url), |
||
704 | DOCUMENT_ID = _doc_id, |
||
705 | PROJECT_NO = prj_No, |
||
706 | }); |
||
707 | _entity.AddToCONVERTER_DOC(new CONVERTER_DOC |
||
708 | { |
||
709 | ID = _id, |
||
710 | CREATE_DATETIME = DateTime.Now, |
||
711 | DOCUMENT_URL = HttpUtility.UrlEncodeUnicode(document_Url), |
||
712 | PROJECT_NO = prj_No, |
||
713 | DOCUMENT_ID = _doc_id, |
||
714 | }); |
||
715 | _entity.SaveChanges(); |
||
716 | } |
||
717 | var _result = remObj.SetConverterPDF(prj_No, _id); |
||
718 | |||
719 | if (_result.Exception != null) |
||
720 | { |
||
721 | return false.ToString(); |
||
722 | } |
||
723 | else |
||
724 | { |
||
725 | return true.ToString(); |
||
726 | } |
||
727 | } |
||
728 | } |
||
729 | |||
730 | //private Guid GetGuid(int Count,Guid ID) |
||
731 | //{ |
||
732 | // Guid _ID = ID; |
||
733 | // string _id = _ID.ToString(); |
||
734 | // DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()); |
||
735 | |||
736 | // if (_entity.CONVERTER_DOC.Where(c => c.ID == _id).Count() > 0) |
||
737 | // { |
||
738 | // _entity.Dispose(); |
||
739 | |||
740 | // if (Count > 10) |
||
741 | // { |
||
742 | // new Exception("GetGuid : Not Generator"); |
||
743 | // } |
||
744 | |||
745 | // if (Count < 3) |
||
746 | // { |
||
747 | // System.Threading.Thread.Sleep(3); |
||
748 | // } |
||
749 | |||
750 | // GetGuid(Count++,GuidGenerator.GetUniqueGuid()); |
||
751 | // } |
||
752 | |||
753 | // return ID; |
||
754 | //} |
||
755 | |||
756 | //GUID생성(최민수 사원 수정) |
||
757 | public string shortGuid() |
||
758 | { |
||
759 | byte[] bytes = new byte[16]; |
||
760 | using (var provider = System.Security.Cryptography.RandomNumberGenerator.Create()) |
||
761 | { |
||
762 | provider.GetBytes(bytes); |
||
763 | } |
||
764 | |||
765 | var guid = new Guid(bytes); |
||
766 | |||
767 | return Convert.ToBase64String(guid.ToByteArray()) |
||
768 | .Substring(0, 10) |
||
769 | .Replace("/", "") |
||
770 | .Replace("+", "") + DateTime.UtcNow.Ticks.ToString("x"); |
||
771 | } |
||
772 | |||
773 | [WebMethod] |
||
774 | public string ExcelExport(string project_no, string slip_no) |
||
775 | { |
||
776 | string _result = "false"; |
||
777 | //FileInfo fileInfo2 = new FileInfo(Path.GetTempFileName()); |
||
778 | //fileInfo2.FullName |
||
779 | try |
||
780 | { |
||
781 | // Excel 첫번째 워크시트 가져오기 |
||
782 | //application = new Excel.Application(); |
||
783 | //workbook = application.Workbooks.Open(xlsxfilepath); |
||
784 | //worksheet = (Excel.Worksheet)workbook.Worksheets.get_Item("Sheet1"); |
||
785 | string xlsxfilepath = @"C:\WebSite\LogView\Doc_Manager\sample.xlsx"; |
||
786 | GemBox.Spreadsheet.SpreadsheetInfo.SetLicense("EXK0-W4HZ-N518-IMEW"); |
||
787 | GemBox.Spreadsheet.ExcelFile excelFile = new GemBox.Spreadsheet.ExcelFile(); |
||
788 | excelFile.LoadXlsx(xlsxfilepath, GemBox.Spreadsheet.XlsxOptions.PreserveMakeCopy); |
||
789 | GemBox.Spreadsheet.ExcelWorksheet ws = excelFile.Worksheets[0]; |
||
790 | FileInfo fileInfo2 = new FileInfo(Path.GetTempFileName().Replace(".tmp", ".xlsx")); |
||
791 | |||
792 | string fileout = @"C:\WebSite\LogView\Doc_Manager\commentexcel_" + DateTime.Now.ToString() + ".xlsx"; |
||
793 | string naspath = Properties.Settings.Default.Excelfilepath; |
||
794 | //@"\\172.20.121.220\comment3\TileSource\Excelexport"; |
||
795 | |||
796 | // 데이타 넣기 |
||
797 | int h = 6; |
||
798 | int w = 1; |
||
799 | |||
800 | |||
801 | //필터 기능 추가 |
||
802 | //Excel.Range Filter_Range = worksheet.Range["B9:" + Ran + "9"]; |
||
803 | //Filter_Range.AutoFilter(1, Type.Missing, Excel.XlAutoFilterOperator.xlAnd, Type.Missing, true); |
||
804 | |||
805 | |||
806 | using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
||
807 | { |
||
808 | var docs = deepViewEntity.DOCUMENT_ITEM.Where(doc => doc.GROUP_NO == slip_no && doc.PROJECT_NO == project_no).ToList(); |
||
809 | if (docs.Count > 0) |
||
810 | { |
||
811 | foreach (var doc in docs) |
||
812 | { |
||
813 | var commentlist = deepViewEntity.MARKUP_DATA.Where(d => d.MARKUP_INFO_VERSION.MARKUP_INFO.DOCINFO.DOCUMENT_ID == doc.DOCUMENT_ID |
||
814 | && d.MARKUP_INFO_VERSION.MARKUP_INFO.CONSOLIDATE == 1).ToList(); |
||
815 | |||
816 | string docNo = doc.DOCUMENT_NO; |
||
817 | string docDesc = doc.DOCUMENT_NAME; |
||
818 | string docRev = doc.REVISION; |
||
819 | foreach (var comment in commentlist) |
||
820 | { |
||
821 | var member = deepViewEntity.MEMBER.Where(m => m.ID == comment.MARKUP_INFO_VERSION.MARKUP_INFO.USER_ID).FirstOrDefault(); |
||
822 | string docdept = member.DEPARTMENT; |
||
823 | string doccomment = string.Empty; |
||
824 | var data = MarkupToPDF.Serialize.Core.JsonSerializerHelper.UnCompressString(comment.DATA.ToString()); |
||
825 | switch (Enum.Parse(typeof(MarkupToPDF.Controls.Common.ControlType), comment.DATA_TYPE.ToString())) |
||
826 | { |
||
827 | case MarkupToPDF.Controls.Common.ControlType.TextControl: |
||
828 | case MarkupToPDF.Controls.Common.ControlType.TextBorder: |
||
829 | case MarkupToPDF.Controls.Common.ControlType.TextCloud: |
||
830 | { |
||
831 | MarkupToPDF.Serialize.S_Control.S_TextControl instance = MarkupToPDF.Serialize.Core.JsonSerializerHelper.JsonDeserialize<MarkupToPDF.Serialize.S_Control.S_TextControl>(data); |
||
832 | doccomment = instance.Text; |
||
833 | } |
||
834 | break; |
||
835 | case MarkupToPDF.Controls.Common.ControlType.ArrowTextBorderControl: |
||
836 | case MarkupToPDF.Controls.Common.ControlType.ArrowTextCloudControl: |
||
837 | case MarkupToPDF.Controls.Common.ControlType.ArrowTextControl: |
||
838 | case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextBorderControl: |
||
839 | case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextCloudControl: |
||
840 | case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextControl: |
||
841 | { |
||
842 | MarkupToPDF.Serialize.S_Control.S_ArrowTextControl instance = MarkupToPDF.Serialize.Core.JsonSerializerHelper.JsonDeserialize<MarkupToPDF.Serialize.S_Control.S_ArrowTextControl>(data); |
||
843 | doccomment = instance.ArrowText; |
||
844 | } |
||
845 | break; |
||
846 | } |
||
847 | ws.Cells[h, w].Value = string.Format("{0}\n({1})", docNo, docDesc); |
||
848 | ws.Cells[h, w + 1].Value = docRev; |
||
849 | ws.Cells[h, w + 2].Value = docdept; |
||
850 | ws.Cells[h, w + 3].Value = doccomment; |
||
851 | h++; |
||
852 | } |
||
853 | } |
||
854 | } |
||
855 | else |
||
856 | { |
||
857 | _result = "ERROR : 해당 Slip 의 데이터가 없습니다."; |
||
858 | } |
||
859 | |||
860 | |||
861 | } |
||
862 | |||
863 | int columnCount = ws.CalculateMaxUsedColumns(); |
||
864 | for (int i = 0; i < columnCount; i++) |
||
865 | ws.Columns[i].AutoFit(); |
||
866 | //worksheet.Columns.AutoFit(); |
||
867 | // 엑셀파일 저장 |
||
868 | |||
869 | excelFile.Save(fileInfo2.FullName); |
||
870 | fileInfo2.MoveTo(naspath + "\\" + fileInfo2.Name); |
||
871 | //workbook.SaveAs(fileout); |
||
872 | ////workbook.Save(); |
||
873 | //workbook.Close(true); |
||
874 | //application.Quit(); |
||
875 | _result = Properties.Settings.Default.Excelresulturl + fileInfo2.Name; |
||
876 | } |
||
877 | catch (Exception e) |
||
878 | { |
||
879 | _result = "ERROR : " + e.ToString(); |
||
880 | } |
||
881 | return _result; |
||
882 | } |
||
883 | |||
884 | private static void ReleaseExcelObject(object obj) |
||
885 | { |
||
886 | try |
||
887 | { |
||
888 | if (obj != null) |
||
889 | { |
||
890 | obj = null; |
||
891 | } |
||
892 | } |
||
893 | catch (Exception ex) |
||
894 | { |
||
895 | obj = null; |
||
896 | throw ex; |
||
897 | } |
||
898 | finally |
||
899 | { |
||
900 | GC.Collect(); |
||
901 | } |
||
902 | } |
||
903 | } |
||
904 | } |