markus / ConvertService / ServiceBase / ConvertionWebService / Conversion.asmx.cs @ 3c71b3a5
이력 | 보기 | 이력해설 | 다운로드 (34.6 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 (!prj_No.Equals("150128")) |
158 |
{ |
159 |
//Omsk 는 웹서비스 호출 시 인코딩 |
160 |
//Omsk 제외는 Markus 에서 인코딩 |
161 |
document_Url = Base64Decode(document_Url); |
162 |
} |
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 Base64Decode(string data) |
326 |
{ |
327 |
try |
328 |
{ |
329 |
|
330 |
System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); |
331 |
System.Text.Decoder utf8Decode = encoder.GetDecoder(); |
332 |
|
333 |
byte[] todecode_byte = Convert.FromBase64String(data); |
334 |
|
335 |
int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); |
336 |
|
337 |
char[] decoded_char = new char[charCount]; |
338 |
|
339 |
utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); |
340 |
|
341 |
string result = new String(decoded_char); |
342 |
|
343 |
return result; |
344 |
|
345 |
} |
346 |
|
347 |
catch (Exception e) |
348 |
{ |
349 |
throw new Exception("Error in Base64Decode: " + e.Message); |
350 |
} |
351 |
} |
352 |
[WebMethod] |
353 |
public string UpdateSlip(string EnsembleId, string SlipNo, string slipLink) |
354 |
{ |
355 |
string _result = null; |
356 |
try |
357 |
{ |
358 |
using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
359 |
{ |
360 |
var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault(); |
361 |
if(!string.IsNullOrEmpty(slipLink)) |
362 |
doc.GROUP_NO = SlipNo; |
363 |
if(!string.IsNullOrEmpty(slipLink)) |
364 |
{ |
365 |
if (!slipLink.Contains("http://")) |
366 |
slipLink = Base64Decode(slipLink); |
367 |
doc.ENSEMBLEINFO_URL = slipLink; |
368 |
} |
369 |
|
370 |
deepViewEntity.SaveChanges(); |
371 |
} |
372 |
} |
373 |
catch (Exception ex) |
374 |
{ |
375 |
logger.Error($"Conversion Web Service UpdateSlip Error EnsembleId : {EnsembleId} SlipNo : {SlipNo} slipLink: {slipLink}", ex); |
376 |
_result = ex.Message.ToString(); |
377 |
} |
378 |
return _result; |
379 |
} |
380 |
[WebMethod] |
381 |
public string UpdateResult(string EnsembleId, string Result, string FinalPDFUrl) |
382 |
{ |
383 |
string _result = null; |
384 |
try |
385 |
{ |
386 |
using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
387 |
{ |
388 |
var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault(); |
389 |
doc.RESULT = Result; |
390 |
doc.RESULT_FILE = FinalPDFUrl; |
391 |
deepViewEntity.SaveChanges(); |
392 |
} |
393 |
} |
394 |
catch (Exception ex) |
395 |
{ |
396 |
logger.Error("Conversion Web Service UpdateResult Error", ex); |
397 |
_result = ex.Message.ToString(); |
398 |
} |
399 |
return _result; |
400 |
} |
401 |
[WebMethod] |
402 |
public string UpdateVP(string EnsembleId, string rev_No, string document_No, string document_Name, string pdf_url) |
403 |
{ |
404 |
string _result = null; |
405 |
try |
406 |
{ |
407 |
using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
408 |
{ |
409 |
var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault(); |
410 |
if(!string.IsNullOrEmpty(rev_No)) |
411 |
doc.REVISION = rev_No; |
412 |
if (!string.IsNullOrEmpty(document_No)) |
413 |
doc.DOCUMENT_NO = document_No; |
414 |
if (!string.IsNullOrEmpty(document_Name)) |
415 |
doc.DOCUMENT_NAME = document_Name; |
416 |
if (!string.IsNullOrEmpty(pdf_url)) |
417 |
{ |
418 |
string url = pdf_url; |
419 |
if (!doc.PROJECT_NO.Equals("150128")) |
420 |
{ |
421 |
url = HttpUtility.UrlEncodeUnicode(url); |
422 |
} |
423 |
doc.ORIGINAL_FILE = url; |
424 |
} |
425 |
deepViewEntity.SaveChanges(); |
426 |
} |
427 |
} |
428 |
catch (Exception ex) |
429 |
{ |
430 |
logger.Error("Conversion Web Service UpdateVP Error", ex); |
431 |
_result = ex.Message.ToString(); |
432 |
} |
433 |
return _result; |
434 |
} |
435 |
[WebMethod] |
436 |
public string CoverConvert(string prj_No, string _id) |
437 |
{ |
438 |
string _result = null; |
439 |
try |
440 |
{ |
441 |
SendCoverConvert(prj_No, _id); |
442 |
} |
443 |
catch (Exception ex) |
444 |
{ |
445 |
logger.Error("Conversion Web Service CoverConvert Error", ex); |
446 |
_result = ex.Message.ToString(); |
447 |
} |
448 |
return _result; |
449 |
} |
450 |
private string SendCoverConvert(string prj_No, string _id) |
451 |
{ |
452 |
if (remObj == null) |
453 |
{ |
454 |
return "Window Service Connection Error"; |
455 |
} |
456 |
else |
457 |
{ |
458 |
var _result = remObj.SetConverterCoverPDF(prj_No, _id); |
459 |
|
460 |
if (_result.Exception != null) |
461 |
{ |
462 |
return false.ToString(); |
463 |
} |
464 |
else |
465 |
{ |
466 |
return true.ToString(); |
467 |
} |
468 |
} |
469 |
} |
470 |
private string SendKcom(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url) |
471 |
{ |
472 |
string result = false.ToString(); |
473 |
|
474 |
if (remObj == null) |
475 |
{ |
476 |
result = "Window Service Connection Error"; |
477 |
} |
478 |
else |
479 |
{ |
480 |
//string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString(); |
481 |
string _id = shortGuid(); |
482 |
string _doc_id = ((UInt32)document_Id.GetHashCode()).ToString(); |
483 |
using (DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
484 |
{ |
485 |
if (string.IsNullOrEmpty(group_No)) |
486 |
{ |
487 |
group_No = "0"; |
488 |
} |
489 |
if (!prj_No.Equals("150128")) |
490 |
{ |
491 |
//Omsk 는 웹서비스 호출 시 인코딩 |
492 |
//Omsk 제외는 Markus 에서 인코딩 |
493 |
document_Url = Base64Decode(document_Url); |
494 |
} |
495 |
var doc = _entity.DOCUMENT_ITEM.Where(d => d.ID == document_Id).FirstOrDefault(); |
496 |
if(doc != null) |
497 |
{ |
498 |
doc.REVISION = rev_No; |
499 |
doc.ORIGINAL_FILE = document_Url; |
500 |
doc.GROUP_NO = group_No; |
501 |
doc.DOCUMENT_NO = document_No; |
502 |
doc.DOCUMENT_NAME = document_Name; |
503 |
}else |
504 |
{ |
505 |
_entity.AddToDOCUMENT_ITEM(new DOCUMENT_ITEM |
506 |
{ |
507 |
ID = document_Id, |
508 |
REVISION = rev_No, |
509 |
DOCUMENT_NO = document_No, |
510 |
DOCUMENT_NAME = document_Name, |
511 |
GROUP_NO = group_No, |
512 |
ORIGINAL_FILE = document_Url, |
513 |
DOCUMENT_ID = _doc_id, |
514 |
PROJECT_NO = prj_No, |
515 |
}); |
516 |
} |
517 |
|
518 |
_entity.AddToCONVERTER_DOC(new CONVERTER_DOC |
519 |
{ |
520 |
ID = _id, |
521 |
CREATE_DATETIME = DateTime.Now, |
522 |
DOCUMENT_URL = document_Url, |
523 |
PROJECT_NO = prj_No, |
524 |
DOCUMENT_ID = _doc_id, |
525 |
}); |
526 |
_entity.SaveChanges(); |
527 |
} |
528 |
|
529 |
if (Properties.Settings.Default.MARKUS_V3_PROJECTS.Split(',').Contains(prj_No)) |
530 |
{ |
531 |
try |
532 |
{ |
533 |
System.Net.WebClient client = new System.Net.WebClient(); |
534 |
var convertResult = client.DownloadString($"{Properties.Settings.Default.MARKUS_V3_ADDRESS}/Rest/ConvertAdd?ProjectNo={prj_No}&DocumentID={_id}"); |
535 |
|
536 |
JObject jObject = JObject.Parse(convertResult, new JsonLoadSettings()); |
537 |
result = jObject["ConvertAddResult"].ToString(); |
538 |
} |
539 |
catch (Exception ex) |
540 |
{ |
541 |
logger.Error("Conversion Web Service SendKcom Error", ex); |
542 |
result = $"Markus V3 Connect Error {ex.Message}"; |
543 |
} |
544 |
} |
545 |
else |
546 |
{ |
547 |
var convertResult = remObj.SetConverterPDF(prj_No, _id); |
548 |
|
549 |
if (convertResult.Exception != null) |
550 |
{ |
551 |
result = false.ToString(); |
552 |
} |
553 |
else |
554 |
{ |
555 |
result = true.ToString(); |
556 |
} |
557 |
} |
558 |
|
559 |
} |
560 |
|
561 |
return result; |
562 |
} |
563 |
|
564 |
private string ManualSendKcom(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url) |
565 |
{ |
566 |
if (remObj == null) |
567 |
{ |
568 |
return "Window Service Connection Error"; |
569 |
} |
570 |
else |
571 |
{ |
572 |
//string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString(); |
573 |
string _id = shortGuid(); |
574 |
string _doc_id = ((UInt32)document_Id.GetHashCode()).ToString(); |
575 |
using (DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
576 |
{ |
577 |
var doc = _entity.DOCUMENT_ITEM.Where(d => d.ID == document_Id).FirstOrDefault(); |
578 |
if (doc != null) |
579 |
{ |
580 |
var converterdoc = _entity.CONVERTER_DOC.Where(c => c.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault(); |
581 |
_entity.DeleteObject(converterdoc); |
582 |
_entity.DeleteObject(doc); |
583 |
_entity.SaveChanges(); |
584 |
document_Url = HttpUtility.UrlDecode(document_Url); |
585 |
} |
586 |
int cnt = _entity.DOCUMENT_ITEM.ToList().Count; |
587 |
if (string.IsNullOrEmpty(group_No)) |
588 |
{ |
589 |
group_No = "0"; |
590 |
} |
591 |
|
592 |
_entity.AddToDOCUMENT_ITEM(new DOCUMENT_ITEM |
593 |
{ |
594 |
ID = document_Id, |
595 |
REVISION = rev_No, |
596 |
DOCUMENT_NO = document_No, |
597 |
DOCUMENT_NAME = document_Name, |
598 |
GROUP_NO = group_No, |
599 |
ORIGINAL_FILE = HttpUtility.UrlEncodeUnicode(document_Url), |
600 |
DOCUMENT_ID = _doc_id, |
601 |
PROJECT_NO = prj_No, |
602 |
}); |
603 |
_entity.AddToCONVERTER_DOC(new CONVERTER_DOC |
604 |
{ |
605 |
ID = _id, |
606 |
CREATE_DATETIME = DateTime.Now, |
607 |
DOCUMENT_URL = HttpUtility.UrlEncodeUnicode(document_Url), |
608 |
PROJECT_NO = prj_No, |
609 |
DOCUMENT_ID = _doc_id, |
610 |
}); |
611 |
_entity.SaveChanges(); |
612 |
} |
613 |
var _result = remObj.SetConverterPDF(prj_No, _id); |
614 |
|
615 |
if (_result.Exception != null) |
616 |
{ |
617 |
return false.ToString(); |
618 |
} |
619 |
else |
620 |
{ |
621 |
return true.ToString(); |
622 |
} |
623 |
} |
624 |
} |
625 |
|
626 |
//private Guid GetGuid(int Count,Guid ID) |
627 |
//{ |
628 |
// Guid _ID = ID; |
629 |
// string _id = _ID.ToString(); |
630 |
// DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()); |
631 |
|
632 |
// if (_entity.CONVERTER_DOC.Where(c => c.ID == _id).Count() > 0) |
633 |
// { |
634 |
// _entity.Dispose(); |
635 |
|
636 |
// if (Count > 10) |
637 |
// { |
638 |
// new Exception("GetGuid : Not Generator"); |
639 |
// } |
640 |
|
641 |
// if (Count < 3) |
642 |
// { |
643 |
// System.Threading.Thread.Sleep(3); |
644 |
// } |
645 |
|
646 |
// GetGuid(Count++,GuidGenerator.GetUniqueGuid()); |
647 |
// } |
648 |
|
649 |
// return ID; |
650 |
//} |
651 |
|
652 |
//GUID생성(최민수 사원 수정) |
653 |
public string shortGuid() |
654 |
{ |
655 |
byte[] bytes = new byte[16]; |
656 |
using (var provider = System.Security.Cryptography.RandomNumberGenerator.Create()) |
657 |
{ |
658 |
provider.GetBytes(bytes); |
659 |
} |
660 |
|
661 |
var guid = new Guid(bytes); |
662 |
|
663 |
return Convert.ToBase64String(guid.ToByteArray()) |
664 |
.Substring(0, 10) |
665 |
.Replace("/", "") |
666 |
.Replace("+", "") + DateTime.UtcNow.Ticks.ToString("x"); |
667 |
} |
668 |
|
669 |
[WebMethod] |
670 |
public string ExcelExport(string project_no, string slip_no) |
671 |
{ |
672 |
string _result = "false"; |
673 |
//FileInfo fileInfo2 = new FileInfo(Path.GetTempFileName()); |
674 |
//fileInfo2.FullName |
675 |
try |
676 |
{ |
677 |
// Excel 첫번째 워크시트 가져오기 |
678 |
//application = new Excel.Application(); |
679 |
//workbook = application.Workbooks.Open(xlsxfilepath); |
680 |
//worksheet = (Excel.Worksheet)workbook.Worksheets.get_Item("Sheet1"); |
681 |
string xlsxfilepath = @"C:\WebSite\LogView\Doc_Manager\sample.xlsx"; |
682 |
GemBox.Spreadsheet.SpreadsheetInfo.SetLicense("EXK0-W4HZ-N518-IMEW"); |
683 |
GemBox.Spreadsheet.ExcelFile excelFile = new GemBox.Spreadsheet.ExcelFile(); |
684 |
excelFile.LoadXlsx(xlsxfilepath, GemBox.Spreadsheet.XlsxOptions.PreserveMakeCopy); |
685 |
GemBox.Spreadsheet.ExcelWorksheet ws = excelFile.Worksheets[0]; |
686 |
FileInfo fileInfo2 = new FileInfo(Path.GetTempFileName().Replace(".tmp", ".xlsx")); |
687 |
|
688 |
string fileout = @"C:\WebSite\LogView\Doc_Manager\commentexcel_" + DateTime.Now.ToString() + ".xlsx"; |
689 |
string naspath = Properties.Settings.Default.Excelfilepath; |
690 |
//@"\\172.20.121.220\comment3\TileSource\Excelexport"; |
691 |
|
692 |
// 데이타 넣기 |
693 |
int h = 6; |
694 |
int w = 1; |
695 |
|
696 |
|
697 |
//필터 기능 추가 |
698 |
//Excel.Range Filter_Range = worksheet.Range["B9:" + Ran + "9"]; |
699 |
//Filter_Range.AutoFilter(1, Type.Missing, Excel.XlAutoFilterOperator.xlAnd, Type.Missing, true); |
700 |
|
701 |
|
702 |
using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
703 |
{ |
704 |
var docs = deepViewEntity.DOCUMENT_ITEM.Where(doc => doc.GROUP_NO == slip_no && doc.PROJECT_NO == project_no).ToList(); |
705 |
if (docs.Count > 0) |
706 |
{ |
707 |
foreach (var doc in docs) |
708 |
{ |
709 |
var commentlist = deepViewEntity.MARKUP_DATA.Where(d => d.MARKUP_INFO_VERSION.MARKUP_INFO.DOCINFO.DOCUMENT_ID == doc.DOCUMENT_ID |
710 |
&& d.MARKUP_INFO_VERSION.MARKUP_INFO.CONSOLIDATE == 1).ToList(); |
711 |
|
712 |
string docNo = doc.DOCUMENT_NO; |
713 |
string docDesc = doc.DOCUMENT_NAME; |
714 |
string docRev = doc.REVISION; |
715 |
foreach (var comment in commentlist) |
716 |
{ |
717 |
var member = deepViewEntity.MEMBER.Where(m => m.ID == comment.MARKUP_INFO_VERSION.MARKUP_INFO.USER_ID).FirstOrDefault(); |
718 |
string docdept = member.DEPARTMENT; |
719 |
string doccomment = string.Empty; |
720 |
var data = MarkupToPDF.Serialize.Core.JsonSerializerHelper.UnCompressString(comment.DATA.ToString()); |
721 |
switch (Enum.Parse(typeof(MarkupToPDF.Controls.Common.ControlType), comment.DATA_TYPE.ToString())) |
722 |
{ |
723 |
case MarkupToPDF.Controls.Common.ControlType.TextControl: |
724 |
case MarkupToPDF.Controls.Common.ControlType.TextBorder: |
725 |
case MarkupToPDF.Controls.Common.ControlType.TextCloud: |
726 |
{ |
727 |
MarkupToPDF.Serialize.S_Control.S_TextControl instance = MarkupToPDF.Serialize.Core.JsonSerializerHelper.JsonDeserialize<MarkupToPDF.Serialize.S_Control.S_TextControl>(data); |
728 |
doccomment = instance.Text; |
729 |
} |
730 |
break; |
731 |
case MarkupToPDF.Controls.Common.ControlType.ArrowTextBorderControl: |
732 |
case MarkupToPDF.Controls.Common.ControlType.ArrowTextCloudControl: |
733 |
case MarkupToPDF.Controls.Common.ControlType.ArrowTextControl: |
734 |
case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextBorderControl: |
735 |
case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextCloudControl: |
736 |
case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextControl: |
737 |
{ |
738 |
MarkupToPDF.Serialize.S_Control.S_ArrowTextControl instance = MarkupToPDF.Serialize.Core.JsonSerializerHelper.JsonDeserialize<MarkupToPDF.Serialize.S_Control.S_ArrowTextControl>(data); |
739 |
doccomment = instance.ArrowText; |
740 |
} |
741 |
break; |
742 |
} |
743 |
ws.Cells[h, w].Value = string.Format("{0}\n({1})", docNo, docDesc); |
744 |
ws.Cells[h, w + 1].Value = docRev; |
745 |
ws.Cells[h, w + 2].Value = docdept; |
746 |
ws.Cells[h, w + 3].Value = doccomment; |
747 |
h++; |
748 |
} |
749 |
} |
750 |
} |
751 |
else |
752 |
{ |
753 |
_result = "ERROR : 해당 Slip 의 데이터가 없습니다."; |
754 |
} |
755 |
|
756 |
|
757 |
} |
758 |
|
759 |
int columnCount = ws.CalculateMaxUsedColumns(); |
760 |
for (int i = 0; i < columnCount; i++) |
761 |
ws.Columns[i].AutoFit(); |
762 |
//worksheet.Columns.AutoFit(); |
763 |
// 엑셀파일 저장 |
764 |
|
765 |
excelFile.Save(fileInfo2.FullName); |
766 |
fileInfo2.MoveTo(naspath + "\\" + fileInfo2.Name); |
767 |
//workbook.SaveAs(fileout); |
768 |
////workbook.Save(); |
769 |
//workbook.Close(true); |
770 |
//application.Quit(); |
771 |
_result = Properties.Settings.Default.Excelresulturl + fileInfo2.Name; |
772 |
} |
773 |
catch (Exception e) |
774 |
{ |
775 |
_result = "ERROR : " + e.ToString(); |
776 |
} |
777 |
return _result; |
778 |
} |
779 |
|
780 |
private static void ReleaseExcelObject(object obj) |
781 |
{ |
782 |
try |
783 |
{ |
784 |
if (obj != null) |
785 |
{ |
786 |
obj = null; |
787 |
} |
788 |
} |
789 |
catch (Exception ex) |
790 |
{ |
791 |
obj = null; |
792 |
throw ex; |
793 |
} |
794 |
finally |
795 |
{ |
796 |
GC.Collect(); |
797 |
} |
798 |
} |
799 |
} |
800 |
} |