markus / FinalService / KCOM_FinalService / ConsoleApp1 / Program.cs @ e05bed4e
이력 | 보기 | 이력해설 | 다운로드 (8.07 KB)
1 |
using IFinalPDF; |
---|---|
2 |
using KCOMDataModel; |
3 |
using KCOMDataModel.Common; |
4 |
using KCOMDataModel.DataModel; |
5 |
using System; |
6 |
using System.Collections.Generic; |
7 |
using System.IO; |
8 |
using System.Linq; |
9 |
using System.Text; |
10 |
|
11 |
namespace ConsoleApp1 |
12 |
{ |
13 |
static class Program |
14 |
{ |
15 |
static void Main(string[] args) |
16 |
{ |
17 |
string PdfFilePathRoot = ""; |
18 |
string _FinalPDFStorgeLocal = ""; |
19 |
string _FinalPDFStorgeRemote = ""; |
20 |
|
21 |
//using (KCOMEntities _entity = new KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString())) |
22 |
//{ |
23 |
// var _properties = _entity.PROPERTIES.Where(pro => pro.PROPERTY == "000000"); |
24 |
|
25 |
// if (_properties.Count() > 0) |
26 |
// { |
27 |
// PdfFilePathRoot = _properties.Where(t => t.TYPE == MarkupToPDF.PropertiesType.Const_TileSorcePath).First().VALUE; |
28 |
// _FinalPDFStorgeLocal = _properties.Where(t => t.TYPE == MarkupToPDF.PropertiesType.Const_FinalPDFStorgeLocal).First().VALUE; |
29 |
// _FinalPDFStorgeRemote = _properties.Where(t => t.TYPE == MarkupToPDF.PropertiesType.Const_FinalPDFStorgeRemote).First().VALUE; |
30 |
// } |
31 |
//} |
32 |
// using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString("000000").ToString())) |
33 |
//{ |
34 |
// var _DOCINFO = _entity.DOCINFO.Where(doc => doc.ID == "e16c382e-5c33-3883-d45b-47e4f4d4c23f"); |
35 |
|
36 |
// if (_DOCINFO.Count() > 0) |
37 |
// { |
38 |
// var DocInfoItem = _DOCINFO.FirstOrDefault(); |
39 |
|
40 |
// PdfFilePathRoot = PdfFilePathRoot + @"\" + "000000" + "_Tile" + @"\" |
41 |
// + (System.Convert.ToInt64("11111111") / 100).ToString() |
42 |
// + @"\" + "11111111" + @"\"; |
43 |
// } |
44 |
//} |
45 |
try |
46 |
{ |
47 |
Console.WriteLine("Test Process..."); |
48 |
Console.WriteLine("Insert Final PDF id :"); |
49 |
string inputstr = Console.ReadLine(); |
50 |
using (KCOMEntities _entity = new KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString())) |
51 |
{ |
52 |
//FINAL_PDF item = _entity.FINAL_PDF.Where(d => d.ID == "ngKwBgMotw8d56dea3839120d").FirstOrDefault(); |
53 |
FINAL_PDF item = _entity.FINAL_PDF.Where(d => d.ID == inputstr).FirstOrDefault(); |
54 |
if (item != null) |
55 |
{ |
56 |
Console.WriteLine("final pdf start"); |
57 |
MarkupToPDF.MarkupToPDF pdf = new MarkupToPDF.MarkupToPDF(); |
58 |
pdf.EndFinal += Pdf_EndFinal; |
59 |
pdf.FinalMakeError += Pdf_FinalMakeError; |
60 |
//pdf.MakeFinalPDF(_entity.FINAL_PDF.FirstOrDefault()); |
61 |
pdf.MakeFinalPDF(item); |
62 |
//_Thread.Add(item); |
63 |
} |
64 |
else |
65 |
{ |
66 |
Console.WriteLine("item is null"); |
67 |
} |
68 |
|
69 |
} |
70 |
|
71 |
} |
72 |
catch (Exception ex) |
73 |
{ |
74 |
Console.WriteLine("error: "+ ex.ToString()); |
75 |
} |
76 |
|
77 |
} |
78 |
|
79 |
private static void Pdf_FinalMakeError(object sender, MarkupToPDF.MakeFinalErrorArgs e) |
80 |
{ |
81 |
|
82 |
} |
83 |
static List<FINAL_PDF> _Thread = new List<FINAL_PDF>(); |
84 |
private static void Pdf_EndFinal(object sender, MarkupToPDF.EndFinalEventArgs e) |
85 |
{ |
86 |
FINAL_PDF _item = (sender as MarkupToPDF.MarkupToPDF).FinalItem; |
87 |
|
88 |
SetFinalState(_item.ID, FinalStatus.PdfStamp); |
89 |
|
90 |
try |
91 |
{ |
92 |
Console.WriteLine("final pdf end"); |
93 |
string soapurl = string.Empty; |
94 |
using (KCOMDataModel.DataModel.KCOMEntities _systemEntity = new KCOMDataModel.DataModel.KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString())) |
95 |
{ |
96 |
var item = _systemEntity.PROPERTIES.Where(data => data.TYPE == "UpLoadServiceUrl").FirstOrDefault(); |
97 |
if (item != null) soapurl = item.VALUE; |
98 |
} |
99 |
Console.WriteLine("soapurl:"+soapurl); |
100 |
if (!string.IsNullOrEmpty(soapurl)) |
101 |
{ |
102 |
//Legacy IF |
103 |
KeyValuePair<bool, string> result = UploadFinal.UploadFinal.UploadFinalPDF(e.FinalPDFPath.Replace(@"\\172.20.121.220\comment3\finalPDF\", ""), e.OriginPDFName, e.FinalPDF, soapurl); |
104 |
if (result.Key) |
105 |
{ |
106 |
SetFinalState(_item.ID, FinalStatus.Success); |
107 |
} |
108 |
else |
109 |
{ |
110 |
SetFinalState(_item.ID, FinalStatus.Error); |
111 |
Console.WriteLine("pram1:"+ e.FinalPDFPath.Replace(@"\\172.20.121.220\comment3\finalPDF\", "")+",pram2:"+ e.OriginPDFName); |
112 |
//_Log.Write("Upload error .." + e.FinalPDFPath + ",pdfname:" + e.OriginPDFName); |
113 |
} |
114 |
} |
115 |
else |
116 |
{ |
117 |
///TODO: 저장할 폴더 위치를 configuration으로 빼주세요 |
118 |
///Local Test 용 저장 위치 |
119 |
string savepath = CommonLib.Common.GetConfigString("DebugSavePath", "URL", ""); |
120 |
|
121 |
string saveFolder = String.Format(savepath, _item.PROJECT_NO, Convert.ToInt32(_item.DOCUMENT_ID) / 100, _item.DOCUMENT_ID); |
122 |
if (!System.IO.Directory.Exists(saveFolder)) |
123 |
{ |
124 |
System.IO.Directory.CreateDirectory(saveFolder); |
125 |
} |
126 |
|
127 |
//this._Log.Write(String.Format("saveFolder : {0}", saveFolder) + DateTime.Now); |
128 |
System.IO.File.Copy(e.FinalPDFPath, saveFolder + e.OriginPDFName, true); |
129 |
|
130 |
using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(_item.PROJECT_NO).ToString())) |
131 |
{ |
132 |
var item = _entity.DOCUMENT_ITEM.Where(d => d.DOCUMENT_ID == _item.DOCUMENT_ID).FirstOrDefault(); |
133 |
///TODO: RESULT FILE 경로 위치를 configuration으로 빼주세요 |
134 |
///Local Test 용 result url |
135 |
|
136 |
string resultpath = CommonLib.Common.GetConfigString("DebugResultUrlPath", "URL", ""); |
137 |
item.RESULT_FILE = String.Format(resultpath.ToString(), _item.PROJECT_NO, Convert.ToInt32(_item.DOCUMENT_ID) / 100, _item.DOCUMENT_ID, e.OriginPDFName); |
138 |
|
139 |
//sendReqLog("RESULT_FILE_PATH", item.RESULT_FILE); |
140 |
_entity.SaveChanges(); |
141 |
SetFinalState(_item.ID, FinalStatus.Success); |
142 |
//_Thread.Remove(_T.First()); |
143 |
} |
144 |
} |
145 |
} |
146 |
catch (Exception ex) |
147 |
{ |
148 |
SetFinalState(_item.ID, FinalStatus.Error); |
149 |
//_Log.Write("에러 .." + ex.Message); |
150 |
//_Thread.Remove(_T.First()); |
151 |
} |
152 |
} |
153 |
private static void SetFinalState(string finalID, FinalStatus status) |
154 |
{ |
155 |
using (KCOMDataModel.DataModel.KCOMEntities _entity = new KCOMDataModel.DataModel.KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString())) |
156 |
{ |
157 |
var finalList = _entity.FINAL_PDF.Where(final => final.ID == finalID); |
158 |
|
159 |
if (finalList.Count() > 0) |
160 |
{ |
161 |
if (status == FinalStatus.Create) |
162 |
{ |
163 |
finalList.First().START_DATETIME = DateTime.Now; |
164 |
} |
165 |
if (status == FinalStatus.Success) |
166 |
{ |
167 |
finalList.First().END_DATETIME = DateTime.Now; |
168 |
} |
169 |
|
170 |
finalList.First().STATUS = (int)status; |
171 |
_entity.SaveChanges(); |
172 |
} |
173 |
}; |
174 |
} |
175 |
} |
176 |
} |