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