24 |
|
|
25 |
public string[] filterTranscations { get; private set; } |
public string[] filterTranscations { get; private set; } |
26 |
|
|
27 |
|
Logfile logFile; |
28 |
|
|
29 |
|
|
30 |
public static readonly string queueNameIndbakke = "DAO.INDBAKKE"; |
public static readonly string queueNameIndbakke = "DAO.INDBAKKE"; |
31 |
public static readonly string queueNameDimaps = "DAO.SAMLET"; |
public static readonly string queueNameDimaps = "DAO.SAMLET"; |
36 |
protected FilterController() |
protected FilterController() |
37 |
{ |
{ |
38 |
initialize(); |
initialize(); |
39 |
|
logFile = new Logfile(LogfileType.LogEvents, "filter", logDirectory); |
40 |
|
logFile.addSingleLogEntry("Starting service"); |
41 |
} |
} |
42 |
|
|
43 |
private void initialize() |
private void initialize() |
49 |
//Læser globale MQ Parametre |
//Læser globale MQ Parametre |
50 |
mqHost = (string)key.GetValue("MQHost"); |
mqHost = (string)key.GetValue("MQHost"); |
51 |
if (mqHost == null || mqHost.Length == 0) |
if (mqHost == null || mqHost.Length == 0) |
52 |
|
{ |
53 |
|
key.SetValue("MQHost", "", RegistryValueKind.String); |
54 |
throw new System.ArgumentException("MQHost cannot be null or empty"); |
throw new System.ArgumentException("MQHost cannot be null or empty"); |
55 |
|
} |
56 |
|
|
57 |
mqChannel = (string)key.GetValue("MQChannel"); |
mqChannel = (string)key.GetValue("MQChannel"); |
58 |
if (mqChannel == null || mqChannel.Length == 0) |
if (mqChannel == null || mqChannel.Length == 0) |
59 |
|
{ |
60 |
|
key.SetValue("MQChannel", "", RegistryValueKind.String); |
61 |
throw new System.ArgumentException("MQChannel cannot be null or empty"); |
throw new System.ArgumentException("MQChannel cannot be null or empty"); |
62 |
|
} |
63 |
|
|
64 |
mqQueueManager = (string)key.GetValue("MQQueueManager"); |
mqQueueManager = (string)key.GetValue("MQQueueManager"); |
65 |
if (mqQueueManager == null || mqQueueManager.Length == 0) |
if (mqQueueManager == null || mqQueueManager.Length == 0) |
66 |
|
{ |
67 |
|
key.SetValue("MQQueueManager", "", RegistryValueKind.String); |
68 |
throw new System.ArgumentException("MQQueueManager cannot be null or empty"); |
throw new System.ArgumentException("MQQueueManager cannot be null or empty"); |
69 |
|
} |
70 |
|
|
71 |
//////////// |
//////////// |
72 |
|
|
73 |
logDirectory = (string)key.GetValue("LogDirectory"); |
logDirectory = (string)key.GetValue("LogDirectory"); |
74 |
if (logDirectory == null || logDirectory.Length == 0) |
if (logDirectory == null || logDirectory.Length == 0) |
75 |
|
{ |
76 |
|
key.SetValue("LogDirectory", "", RegistryValueKind.String); |
77 |
throw new System.ArgumentException("LogDirectory cannot be null or empty"); |
throw new System.ArgumentException("LogDirectory cannot be null or empty"); |
78 |
|
} |
79 |
|
|
80 |
if (Directory.Exists(logDirectory) == false) |
if (Directory.Exists(logDirectory) == false) |
81 |
{ |
{ |
86 |
|
|
87 |
String tmpFilterTransactions = (string)key.GetValue("FilterTransactions"); |
String tmpFilterTransactions = (string)key.GetValue("FilterTransactions"); |
88 |
if (tmpFilterTransactions == null || tmpFilterTransactions.Length == 0) |
if (tmpFilterTransactions == null || tmpFilterTransactions.Length == 0) |
89 |
|
{ |
90 |
|
key.SetValue("FilterTransactions", "", RegistryValueKind.String); |
91 |
throw new System.ArgumentException("FilterTransactions cannot be null or empty"); |
throw new System.ArgumentException("FilterTransactions cannot be null or empty"); |
92 |
|
} |
93 |
|
tmpFilterTransactions = tmpFilterTransactions.Replace(';', ','); |
94 |
filterTranscations = Regex.Split(tmpFilterTransactions, ","); |
filterTranscations = Regex.Split(tmpFilterTransactions, ","); |
95 |
|
|
96 |
for (int i = 0; i < filterTranscations.Length; i++) |
for (int i = 0; i < filterTranscations.Length; i++) |
97 |
{ |
{ |
98 |
filterTranscations[i] = filterTranscations[i].Trim(); |
filterTranscations[i] = filterTranscations[i].Trim().ToUpper(); |
99 |
} |
} |
100 |
|
|
101 |
//////////// |
//////////// |
103 |
} |
} |
104 |
|
|
105 |
|
|
|
private Hashtable getConnectionProperties() |
|
|
{ |
|
|
Hashtable connProperties = new Hashtable(); |
|
|
connProperties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT); |
|
|
connProperties.Add(MQC.HOST_NAME_PROPERTY, mqHost); |
|
|
connProperties.Add(MQC.CHANNEL_PROPERTY, mqChannel); |
|
|
return connProperties; |
|
|
} |
|
106 |
|
|
107 |
|
|
108 |
public void transportAllMessages() |
public void transportAllMessages() |
109 |
{ |
{ |
110 |
|
try |
111 |
|
{ |
112 |
|
transportMessagesWorker(); |
113 |
|
} |
114 |
|
catch (Exception e) |
115 |
|
{ |
116 |
|
logFile.addSingleLogEntry("Error during transportAllMessages: " + e.Message); |
117 |
|
} |
118 |
|
} |
119 |
|
|
120 |
|
private void transportMessagesWorker() |
121 |
|
{ |
122 |
int messageCount = 0; |
int messageCount = 0; |
123 |
|
|
124 |
MQQueueManager mqMgr = null; |
MQQueueManager mqMgr = null; |
126 |
MQQueue queueMysql = null; |
MQQueue queueMysql = null; |
127 |
MQQueue queueDimaps = null; |
MQQueue queueDimaps = null; |
128 |
MQQueue queueStore = null; |
MQQueue queueStore = null; |
129 |
|
|
130 |
|
using (Logfile translog = new Logfile(LogfileType.LogTransactions, "filter", logDirectory)) |
131 |
try |
try |
132 |
{ |
{ |
133 |
//MQ options |
//MQ options |
134 |
Hashtable connProps = getConnectionProperties(); |
Hashtable connProps = MQHelper.getConnectionProperties(mqHost, mqChannel); |
135 |
int openInputOptions = MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING; |
int openInputOptions = MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING; |
136 |
int openOutputOptions = MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING; |
int openOutputOptions = MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING; |
137 |
|
|
139 |
//MQ objects i v6 implementerer ikke IDisposable og kan derfor ikke bruges med "using" statement |
//MQ objects i v6 implementerer ikke IDisposable og kan derfor ikke bruges med "using" statement |
140 |
mqMgr = new MQQueueManager(mqQueueManager, connProps);//stage 1 connect to mq |
mqMgr = new MQQueueManager(mqQueueManager, connProps);//stage 1 connect to mq |
141 |
|
|
|
queueIndbakke = mqMgr.AccessQueue(queueNameIndbakke, openInputOptions); |
|
142 |
|
|
143 |
queueMysql = mqMgr.AccessQueue(queueNameMysql, openOutputOptions); |
queueIndbakke = MQHelper.openQueueHelper(queueNameIndbakke, mqMgr, openInputOptions); |
144 |
queueDimaps = mqMgr.AccessQueue(queueNameDimaps, openOutputOptions); |
|
145 |
queueStore = mqMgr.AccessQueue(queueNameStore, openOutputOptions); |
queueMysql = MQHelper.openQueueHelper(queueNameMysql, mqMgr, openOutputOptions); |
146 |
|
queueDimaps = MQHelper.openQueueHelper(queueNameDimaps, mqMgr, openOutputOptions); |
147 |
|
queueStore = MQHelper.openQueueHelper(queueNameStore, mqMgr, openOutputOptions); |
148 |
|
|
149 |
|
|
150 |
bool isContinue = true; |
bool isContinue = true; |
160 |
queueIndbakke.Get(mqMsg, mqGetMsgOpts); |
queueIndbakke.Get(mqMsg, mqGetMsgOpts); |
161 |
if (mqMsg.Format.CompareTo(MQC.MQFMT_STRING) == 0) |
if (mqMsg.Format.CompareTo(MQC.MQFMT_STRING) == 0) |
162 |
{ |
{ |
163 |
string saltiiString = mqMsg.ReadString(mqMsg.MessageLength); |
string salt2String = mqMsg.ReadString(mqMsg.MessageLength); |
164 |
//System.Console.WriteLine(msgString); |
//System.Console.WriteLine(msgString); |
165 |
|
|
166 |
|
|
167 |
// Hvis transaktionen starter med et ? er det ikke en gyldig transaktion |
// validér at headeren er gyldig |
168 |
// validér ligeledes at headeren er gyldig |
if ( Salt2Helper.validateSalt2Header(salt2String) == false) |
|
if (saltiiString.StartsWith("?") || Salt2Helper.validateSalt2Header(saltiiString) == false) |
|
169 |
{ |
{ |
170 |
string discarded_filename = Logfile.getLogFilename(LogfileType.LogTransactions, logDirectory, "filter"); |
|
171 |
using (StreamWriter discardedlog = new StreamWriter(discarded_filename, true)) |
|
172 |
|
using (Logfile discardedlog = new Logfile(LogfileType.LogDiscarded, "filter", logDirectory)) |
173 |
{ |
{ |
174 |
discardedlog.WriteLine(Logfile.getNowString() + " " + saltiiString); |
discardedlog.writeLogEntry(salt2String); |
175 |
} |
} |
176 |
continue; //gå frem til at tage næste transaktion fra køen |
continue; //gå frem til at tage næste transaktion fra køen |
177 |
} |
} |
178 |
|
|
179 |
|
translog.writeLogEntry(salt2String); |
180 |
|
|
181 |
MQPutMessageOptions pmo = new MQPutMessageOptions(); // accept the defaults, |
MQPutMessageOptions pmo = new MQPutMessageOptions(); // accept the defaults, |
182 |
// same as MQPMO_DEFAULT |
// same as MQPMO_DEFAULT |
183 |
|
|
184 |
MQMessage msg = new MQMessage(); |
MQMessage msg = new MQMessage(); |
185 |
msg.Format = MQC.MQFMT_STRING; |
msg.Format = MQC.MQFMT_STRING; |
186 |
msg.CharacterSet = 1252; |
msg.CharacterSet = 1252; |
187 |
msg.WriteString(saltiiString); |
msg.WriteString(salt2String); |
188 |
|
|
189 |
Salt2Header header = Salt2Helper.parseHeader(saltiiString); |
Salt2Header header = Salt2Helper.parseHeader(salt2String); |
190 |
queueMysql.Put(msg, pmo); |
queueMysql.Put(msg, pmo); |
191 |
if (saveForLater(header)) |
if (saveForLater(header)) |
192 |
{ |
{ |
197 |
queueDimaps.Put(msg, pmo); |
queueDimaps.Put(msg, pmo); |
198 |
} |
} |
199 |
|
|
200 |
|
|
201 |
|
|
202 |
messageCount++;// increment per run message counter |
messageCount++;// increment per run message counter |
203 |
if (messageCount >= 10000) // if we have moved 10000 messages in this run - let it go |
if (messageCount >= 10000) // if we have moved 10000 messages in this run - let it go |
240 |
} |
} |
241 |
finally |
finally |
242 |
{ |
{ |
243 |
closeQueue(queueIndbakke); |
MQHelper.closeQueueSafe(queueIndbakke); |
244 |
closeQueue(queueMysql); |
MQHelper.closeQueueSafe(queueMysql); |
245 |
closeQueue(queueDimaps); |
MQHelper.closeQueueSafe(queueDimaps); |
246 |
closeQueue(queueStore); |
MQHelper.closeQueueSafe(queueStore); |
|
|
|
247 |
|
|
248 |
if (mqMgr != null && mqMgr.IsOpen) |
MQHelper.closeQueueManagerSafe(mqMgr); |
|
{ |
|
|
try |
|
|
{ |
|
|
mqMgr.Close(); |
|
|
} |
|
|
catch (Exception e) |
|
|
{ |
|
|
Console.WriteLine("Error cleaning up qmgr " + e.Message); |
|
|
} |
|
|
} |
|
249 |
} |
} |
250 |
} |
} |
251 |
|
|
252 |
private Boolean saveForLater(Salt2Header header) |
private Boolean saveForLater(Salt2Header header) |
253 |
{ |
{ |
254 |
|
|
255 |
DateTime now = DateTime.Now; |
DateTime now = DateTime.Now; |
256 |
int hour = now.Hour; |
int hour = now.Hour; |
257 |
if (hour >= 14 && hour < 18) |
if (hour >= 14 && hour < 18) |
258 |
{ |
{ |
259 |
|
|
260 |
if (contains(header.transaktionForkortelse, this.filterTranscations) ) //Så længe vi skal være net3.0 kompatible er LINQ problematisk |
if (contains(header.transaktionForkortelse, this.filterTranscations) ) //Så længe vi skal være .net3.0 kompatible er LINQ problematisk (LINQ kræver 3.5) |
261 |
{ |
{ |
262 |
return true; |
return true; |
263 |
} |
} |
286 |
return false; |
return false; |
287 |
} |
} |
288 |
|
|
|
private void closeQueue(MQQueue queue) |
|
|
{ |
|
|
if (queue != null && queue.IsOpen) |
|
|
{ |
|
|
try |
|
|
{ |
|
|
queue.Close(); |
|
|
} |
|
|
catch (Exception e) |
|
|
{ |
|
|
Console.WriteLine("Error cleaning up queue " + e.Message); |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
289 |
|
|
290 |
|
|
291 |
|
|