프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / FinalServiceV3 / KCOM_FinalService / UploadFinal / UploadPDF.cs @ 6a19b48d

이력 | 보기 | 이력해설 | 다운로드 (12.2 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 log4net;
12
using Markus.EntityModel;
13

    
14
namespace UploadFinal
15
{
16
    public class UploadFinal
17
    {
18
        public static ILog Logger = null;
19
        private static string CIConnectionString;
20
        private static string MarkusConnectionString;
21

    
22
        public static KeyValuePair<bool, string> UploadFinalPDF(string PdfFilePath, string OriginFileName, FINAL_PDF FinalPDF, string UploadServiceUrl)
23
        {
24
            Logger = LogManager.GetLogger(typeof(UploadFinal));
25

    
26
            string _vendorItemId = null;
27
            string _objid = null;
28
            string _SharepointItemID = null;
29
            string _slipNO = null;
30
            bool _ResultFlag = false;
31
            string _ResultMsg = "";
32

    
33
            try
34
            {
35
                string docurl = string.Empty;
36
                //XML escape & 치환
37
                OriginFileName = OriginFileName.Replace("&","&amp;");
38
                using (Markus.EntityModel.MarkusModel _entity = new Markus.EntityModel.MarkusModel(CIConnectionString))
39
                {
40
                    var _docInfoList = _entity.DOCINFO.Where(doc => doc.ID == FinalPDF.DOCINFO_ID);
41

    
42
                    if (_docInfoList.Count() > 0)
43
                        _SharepointItemID = _docInfoList.First().DOCUMENT_ID;
44

    
45
                    var _vendoritems = _entity.DOCUMENT_ITEM.Where(item => item.DOCUMENT_ID == _SharepointItemID && item.PROJECT_NO == FinalPDF.PROJECT_NO);
46

    
47
                    if (_vendoritems.Count() > 0)
48
                    {
49
                        _objid = _vendoritems.First().ID;
50
                        _slipNO = _vendoritems.First().GROUP_NO;
51
                        docurl = _vendoritems.First().ORIGINAL_FILE;
52
                    }
53
                }
54

    
55
                //EnsemblePlusWebService.DLMWebServiceClient client = new EnsemblePlusWebService.DLMWebServiceClient();
56
                //var result = client.fnFinalPDFCheckInService(FinalPDF.PROJECT_NO, _objid, _slipNO, PdfFilePath);
57

    
58
                WebClient webClient = new WebClient();
59
                string data = string.Empty;
60

    
61
                Logger.Info($"doc Uri :{docurl}");
62

    
63
                if (docurl.ToUpper().Contains("VPCS_DOCLIB"))
64
                {
65
                    string connectionString = "data source=ESB-DB;Initial Catalog=markus;uid=ProjectPortalDBConn;password=ProjectPortalDBConn";
66
                    SqlConnection sqlConn = new SqlConnection(connectionString);
67
                    SqlCommand sqlComm = new SqlCommand();
68
                    sqlComm.Connection = sqlConn;
69
                    sqlComm.CommandText = string.Format("SELECT [DBConnectString]  FROM [PortalEV].[dbo].[Setting]  where [ProjectNumber] = '{0}'", FinalPDF.PROJECT_NO);
70
                    string ciconnectionStr = string.Empty;
71

    
72
                    sqlConn.Open();
73
                    using (SqlDataReader SqlRs = sqlComm.ExecuteReader())
74
                    {
75

    
76
                        while (SqlRs.Read())
77
                        {
78
                            ciconnectionStr = SqlRs[0].ToString();
79
                        }
80
                    }
81
                    sqlConn.Close();
82
                    sqlConn = new SqlConnection(ciconnectionStr);
83
                    sqlComm.Connection = sqlConn;
84
                    sqlComm.CommandText = string.Format("SELECT [vendor_item_id]  FROM [vendor_item]  where [sharepoint_itemid] = '{0}'", _objid);
85
                    sqlConn.Open();
86
                    using (SqlDataReader SqlRs = sqlComm.ExecuteReader())
87
                    {
88

    
89
                        while (SqlRs.Read())
90
                        {
91
                            _objid = SqlRs[0].ToString();
92
                        }
93
                    }
94
                    sqlConn.Close();
95
                    UploadServiceUrl = "http://esb-vpcs-new.daelimplant.com/ProjectPortal/UserControls/DaelimCI2/FinalPDFUpload/UploadVpcsFile.asmx";
96

    
97
                    string finalpdfroot = CommonLib.Common.GetConfigString("FinalPDFRootUrl", "URL", "");
98

    
99
                    if (!string.IsNullOrEmpty(finalpdfroot))
100
                    {
101
                        string filename = Path.GetFileName(PdfFilePath);
102
                        PdfFilePath = !string.IsNullOrEmpty(finalpdfroot) ? finalpdfroot + filename : filename;
103
                    }
104

    
105
                    Logger.Info($"UploadServiceUrl :{UploadServiceUrl}");
106

    
107
                    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\">"
108
                                     + "<ProjectNo>" + FinalPDF.PROJECT_NO + "</ProjectNo>"
109
                                     + "<VendorItemID>" + _objid + "</VendorItemID>"
110
                                     + "<SlipNumber>" + _slipNO + "</SlipNumber>"
111
                                     + "<filePath>" + PdfFilePath + "</filePath>"
112
                                     + "<OriginFileName>" + OriginFileName + "</OriginFileName></UploadFinalPDF></soap12:Body></soap12:Envelope>";
113

    
114
                    Logger.Info($"PROJECT_NO  :{FinalPDF.PROJECT_NO}");
115
                    Logger.Info($"FinalPDF.  :{_objid}");
116
                    Logger.Info($"SlipNumber  :{_slipNO}");
117
                    Logger.Info($"filePath  :{PdfFilePath}");
118
                    Logger.Info($"OriginFileName  :{OriginFileName}");
119

    
120
                    //WriteLog(data);
121
                    webClient.Headers.Add(HttpRequestHeader.ContentType, "application/soap+xml; charset=utf-8");
122
                    webClient.Headers.Add("SOAPAction", "http://FinalPDFUpload/UploadFinalPDF");
123
                    webClient.Encoding = System.Text.Encoding.UTF8;
124

    
125
                    string _result = webClient.UploadString(new Uri(UploadServiceUrl), data);
126
                    XmlTextReader reader = new XmlTextReader(new System.IO.StringReader(_result));
127

    
128
                    while (reader.Read())
129
                    {
130
                        switch (reader.NodeType)
131
                        {
132
                            case XmlNodeType.Element:
133
                                if (reader.Name == "Seccess")
134
                                {
135
                                    reader.Read();
136

    
137
                                    if (!string.IsNullOrWhiteSpace(reader.Value))
138
                                        _ResultFlag = Convert.ToBoolean(reader.Value);
139
                                }
140

    
141
                                if (reader.Name == "Message")
142
                                {
143
                                    reader.Read();
144

    
145
                                    if (!string.IsNullOrWhiteSpace(reader.Value))
146
                                        _ResultMsg = reader.Value;
147
                                }
148

    
149
                                if (reader.Name == "FinalPDFUrl")
150
                                {
151
                                    reader.Read();
152

    
153
                                    if (!string.IsNullOrWhiteSpace(reader.Value))
154
                                        _ResultMsg = reader.Value;
155
                                }
156

    
157
                                break;                                
158
                        }
159
                    }
160
                    return new KeyValuePair<bool, string>(_ResultFlag, _ResultMsg);
161
                }
162
                else
163
                {
164
                    Logger.Info($"UploadServiceUrl :{UploadServiceUrl}");
165
                    // 앙상블+는 파일명만 전달함
166

    
167
                    string finalpdfroot = CommonLib.Common.GetConfigString("FinalPDFRootUrl", "URL", "");
168

    
169
                    PdfFilePath = PdfFilePath.Split('/').Last();
170

    
171
                    if (PdfFilePath.StartsWith(finalpdfroot))
172
                    {
173
                        PdfFilePath = PdfFilePath.Split('\\').Last();
174
                    }
175

    
176
                    data = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ens=\"http://EnsemblePlus.Webservice\"> <soapenv:Header/> <soapenv:Body> <ens:fnFinalPDFCheckInService>"
177
                    + "<ens:ProjectNo>" + FinalPDF.PROJECT_NO + "</ens:ProjectNo>"
178
                    + "<ens:ObjectId>" + _objid + "</ens:ObjectId>"
179
                    + "<ens:SlipNumber>" + _slipNO + "</ens:SlipNumber>"
180
                    + "<ens:filePath>" + PdfFilePath + "</ens:filePath>"
181
                    + "<ens:OriginalFileName>" + OriginFileName + "</ens:OriginalFileName>"
182
                    + "</ens:fnFinalPDFCheckInService> </soapenv:Body></soapenv:Envelope>";
183

    
184
                    Logger.Info($"PROJECT_NO  :{FinalPDF.PROJECT_NO}");
185
                    Logger.Info($"FinalPDF.  :{_objid}");
186
                    Logger.Info($"SlipNumber  :{_slipNO}");
187
                    Logger.Info($"filePath  :{PdfFilePath}");
188
                    Logger.Info($"OriginFileName  :{OriginFileName}");
189

    
190
                    webClient.Headers.Add(HttpRequestHeader.ContentType, "text/xml");
191
                    webClient.Headers.Add("SOAPAction", "http://EnsemblePlus.Webservice");
192
                    webClient.Encoding = System.Text.Encoding.UTF8;
193
                    var result = webClient.UploadString(new Uri(UploadServiceUrl), data);
194
                    XmlDocument xmlDoc = new XmlDocument();
195
                    xmlDoc.LoadXml(result);
196
                    XmlNodeList list = xmlDoc.GetElementsByTagName("fnFinalPDFCheckInServiceReturn");
197
                    if (list.Count > 0)
198
                    {
199
                        if (list[0].InnerText == "Success")
200
                        {
201
                            return new KeyValuePair<bool, string>(true, "Success");
202
                        }
203
                        else
204
                        {
205
                            return new KeyValuePair<bool, string>(false, "Fail - " + data);
206
                        }
207
                    }
208
                    else
209
                    {
210
                        return new KeyValuePair<bool, string>(false, "Not Completed");
211
                    }
212
                }
213
               
214
               
215
                
216
                
217
            }
218
            catch (Exception ex)
219
            {
220
                return new KeyValuePair<bool, string>(false, ex.Message);
221
            }
222

    
223
            //return new KeyValuePair<bool, string>(_ResultFlag,_ResultMsg);
224
        }
225

    
226
        static void webClient_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
227
        {
228
            Console.WriteLine("UploadStringCompleted: {0}", e.Result);
229
        }
230
        public static void SendOnMessage(string subject, string content)
231
        {
232

    
233
            //MailMessage mail = new MailMessage();
234
            //mail.From = new MailAddress("h2011357@daelim.co.kr", "시스템관리자", System.Text.Encoding.UTF8);
235
            //mail.To.Add("h2011357@daelim.co.kr");
236
            //mail.Subject = subject;
237
            //mail.Body = content;
238
            //mail.BodyEncoding = System.Text.Encoding.UTF8;//한글이 안깨지기 위해서 사용
239
            //mail.SubjectEncoding = System.Text.Encoding.UTF8;//한글이 안깨지기 위해서 사용
240

    
241
            //SmtpClient SmtpServer = new SmtpClient("any.daelim.co.kr");
242
            //SmtpServer.Send(mail); // 메일 발송
243
            //mail.Dispose();
244
        }
245
        public static void WriteLog(string strLog)
246
        {
247
            StreamWriter log;
248
            FileStream fileStream = null;
249
            DirectoryInfo logDirInfo = null;
250
            FileInfo logFileInfo;
251

    
252
            string logFilePath = "C:\\Logs\\";
253
            logFilePath = logFilePath + "Log-" + System.DateTime.Today.ToString("MM-dd-yyyy") + "." + "txt";
254
            logFileInfo = new FileInfo(logFilePath);
255
            logDirInfo = new DirectoryInfo(logFileInfo.DirectoryName);
256
            if (!logDirInfo.Exists) logDirInfo.Create();
257
            if (!logFileInfo.Exists)
258
            {
259
                fileStream = logFileInfo.Create();
260
            }
261
            else
262
            {
263
                fileStream = new FileStream(logFilePath, FileMode.Append);
264
            }
265
            log = new StreamWriter(fileStream);
266
            log.WriteLine(strLog);
267
            log.Close();
268
        }
269
    }
270
}
클립보드 이미지 추가 (최대 크기: 500 MB)