markus / FinalService / FinalServiceBase / UploadFinal / UploadPDF.cs @ 42d49521
이력 | 보기 | 이력해설 | 다운로드 (12.1 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Text; |
5 |
using System.IO; |
6 |
using System.Net; |
7 |
using System.Xml; |
8 |
using System.Xml.Linq; |
9 |
using System.Net.Mail; |
10 |
using System.Data.SqlClient; |
11 |
using KCOMDataModel.DataModel; |
12 |
using KCOMDataModel.Common; |
13 |
using log4net; |
14 |
|
15 |
namespace UploadFinal |
16 |
{ |
17 |
public class UploadFinal |
18 |
{ |
19 |
public static ILog Logger = null; |
20 |
|
21 |
public static KeyValuePair<bool, string> UploadFinalPDF(string PdfFilePath, string OriginFileName, FINAL_PDF FinalPDF, string UploadServiceUrl) |
22 |
{ |
23 |
Logger = LogManager.GetLogger(typeof(UploadFinal)); |
24 |
|
25 |
string _vendorItemId = null; |
26 |
string _objid = null; |
27 |
string _SharepointItemID = null; |
28 |
string _slipNO = null; |
29 |
bool _ResultFlag = false; |
30 |
string _ResultMsg = ""; |
31 |
|
32 |
try |
33 |
{ |
34 |
string docurl = string.Empty; |
35 |
//XML escape & 치환 |
36 |
OriginFileName = OriginFileName.Replace("&","&"); |
37 |
using (CIEntities dc = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(FinalPDF.PROJECT_NO).ToString())) |
38 |
{ |
39 |
var _docInfoList = dc.DOCINFO.Where(doc => doc.ID == FinalPDF.DOCINFO_ID); |
40 |
|
41 |
if (_docInfoList.Count() > 0) |
42 |
_SharepointItemID = _docInfoList.First().DOCUMENT_ID; |
43 |
|
44 |
var _vendoritems = dc.DOCUMENT_ITEM.Where(item => item.DOCUMENT_ID == _SharepointItemID && item.PROJECT_NO == FinalPDF.PROJECT_NO); |
45 |
|
46 |
if (_vendoritems.Count() > 0) |
47 |
{ |
48 |
_objid = _vendoritems.First().ID; |
49 |
_slipNO = _vendoritems.First().GROUP_NO; |
50 |
docurl = _vendoritems.First().ORIGINAL_FILE; |
51 |
} |
52 |
} |
53 |
|
54 |
//EnsemblePlusWebService.DLMWebServiceClient client = new EnsemblePlusWebService.DLMWebServiceClient(); |
55 |
//var result = client.fnFinalPDFCheckInService(FinalPDF.PROJECT_NO, _objid, _slipNO, PdfFilePath); |
56 |
|
57 |
WebClient webClient = new WebClient(); |
58 |
string data = string.Empty; |
59 |
|
60 |
Logger.Info($"doc Uri :{docurl}"); |
61 |
|
62 |
if (docurl.ToUpper().Contains("VPCS_DOCLIB")) |
63 |
{ |
64 |
string connectionString = "data source=ESB-DB;Initial Catalog=markus;uid=ProjectPortalDBConn;password=ProjectPortalDBConn"; |
65 |
SqlConnection sqlConn = new SqlConnection(connectionString); |
66 |
SqlCommand sqlComm = new SqlCommand(); |
67 |
sqlComm.Connection = sqlConn; |
68 |
sqlComm.CommandText = string.Format("SELECT [DBConnectString] FROM [PortalEV].[dbo].[Setting] where [ProjectNumber] = '{0}'", FinalPDF.PROJECT_NO); |
69 |
string ciconnectionStr = string.Empty; |
70 |
|
71 |
sqlConn.Open(); |
72 |
using (SqlDataReader SqlRs = sqlComm.ExecuteReader()) |
73 |
{ |
74 |
|
75 |
while (SqlRs.Read()) |
76 |
{ |
77 |
ciconnectionStr = SqlRs[0].ToString(); |
78 |
} |
79 |
} |
80 |
sqlConn.Close(); |
81 |
sqlConn = new SqlConnection(ciconnectionStr); |
82 |
sqlComm.Connection = sqlConn; |
83 |
sqlComm.CommandText = string.Format("SELECT [vendor_item_id] FROM [vendor_item] where [sharepoint_itemid] = '{0}'", _objid); |
84 |
sqlConn.Open(); |
85 |
using (SqlDataReader SqlRs = sqlComm.ExecuteReader()) |
86 |
{ |
87 |
|
88 |
while (SqlRs.Read()) |
89 |
{ |
90 |
_objid = SqlRs[0].ToString(); |
91 |
} |
92 |
} |
93 |
sqlConn.Close(); |
94 |
UploadServiceUrl = "http://esb-vpcs-new.daelimplant.com/ProjectPortal/UserControls/DaelimCI2/FinalPDFUpload/UploadVpcsFile.asmx"; |
95 |
|
96 |
string finalpdfroot = CommonLib.Common.GetConfigString("FinalPDFRootUrl", "URL", ""); |
97 |
|
98 |
if (!string.IsNullOrEmpty(finalpdfroot)) |
99 |
{ |
100 |
string filename = Path.GetFileName(PdfFilePath); |
101 |
PdfFilePath = !string.IsNullOrEmpty(finalpdfroot) ? finalpdfroot + filename : filename; |
102 |
} |
103 |
|
104 |
Logger.Info($"UploadServiceUrl :{UploadServiceUrl}"); |
105 |
|
106 |
data = "<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\" ><soap12:Body><UploadFinalPDF xmlns=\"http://FinalPDFUpload\">" |
107 |
+ "<ProjectNo>" + FinalPDF.PROJECT_NO + "</ProjectNo>" |
108 |
+ "<VendorItemID>" + _objid + "</VendorItemID>" |
109 |
+ "<SlipNumber>" + _slipNO + "</SlipNumber>" |
110 |
+ "<filePath>" + PdfFilePath + "</filePath>" |
111 |
+ "<OriginFileName>" + OriginFileName + "</OriginFileName></UploadFinalPDF></soap12:Body></soap12:Envelope>"; |
112 |
|
113 |
Logger.Info($"PROJECT_NO :{FinalPDF.PROJECT_NO}"); |
114 |
Logger.Info($"FinalPDF. :{_objid}"); |
115 |
Logger.Info($"SlipNumber :{_slipNO}"); |
116 |
Logger.Info($"filePath :{PdfFilePath}"); |
117 |
Logger.Info($"OriginFileName :{OriginFileName}"); |
118 |
|
119 |
//WriteLog(data); |
120 |
webClient.Headers.Add(HttpRequestHeader.ContentType, "application/soap+xml; charset=utf-8"); |
121 |
webClient.Headers.Add("SOAPAction", "http://FinalPDFUpload/UploadFinalPDF"); |
122 |
webClient.Encoding = System.Text.Encoding.UTF8; |
123 |
|
124 |
string _result = webClient.UploadString(new Uri(UploadServiceUrl), data); |
125 |
XmlTextReader reader = new XmlTextReader(new System.IO.StringReader(_result)); |
126 |
|
127 |
while (reader.Read()) |
128 |
{ |
129 |
switch (reader.NodeType) |
130 |
{ |
131 |
case XmlNodeType.Element: |
132 |
if (reader.Name == "Seccess") |
133 |
{ |
134 |
reader.Read(); |
135 |
|
136 |
if (!string.IsNullOrWhiteSpace(reader.Value)) |
137 |
_ResultFlag = Convert.ToBoolean(reader.Value); |
138 |
} |
139 |
|
140 |
if (reader.Name == "Message") |
141 |
{ |
142 |
reader.Read(); |
143 |
|
144 |
if (!string.IsNullOrWhiteSpace(reader.Value)) |
145 |
_ResultMsg = reader.Value; |
146 |
} |
147 |
|
148 |
if (reader.Name == "FinalPDFUrl") |
149 |
{ |
150 |
reader.Read(); |
151 |
|
152 |
if (!string.IsNullOrWhiteSpace(reader.Value)) |
153 |
_ResultMsg = reader.Value; |
154 |
} |
155 |
|
156 |
break; |
157 |
} |
158 |
} |
159 |
return new KeyValuePair<bool, string>(_ResultFlag, _ResultMsg); |
160 |
} |
161 |
else |
162 |
{ |
163 |
Logger.Info($"UploadServiceUrl :{UploadServiceUrl}"); |
164 |
// 앙상블+는 파일명만 전달함 |
165 |
|
166 |
string finalpdfroot = CommonLib.Common.GetConfigString("FinalPDFRootUrl", "URL", ""); |
167 |
|
168 |
PdfFilePath = PdfFilePath.Split('/').Last(); |
169 |
|
170 |
if (PdfFilePath.StartsWith(finalpdfroot)) |
171 |
{ |
172 |
PdfFilePath = PdfFilePath.Split('\\').Last(); |
173 |
} |
174 |
|
175 |
data = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ens=\"http://EnsemblePlus.Webservice\"> <soapenv:Header/> <soapenv:Body> <ens:fnFinalPDFCheckInService>" |
176 |
+ "<ens:ProjectNo>" + FinalPDF.PROJECT_NO + "</ens:ProjectNo>" |
177 |
+ "<ens:ObjectId>" + _objid + "</ens:ObjectId>" |
178 |
+ "<ens:SlipNumber>" + _slipNO + "</ens:SlipNumber>" |
179 |
+ "<ens:filePath>" + PdfFilePath + "</ens:filePath>" |
180 |
+ "<ens:OriginalFileName>" + OriginFileName + "</ens:OriginalFileName>" |
181 |
+ "</ens:fnFinalPDFCheckInService> </soapenv:Body></soapenv:Envelope>"; |
182 |
|
183 |
Logger.Info($"PROJECT_NO :{FinalPDF.PROJECT_NO}"); |
184 |
Logger.Info($"FinalPDF. :{_objid}"); |
185 |
Logger.Info($"SlipNumber :{_slipNO}"); |
186 |
Logger.Info($"filePath :{PdfFilePath}"); |
187 |
Logger.Info($"OriginFileName :{OriginFileName}"); |
188 |
|
189 |
webClient.Headers.Add(HttpRequestHeader.ContentType, "text/xml"); |
190 |
webClient.Headers.Add("SOAPAction", "http://EnsemblePlus.Webservice"); |
191 |
webClient.Encoding = System.Text.Encoding.UTF8; |
192 |
var result = webClient.UploadString(new Uri(UploadServiceUrl), data); |
193 |
XmlDocument xmlDoc = new XmlDocument(); |
194 |
xmlDoc.LoadXml(result); |
195 |
XmlNodeList list = xmlDoc.GetElementsByTagName("fnFinalPDFCheckInServiceReturn"); |
196 |
if (list.Count > 0) |
197 |
{ |
198 |
if (list[0].InnerText == "Success") |
199 |
{ |
200 |
return new KeyValuePair<bool, string>(true, "Success"); |
201 |
} |
202 |
else |
203 |
{ |
204 |
return new KeyValuePair<bool, string>(false, "Fail - " + data); |
205 |
} |
206 |
} |
207 |
else |
208 |
{ |
209 |
return new KeyValuePair<bool, string>(false, "Not Completed"); |
210 |
} |
211 |
} |
212 |
|
213 |
|
214 |
|
215 |
|
216 |
} |
217 |
catch (Exception ex) |
218 |
{ |
219 |
return new KeyValuePair<bool, string>(false, ex.Message); |
220 |
} |
221 |
|
222 |
//return new KeyValuePair<bool, string>(_ResultFlag,_ResultMsg); |
223 |
} |
224 |
|
225 |
static void webClient_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e) |
226 |
{ |
227 |
Console.WriteLine("UploadStringCompleted: {0}", e.Result); |
228 |
} |
229 |
public static void SendOnMessage(string subject, string content) |
230 |
{ |
231 |
|
232 |
//MailMessage mail = new MailMessage(); |
233 |
//mail.From = new MailAddress("h2011357@daelim.co.kr", "시스템관리자", System.Text.Encoding.UTF8); |
234 |
//mail.To.Add("h2011357@daelim.co.kr"); |
235 |
//mail.Subject = subject; |
236 |
//mail.Body = content; |
237 |
//mail.BodyEncoding = System.Text.Encoding.UTF8;//한글이 안깨지기 위해서 사용 |
238 |
//mail.SubjectEncoding = System.Text.Encoding.UTF8;//한글이 안깨지기 위해서 사용 |
239 |
|
240 |
//SmtpClient SmtpServer = new SmtpClient("any.daelim.co.kr"); |
241 |
//SmtpServer.Send(mail); // 메일 발송 |
242 |
//mail.Dispose(); |
243 |
} |
244 |
public static void WriteLog(string strLog) |
245 |
{ |
246 |
StreamWriter log; |
247 |
FileStream fileStream = null; |
248 |
DirectoryInfo logDirInfo = null; |
249 |
FileInfo logFileInfo; |
250 |
|
251 |
string logFilePath = "C:\\Logs\\"; |
252 |
logFilePath = logFilePath + "Log-" + System.DateTime.Today.ToString("MM-dd-yyyy") + "." + "txt"; |
253 |
logFileInfo = new FileInfo(logFilePath); |
254 |
logDirInfo = new DirectoryInfo(logFileInfo.DirectoryName); |
255 |
if (!logDirInfo.Exists) logDirInfo.Create(); |
256 |
if (!logFileInfo.Exists) |
257 |
{ |
258 |
fileStream = logFileInfo.Create(); |
259 |
} |
260 |
else |
261 |
{ |
262 |
fileStream = new FileStream(logFilePath, FileMode.Append); |
263 |
} |
264 |
log = new StreamWriter(fileStream); |
265 |
log.WriteLine(strLog); |
266 |
log.Close(); |
267 |
} |
268 |
} |
269 |
} |