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