markus / ConvertService / ServiceBase / ConvertionWebService / Conversion.asmx.cs @ bc28fe10
이력 | 보기 | 이력해설 | 다운로드 (33.8 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 Excel = Microsoft.Office.Interop.Excel; |
14 |
using MarkupToPDF; |
15 |
using System.IO; |
16 |
using Newtonsoft.Json; |
17 |
using Newtonsoft.Json.Linq; |
18 |
using log4net; |
19 |
|
20 |
namespace ConvertionWebService |
21 |
{ |
22 |
/// <summary> |
23 |
/// Summary description for Conversio |
24 |
/// </summary> |
25 |
[WebService(Namespace = "http://tempuri.org/")] |
26 |
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] |
27 |
[System.ComponentModel.ToolboxItem(false)] |
28 |
public class Conversion : System.Web.Services.WebService |
29 |
{ |
30 |
|
31 |
RemConverterPDFObject remObj = null; |
32 |
protected ILog logger = LogManager.GetLogger(typeof(Conversion)); |
33 |
public Conversion() |
34 |
{ |
35 |
try |
36 |
{ |
37 |
System.Runtime.Remoting.Channels.IChannel _ch = ChannelServices.GetChannel("tcp"); |
38 |
|
39 |
if(_ch == null) |
40 |
{ |
41 |
TcpChannel chan = new TcpChannel(); |
42 |
ChannelServices.RegisterChannel(chan, false); |
43 |
} |
44 |
// Create an instance of the remote object |
45 |
remObj = (RemConverterPDFObject)Activator.GetObject(typeof(RemConverterPDFObject), |
46 |
Properties.Settings.Default.ConverterRemotingUrl); |
47 |
|
48 |
} |
49 |
catch (Exception ex) |
50 |
{ |
51 |
logger.Error("Conversion Web Service Conversion Error", ex); |
52 |
SendNotice(ex.ToString()); |
53 |
} |
54 |
} |
55 |
|
56 |
private void SendNotice(string ex) |
57 |
{ |
58 |
if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.ErrorNoticeID)) |
59 |
{ |
60 |
var _lstID = Properties.Settings.Default.ErrorNoticeID.Split(';').ToList(); |
61 |
//EmailClient.EmailClient _client = new EmailClient.EmailClient(_lstID.First()); |
62 |
StringBuilder _bl = new StringBuilder(); |
63 |
_bl.AppendLine("Conversion Web Service Error"); |
64 |
_bl.AppendLine(ex); |
65 |
//var _emailResult = _client.SendEmail(_lstID, _lstID, "<Conversion Web Service Error>", _bl.ToString(), false); |
66 |
} |
67 |
else |
68 |
{ |
69 |
logger.Error("Conversion Web Service Error",new Exception(ex)); |
70 |
} |
71 |
} |
72 |
|
73 |
[WebMethod] |
74 |
public string ConvertRun(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url) |
75 |
{ |
76 |
string _result = null; |
77 |
try |
78 |
{ |
79 |
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}"); |
80 |
|
81 |
using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
82 |
{ |
83 |
//_result = ConnectStringBuilder.DeepViewConnectionString().ToString(); |
84 |
//var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber && DateTime.Parse(r.RUN_DATETIME)<= DateTime.Now); |
85 |
//var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber); |
86 |
var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO != null); |
87 |
|
88 |
if (_RunProjects.Count() > 0) |
89 |
{ |
90 |
_result = SendKcom(rev_No, document_No, document_Name, group_No, prj_No, document_Id, document_Url); |
91 |
} |
92 |
else |
93 |
{ |
94 |
_result = false.ToString(); |
95 |
} |
96 |
} |
97 |
} |
98 |
catch (Exception ex) |
99 |
{ |
100 |
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); |
101 |
_result = ex.Message.ToString(); |
102 |
SendNotice("Project NO : " + prj_No + "\r\n DocumentUrl : " + document_Url + "\r\n Error" + ex.ToString()); |
103 |
} |
104 |
return _result; |
105 |
} |
106 |
|
107 |
[WebMethod] |
108 |
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) |
109 |
{ |
110 |
string _result = null; |
111 |
try |
112 |
{ |
113 |
using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
114 |
{ |
115 |
//_result = ConnectStringBuilder.DeepViewConnectionString().ToString(); |
116 |
//var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber && DateTime.Parse(r.RUN_DATETIME)<= DateTime.Now); |
117 |
//var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber); |
118 |
var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO != null); |
119 |
|
120 |
if (_RunProjects.Count() > 0) |
121 |
{ |
122 |
_result = SendKcom(rev_No, document_No, document_Name, group_No, prj_No, document_Id, document_Url,ignoreComment); |
123 |
} |
124 |
else |
125 |
{ |
126 |
_result = false.ToString(); |
127 |
} |
128 |
} |
129 |
} |
130 |
catch (Exception ex) |
131 |
{ |
132 |
_result = ex.Message.ToString(); |
133 |
SendNotice("Project NO : " + prj_No + "\r\n DocumentUrl : " + document_Url + "\r\n Error" + ex.ToString()); |
134 |
} |
135 |
return _result; |
136 |
} |
137 |
|
138 |
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) |
139 |
{ |
140 |
string result = false.ToString(); |
141 |
|
142 |
if (remObj == null) |
143 |
{ |
144 |
result = "Window Service Connection Error"; |
145 |
} |
146 |
else |
147 |
{ |
148 |
//string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString(); |
149 |
string _id = shortGuid(); |
150 |
string _doc_id = ((UInt32)document_Id.GetHashCode()).ToString(); |
151 |
|
152 |
using (DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
153 |
{ |
154 |
var doc = _entity.DOCUMENT_ITEM.Where(d => d.ID == document_Id).FirstOrDefault(); |
155 |
if (doc != null) |
156 |
{ |
157 |
if (bool.Parse(ignoreComment)) |
158 |
{ |
159 |
try |
160 |
{ |
161 |
var docinfo = _entity.DOCINFO.Where(x => x.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault(); |
162 |
var markupinfos = _entity.MARKUP_INFO.Where(x => x.DOCINFO_ID == docinfo.ID).ToList(); |
163 |
foreach (var markupinfo in markupinfos) |
164 |
{ |
165 |
var markupinfoversions = _entity.MARKUP_INFO_VERSION.Where(x => x.MARKUPINFO_ID == markupinfo.ID).ToList(); |
166 |
foreach (var markupinfoversion in markupinfoversions) |
167 |
{ |
168 |
var markupdatas = _entity.MARKUP_DATA.Where(x => x.MARKUPINFO_VERSION_ID == markupinfoversion.ID).ToList(); |
169 |
foreach (var markupdata in markupdatas) |
170 |
{ |
171 |
_entity.DeleteObject(markupdata); |
172 |
} |
173 |
_entity.DeleteObject(markupinfoversion); |
174 |
} |
175 |
_entity.DeleteObject(markupinfo); |
176 |
} |
177 |
_entity.SaveChanges(); |
178 |
} |
179 |
catch (Exception ex) |
180 |
{ |
181 |
result = "deleteobject error:"+ex.ToString(); |
182 |
} |
183 |
|
184 |
} |
185 |
var converterdoc = _entity.CONVERTER_DOC.Where(c => c.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault(); |
186 |
_entity.DeleteObject(converterdoc); |
187 |
_entity.DeleteObject(doc); |
188 |
_entity.SaveChanges(); |
189 |
document_Url = HttpUtility.UrlDecode(document_Url); |
190 |
} |
191 |
int cnt = _entity.DOCUMENT_ITEM.ToList().Count; |
192 |
if (string.IsNullOrEmpty(group_No)) |
193 |
{ |
194 |
group_No = "0"; |
195 |
} |
196 |
if (!prj_No.Equals("150128")) |
197 |
{ |
198 |
//Omsk 는 웹서비스 호출 시 인코딩 |
199 |
//Omsk 제외는 Markus 에서 인코딩 |
200 |
document_Url = Base64Decode(document_Url); |
201 |
} |
202 |
_entity.AddToDOCUMENT_ITEM(new DOCUMENT_ITEM |
203 |
{ |
204 |
ID = document_Id, |
205 |
REVISION = rev_No, |
206 |
DOCUMENT_NO = document_No, |
207 |
DOCUMENT_NAME = document_Name, |
208 |
GROUP_NO = group_No, |
209 |
ORIGINAL_FILE = document_Url, |
210 |
DOCUMENT_ID = _doc_id, |
211 |
PROJECT_NO = prj_No, |
212 |
}); |
213 |
_entity.AddToCONVERTER_DOC(new CONVERTER_DOC |
214 |
{ |
215 |
ID = _id, |
216 |
CREATE_DATETIME = DateTime.Now, |
217 |
DOCUMENT_URL = document_Url, |
218 |
PROJECT_NO = prj_No, |
219 |
DOCUMENT_ID = _doc_id, |
220 |
}); |
221 |
_entity.SaveChanges(); |
222 |
} |
223 |
|
224 |
if (Properties.Settings.Default.MARKUS_V3_PROJECTS.Split(',').Contains(prj_No)) |
225 |
{ |
226 |
try |
227 |
{ |
228 |
System.Net.WebClient client = new System.Net.WebClient(); |
229 |
var convertResult = client.DownloadString($"{Properties.Settings.Default.MARKUS_V3_ADDRESS}/Rest/ConvertAdd?ProjectNo={prj_No}&DocumentID={_id}"); |
230 |
|
231 |
JObject jObject = JObject.Parse(convertResult, new JsonLoadSettings()); |
232 |
result = jObject["ConvertAddResult"].ToString(); |
233 |
} |
234 |
catch (Exception ex) |
235 |
{ |
236 |
result = $"Markus V3 Connect Error {ex.Message}"; |
237 |
} |
238 |
} |
239 |
else |
240 |
{ |
241 |
var convertResult = remObj.SetConverterPDF(prj_No, _id); |
242 |
|
243 |
if (convertResult.Exception != null) |
244 |
{ |
245 |
result = false.ToString(); |
246 |
} |
247 |
else |
248 |
{ |
249 |
result = true.ToString(); |
250 |
} |
251 |
} |
252 |
|
253 |
} |
254 |
|
255 |
return result; |
256 |
} |
257 |
[WebMethod] |
258 |
public string ManualConvert(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url) |
259 |
{ |
260 |
string _result = null; |
261 |
try |
262 |
{ |
263 |
using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
264 |
{ |
265 |
//_result = ConnectStringBuilder.DeepViewConnectionString().ToString(); |
266 |
//var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber && DateTime.Parse(r.RUN_DATETIME)<= DateTime.Now); |
267 |
//var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber); |
268 |
var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO != null); |
269 |
|
270 |
if (_RunProjects.Count() > 0) |
271 |
{ |
272 |
_result = ManualSendKcom(rev_No, document_No, document_Name, group_No, prj_No, document_Id, document_Url); |
273 |
} |
274 |
else |
275 |
{ |
276 |
_result = false.ToString(); |
277 |
} |
278 |
} |
279 |
} |
280 |
catch (Exception ex) |
281 |
{ |
282 |
logger.Error("Conversion Web Service ManualConvert Error", ex); |
283 |
_result = ex.Message.ToString(); |
284 |
SendNotice("Project NO : " + prj_No + "\r\n DocumentUrl : " + document_Url + "\r\n Error" + ex.ToString()); |
285 |
} |
286 |
return _result; |
287 |
} |
288 |
[WebMethod] |
289 |
public string UpdateUrlEncode(string EnsembleId) |
290 |
{ |
291 |
string _result = null; |
292 |
try |
293 |
{ |
294 |
using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
295 |
{ |
296 |
var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault(); |
297 |
string url = doc.ORIGINAL_FILE; |
298 |
if (url.Contains("http://")) |
299 |
{ |
300 |
//기존 url 이 인코딩 안되 있으면 인코딩 작업. |
301 |
url = HttpUtility.UrlEncodeUnicode(url); |
302 |
doc.ORIGINAL_FILE = url; |
303 |
|
304 |
var convertdoc = deepViewEntity.CONVERTER_DOC.Where(d => d.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault(); |
305 |
if(convertdoc != null) |
306 |
convertdoc.DOCUMENT_URL = url; |
307 |
var docinfo = deepViewEntity.DOCINFO.Where(d => d.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault(); |
308 |
if(docinfo != null) |
309 |
docinfo.ORIGINAL_FILE = url; |
310 |
} |
311 |
|
312 |
deepViewEntity.SaveChanges(); |
313 |
} |
314 |
} |
315 |
catch (Exception ex) |
316 |
{ |
317 |
logger.Error("Conversion Web Service UpdateUrlEncode Error", ex); |
318 |
_result = ex.Message.ToString(); |
319 |
} |
320 |
return _result; |
321 |
} |
322 |
public string Base64Decode(string data) |
323 |
{ |
324 |
try |
325 |
{ |
326 |
|
327 |
System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); |
328 |
System.Text.Decoder utf8Decode = encoder.GetDecoder(); |
329 |
|
330 |
byte[] todecode_byte = Convert.FromBase64String(data); |
331 |
|
332 |
int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); |
333 |
|
334 |
char[] decoded_char = new char[charCount]; |
335 |
|
336 |
utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); |
337 |
|
338 |
string result = new String(decoded_char); |
339 |
|
340 |
return result; |
341 |
|
342 |
} |
343 |
|
344 |
catch (Exception e) |
345 |
{ |
346 |
throw new Exception("Error in Base64Decode: " + e.Message); |
347 |
} |
348 |
} |
349 |
[WebMethod] |
350 |
public string UpdateSlip(string EnsembleId, string SlipNo, string slipLink) |
351 |
{ |
352 |
string _result = null; |
353 |
try |
354 |
{ |
355 |
using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
356 |
{ |
357 |
var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault(); |
358 |
if(!string.IsNullOrEmpty(slipLink)) |
359 |
doc.GROUP_NO = SlipNo; |
360 |
if(!string.IsNullOrEmpty(slipLink)) |
361 |
{ |
362 |
if (!slipLink.Contains("http://")) |
363 |
slipLink = Base64Decode(slipLink); |
364 |
doc.ENSEMBLEINFO_URL = slipLink; |
365 |
} |
366 |
|
367 |
deepViewEntity.SaveChanges(); |
368 |
} |
369 |
} |
370 |
catch (Exception ex) |
371 |
{ |
372 |
logger.Error($"Conversion Web Service UpdateSlip Error EnsembleId : {EnsembleId} SlipNo : {SlipNo} slipLink: {slipLink}", ex); |
373 |
_result = ex.Message.ToString(); |
374 |
} |
375 |
return _result; |
376 |
} |
377 |
[WebMethod] |
378 |
public string UpdateResult(string EnsembleId, string Result, string FinalPDFUrl) |
379 |
{ |
380 |
string _result = null; |
381 |
try |
382 |
{ |
383 |
using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
384 |
{ |
385 |
var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault(); |
386 |
doc.RESULT = Result; |
387 |
doc.RESULT_FILE = FinalPDFUrl; |
388 |
deepViewEntity.SaveChanges(); |
389 |
} |
390 |
} |
391 |
catch (Exception ex) |
392 |
{ |
393 |
logger.Error("Conversion Web Service UpdateResult Error", ex); |
394 |
_result = ex.Message.ToString(); |
395 |
} |
396 |
return _result; |
397 |
} |
398 |
[WebMethod] |
399 |
public string UpdateVP(string EnsembleId, string rev_No, string document_No, string document_Name, string pdf_url) |
400 |
{ |
401 |
string _result = null; |
402 |
try |
403 |
{ |
404 |
using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
405 |
{ |
406 |
var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault(); |
407 |
if(!string.IsNullOrEmpty(rev_No)) |
408 |
doc.REVISION = rev_No; |
409 |
if (!string.IsNullOrEmpty(document_No)) |
410 |
doc.DOCUMENT_NO = document_No; |
411 |
if (!string.IsNullOrEmpty(document_Name)) |
412 |
doc.DOCUMENT_NAME = document_Name; |
413 |
if (!string.IsNullOrEmpty(pdf_url)) |
414 |
{ |
415 |
string url = pdf_url; |
416 |
if (!doc.PROJECT_NO.Equals("150128")) |
417 |
{ |
418 |
url = HttpUtility.UrlEncodeUnicode(url); |
419 |
} |
420 |
doc.ORIGINAL_FILE = url; |
421 |
} |
422 |
deepViewEntity.SaveChanges(); |
423 |
} |
424 |
} |
425 |
catch (Exception ex) |
426 |
{ |
427 |
logger.Error("Conversion Web Service UpdateVP Error", ex); |
428 |
_result = ex.Message.ToString(); |
429 |
} |
430 |
return _result; |
431 |
} |
432 |
[WebMethod] |
433 |
public string CoverConvert(string prj_No, string _id) |
434 |
{ |
435 |
string _result = null; |
436 |
try |
437 |
{ |
438 |
SendCoverConvert(prj_No, _id); |
439 |
} |
440 |
catch (Exception ex) |
441 |
{ |
442 |
logger.Error("Conversion Web Service CoverConvert Error", ex); |
443 |
_result = ex.Message.ToString(); |
444 |
} |
445 |
return _result; |
446 |
} |
447 |
private string SendCoverConvert(string prj_No, string _id) |
448 |
{ |
449 |
if (remObj == null) |
450 |
{ |
451 |
return "Window Service Connection Error"; |
452 |
} |
453 |
else |
454 |
{ |
455 |
var _result = remObj.SetConverterCoverPDF(prj_No, _id); |
456 |
|
457 |
if (_result.Exception != null) |
458 |
{ |
459 |
return false.ToString(); |
460 |
} |
461 |
else |
462 |
{ |
463 |
return true.ToString(); |
464 |
} |
465 |
} |
466 |
} |
467 |
private string SendKcom(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url) |
468 |
{ |
469 |
string result = false.ToString(); |
470 |
|
471 |
if (remObj == null) |
472 |
{ |
473 |
result = "Window Service Connection Error"; |
474 |
} |
475 |
else |
476 |
{ |
477 |
//string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString(); |
478 |
string _id = shortGuid(); |
479 |
string _doc_id = ((UInt32)document_Id.GetHashCode()).ToString(); |
480 |
using (DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
481 |
{ |
482 |
var doc = _entity.DOCUMENT_ITEM.Where(d => d.ID == document_Id).FirstOrDefault(); |
483 |
if(doc != null) |
484 |
{ |
485 |
var converterdoc = _entity.CONVERTER_DOC.Where(c => c.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault(); |
486 |
_entity.DeleteObject(converterdoc); |
487 |
_entity.DeleteObject(doc); |
488 |
_entity.SaveChanges(); |
489 |
document_Url = HttpUtility.UrlDecode(document_Url); |
490 |
} |
491 |
int cnt = _entity.DOCUMENT_ITEM.ToList().Count; |
492 |
if(string.IsNullOrEmpty(group_No)) |
493 |
{ |
494 |
group_No = "0"; |
495 |
} |
496 |
if (!prj_No.Equals("150128")) |
497 |
{ |
498 |
//Omsk 는 웹서비스 호출 시 인코딩 |
499 |
//Omsk 제외는 Markus 에서 인코딩 |
500 |
document_Url = Base64Decode(document_Url); |
501 |
} |
502 |
_entity.AddToDOCUMENT_ITEM(new DOCUMENT_ITEM |
503 |
{ |
504 |
ID = document_Id, |
505 |
REVISION = rev_No, |
506 |
DOCUMENT_NO = document_No, |
507 |
DOCUMENT_NAME = document_Name, |
508 |
GROUP_NO = group_No, |
509 |
ORIGINAL_FILE = document_Url, |
510 |
DOCUMENT_ID = _doc_id, |
511 |
PROJECT_NO = prj_No, |
512 |
}); |
513 |
_entity.AddToCONVERTER_DOC(new CONVERTER_DOC |
514 |
{ |
515 |
ID = _id, |
516 |
CREATE_DATETIME = DateTime.Now, |
517 |
DOCUMENT_URL = document_Url, |
518 |
PROJECT_NO = prj_No, |
519 |
DOCUMENT_ID = _doc_id, |
520 |
}); |
521 |
_entity.SaveChanges(); |
522 |
} |
523 |
|
524 |
if (Properties.Settings.Default.MARKUS_V3_PROJECTS.Split(',').Contains(prj_No)) |
525 |
{ |
526 |
try |
527 |
{ |
528 |
System.Net.WebClient client = new System.Net.WebClient(); |
529 |
var convertResult = client.DownloadString($"{Properties.Settings.Default.MARKUS_V3_ADDRESS}/Rest/ConvertAdd?ProjectNo={prj_No}&DocumentID={_id}"); |
530 |
|
531 |
JObject jObject = JObject.Parse(convertResult, new JsonLoadSettings()); |
532 |
result = jObject["ConvertAddResult"].ToString(); |
533 |
} |
534 |
catch (Exception ex) |
535 |
{ |
536 |
logger.Error("Conversion Web Service SendKcom Error", ex); |
537 |
result = $"Markus V3 Connect Error {ex.Message}"; |
538 |
} |
539 |
} |
540 |
else |
541 |
{ |
542 |
var convertResult = remObj.SetConverterPDF(prj_No, _id); |
543 |
|
544 |
if (convertResult.Exception != null) |
545 |
{ |
546 |
result = false.ToString(); |
547 |
} |
548 |
else |
549 |
{ |
550 |
result = true.ToString(); |
551 |
} |
552 |
} |
553 |
|
554 |
} |
555 |
|
556 |
return result; |
557 |
} |
558 |
|
559 |
private string ManualSendKcom(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url) |
560 |
{ |
561 |
if (remObj == null) |
562 |
{ |
563 |
return "Window Service Connection Error"; |
564 |
} |
565 |
else |
566 |
{ |
567 |
//string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString(); |
568 |
string _id = shortGuid(); |
569 |
string _doc_id = ((UInt32)document_Id.GetHashCode()).ToString(); |
570 |
using (DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
571 |
{ |
572 |
var doc = _entity.DOCUMENT_ITEM.Where(d => d.ID == document_Id).FirstOrDefault(); |
573 |
if (doc != null) |
574 |
{ |
575 |
var converterdoc = _entity.CONVERTER_DOC.Where(c => c.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault(); |
576 |
_entity.DeleteObject(converterdoc); |
577 |
_entity.DeleteObject(doc); |
578 |
_entity.SaveChanges(); |
579 |
document_Url = HttpUtility.UrlDecode(document_Url); |
580 |
} |
581 |
int cnt = _entity.DOCUMENT_ITEM.ToList().Count; |
582 |
if (string.IsNullOrEmpty(group_No)) |
583 |
{ |
584 |
group_No = "0"; |
585 |
} |
586 |
|
587 |
_entity.AddToDOCUMENT_ITEM(new DOCUMENT_ITEM |
588 |
{ |
589 |
ID = document_Id, |
590 |
REVISION = rev_No, |
591 |
DOCUMENT_NO = document_No, |
592 |
DOCUMENT_NAME = document_Name, |
593 |
GROUP_NO = group_No, |
594 |
ORIGINAL_FILE = HttpUtility.UrlEncodeUnicode(document_Url), |
595 |
DOCUMENT_ID = _doc_id, |
596 |
PROJECT_NO = prj_No, |
597 |
}); |
598 |
_entity.AddToCONVERTER_DOC(new CONVERTER_DOC |
599 |
{ |
600 |
ID = _id, |
601 |
CREATE_DATETIME = DateTime.Now, |
602 |
DOCUMENT_URL = HttpUtility.UrlEncodeUnicode(document_Url), |
603 |
PROJECT_NO = prj_No, |
604 |
DOCUMENT_ID = _doc_id, |
605 |
}); |
606 |
_entity.SaveChanges(); |
607 |
} |
608 |
var _result = remObj.SetConverterPDF(prj_No, _id); |
609 |
|
610 |
if (_result.Exception != null) |
611 |
{ |
612 |
return false.ToString(); |
613 |
} |
614 |
else |
615 |
{ |
616 |
return true.ToString(); |
617 |
} |
618 |
} |
619 |
} |
620 |
|
621 |
//private Guid GetGuid(int Count,Guid ID) |
622 |
//{ |
623 |
// Guid _ID = ID; |
624 |
// string _id = _ID.ToString(); |
625 |
// DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()); |
626 |
|
627 |
// if (_entity.CONVERTER_DOC.Where(c => c.ID == _id).Count() > 0) |
628 |
// { |
629 |
// _entity.Dispose(); |
630 |
|
631 |
// if (Count > 10) |
632 |
// { |
633 |
// new Exception("GetGuid : Not Generator"); |
634 |
// } |
635 |
|
636 |
// if (Count < 3) |
637 |
// { |
638 |
// System.Threading.Thread.Sleep(3); |
639 |
// } |
640 |
|
641 |
// GetGuid(Count++,GuidGenerator.GetUniqueGuid()); |
642 |
// } |
643 |
|
644 |
// return ID; |
645 |
//} |
646 |
|
647 |
//GUID생성(최민수 사원 수정) |
648 |
public string shortGuid() |
649 |
{ |
650 |
byte[] bytes = new byte[16]; |
651 |
using (var provider = System.Security.Cryptography.RandomNumberGenerator.Create()) |
652 |
{ |
653 |
provider.GetBytes(bytes); |
654 |
} |
655 |
|
656 |
var guid = new Guid(bytes); |
657 |
|
658 |
return Convert.ToBase64String(guid.ToByteArray()) |
659 |
.Substring(0, 10) |
660 |
.Replace("/", "") |
661 |
.Replace("+", "") + DateTime.UtcNow.Ticks.ToString("x"); |
662 |
} |
663 |
|
664 |
[WebMethod] |
665 |
public string ExcelExport(string project_no,string slip_no) |
666 |
{ |
667 |
string _result = "false"; |
668 |
Excel.Application application = null; |
669 |
Excel.Workbook workbook = null; |
670 |
Excel.Worksheet worksheet = null; |
671 |
string xlsxfilepath = @"D:\sample.xlsx"; |
672 |
|
673 |
string fileout = @"D:\CommentExport_" + DateTime.Now.ToString() + ".xlsx"; |
674 |
|
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 |
|
682 |
// 데이타 넣기 |
683 |
int h = 6; |
684 |
int w = 2; |
685 |
|
686 |
|
687 |
//필터 기능 추가 |
688 |
//Excel.Range Filter_Range = worksheet.Range["B9:" + Ran + "9"]; |
689 |
//Filter_Range.AutoFilter(1, Type.Missing, Excel.XlAutoFilterOperator.xlAnd, Type.Missing, true); |
690 |
|
691 |
|
692 |
using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
693 |
{ |
694 |
var docs = deepViewEntity.DOCUMENT_ITEM.Where(doc => doc.GROUP_NO == slip_no && doc.PROJECT_NO == project_no).ToList(); |
695 |
foreach(var doc in docs) |
696 |
{ |
697 |
var commentlist = deepViewEntity.MARKUP_DATA.Where(d => d.MARKUP_INFO_VERSION.MARKUP_INFO.DOCINFO.DOCUMENT_ID == doc.DOCUMENT_ID |
698 |
&& d.MARKUP_INFO_VERSION.MARKUP_INFO.CONSOLIDATE == 1).ToList(); |
699 |
|
700 |
string docNo = doc.DOCUMENT_NO; |
701 |
string docDesc = doc.DOCUMENT_NAME; |
702 |
string docRev = doc.REVISION; |
703 |
foreach(var comment in commentlist) |
704 |
{ |
705 |
var member = deepViewEntity.MEMBER.Where(m => m.ID == comment.MARKUP_INFO_VERSION.MARKUP_INFO.USER_ID).FirstOrDefault(); |
706 |
string docdept = member.DEPARTMENT; |
707 |
string doccomment = string.Empty; |
708 |
var data = MarkupToPDF.Serialize.Core.JsonSerializerHelper.UnCompressString(comment.DATA.ToString()); |
709 |
switch (Enum.Parse(typeof(MarkupToPDF.Controls.Common.ControlType), comment.DATA_TYPE.ToString())) |
710 |
{ |
711 |
case MarkupToPDF.Controls.Common.ControlType.TextControl: |
712 |
case MarkupToPDF.Controls.Common.ControlType.TextBorder: |
713 |
case MarkupToPDF.Controls.Common.ControlType.TextCloud: |
714 |
{ |
715 |
MarkupToPDF.Serialize.S_Control.S_TextControl instance = MarkupToPDF.Serialize.Core.JsonSerializerHelper.JsonDeserialize<MarkupToPDF.Serialize.S_Control.S_TextControl>(data); |
716 |
doccomment = instance.Text; |
717 |
} |
718 |
break; |
719 |
case MarkupToPDF.Controls.Common.ControlType.ArrowTextBorderControl: |
720 |
case MarkupToPDF.Controls.Common.ControlType.ArrowTextCloudControl: |
721 |
case MarkupToPDF.Controls.Common.ControlType.ArrowTextControl: |
722 |
case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextBorderControl: |
723 |
case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextCloudControl: |
724 |
case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextControl: |
725 |
{ |
726 |
MarkupToPDF.Serialize.S_Control.S_ArrowTextControl instance = MarkupToPDF.Serialize.Core.JsonSerializerHelper.JsonDeserialize<MarkupToPDF.Serialize.S_Control.S_ArrowTextControl>(data); |
727 |
doccomment = instance.ArrowText; |
728 |
} |
729 |
break; |
730 |
} |
731 |
worksheet.Cells[h, w] = string.Format("{0}\n({1})",docNo,docDesc); |
732 |
worksheet.Cells[h, w + 1] = docRev; |
733 |
worksheet.Cells[h, w + 2] = docdept; |
734 |
worksheet.Cells[h, w + 3] = doccomment; |
735 |
h++; |
736 |
} |
737 |
} |
738 |
|
739 |
} |
740 |
|
741 |
|
742 |
worksheet.Columns.AutoFit(); |
743 |
// 엑셀파일 저장 |
744 |
|
745 |
|
746 |
workbook.SaveAs(fileout); |
747 |
//workbook.Save(); |
748 |
workbook.Close(true); |
749 |
application.Quit(); |
750 |
_result = fileout; |
751 |
} |
752 |
catch(Exception e) |
753 |
{ |
754 |
_result = e.Message; |
755 |
} |
756 |
finally |
757 |
{ |
758 |
System.Diagnostics.Process[] ExCel = System.Diagnostics.Process.GetProcessesByName("EXCEL"); |
759 |
if (ExCel.Count() != 0) |
760 |
{ |
761 |
ExCel[0].Kill(); |
762 |
} |
763 |
|
764 |
// Clean up |
765 |
ReleaseExcelObject(worksheet); |
766 |
ReleaseExcelObject(workbook); |
767 |
ReleaseExcelObject(application); |
768 |
|
769 |
} |
770 |
return _result; |
771 |
} |
772 |
|
773 |
private static void ReleaseExcelObject(object obj) |
774 |
{ |
775 |
try |
776 |
{ |
777 |
if (obj != null) |
778 |
{ |
779 |
obj = null; |
780 |
} |
781 |
} |
782 |
catch (Exception ex) |
783 |
{ |
784 |
obj = null; |
785 |
throw ex; |
786 |
} |
787 |
finally |
788 |
{ |
789 |
GC.Collect(); |
790 |
} |
791 |
} |
792 |
} |
793 |
} |