1 |
53c9637d
|
taeseongkim
|
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 |
a53dfe45
|
taeseongkim
|
/// <summary>
|
18 |
|
|
/// web service 목록
|
19 |
|
|
/// </summary>
|
20 |
53c9637d
|
taeseongkim
|
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
|
21 |
1ae729e4
|
taeseongkim
|
//[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, IncludeExceptionDetailInFaults = true)]
|
22 |
53c9637d
|
taeseongkim
|
public partial class ServiceStation : IStationService
|
23 |
|
|
{
|
24 |
a53dfe45
|
taeseongkim
|
/// <summary>
|
25 |
|
|
/// DB에 Convrert Item을 추가 하고 호출
|
26 |
|
|
/// CovnertWebService에서 호출시 사용
|
27 |
|
|
/// </summary>
|
28 |
|
|
/// <param name="ProjectNo"></param>
|
29 |
|
|
/// <param name="ConvertID"></param>
|
30 |
|
|
/// <returns></returns>
|
31 |
53c9637d
|
taeseongkim
|
public string ConvertAdd(string ProjectNo, string ConvertID)
|
32 |
|
|
{
|
33 |
|
|
string result = false.ToString();
|
34 |
|
|
|
35 |
|
|
try
|
36 |
|
|
{
|
37 |
06f13e11
|
taeseongkim
|
result = ConvertProcessAdd(ProjectNo, ConvertID);
|
38 |
949d5058
|
taeseongkim
|
|
39 |
|
|
logger.Info($"ConvertAdd Call Item ProjectNo : {ProjectNo} ConvertID : {ConvertID} result : {result}");
|
40 |
53c9637d
|
taeseongkim
|
}
|
41 |
|
|
catch (Exception ex)
|
42 |
|
|
{
|
43 |
|
|
result = $"ConvertAdd Error {ConvertID}";
|
44 |
|
|
logger.Error($"ConvertAdd Error- {ConvertID}", ex);
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
return result;
|
48 |
|
|
}
|
49 |
|
|
|
50 |
a53dfe45
|
taeseongkim
|
/// <summary>
|
51 |
|
|
/// 별도의 호출 사용
|
52 |
|
|
/// </summary>
|
53 |
|
|
/// <param name="ProjectNo"></param>
|
54 |
|
|
/// <param name="originfilePath"></param>
|
55 |
|
|
/// <param name="DocumentID"></param>
|
56 |
|
|
/// <returns></returns>
|
57 |
53c9637d
|
taeseongkim
|
public string ConvertMenualAdd(string ProjectNo, string originfilePath, string DocumentID)
|
58 |
|
|
{
|
59 |
|
|
string result = false.ToString();
|
60 |
06f13e11
|
taeseongkim
|
string convertID = new Guid().CreateUniqueGuid().ToString().Replace("-", "");
|
61 |
53c9637d
|
taeseongkim
|
|
62 |
|
|
try
|
63 |
|
|
{
|
64 |
|
|
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
|
65 |
|
|
{
|
66 |
5d863c06
|
taeseongkim
|
var convertItem = database.GetConvertItembyDocumentID(ProjectNo, DocumentID);
|
67 |
|
|
|
68 |
|
|
if(convertItem != null)
|
69 |
|
|
{
|
70 |
|
|
var aliveItems = AliveConvertQueue.Where(x => x.ConvertID == convertItem.ConvertID);
|
71 |
|
|
}
|
72 |
|
|
|
73 |
53c9637d
|
taeseongkim
|
if (!database.SetConvertDoc(ProjectNo, convertID, originfilePath, DocumentID))
|
74 |
|
|
{
|
75 |
|
|
logger.Error($"Set Convert Document Error - ProjectNo:{ProjectNo} UniqueID:{convertID} originfilePath:{originfilePath} DocumentID:{DocumentID}");
|
76 |
|
|
}
|
77 |
|
|
else
|
78 |
|
|
{
|
79 |
06f13e11
|
taeseongkim
|
result = ConvertProcessAdd(ProjectNo, convertID);
|
80 |
53c9637d
|
taeseongkim
|
}
|
81 |
|
|
}
|
82 |
|
|
}
|
83 |
|
|
catch (Exception ex)
|
84 |
|
|
{
|
85 |
|
|
result = "DataBase SetConvert Error";
|
86 |
|
|
logger.Error($"ConvertMenualAdd Error- database.SetConvertDoc ProjectNo:{ProjectNo} UniqueID:{convertID} originfilePath:{originfilePath} DocumentID:{DocumentID}", ex);
|
87 |
|
|
}
|
88 |
06f13e11
|
taeseongkim
|
|
89 |
53c9637d
|
taeseongkim
|
return result;
|
90 |
|
|
}
|
91 |
|
|
|
92 |
a53dfe45
|
taeseongkim
|
/// <summary>
|
93 |
|
|
/// ConvertItem의 상태
|
94 |
|
|
/// </summary>
|
95 |
|
|
/// <param name="ProjectNo"></param>
|
96 |
|
|
/// <param name="DocumentID"></param>
|
97 |
|
|
/// <returns></returns>
|
98 |
|
|
public Item GetConvertItem(string ProjectNo, string DocumentID)
|
99 |
|
|
{
|
100 |
|
|
Item result = null;
|
101 |
|
|
|
102 |
|
|
try
|
103 |
|
|
{
|
104 |
|
|
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
|
105 |
|
|
{
|
106 |
|
|
var item = database.GetConvertItembyDocumentID(ProjectNo, DocumentID);
|
107 |
|
|
|
108 |
|
|
if (item != null)
|
109 |
|
|
{
|
110 |
|
|
result =
|
111 |
|
|
new Item
|
112 |
|
|
{
|
113 |
|
|
DocumentID = item.UniqueKey,
|
114 |
|
|
Status = item.ConvertState,
|
115 |
|
|
ProjectNo = item.ProjectNumber,
|
116 |
|
|
TotalPage = item.TotalPage,
|
117 |
|
|
CurrentPageNo = item.CurrentPageNo,
|
118 |
|
|
PdfPath = item.OriginfilePath,
|
119 |
|
|
ConvertPath = item.ConvertPath
|
120 |
|
|
};
|
121 |
53c9637d
|
taeseongkim
|
|
122 |
a53dfe45
|
taeseongkim
|
}
|
123 |
|
|
}
|
124 |
|
|
}
|
125 |
|
|
catch (Exception ex)
|
126 |
|
|
{
|
127 |
|
|
throw new FaultException("Get ConvertItem Error");
|
128 |
|
|
}
|
129 |
53c9637d
|
taeseongkim
|
|
130 |
a53dfe45
|
taeseongkim
|
return result;
|
131 |
|
|
}
|
132 |
|
|
|
133 |
|
|
/// <summary>
|
134 |
|
|
/// Convert Item을 DB에 추가 하고 프로세스 실행시 호출
|
135 |
|
|
/// </summary>
|
136 |
|
|
/// <param name="ProjectNo"></param>
|
137 |
|
|
/// <param name="convertID"></param>
|
138 |
|
|
/// <returns></returns>
|
139 |
53c9637d
|
taeseongkim
|
private string ConvertProcessAdd(string ProjectNo, string convertID)
|
140 |
|
|
{
|
141 |
|
|
string result = false.ToString();
|
142 |
|
|
|
143 |
|
|
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
|
144 |
|
|
{
|
145 |
06f13e11
|
taeseongkim
|
var convertItem = database.GetConvertItem(ProjectNo, convertID);
|
146 |
53c9637d
|
taeseongkim
|
|
147 |
|
|
/// 순서별 Convert Item 처리
|
148 |
|
|
if (convertItem != null)
|
149 |
|
|
{
|
150 |
|
|
try
|
151 |
|
|
{
|
152 |
cdfb57ff
|
taeseongkim
|
if (AliveConvertQueue.Count(c => c.UniqueKey == convertItem.UniqueKey) == 0)
|
153 |
|
|
{
|
154 |
60723dc9
|
taeseongkim
|
if (ServiceStation.AliveConvertQueue.Count() < ServiceProperty.PROCESS_COUNT)
|
155 |
cdfb57ff
|
taeseongkim
|
{
|
156 |
0a89a17f
|
taeseongkim
|
convertItem.ServiceID = this.ServiceID;
|
157 |
cdfb57ff
|
taeseongkim
|
ConvertProcessStart(convertItem);
|
158 |
|
|
result = true.ToString();
|
159 |
|
|
}
|
160 |
949d5058
|
taeseongkim
|
else
|
161 |
|
|
{
|
162 |
|
|
logger.Info($"ConvertAdd ConvertProcess Wait ProcessCount ProjectNo:{ProjectNo} convertID:{convertID} ");
|
163 |
|
|
result = true.ToString();
|
164 |
|
|
}
|
165 |
cdfb57ff
|
taeseongkim
|
}
|
166 |
|
|
else
|
167 |
53c9637d
|
taeseongkim
|
{
|
168 |
65768148
|
swate0609
|
PassConvertItem(ProjectNo, convertID, convertItem.UniqueKey);
|
169 |
53c9637d
|
taeseongkim
|
result = true.ToString();
|
170 |
|
|
}
|
171 |
|
|
}
|
172 |
|
|
catch (Exception ex)
|
173 |
|
|
{
|
174 |
|
|
result = "Convert Process Start Error";
|
175 |
949d5058
|
taeseongkim
|
logger.Error($"ConvertAdd ConvertProcess call Error ProjectNo:{ProjectNo} convertID:{convertID} ", ex);
|
176 |
53c9637d
|
taeseongkim
|
}
|
177 |
|
|
}
|
178 |
|
|
else
|
179 |
|
|
{
|
180 |
949d5058
|
taeseongkim
|
logger.Error($"ConvertAdd ConvertProcess call Error ProjectNo:{ProjectNo} convertID:{convertID} item Null ");
|
181 |
53c9637d
|
taeseongkim
|
result = "Get ConvertItem Error";
|
182 |
|
|
}
|
183 |
|
|
}
|
184 |
|
|
|
185 |
|
|
return result;
|
186 |
|
|
}
|
187 |
|
|
|
188 |
a53dfe45
|
taeseongkim
|
/// <summary>
|
189 |
|
|
/// 각 ConvertProcess의 상태값을 저장
|
190 |
|
|
/// </summary>
|
191 |
|
|
/// <param name="ConvertID"></param>
|
192 |
|
|
/// <param name="status"></param>
|
193 |
|
|
/// <param name="CurrentPage"></param>
|
194 |
|
|
/// <param name="TotalPage"></param>
|
195 |
|
|
/// <param name="Error"></param>
|
196 |
|
|
/// <returns></returns>
|
197 |
06f13e11
|
taeseongkim
|
public bool ConvertProcessState(string ConvertID, int status, int CurrentPage, int TotalPage, string Error)
|
198 |
53c9637d
|
taeseongkim
|
{
|
199 |
06f13e11
|
taeseongkim
|
var items = AliveConvertQueue.Where(x => x.ConvertID == ConvertID);
|
200 |
|
|
|
201 |
|
|
if (items.Count() > 0)
|
202 |
53c9637d
|
taeseongkim
|
{
|
203 |
|
|
var item = items.First();
|
204 |
|
|
|
205 |
|
|
item.TotalPage = TotalPage;
|
206 |
|
|
item.CurrentPageNo = CurrentPage;
|
207 |
|
|
item.ConvertState = ((StatusCodeType)status).ToString();
|
208 |
|
|
}
|
209 |
|
|
|
210 |
|
|
if (CurrentPage % SaveStatusInterval == 0 || !Error.IsNullOrEmpty())
|
211 |
|
|
{
|
212 |
|
|
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
|
213 |
|
|
{
|
214 |
0157b158
|
taeseongkim
|
if (!database.SetConvertState(this.ServiceID, ConvertID, status, CurrentPage, TotalPage, Error))
|
215 |
53c9637d
|
taeseongkim
|
{
|
216 |
|
|
logger.Error($"DataBase Error database.SetConvertState({ConvertID}, {(int)status},{CurrentPage},{TotalPage}, {Error})");
|
217 |
|
|
}
|
218 |
|
|
}
|
219 |
|
|
}
|
220 |
|
|
|
221 |
|
|
return true;
|
222 |
|
|
}
|
223 |
|
|
|
224 |
a53dfe45
|
taeseongkim
|
/// <summary>
|
225 |
|
|
/// Convert Process 완료시 호출
|
226 |
|
|
/// </summary>
|
227 |
|
|
/// <param name="ConvertID"></param>
|
228 |
|
|
/// <param name="status"></param>
|
229 |
|
|
/// <param name="CurrentPage"></param>
|
230 |
|
|
/// <param name="TotalPage"></param>
|
231 |
|
|
/// <param name="Error"></param>
|
232 |
|
|
/// <returns></returns>
|
233 |
06f13e11
|
taeseongkim
|
public bool ConvertFinish(string ConvertID, int status, int CurrentPage, int TotalPage, string Error)
|
234 |
53c9637d
|
taeseongkim
|
{
|
235 |
|
|
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
|
236 |
|
|
{
|
237 |
0157b158
|
taeseongkim
|
if (!database.SetConvertState(this.ServiceID, ConvertID, status, CurrentPage, TotalPage, Error))
|
238 |
53c9637d
|
taeseongkim
|
{
|
239 |
|
|
logger.Error($"DataBase Error database.SetConvertState({ConvertID}, {(int)status},{CurrentPage},{TotalPage}, {Error})");
|
240 |
|
|
}
|
241 |
|
|
}
|
242 |
|
|
|
243 |
|
|
var _convertItem = ServiceStation.AliveConvertQueue.Where(f => f.ConvertID == ConvertID);
|
244 |
|
|
|
245 |
|
|
if (_convertItem.Count() > 0)
|
246 |
06f13e11
|
taeseongkim
|
{
|
247 |
53c9637d
|
taeseongkim
|
ConvertFinish(_convertItem.First());
|
248 |
06f13e11
|
taeseongkim
|
}
|
249 |
53c9637d
|
taeseongkim
|
|
250 |
|
|
return true;
|
251 |
|
|
}
|
252 |
|
|
|
253 |
a53dfe45
|
taeseongkim
|
/// <summary>
|
254 |
|
|
/// 대기중인 Convert Item을 가져옴
|
255 |
|
|
/// </summary>
|
256 |
|
|
/// <returns></returns>
|
257 |
53c9637d
|
taeseongkim
|
public List<ConvertItem> WaitConvertList()
|
258 |
|
|
{
|
259 |
|
|
List<ConvertItem> result = new List<ConvertItem>();
|
260 |
|
|
|
261 |
|
|
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
|
262 |
|
|
{
|
263 |
|
|
result = database.GetConvertItems(Message.StatusCodeType.Wait).ToList();
|
264 |
|
|
}
|
265 |
|
|
|
266 |
|
|
return result;
|
267 |
|
|
}
|
268 |
|
|
|
269 |
a53dfe45
|
taeseongkim
|
/// <summary>
|
270 |
|
|
/// 현재 AliveConvertQueue에 있는 컨버터 리스트
|
271 |
|
|
/// </summary>
|
272 |
|
|
/// <returns></returns>
|
273 |
53c9637d
|
taeseongkim
|
public List<ConvertItem> AliveConvertList()
|
274 |
|
|
{
|
275 |
06f13e11
|
taeseongkim
|
return ServiceStation.AliveConvertQueue;
|
276 |
53c9637d
|
taeseongkim
|
}
|
277 |
|
|
|
278 |
a53dfe45
|
taeseongkim
|
/// <summary>
|
279 |
|
|
/// WCF 시작
|
280 |
|
|
/// </summary>
|
281 |
|
|
/// <returns></returns>
|
282 |
53c9637d
|
taeseongkim
|
public CommunicationState StartWcfService()
|
283 |
|
|
{
|
284 |
|
|
CommunicationState result = CommunicationState.Faulted;
|
285 |
|
|
|
286 |
|
|
try
|
287 |
|
|
{
|
288 |
|
|
if (gServiceHostAddress != null)
|
289 |
|
|
{
|
290 |
|
|
gWcfServiceHost = gWcfServiceHost.WcfCreate(this, typeof(IWcfService.IStationService), gServiceHostAddress);
|
291 |
|
|
}
|
292 |
|
|
|
293 |
|
|
if (gWcfServiceHost?.State != CommunicationState.Faulted)
|
294 |
|
|
{
|
295 |
|
|
result = gWcfServiceHost.State;
|
296 |
|
|
}
|
297 |
|
|
}
|
298 |
|
|
catch (Exception ex)
|
299 |
|
|
{
|
300 |
|
|
logger.Error("Start WCF Service Error ", ex);
|
301 |
|
|
}
|
302 |
|
|
|
303 |
|
|
return result;
|
304 |
|
|
}
|
305 |
|
|
|
306 |
a53dfe45
|
taeseongkim
|
/// <summary>
|
307 |
|
|
/// WCF 중단
|
308 |
|
|
/// </summary>
|
309 |
|
|
/// <returns></returns>
|
310 |
53c9637d
|
taeseongkim
|
private bool StopWcfService()
|
311 |
|
|
{
|
312 |
|
|
bool result = false;
|
313 |
|
|
try
|
314 |
|
|
{
|
315 |
|
|
gWcfServiceHost.Abort();
|
316 |
|
|
result = true;
|
317 |
|
|
}
|
318 |
|
|
catch (Exception ex)
|
319 |
|
|
{
|
320 |
|
|
logger.Error("Stop WCF Service Error ", ex);
|
321 |
|
|
}
|
322 |
|
|
|
323 |
|
|
return result;
|
324 |
|
|
}
|
325 |
|
|
|
326 |
06f13e11
|
taeseongkim
|
public bool ReleaseConvertItems()
|
327 |
|
|
{
|
328 |
|
|
System.Diagnostics.Debug.WriteLine("Call ReleaseConvertItems");
|
329 |
60723dc9
|
taeseongkim
|
if (!IsReleaseItems)
|
330 |
|
|
{
|
331 |
|
|
ReleaseItems();
|
332 |
|
|
}
|
333 |
|
|
|
334 |
06f13e11
|
taeseongkim
|
System.Diagnostics.Debug.WriteLine("end ReleaseConvertItems");
|
335 |
|
|
return true;
|
336 |
|
|
}
|
337 |
53c9637d
|
taeseongkim
|
}
|
338 |
|
|
} |