markus / ConvertService / ServiceBase / ConvertionWebService / Conversion.asmx.cs @ 53f96e00
이력 | 보기 | 이력해설 | 다운로드 (35.4 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 |
if(!document_Url.Contains("http%3a%2f%2f")) |
162 |
{ |
163 |
document_Url = Base64Decode(document_Url); |
164 |
document_Url = HttpUtility.UrlEncodeUnicode(document_Url); |
165 |
} |
166 |
} |
167 |
var doc = _entity.DOCUMENT_ITEM.Where(d => d.ID == document_Id).FirstOrDefault(); |
168 |
if (doc != null) |
169 |
{ |
170 |
if (bool.Parse(ignoreComment)) |
171 |
{ |
172 |
try |
173 |
{ |
174 |
var docinfo = _entity.DOCINFO.Where(x => x.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault(); |
175 |
var markupinfos = _entity.MARKUP_INFO.Where(x => x.DOCINFO_ID == docinfo.ID).ToList(); |
176 |
foreach (var markupinfo in markupinfos) |
177 |
{ |
178 |
var markupinfoversions = _entity.MARKUP_INFO_VERSION.Where(x => x.MARKUPINFO_ID == markupinfo.ID).ToList(); |
179 |
foreach (var markupinfoversion in markupinfoversions) |
180 |
{ |
181 |
var markupdatas = _entity.MARKUP_DATA.Where(x => x.MARKUPINFO_VERSION_ID == markupinfoversion.ID).ToList(); |
182 |
foreach (var markupdata in markupdatas) |
183 |
{ |
184 |
_entity.DeleteObject(markupdata); |
185 |
} |
186 |
_entity.DeleteObject(markupinfoversion); |
187 |
} |
188 |
_entity.DeleteObject(markupinfo); |
189 |
} |
190 |
_entity.SaveChanges(); |
191 |
} |
192 |
catch (Exception ex) |
193 |
{ |
194 |
result = "deleteobject error:"+ex.ToString(); |
195 |
} |
196 |
|
197 |
}else |
198 |
{ |
199 |
doc.REVISION = rev_No; |
200 |
doc.ORIGINAL_FILE = document_Url; |
201 |
doc.GROUP_NO = group_No; |
202 |
doc.DOCUMENT_NO = document_No; |
203 |
doc.DOCUMENT_NAME = document_Name; |
204 |
} |
205 |
}else |
206 |
{ |
207 |
_entity.AddToDOCUMENT_ITEM(new DOCUMENT_ITEM |
208 |
{ |
209 |
ID = document_Id, |
210 |
REVISION = rev_No, |
211 |
DOCUMENT_NO = document_No, |
212 |
DOCUMENT_NAME = document_Name, |
213 |
GROUP_NO = group_No, |
214 |
ORIGINAL_FILE = document_Url, |
215 |
DOCUMENT_ID = _doc_id, |
216 |
PROJECT_NO = prj_No, |
217 |
}); |
218 |
} |
219 |
|
220 |
_entity.AddToCONVERTER_DOC(new CONVERTER_DOC |
221 |
{ |
222 |
ID = _id, |
223 |
CREATE_DATETIME = DateTime.Now, |
224 |
DOCUMENT_URL = document_Url, |
225 |
PROJECT_NO = prj_No, |
226 |
DOCUMENT_ID = _doc_id, |
227 |
}); |
228 |
_entity.SaveChanges(); |
229 |
} |
230 |
|
231 |
if (Properties.Settings.Default.MARKUS_V3_PROJECTS.Split(',').Contains(prj_No)) |
232 |
{ |
233 |
try |
234 |
{ |
235 |
System.Net.WebClient client = new System.Net.WebClient(); |
236 |
var convertResult = client.DownloadString($"{Properties.Settings.Default.MARKUS_V3_ADDRESS}/Rest/ConvertAdd?ProjectNo={prj_No}&DocumentID={_id}"); |
237 |
|
238 |
JObject jObject = JObject.Parse(convertResult, new JsonLoadSettings()); |
239 |
result = jObject["ConvertAddResult"].ToString(); |
240 |
} |
241 |
catch (Exception ex) |
242 |
{ |
243 |
result = $"Markus V3 Connect Error {ex.Message}"; |
244 |
} |
245 |
} |
246 |
else |
247 |
{ |
248 |
var convertResult = remObj.SetConverterPDF(prj_No, _id); |
249 |
|
250 |
if (convertResult.Exception != null) |
251 |
{ |
252 |
result = false.ToString(); |
253 |
} |
254 |
else |
255 |
{ |
256 |
result = true.ToString(); |
257 |
} |
258 |
} |
259 |
|
260 |
} |
261 |
|
262 |
return result; |
263 |
} |
264 |
[WebMethod] |
265 |
public string ManualConvert(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url) |
266 |
{ |
267 |
string _result = null; |
268 |
try |
269 |
{ |
270 |
using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
271 |
{ |
272 |
//_result = ConnectStringBuilder.DeepViewConnectionString().ToString(); |
273 |
//var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber && DateTime.Parse(r.RUN_DATETIME)<= DateTime.Now); |
274 |
//var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber); |
275 |
var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO != null); |
276 |
|
277 |
if (_RunProjects.Count() > 0) |
278 |
{ |
279 |
_result = ManualSendKcom(rev_No, document_No, document_Name, group_No, prj_No, document_Id, document_Url); |
280 |
} |
281 |
else |
282 |
{ |
283 |
_result = false.ToString(); |
284 |
} |
285 |
} |
286 |
} |
287 |
catch (Exception ex) |
288 |
{ |
289 |
logger.Error("Conversion Web Service ManualConvert Error", ex); |
290 |
_result = ex.Message.ToString(); |
291 |
SendNotice("Project NO : " + prj_No + "\r\n DocumentUrl : " + document_Url + "\r\n Error" + ex.ToString()); |
292 |
} |
293 |
return _result; |
294 |
} |
295 |
[WebMethod] |
296 |
public string UpdateUrlEncode(string EnsembleId) |
297 |
{ |
298 |
string _result = null; |
299 |
try |
300 |
{ |
301 |
using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
302 |
{ |
303 |
var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault(); |
304 |
string url = doc.ORIGINAL_FILE; |
305 |
if (url.Contains("http://")) |
306 |
{ |
307 |
//기존 url 이 인코딩 안되 있으면 인코딩 작업. |
308 |
url = HttpUtility.UrlEncodeUnicode(url); |
309 |
doc.ORIGINAL_FILE = url; |
310 |
|
311 |
var convertdoc = deepViewEntity.CONVERTER_DOC.Where(d => d.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault(); |
312 |
if(convertdoc != null) |
313 |
convertdoc.DOCUMENT_URL = url; |
314 |
var docinfo = deepViewEntity.DOCINFO.Where(d => d.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault(); |
315 |
if(docinfo != null) |
316 |
docinfo.ORIGINAL_FILE = url; |
317 |
} |
318 |
|
319 |
deepViewEntity.SaveChanges(); |
320 |
} |
321 |
} |
322 |
catch (Exception ex) |
323 |
{ |
324 |
logger.Error("Conversion Web Service UpdateUrlEncode Error", ex); |
325 |
_result = ex.Message.ToString(); |
326 |
} |
327 |
return _result; |
328 |
} |
329 |
public string Base64Decode(string data) |
330 |
{ |
331 |
try |
332 |
{ |
333 |
if(data.Contains("http://")) |
334 |
{ |
335 |
return data; |
336 |
}else |
337 |
{ |
338 |
System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); |
339 |
System.Text.Decoder utf8Decode = encoder.GetDecoder(); |
340 |
|
341 |
byte[] todecode_byte = Convert.FromBase64String(data); |
342 |
|
343 |
int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); |
344 |
|
345 |
char[] decoded_char = new char[charCount]; |
346 |
|
347 |
utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); |
348 |
|
349 |
string result = new String(decoded_char); |
350 |
|
351 |
return result; |
352 |
} |
353 |
|
354 |
|
355 |
} |
356 |
|
357 |
catch (Exception e) |
358 |
{ |
359 |
throw new Exception("Error in Base64Decode: " + e.Message); |
360 |
} |
361 |
} |
362 |
[WebMethod] |
363 |
public string UpdateSlip(string EnsembleId, string SlipNo, string slipLink) |
364 |
{ |
365 |
string _result = null; |
366 |
try |
367 |
{ |
368 |
using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
369 |
{ |
370 |
var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault(); |
371 |
if(!string.IsNullOrEmpty(slipLink)) |
372 |
doc.GROUP_NO = SlipNo; |
373 |
if(!string.IsNullOrEmpty(slipLink)) |
374 |
{ |
375 |
if (!slipLink.Contains("http://")) |
376 |
slipLink = Base64Decode(slipLink); |
377 |
throw new Exception("doc.ENSEMBLEINFO_URL not support"); |
378 |
//doc.ENSEMBLEINFO_URL = slipLink; |
379 |
} |
380 |
|
381 |
deepViewEntity.SaveChanges(); |
382 |
} |
383 |
} |
384 |
catch (Exception ex) |
385 |
{ |
386 |
logger.Error($"Conversion Web Service UpdateSlip Error EnsembleId : {EnsembleId} SlipNo : {SlipNo} slipLink: {slipLink}", ex); |
387 |
_result = ex.Message.ToString(); |
388 |
} |
389 |
return _result; |
390 |
} |
391 |
[WebMethod] |
392 |
public string UpdateResult(string EnsembleId, string Result, string FinalPDFUrl) |
393 |
{ |
394 |
string _result = null; |
395 |
try |
396 |
{ |
397 |
using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
398 |
{ |
399 |
var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault(); |
400 |
doc.RESULT = Result; |
401 |
doc.RESULT_FILE = FinalPDFUrl; |
402 |
deepViewEntity.SaveChanges(); |
403 |
} |
404 |
} |
405 |
catch (Exception ex) |
406 |
{ |
407 |
logger.Error("Conversion Web Service UpdateResult Error", ex); |
408 |
_result = ex.Message.ToString(); |
409 |
} |
410 |
return _result; |
411 |
} |
412 |
[WebMethod] |
413 |
public string UpdateVP(string EnsembleId, string rev_No, string document_No, string document_Name, string pdf_url) |
414 |
{ |
415 |
string _result = null; |
416 |
try |
417 |
{ |
418 |
using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
419 |
{ |
420 |
var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault(); |
421 |
if(!string.IsNullOrEmpty(rev_No)) |
422 |
doc.REVISION = rev_No; |
423 |
if (!string.IsNullOrEmpty(document_No)) |
424 |
doc.DOCUMENT_NO = document_No; |
425 |
if (!string.IsNullOrEmpty(document_Name)) |
426 |
doc.DOCUMENT_NAME = document_Name; |
427 |
if (!string.IsNullOrEmpty(pdf_url)) |
428 |
{ |
429 |
string url = pdf_url; |
430 |
if (!doc.PROJECT_NO.Equals("150128")) |
431 |
{ |
432 |
url = HttpUtility.UrlEncodeUnicode(url); |
433 |
} |
434 |
doc.ORIGINAL_FILE = url; |
435 |
} |
436 |
deepViewEntity.SaveChanges(); |
437 |
} |
438 |
} |
439 |
catch (Exception ex) |
440 |
{ |
441 |
logger.Error("Conversion Web Service UpdateVP Error", ex); |
442 |
_result = ex.Message.ToString(); |
443 |
} |
444 |
return _result; |
445 |
} |
446 |
[WebMethod] |
447 |
public string CoverConvert(string prj_No, string _id) |
448 |
{ |
449 |
string _result = null; |
450 |
try |
451 |
{ |
452 |
SendCoverConvert(prj_No, _id); |
453 |
} |
454 |
catch (Exception ex) |
455 |
{ |
456 |
logger.Error("Conversion Web Service CoverConvert Error", ex); |
457 |
_result = ex.Message.ToString(); |
458 |
} |
459 |
return _result; |
460 |
} |
461 |
private string SendCoverConvert(string prj_No, string _id) |
462 |
{ |
463 |
if (remObj == null) |
464 |
{ |
465 |
return "Window Service Connection Error"; |
466 |
} |
467 |
else |
468 |
{ |
469 |
var _result = remObj.SetConverterCoverPDF(prj_No, _id); |
470 |
|
471 |
if (_result.Exception != null) |
472 |
{ |
473 |
return false.ToString(); |
474 |
} |
475 |
else |
476 |
{ |
477 |
return true.ToString(); |
478 |
} |
479 |
} |
480 |
} |
481 |
private string SendKcom(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url) |
482 |
{ |
483 |
string result = false.ToString(); |
484 |
|
485 |
if (remObj == null) |
486 |
{ |
487 |
result = "Window Service Connection Error"; |
488 |
} |
489 |
else |
490 |
{ |
491 |
//string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString(); |
492 |
string _id = shortGuid(); |
493 |
string _doc_id = ((UInt32)document_Id.GetHashCode()).ToString(); |
494 |
using (DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
495 |
{ |
496 |
if (string.IsNullOrEmpty(group_No)) |
497 |
{ |
498 |
group_No = "0"; |
499 |
} |
500 |
if (!prj_No.Equals("150128")) |
501 |
{ |
502 |
//Omsk 는 웹서비스 호출 시 인코딩 |
503 |
//Omsk 제외는 Markus 에서 인코딩 |
504 |
if (!document_Url.Contains("http%3a%2f%2f")) |
505 |
{ |
506 |
document_Url = Base64Decode(document_Url); |
507 |
document_Url = HttpUtility.UrlEncodeUnicode(document_Url); |
508 |
} |
509 |
} |
510 |
var doc = _entity.DOCUMENT_ITEM.Where(d => d.ID == document_Id).FirstOrDefault(); |
511 |
if(doc != null) |
512 |
{ |
513 |
doc.REVISION = rev_No; |
514 |
doc.GROUP_NO = group_No; |
515 |
doc.DOCUMENT_NO = document_No; |
516 |
doc.DOCUMENT_NAME = document_Name; |
517 |
doc.ORIGINAL_FILE = document_Url; |
518 |
} |
519 |
else |
520 |
{ |
521 |
_entity.AddToDOCUMENT_ITEM(new DOCUMENT_ITEM |
522 |
{ |
523 |
ID = document_Id, |
524 |
REVISION = rev_No, |
525 |
DOCUMENT_NO = document_No, |
526 |
DOCUMENT_NAME = document_Name, |
527 |
GROUP_NO = group_No, |
528 |
ORIGINAL_FILE = document_Url, |
529 |
DOCUMENT_ID = _doc_id, |
530 |
PROJECT_NO = prj_No, |
531 |
}); |
532 |
} |
533 |
|
534 |
_entity.AddToCONVERTER_DOC(new CONVERTER_DOC |
535 |
{ |
536 |
ID = _id, |
537 |
CREATE_DATETIME = DateTime.Now, |
538 |
DOCUMENT_URL = document_Url, |
539 |
PROJECT_NO = prj_No, |
540 |
DOCUMENT_ID = _doc_id, |
541 |
}); |
542 |
_entity.SaveChanges(); |
543 |
} |
544 |
|
545 |
if (Properties.Settings.Default.MARKUS_V3_PROJECTS.Split(',').Contains(prj_No)) |
546 |
{ |
547 |
try |
548 |
{ |
549 |
System.Net.WebClient client = new System.Net.WebClient(); |
550 |
var convertResult = client.DownloadString($"{Properties.Settings.Default.MARKUS_V3_ADDRESS}/Rest/ConvertAdd?ProjectNo={prj_No}&DocumentID={_id}"); |
551 |
|
552 |
JObject jObject = JObject.Parse(convertResult, new JsonLoadSettings()); |
553 |
result = jObject["ConvertAddResult"].ToString(); |
554 |
} |
555 |
catch (Exception ex) |
556 |
{ |
557 |
logger.Error("Conversion Web Service SendKcom Error", ex); |
558 |
result = $"Markus V3 Connect Error {ex.Message}"; |
559 |
} |
560 |
} |
561 |
else |
562 |
{ |
563 |
var convertResult = remObj.SetConverterPDF(prj_No, _id); |
564 |
|
565 |
if (convertResult.Exception != null) |
566 |
{ |
567 |
result = false.ToString(); |
568 |
} |
569 |
else |
570 |
{ |
571 |
result = true.ToString(); |
572 |
} |
573 |
} |
574 |
|
575 |
} |
576 |
|
577 |
return result; |
578 |
} |
579 |
|
580 |
private string ManualSendKcom(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url) |
581 |
{ |
582 |
if (remObj == null) |
583 |
{ |
584 |
return "Window Service Connection Error"; |
585 |
} |
586 |
else |
587 |
{ |
588 |
//string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString(); |
589 |
string _id = shortGuid(); |
590 |
string _doc_id = ((UInt32)document_Id.GetHashCode()).ToString(); |
591 |
using (DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
592 |
{ |
593 |
var doc = _entity.DOCUMENT_ITEM.Where(d => d.ID == document_Id).FirstOrDefault(); |
594 |
if (doc != null) |
595 |
{ |
596 |
var converterdoc = _entity.CONVERTER_DOC.Where(c => c.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault(); |
597 |
_entity.DeleteObject(converterdoc); |
598 |
_entity.DeleteObject(doc); |
599 |
_entity.SaveChanges(); |
600 |
document_Url = HttpUtility.UrlDecode(document_Url); |
601 |
} |
602 |
int cnt = _entity.DOCUMENT_ITEM.ToList().Count; |
603 |
if (string.IsNullOrEmpty(group_No)) |
604 |
{ |
605 |
group_No = "0"; |
606 |
} |
607 |
|
608 |
_entity.AddToDOCUMENT_ITEM(new DOCUMENT_ITEM |
609 |
{ |
610 |
ID = document_Id, |
611 |
REVISION = rev_No, |
612 |
DOCUMENT_NO = document_No, |
613 |
DOCUMENT_NAME = document_Name, |
614 |
GROUP_NO = group_No, |
615 |
ORIGINAL_FILE = HttpUtility.UrlEncodeUnicode(document_Url), |
616 |
DOCUMENT_ID = _doc_id, |
617 |
PROJECT_NO = prj_No, |
618 |
}); |
619 |
_entity.AddToCONVERTER_DOC(new CONVERTER_DOC |
620 |
{ |
621 |
ID = _id, |
622 |
CREATE_DATETIME = DateTime.Now, |
623 |
DOCUMENT_URL = HttpUtility.UrlEncodeUnicode(document_Url), |
624 |
PROJECT_NO = prj_No, |
625 |
DOCUMENT_ID = _doc_id, |
626 |
}); |
627 |
_entity.SaveChanges(); |
628 |
} |
629 |
var _result = remObj.SetConverterPDF(prj_No, _id); |
630 |
|
631 |
if (_result.Exception != null) |
632 |
{ |
633 |
return false.ToString(); |
634 |
} |
635 |
else |
636 |
{ |
637 |
return true.ToString(); |
638 |
} |
639 |
} |
640 |
} |
641 |
|
642 |
//private Guid GetGuid(int Count,Guid ID) |
643 |
//{ |
644 |
// Guid _ID = ID; |
645 |
// string _id = _ID.ToString(); |
646 |
// DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()); |
647 |
|
648 |
// if (_entity.CONVERTER_DOC.Where(c => c.ID == _id).Count() > 0) |
649 |
// { |
650 |
// _entity.Dispose(); |
651 |
|
652 |
// if (Count > 10) |
653 |
// { |
654 |
// new Exception("GetGuid : Not Generator"); |
655 |
// } |
656 |
|
657 |
// if (Count < 3) |
658 |
// { |
659 |
// System.Threading.Thread.Sleep(3); |
660 |
// } |
661 |
|
662 |
// GetGuid(Count++,GuidGenerator.GetUniqueGuid()); |
663 |
// } |
664 |
|
665 |
// return ID; |
666 |
//} |
667 |
|
668 |
//GUID생성(최민수 사원 수정) |
669 |
public string shortGuid() |
670 |
{ |
671 |
byte[] bytes = new byte[16]; |
672 |
using (var provider = System.Security.Cryptography.RandomNumberGenerator.Create()) |
673 |
{ |
674 |
provider.GetBytes(bytes); |
675 |
} |
676 |
|
677 |
var guid = new Guid(bytes); |
678 |
|
679 |
return Convert.ToBase64String(guid.ToByteArray()) |
680 |
.Substring(0, 10) |
681 |
.Replace("/", "") |
682 |
.Replace("+", "") + DateTime.UtcNow.Ticks.ToString("x"); |
683 |
} |
684 |
|
685 |
[WebMethod] |
686 |
public string ExcelExport(string project_no, string slip_no) |
687 |
{ |
688 |
string _result = "false"; |
689 |
//FileInfo fileInfo2 = new FileInfo(Path.GetTempFileName()); |
690 |
//fileInfo2.FullName |
691 |
try |
692 |
{ |
693 |
// Excel 첫번째 워크시트 가져오기 |
694 |
//application = new Excel.Application(); |
695 |
//workbook = application.Workbooks.Open(xlsxfilepath); |
696 |
//worksheet = (Excel.Worksheet)workbook.Worksheets.get_Item("Sheet1"); |
697 |
string xlsxfilepath = @"C:\WebSite\LogView\Doc_Manager\sample.xlsx"; |
698 |
GemBox.Spreadsheet.SpreadsheetInfo.SetLicense("EXK0-W4HZ-N518-IMEW"); |
699 |
GemBox.Spreadsheet.ExcelFile excelFile = new GemBox.Spreadsheet.ExcelFile(); |
700 |
excelFile.LoadXlsx(xlsxfilepath, GemBox.Spreadsheet.XlsxOptions.PreserveMakeCopy); |
701 |
GemBox.Spreadsheet.ExcelWorksheet ws = excelFile.Worksheets[0]; |
702 |
FileInfo fileInfo2 = new FileInfo(Path.GetTempFileName().Replace(".tmp", ".xlsx")); |
703 |
|
704 |
string fileout = @"C:\WebSite\LogView\Doc_Manager\commentexcel_" + DateTime.Now.ToString() + ".xlsx"; |
705 |
string naspath = Properties.Settings.Default.Excelfilepath; |
706 |
//@"\\172.20.121.220\comment3\TileSource\Excelexport"; |
707 |
|
708 |
// 데이타 넣기 |
709 |
int h = 6; |
710 |
int w = 1; |
711 |
|
712 |
|
713 |
//필터 기능 추가 |
714 |
//Excel.Range Filter_Range = worksheet.Range["B9:" + Ran + "9"]; |
715 |
//Filter_Range.AutoFilter(1, Type.Missing, Excel.XlAutoFilterOperator.xlAnd, Type.Missing, true); |
716 |
|
717 |
|
718 |
using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
719 |
{ |
720 |
var docs = deepViewEntity.DOCUMENT_ITEM.Where(doc => doc.GROUP_NO == slip_no && doc.PROJECT_NO == project_no).ToList(); |
721 |
if (docs.Count > 0) |
722 |
{ |
723 |
foreach (var doc in docs) |
724 |
{ |
725 |
var commentlist = deepViewEntity.MARKUP_DATA.Where(d => d.MARKUP_INFO_VERSION.MARKUP_INFO.DOCINFO.DOCUMENT_ID == doc.DOCUMENT_ID |
726 |
&& d.MARKUP_INFO_VERSION.MARKUP_INFO.CONSOLIDATE == 1).ToList(); |
727 |
|
728 |
string docNo = doc.DOCUMENT_NO; |
729 |
string docDesc = doc.DOCUMENT_NAME; |
730 |
string docRev = doc.REVISION; |
731 |
foreach (var comment in commentlist) |
732 |
{ |
733 |
var member = deepViewEntity.MEMBER.Where(m => m.ID == comment.MARKUP_INFO_VERSION.MARKUP_INFO.USER_ID).FirstOrDefault(); |
734 |
string docdept = member.DEPARTMENT; |
735 |
string doccomment = string.Empty; |
736 |
var data = MarkupToPDF.Serialize.Core.JsonSerializerHelper.UnCompressString(comment.DATA.ToString()); |
737 |
switch (Enum.Parse(typeof(MarkupToPDF.Controls.Common.ControlType), comment.DATA_TYPE.ToString())) |
738 |
{ |
739 |
case MarkupToPDF.Controls.Common.ControlType.TextControl: |
740 |
case MarkupToPDF.Controls.Common.ControlType.TextBorder: |
741 |
case MarkupToPDF.Controls.Common.ControlType.TextCloud: |
742 |
{ |
743 |
MarkupToPDF.Serialize.S_Control.S_TextControl instance = MarkupToPDF.Serialize.Core.JsonSerializerHelper.JsonDeserialize<MarkupToPDF.Serialize.S_Control.S_TextControl>(data); |
744 |
doccomment = instance.Text; |
745 |
} |
746 |
break; |
747 |
case MarkupToPDF.Controls.Common.ControlType.ArrowTextBorderControl: |
748 |
case MarkupToPDF.Controls.Common.ControlType.ArrowTextCloudControl: |
749 |
case MarkupToPDF.Controls.Common.ControlType.ArrowTextControl: |
750 |
case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextBorderControl: |
751 |
case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextCloudControl: |
752 |
case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextControl: |
753 |
{ |
754 |
MarkupToPDF.Serialize.S_Control.S_ArrowTextControl instance = MarkupToPDF.Serialize.Core.JsonSerializerHelper.JsonDeserialize<MarkupToPDF.Serialize.S_Control.S_ArrowTextControl>(data); |
755 |
doccomment = instance.ArrowText; |
756 |
} |
757 |
break; |
758 |
} |
759 |
ws.Cells[h, w].Value = string.Format("{0}\n({1})", docNo, docDesc); |
760 |
ws.Cells[h, w + 1].Value = docRev; |
761 |
ws.Cells[h, w + 2].Value = docdept; |
762 |
ws.Cells[h, w + 3].Value = doccomment; |
763 |
h++; |
764 |
} |
765 |
} |
766 |
} |
767 |
else |
768 |
{ |
769 |
_result = "ERROR : 해당 Slip 의 데이터가 없습니다."; |
770 |
} |
771 |
|
772 |
|
773 |
} |
774 |
|
775 |
int columnCount = ws.CalculateMaxUsedColumns(); |
776 |
for (int i = 0; i < columnCount; i++) |
777 |
ws.Columns[i].AutoFit(); |
778 |
//worksheet.Columns.AutoFit(); |
779 |
// 엑셀파일 저장 |
780 |
|
781 |
excelFile.Save(fileInfo2.FullName); |
782 |
fileInfo2.MoveTo(naspath + "\\" + fileInfo2.Name); |
783 |
//workbook.SaveAs(fileout); |
784 |
////workbook.Save(); |
785 |
//workbook.Close(true); |
786 |
//application.Quit(); |
787 |
_result = Properties.Settings.Default.Excelresulturl + fileInfo2.Name; |
788 |
} |
789 |
catch (Exception e) |
790 |
{ |
791 |
_result = "ERROR : " + e.ToString(); |
792 |
} |
793 |
return _result; |
794 |
} |
795 |
|
796 |
private static void ReleaseExcelObject(object obj) |
797 |
{ |
798 |
try |
799 |
{ |
800 |
if (obj != null) |
801 |
{ |
802 |
obj = null; |
803 |
} |
804 |
} |
805 |
catch (Exception ex) |
806 |
{ |
807 |
obj = null; |
808 |
throw ex; |
809 |
} |
810 |
finally |
811 |
{ |
812 |
GC.Collect(); |
813 |
} |
814 |
} |
815 |
} |
816 |
} |