markus / FinalService / KCOM_FinalService / FinalProcess / Program.cs @ cf1cc862
이력 | 보기 | 이력해설 | 다운로드 (4.21 KB)
1 | 1305c420 | taeseongkim | using IFinalPDF; |
---|---|---|---|
2 | using KCOMDataModel.DataModel; |
||
3 | using log4net; |
||
4 | using MarkupToPDF; |
||
5 | using System; |
||
6 | using System.Collections.Generic; |
||
7 | using System.Linq; |
||
8 | using System.Text; |
||
9 | using System.Threading.Tasks; |
||
10 | using System.Windows.Forms; |
||
11 | |||
12 | namespace FinalProcess |
||
13 | { |
||
14 | class Program |
||
15 | { |
||
16 | protected static ILog logger; |
||
17 | public static FINAL_PDF finalPdf = null; |
||
18 | public static string RemoteAddress = null; |
||
19 | |||
20 | static void Main(string[] args) |
||
21 | { |
||
22 | try |
||
23 | { |
||
24 | logger = LogManager.GetLogger(typeof(Program)); |
||
25 | |||
26 | if (args.Length == 2) |
||
27 | { |
||
28 | string finalID = args[0]; |
||
29 | RemoteAddress = args[1]; |
||
30 | |||
31 | logger.Info($"FinalProcess Final ID :{args[0]}"); |
||
32 | |||
33 | MarkupToPDF.MarkupToPDF _markuptoPDF = new MarkupToPDF.MarkupToPDF(); |
||
34 | _markuptoPDF.FinalMakeError += new EventHandler<MarkupToPDF.MakeFinalErrorArgs>(_markuptoPDF_FinalMakeError); |
||
35 | _markuptoPDF.StatusChanged += new EventHandler<MarkupToPDF.StatusChangedEventArgs>(_markuptoPDF_StatusChange); |
||
36 | |||
37 | using (KCOMDataModel.DataModel.KCOMEntities _entity = new KCOMDataModel.DataModel.KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString())) |
||
38 | { |
||
39 | var items = _entity.FINAL_PDF.Where(x => x.ID == finalID); |
||
40 | |||
41 | if(items.Count() > 0) |
||
42 | { |
||
43 | finalPdf = items.First(); |
||
44 | } |
||
45 | } |
||
46 | |||
47 | if (finalPdf != null) |
||
48 | { |
||
49 | var result = _markuptoPDF.MakeFinalPDF(finalPdf); |
||
50 | |||
51 | using (KCOMDataModel.DataModel.KCOMEntities _entity = new KCOMDataModel.DataModel.KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString())) |
||
52 | { |
||
53 | var items = _entity.FINAL_PDF.Where(x => x.ID == finalID); |
||
54 | |||
55 | if (items.Count() > 0) |
||
56 | { |
||
57 | if (result.Error == null) |
||
58 | { |
||
59 | items.First().STATUS = 4; |
||
60 | items.First().END_DATETIME = DateTime.Now; |
||
61 | } |
||
62 | } |
||
63 | } |
||
64 | } |
||
65 | } |
||
66 | } |
||
67 | catch (Exception ex) |
||
68 | { |
||
69 | logger.Error($"FinalProcess Final ID :{args[0]}", ex); |
||
70 | } |
||
71 | finally |
||
72 | { |
||
73 | GC.Collect(); |
||
74 | GC.WaitForPendingFinalizers(); |
||
75 | GC.Collect(); |
||
76 | |||
77 | Application.Exit(); |
||
78 | } |
||
79 | } |
||
80 | |||
81 | public static void StatusChange(FinalStatus status,string ex) |
||
82 | { |
||
83 | using (KCOMDataModel.DataModel.KCOMEntities _entity = new KCOMDataModel.DataModel.KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString())) |
||
84 | { |
||
85 | var items = _entity.FINAL_PDF.Where(x => x.ID == finalPdf.ID); |
||
86 | |||
87 | if (items.Count() > 0) |
||
88 | { |
||
89 | cf1cc862 | taeseongkim | var currentItem = items.First(); |
90 | |||
91 | currentItem.STATUS = (int)status; |
||
92 | 1305c420 | taeseongkim | |
93 | if(!string.IsNullOrWhiteSpace(ex)) |
||
94 | { |
||
95 | cf1cc862 | taeseongkim | int exLength = (currentItem.EXCEPTION == null)? 0: currentItem.EXCEPTION.Length; |
96 | |||
97 | if (exLength < int.MaxValue - ex.Length) |
||
98 | { |
||
99 | currentItem.EXCEPTION = currentItem.EXCEPTION + " " + ex; |
||
100 | } |
||
101 | else |
||
102 | 1305c420 | taeseongkim | { |
103 | } |
||
104 | } |
||
105 | |||
106 | _entity.SaveChanges(); |
||
107 | } |
||
108 | } |
||
109 | } |
||
110 | |||
111 | private static void _markuptoPDF_StatusChange(object sender, StatusChangedEventArgs e) |
||
112 | { |
||
113 | cf1cc862 | taeseongkim | StatusChange(e.Status, e.Message); |
114 | 1305c420 | taeseongkim | } |
115 | |||
116 | private static void _markuptoPDF_FinalMakeError(object sender, MakeFinalErrorArgs e) |
||
117 | { |
||
118 | StatusChange(FinalStatus.Error, e.Message); |
||
119 | } |
||
120 | } |
||
121 | } |