markus / FinalService / KCOM_FinalService / ConsoleApp1 / Program.cs @ 061e47a0
이력 | 보기 | 이력해설 | 다운로드 (7.06 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 (DataController dc = new DataController()) |
52 |
{ |
53 |
var finals = dc.GetFinalpdfs(inputstr); |
54 |
if(finals.Count > 0) |
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(finals[0]); |
61 |
} |
62 |
else |
63 |
{ |
64 |
Console.WriteLine("item is null"); |
65 |
} |
66 |
} |
67 |
|
68 |
} |
69 |
catch (Exception ex) |
70 |
{ |
71 |
Console.WriteLine("error: "+ ex.ToString()); |
72 |
} |
73 |
|
74 |
} |
75 |
|
76 |
private static void Pdf_FinalMakeError(object sender, MarkupToPDF.MakeFinalErrorArgs e) |
77 |
{ |
78 |
|
79 |
} |
80 |
static List<CommonLib.MARKUS_API.FINAL_PDF> _Thread = new List<CommonLib.MARKUS_API.FINAL_PDF>(); |
81 |
private static void Pdf_EndFinal(object sender, MarkupToPDF.EndFinalEventArgs e) |
82 |
{ |
83 |
FINAL_PDF _item = (sender as MarkupToPDF.MarkupToPDF).FinalItem; |
84 |
|
85 |
SetFinalState(_item.ID, FinalStatus.PdfStamp); |
86 |
|
87 |
try |
88 |
{ |
89 |
Console.WriteLine("final pdf end"); |
90 |
string soapurl = CommonLib.Common.GetConfigString("UpLoadServiceUrl", "URL", ""); |
91 |
Console.WriteLine("soapurl:"+soapurl); |
92 |
if (!string.IsNullOrEmpty(soapurl)) |
93 |
{ |
94 |
//Legacy IF |
95 |
KeyValuePair<bool, string> result = UploadFinal.UploadFinal.UploadFinalPDF(e.FinalPDFPath.Replace(@"\\172.20.121.220\comment3\finalPDF\", ""), e.OriginPDFName, e.FinalPDF, soapurl); |
96 |
if (result.Key) |
97 |
{ |
98 |
SetFinalState(_item.ID, FinalStatus.Success); |
99 |
} |
100 |
else |
101 |
{ |
102 |
SetFinalState(_item.ID, FinalStatus.Error); |
103 |
Console.WriteLine("pram1:"+ e.FinalPDFPath.Replace(@"\\172.20.121.220\comment3\finalPDF\", "")+",pram2:"+ e.OriginPDFName); |
104 |
//_Log.Write("Upload error .." + e.FinalPDFPath + ",pdfname:" + e.OriginPDFName); |
105 |
} |
106 |
} |
107 |
else |
108 |
{ |
109 |
///TODO: 저장할 폴더 위치를 configuration으로 빼주세요 |
110 |
///Local Test 용 저장 위치 |
111 |
string savepath = CommonLib.Common.GetConfigString("DebugSavePath", "URL", ""); |
112 |
|
113 |
string saveFolder = String.Format(savepath, _item.PROJECT_NO, Convert.ToInt32(_item.DOCUMENT_ID) / 100, _item.DOCUMENT_ID); |
114 |
if (!System.IO.Directory.Exists(saveFolder)) |
115 |
{ |
116 |
System.IO.Directory.CreateDirectory(saveFolder); |
117 |
} |
118 |
|
119 |
//this._Log.Write(String.Format("saveFolder : {0}", saveFolder) + DateTime.Now); |
120 |
System.IO.File.Copy(e.FinalPDFPath, saveFolder + e.OriginPDFName, true); |
121 |
using (DataController dataController = new DataController()) |
122 |
{ |
123 |
string resultpath = CommonLib.Common.GetConfigString("DebugResultUrlPath", "URL", ""); |
124 |
string url = String.Format(resultpath, _item.PROJECT_NO, Convert.ToInt32(_item.DOCUMENT_ID) / 100, _item.DOCUMENT_ID, e.OriginPDFName); |
125 |
var result = dataController.SetFinalPDFUrl(_item.PROJECT_NO, _item.DOCUMENT_ID, url); |
126 |
|
127 |
SetFinalState(_item.ID, FinalStatus.Success); |
128 |
} |
129 |
} |
130 |
} |
131 |
catch (Exception ex) |
132 |
{ |
133 |
SetFinalState(_item.ID, FinalStatus.Error); |
134 |
//_Log.Write("에러 .." + ex.Message); |
135 |
//_Thread.Remove(_T.First()); |
136 |
} |
137 |
} |
138 |
private static void SetFinalState(string finalID, FinalStatus status) |
139 |
{ |
140 |
using (KCOMDataModel.DataModel.KCOMEntities _entity = new KCOMDataModel.DataModel.KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString())) |
141 |
{ |
142 |
var finalList = _entity.FINAL_PDF.Where(final => final.ID == finalID); |
143 |
|
144 |
if (finalList.Count() > 0) |
145 |
{ |
146 |
if (status == FinalStatus.Create) |
147 |
{ |
148 |
finalList.First().START_DATETIME = DateTime.Now; |
149 |
} |
150 |
if (status == FinalStatus.Success) |
151 |
{ |
152 |
finalList.First().END_DATETIME = DateTime.Now; |
153 |
} |
154 |
|
155 |
finalList.First().STATUS = (int)status; |
156 |
_entity.SaveChanges(); |
157 |
} |
158 |
}; |
159 |
} |
160 |
} |
161 |
} |