markus / ConvertService / ServiceBase / Markus.Service.Station / StationService / ServiceStationWCF.cs @ 53c9637d
이력 | 보기 | 이력해설 | 다운로드 (8.88 KB)
1 |
using Markus.Message; |
---|---|
2 |
using Markus.Service.Extensions; |
3 |
using Markus.Service.Interface; |
4 |
using Markus.Service.IWcfService; |
5 |
using System; |
6 |
using System.Collections.Generic; |
7 |
using System.Diagnostics; |
8 |
using System.Linq; |
9 |
using System.ServiceModel; |
10 |
using System.ServiceModel.Activation; |
11 |
using System.ServiceModel.Web; |
12 |
using System.Text; |
13 |
using System.Threading.Tasks; |
14 |
|
15 |
namespace Markus.Service |
16 |
{ |
17 |
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] |
18 |
//[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, IncludeExceptionDetailInFaults = true)] |
19 |
public partial class ServiceStation : IStationService |
20 |
{ |
21 |
public string ConvertAdd(string ProjectNo, string ConvertID) |
22 |
{ |
23 |
string result = false.ToString(); |
24 |
|
25 |
try |
26 |
{ |
27 |
result = ConvertProcessAdd(ProjectNo,ConvertID); |
28 |
} |
29 |
catch (Exception ex) |
30 |
{ |
31 |
result = $"ConvertAdd Error {ConvertID}"; |
32 |
logger.Error($"ConvertAdd Error- {ConvertID}", ex); |
33 |
} |
34 |
|
35 |
return result; |
36 |
} |
37 |
|
38 |
public string ConvertMenualAdd(string ProjectNo, string originfilePath, string DocumentID) |
39 |
{ |
40 |
string result = false.ToString(); |
41 |
string convertID = new Guid().CreateUniqueGuid().ToString().Replace("-",""); |
42 |
|
43 |
try |
44 |
{ |
45 |
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
46 |
{ |
47 |
if (!database.SetConvertDoc(ProjectNo, convertID, originfilePath, DocumentID)) |
48 |
{ |
49 |
logger.Error($"Set Convert Document Error - ProjectNo:{ProjectNo} UniqueID:{convertID} originfilePath:{originfilePath} DocumentID:{DocumentID}"); |
50 |
} |
51 |
else |
52 |
{ |
53 |
result = ConvertProcessAdd(ProjectNo,convertID); |
54 |
} |
55 |
} |
56 |
} |
57 |
catch (Exception ex) |
58 |
{ |
59 |
result = "DataBase SetConvert Error"; |
60 |
logger.Error($"ConvertMenualAdd Error- database.SetConvertDoc ProjectNo:{ProjectNo} UniqueID:{convertID} originfilePath:{originfilePath} DocumentID:{DocumentID}", ex); |
61 |
} |
62 |
|
63 |
return result; |
64 |
} |
65 |
|
66 |
|
67 |
|
68 |
private string ConvertProcessAdd(string ProjectNo, string convertID) |
69 |
{ |
70 |
string result = false.ToString(); |
71 |
|
72 |
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
73 |
{ |
74 |
var convertItem = database.GetConvertItem(ProjectNo,convertID); |
75 |
|
76 |
/// 순서별 Convert Item 처리 |
77 |
if (convertItem != null) |
78 |
{ |
79 |
try |
80 |
{ |
81 |
if (ServiceStation.AliveConvertQueue.Count() < MultiProcessCount) |
82 |
{ |
83 |
ConvertProcessStart(convertItem); |
84 |
result = true.ToString(); |
85 |
} |
86 |
} |
87 |
catch (Exception ex) |
88 |
{ |
89 |
result = "Convert Process Start Error"; |
90 |
logger.Error("ConvertMenualAdd ConvertProcess call Error ProjectNo:{ProjectNo} UniqueID:{UniqueID} originfilePath:{originfilePath} DocumentID:{DocumentID}", ex); |
91 |
} |
92 |
} |
93 |
else |
94 |
{ |
95 |
result = "Get ConvertItem Error"; |
96 |
} |
97 |
} |
98 |
|
99 |
return result; |
100 |
} |
101 |
|
102 |
public bool ConvertProcessState(string ConvertID, int status, int CurrentPage, int TotalPage,string Error) |
103 |
{ |
104 |
var items =AliveConvertQueue.Where(x => x.ConvertID == ConvertID); |
105 |
|
106 |
if(items.Count() > 0) |
107 |
{ |
108 |
var item = items.First(); |
109 |
|
110 |
item.TotalPage = TotalPage; |
111 |
item.CurrentPageNo = CurrentPage; |
112 |
item.ConvertState = ((StatusCodeType)status).ToString(); |
113 |
} |
114 |
|
115 |
if (CurrentPage % SaveStatusInterval == 0 || !Error.IsNullOrEmpty()) |
116 |
{ |
117 |
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
118 |
{ |
119 |
if (!database.SetConvertState(ConvertID, status, CurrentPage, TotalPage, Error)) |
120 |
{ |
121 |
logger.Error($"DataBase Error database.SetConvertState({ConvertID}, {(int)status},{CurrentPage},{TotalPage}, {Error})"); |
122 |
} |
123 |
} |
124 |
} |
125 |
|
126 |
return true; |
127 |
} |
128 |
|
129 |
public bool ConvertFinish( string ConvertID, int status, int CurrentPage, int TotalPage, string Error) |
130 |
{ |
131 |
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
132 |
{ |
133 |
if (!database.SetConvertState(ConvertID, status, CurrentPage, TotalPage, Error)) |
134 |
{ |
135 |
logger.Error($"DataBase Error database.SetConvertState({ConvertID}, {(int)status},{CurrentPage},{TotalPage}, {Error})"); |
136 |
} |
137 |
} |
138 |
|
139 |
var _convertItem = ServiceStation.AliveConvertQueue.Where(f => f.ConvertID == ConvertID); |
140 |
|
141 |
if (_convertItem.Count() > 0) |
142 |
ConvertFinish(_convertItem.First()); |
143 |
|
144 |
return true; |
145 |
} |
146 |
|
147 |
public List<ConvertItem> WaitConvertList() |
148 |
{ |
149 |
List<ConvertItem> result = new List<ConvertItem>(); |
150 |
|
151 |
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
152 |
{ |
153 |
result = database.GetConvertItems(Message.StatusCodeType.Wait).ToList(); |
154 |
} |
155 |
|
156 |
return result; |
157 |
} |
158 |
|
159 |
public List<ConvertItem> AliveConvertList() |
160 |
{ |
161 |
return ServiceStation.AliveConvertQueue.ToList(); |
162 |
} |
163 |
|
164 |
public bool SettingMultiProcess(int Value) |
165 |
{ |
166 |
bool result = false; |
167 |
|
168 |
try |
169 |
{ |
170 |
MultiProcessCount = Value; |
171 |
|
172 |
var config = ConfigHelper.AppConfig(configFileName); |
173 |
|
174 |
config.SetValue(CONFIG_DEFINE.SERVICE, CONFIG_DEFINE.CONVERT_SERVICE_PROCESS, Value.ToString()); |
175 |
config.Save(configFileName); |
176 |
|
177 |
result = true; |
178 |
} |
179 |
catch (Exception ex) |
180 |
{ |
181 |
logger.Error("SettingMultiProcess Error ", ex); |
182 |
} |
183 |
|
184 |
return result; |
185 |
} |
186 |
|
187 |
public CommunicationState StartWcfService() |
188 |
{ |
189 |
CommunicationState result = CommunicationState.Faulted; |
190 |
|
191 |
try |
192 |
{ |
193 |
if (gServiceHostAddress != null) |
194 |
{ |
195 |
gWcfServiceHost = gWcfServiceHost.WcfCreate(this, typeof(IWcfService.IStationService), gServiceHostAddress); |
196 |
} |
197 |
|
198 |
if (gWcfServiceHost?.State != CommunicationState.Faulted) |
199 |
{ |
200 |
result = gWcfServiceHost.State; |
201 |
} |
202 |
} |
203 |
catch (Exception ex) |
204 |
{ |
205 |
logger.Error("Start WCF Service Error ", ex); |
206 |
} |
207 |
|
208 |
return result; |
209 |
} |
210 |
|
211 |
private bool StopWcfService() |
212 |
{ |
213 |
bool result = false; |
214 |
try |
215 |
{ |
216 |
gWcfServiceHost.Abort(); |
217 |
result = true; |
218 |
} |
219 |
catch (Exception ex) |
220 |
{ |
221 |
logger.Error("Stop WCF Service Error ", ex); |
222 |
} |
223 |
|
224 |
return result; |
225 |
} |
226 |
|
227 |
public Item GetConvertItem(string ProjectNo, string DocumentID) |
228 |
{ |
229 |
Item result = null; |
230 |
|
231 |
try |
232 |
{ |
233 |
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
234 |
{ |
235 |
var item = database.GetConvertItembyDocumentID(ProjectNo, DocumentID); |
236 |
|
237 |
if (item != null) |
238 |
{ |
239 |
result = |
240 |
new Item |
241 |
{ |
242 |
DocumentID = item.UniqueKey, |
243 |
Status = item.ConvertState, |
244 |
ProjectNo = item.ProjectNumber, |
245 |
TotalPage = item.TotalPage, |
246 |
CurrentPageNo = item.CurrentPageNo, |
247 |
PdfPath = item.OriginfilePath, |
248 |
ConvertPath = item.ConvertPath |
249 |
}; |
250 |
|
251 |
} |
252 |
} |
253 |
} |
254 |
catch (Exception ex) |
255 |
{ |
256 |
throw new FaultException("Get ConvertItem Error"); |
257 |
} |
258 |
|
259 |
return result; |
260 |
} |
261 |
} |
262 |
} |