-
Notifications
You must be signed in to change notification settings - Fork 0
/
MatchingProcess.Activator.cs
333 lines (288 loc) · 19.1 KB
/
MatchingProcess.Activator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
/******************************************************************************
* Copyright (C) 2010-2016 GlobalTranz - All Rights Reserved.
*
* Proprietary and confidential. Unauthorized copying of this file, via any
* medium is strictly prohibited without the explicit permission of GlobalTranz.
******************************************************************************/
namespace GlobalTranz.MatchingProcess.Service
{
#region Namespaces
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Configuration;
using System.Workflow.Runtime;
using System.Workflow.Runtime.Hosting;
using GlobalTranz.EDI.Contracts;
using workflow = GlobalTranz.EDI.Workflows;
using GlobalTranz.Framework.Common.Models.Business.EDIAutomation;
using GlobalTranz.Framework.Common.Enum;
using GlobalTranz.EDI.BusinessLogic;
using GlobalTranz.Common.BusinessLogic;
#endregion Namespaces
/// <summary>
/// Class for implementation of service logic.
/// </summary>
/// <createDetail>
/// <id>US4444</id> <by>Baljinder Dadyala</by> <date>20-08-2013</date>
/// </createDetail>
public partial class MatchingProcess : IMatchingProcess
{
#region Static Members
private static AutoResetEvent waitHandle = new AutoResetEvent(false);
private static WorkflowRuntime workflowRuntime = new WorkflowRuntime();
private static EDICarrierSettings carrierSettingsDataset;
#endregion Static Members
#region Public Method Implementation
/// <summary>
/// Starts the Sales Order Matching Process.
/// </summary>
/// <param name="venderBillId">Vendor Bill Id</param>
/// <param name="forceAttach">Force Attach</param>
/// <param name="salesOrderId">Optional Parameter SalesOrder Id</param>
/// <createDetail>
/// <id>US4444</id> <by>Manoj Bhuyan</by> <date>20-08-2013</date>
/// </createDetail>
public void SaleOrderMatchingService(long venderBillId, long salesOrderId, Int16 forceAttach)
{
Logger.FileLogger soLogger = new Logger.FileLogger() { FileNameWithDateTime = Constants.SalesOrderLogFileName + (new Random()).Next(99999999).ToString(), FilePath = (string.IsNullOrEmpty(ConfigurationManager.AppSettings[MatchingProcess.Constants.ErrorLogFilePath]) ? string.Empty : ConfigurationManager.AppSettings[MatchingProcess.Constants.ErrorLogFilePath]), LogToConsole = Convert.ToBoolean(ConfigurationManager.AppSettings[MatchingProcess.Constants.IsLoggedToConsole]) };
soLogger.LogMessage(message: "Method Entry", logType: Logger.Logger.LogType.Information, logDate: true, logTraceDetails: true);
soLogger.LogMessage(message: string.Format("Input parameter details. Vendor Bill Id: {0}; Is Force Attached: {1}; Sales Order Id: {2}", venderBillId, forceAttach, salesOrderId), logType: Logger.Logger.LogType.Information, logDate: true, logTraceDetails: true);
try
{
using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("VendorBillIdParam", venderBillId);
parameters.Add("ForceAttachParam", forceAttach);
parameters.Add("SalesOrderIdParam", salesOrderId);
AutoResetEvent waitHandle = new AutoResetEvent(false);
workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
{
soLogger.LogMessage(message: "Workflow completed", logType: Logger.Logger.LogType.Information, logDate: true);
waitHandle.Set();
};
workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
{
soLogger.LogException(e.Exception);
waitHandle.Set();
};
workflowRuntime.Stopped += delegate(object sender, WorkflowRuntimeEventArgs e)
{
soLogger.LogMessage("Workflow stopped", logType: Logger.Logger.LogType.Information, logDate: true);
};
workflowRuntime.WorkflowAborted += delegate(object sender, WorkflowEventArgs e)
{
soLogger.LogMessage(message: "Workflow is aborted", logType: Logger.Logger.LogType.Information, logDate: true);
};
workflowRuntime.WorkflowCreated += delegate(object sender, WorkflowEventArgs e)
{
soLogger.LogMessage(message: string.Format(" Workflow : {0} is created", e.WorkflowInstance.GetWorkflowDefinition().Name), logType: Logger.Logger.LogType.Information, logDate: true);
};
workflowRuntime.WorkflowStarted += delegate(object sender, WorkflowEventArgs e)
{
soLogger.LogMessage(message: string.Format(" Workflow : {0} is started", e.WorkflowInstance.GetWorkflowDefinition().Name), logType: Logger.Logger.LogType.Information, logDate: true);
};
workflowRuntime.WorkflowSuspended += delegate(object sender, WorkflowSuspendedEventArgs e)
{
soLogger.LogMessage(message: string.Format(" Workflow : {0} is suspended", e.WorkflowInstance.GetWorkflowDefinition().Name), logType: Logger.Logger.LogType.Information, logDate: true);
};
workflowRuntime.WorkflowResumed += delegate(object sender, WorkflowEventArgs e)
{
soLogger.LogMessage(message: string.Format(" Workflow : {0} is resuming", e.WorkflowInstance.GetWorkflowDefinition().Name), logType: Logger.Logger.LogType.Information, logDate: true);
};
workflowRuntime.WorkflowIdled += delegate(object sender, WorkflowEventArgs e)
{
soLogger.LogMessage(message: string.Format(" Workflow : {0} is idle", e.WorkflowInstance.GetWorkflowDefinition().Name), logType: Logger.Logger.LogType.Information, logDate: true);
};
WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(typeof(workflow.SalesOrderMatchingProcess), parameters);
soLogger.LogMessage(string.Format("Process start time: {0}", DateTime.Now.ToLongTimeString()), logType: Logger.Logger.LogType.Information, logDate: true);
workflowInstance.Start();
waitHandle.WaitOne();
soLogger.LogMessage(string.Format("Process end time: {0}", DateTime.Now.ToLongTimeString()), logType: Logger.Logger.LogType.Information, logDate: true);
}
}
catch (Exception ex)
{
soLogger.LogException(exception: ex, logType: Logger.Logger.LogType.Error);
Contract matchingProcessFault = new Contract();
matchingProcessFault.ErrorSource = "Error in Sales Order ";
matchingProcessFault.ErrorDetail = ex.ToString();
}
soLogger.LogMessage(message: "Method Exit", logType: Logger.Logger.LogType.Information, logDate: true, logTraceDetails: true);
}
/// <summary>
/// Starts the Vendor Bill Matching Process
/// </summary>
/// <param name="salesOrderId">Sales Order Id</param>
/// <createDetail>
/// <id>US4444</id> <by>Manoj Bhuyan</by> <date>20-08-2013</date>
/// </createDetail>
public void VendorBillMatchingService(long salesOrderId)
{
Logger.FileLogger vbLogger = new Logger.FileLogger() { FileNameWithDateTime = Constants.VendorBillLogFileName + (new Random()).Next(99999999).ToString(), FilePath = (string.IsNullOrEmpty(ConfigurationManager.AppSettings[MatchingProcess.Constants.ErrorLogFilePath]) ? string.Empty : ConfigurationManager.AppSettings[MatchingProcess.Constants.ErrorLogFilePath]), LogToConsole = Convert.ToBoolean(ConfigurationManager.AppSettings[MatchingProcess.Constants.IsLoggedToConsole]) };
vbLogger.LogMessage(message: "Method Entry", logType: Logger.Logger.LogType.Information, logDate: true, logTraceDetails: true);
vbLogger.LogMessage(message: string.Format("Input parameter details. Sales Order Id: {0}", salesOrderId), logType: Logger.Logger.LogType.Information, logDate: true, logTraceDetails: true);
try
{
using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("SalesOrderId", salesOrderId);
AutoResetEvent waitHandle = new AutoResetEvent(false);
workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
{
vbLogger.LogMessage(message: "Workflow completed", logType: Logger.Logger.LogType.Information, logDate: true);
waitHandle.Set();
};
workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
{
vbLogger.LogException(e.Exception);
waitHandle.Set();
};
workflowRuntime.Stopped += delegate(object sender, WorkflowRuntimeEventArgs e)
{
vbLogger.LogMessage("Workflow stopped", logType: Logger.Logger.LogType.Information, logDate: true);
};
workflowRuntime.WorkflowAborted += delegate(object sender, WorkflowEventArgs e)
{
vbLogger.LogMessage(message: "Workflow is aborted", logType: Logger.Logger.LogType.Information, logDate: true);
};
workflowRuntime.WorkflowCreated += delegate(object sender, WorkflowEventArgs e)
{
vbLogger.LogMessage(message: string.Format(" Workflow : {0} is created", e.WorkflowInstance.GetWorkflowDefinition().Name), logType: Logger.Logger.LogType.Information, logDate: true);
};
workflowRuntime.WorkflowStarted += delegate(object sender, WorkflowEventArgs e)
{
vbLogger.LogMessage(message: string.Format(" Workflow : {0} is started", e.WorkflowInstance.GetWorkflowDefinition().Name), logType: Logger.Logger.LogType.Information, logDate: true);
};
workflowRuntime.WorkflowSuspended += delegate(object sender, WorkflowSuspendedEventArgs e)
{
vbLogger.LogMessage(message: string.Format(" Workflow : {0} is suspended", e.WorkflowInstance.GetWorkflowDefinition().Name), logType: Logger.Logger.LogType.Information, logDate: true);
};
workflowRuntime.WorkflowResumed += delegate(object sender, WorkflowEventArgs e)
{
vbLogger.LogMessage(message: string.Format(" Workflow : {0} is resuming", e.WorkflowInstance.GetWorkflowDefinition().Name), logType: Logger.Logger.LogType.Information, logDate: true);
};
workflowRuntime.WorkflowIdled += delegate(object sender, WorkflowEventArgs e)
{
vbLogger.LogMessage(message: string.Format(" Workflow : {0} is idle", e.WorkflowInstance.GetWorkflowDefinition().Name), logType: Logger.Logger.LogType.Information, logDate: true);
};
WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(typeof(workflow.VendorBillMatchingProcess), parameters);
vbLogger.LogMessage(string.Format("Process start time: {0}", DateTime.Now.ToLongTimeString()), logType: Logger.Logger.LogType.Information, logDate: true);
workflowInstance.Start();
waitHandle.WaitOne();
vbLogger.LogMessage(string.Format("Process end time: {0}", DateTime.Now.ToLongTimeString()), logType: Logger.Logger.LogType.Information, logDate: true);
}
}
catch (Exception ex)
{
vbLogger.LogException(exception: ex, logType: Logger.Logger.LogType.Error);
Contract matchingProcessFault = new Contract();
matchingProcessFault.ErrorSource = "Error in VendorBillMatchingService ";
matchingProcessFault.ErrorDetail = ex.ToString();
}
vbLogger.LogMessage(message: "Method Exit", logType: Logger.Logger.LogType.Information, logDate: true, logTraceDetails: true);
}
/// <summary>
/// Starts the EDI210 Matching Process
/// </summary>
/// <createDetail>
/// <id>US4444</id> <by>Manoj Bhuyan</by> <date>20-08-2013</date>
/// </createDetail>
public void EDI210MatchingProcess()
{
Logger.FileLogger ediLogger = new Logger.FileLogger() { FileNameWithDateTime = Constants.EDI210LogFileName + (new Random()).Next(99999999).ToString(), FilePath = (string.IsNullOrEmpty(ConfigurationManager.AppSettings[MatchingProcess.Constants.ErrorLogFilePath]) ? string.Empty : ConfigurationManager.AppSettings[MatchingProcess.Constants.ErrorLogFilePath]), LogToConsole = Convert.ToBoolean(ConfigurationManager.AppSettings[MatchingProcess.Constants.IsLoggedToConsole]) };
ediLogger.LogMessage(message: "Method Entry", logType: Logger.Logger.LogType.Information, logDate: true, logTraceDetails: true);
int PriorityCount = 0;
PriorityCount = Convert.ToInt32(ConfigurationManager.AppSettings[Constants.PriorityThreadCount].ToString());
//Get basic carrier settings
carrierSettingsDataset = RetriveCarrierSetting(PriorityCount, ediLogger);
var priorityCarriers = (from carriers in carrierSettingsDataset.Tables[carrierSettingsDataset._EDICarrierSettings.ToString()].AsEnumerable()
where carriers.Field<int>(carrierSettingsDataset._EDICarrierSettings.PriorityColumn) == 1
select carriers.Field<int>(carrierSettingsDataset._EDICarrierSettings.CarrierIDColumn));
//Convert result to array
int[] carrierlist = priorityCarriers.ToArray<int>();
int[] carrierlist1 = { 108 };
this.StartEDI210MatchingProcess(carrierlist, PriorityCount, ediLogger);
ediLogger.LogMessage(message: "Method Exit", logType: Logger.Logger.LogType.Information, logDate: true, logTraceDetails: true);
}
#endregion Public Method Implementation
#region Private Method Implementation
/// <summary>
/// Start EDI210 Matching Process Workflow
/// </summary>
/// <param name="carriers">Int Array of Priority Carriers</param>
/// <param name="priority">Priority Thread Count</param>
/// <param name="ediLogger">Logger Object</param>
/// <createDetail>
/// <id>US4444</id> <by>Manoj Bhuyan</by> <date>20-08-2013</date>
/// </createDetail>
private void StartEDI210MatchingProcess(int[] carriers, int priority, Logger.FileLogger ediLogger)
{
ediLogger.LogMessage(message: "Method Entry", logType: Logger.Logger.LogType.Information, logDate: true, logTraceDetails: true);
try
{
using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
{
workflowRuntime.WorkflowStarted += delegate(object sender, WorkflowEventArgs e)
{
ediLogger.LogMessage(message: " EDI210 Workflow is started", logType: Logger.Logger.LogType.Information, logDate: true);
};
workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
{
ediLogger.LogMessage(message: " EDI210 Workflow is completed", logType: Logger.Logger.LogType.Information, logDate: true);
};
workflowRuntime.WorkflowIdled += delegate(object sender, WorkflowEventArgs e)
{
ediLogger.LogMessage(message: " EDI210 Workflow is idle", logType: Logger.Logger.LogType.Information, logDate: true);
};
workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
{
ediLogger.LogException(e.Exception);
};
AutoResetEvent waitHandle = new AutoResetEvent(false);
workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) { waitHandle.Set(); };
workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
{
ediLogger.LogException(e.Exception);
waitHandle.Set();
};
WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(workflow.EDI210MatchingProcess));
instance.Start();
waitHandle.WaitOne();
}
}
catch (Exception ex)
{
ediLogger.LogException(exception: ex);
Contract matchingProcessFault = new Contract();
matchingProcessFault.ErrorSource = "Error in EDI210MatchingService ";
matchingProcessFault.ErrorDetail = ex.ToString();
}
ediLogger.LogMessage(message: "Method Exit", logType: Logger.Logger.LogType.Information, logDate: true, logTraceDetails: true);
}
/// <summary>
/// This function used to retrieve the basic carrier settings
/// </summary>
/// <returns></returns>
/// <createDetail>
/// <id>US4444</id> <by>Manoj Bhuyan</by> <date>20-08-2013</date>
/// </createDetail>
private static EDICarrierSettings RetriveCarrierSetting(int priority, Logger.FileLogger ediLogger)
{
ediLogger.LogMessage(message: "Method Entry", logType: Logger.Logger.LogType.Information, logDate: true, logTraceDetails: true);
EdiAutomationController controller = new EdiAutomationController();
EDICarrierSettings ediCarrierSettings = controller.RetriveCarrierSettings(0, priority, Convert.ToInt32(EDITypes.EDI210));
ediLogger.LogMessage(message: "Method Exit", logType: Logger.Logger.LogType.Information, logDate: true, logTraceDetails: true);
return ediCarrierSettings;
}
#endregion Private Method Implementation
}
}