markus / FinalService / KCOM_FinalService / FinalProcess / Program.cs @ 1305c420
이력 | 보기 | 이력해설 | 다운로드 (4.01 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 |
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 |
items.First().STATUS = (int)status; |
90 |
|
91 |
if(!string.IsNullOrWhiteSpace(ex)) |
92 |
{ |
93 |
if (items.First().EXCEPTION.Length < int.MaxValue - ex.Length) |
94 |
{ |
95 |
items.First().EXCEPTION = items.First().EXCEPTION + ex; |
96 |
} |
97 |
} |
98 |
|
99 |
_entity.SaveChanges(); |
100 |
} |
101 |
} |
102 |
} |
103 |
|
104 |
|
105 |
private static void _markuptoPDF_StatusChange(object sender, StatusChangedEventArgs e) |
106 |
{ |
107 |
StatusChange(FinalStatus.Error, e.Error); |
108 |
} |
109 |
|
110 |
private static void _markuptoPDF_FinalMakeError(object sender, MakeFinalErrorArgs e) |
111 |
{ |
112 |
StatusChange(FinalStatus.Error, e.Message); |
113 |
} |
114 |
} |
115 |
} |