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 |
//////////// |
//////////// |
105 |
|
|
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 |
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; |
167 |
// validér at headeren er gyldig |
// validér at headeren er gyldig |
168 |
if ( Salt2Helper.validateSalt2Header(salt2String) == false) |
if ( Salt2Helper.validateSalt2Header(salt2String) == 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() + " " + salt2String); |
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 |
|
|
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 |
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) |