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