/[projects]/dao/DaoMqPump2/MQFilter/FilterController.cs
ViewVC logotype

Diff of /dao/DaoMqPump2/MQFilter/FilterController.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2175 by torben, Mon May 19 11:59:45 2014 UTC revision 2183 by torben, Wed May 21 09:56:21 2014 UTC
# Line 16  namespace MQFilter Line 16  namespace MQFilter
16      class FilterController      class FilterController
17      {      {
18    
19            public const int TRANSACTIONS_PER_RUN = 2000;
20    
21          public string mqHost { get; private set; }          public string mqHost { get; private set; }
22          public string mqChannel { get; private set; }          public string mqChannel { get; private set; }
23          public string mqQueueManager { get; private set; }          public string mqQueueManager { get; private set; }
# Line 24  namespace MQFilter Line 26  namespace MQFilter
26    
27          public string[] filterTranscations { get; private set; }          public string[] filterTranscations { get; private set; }
28    
29            Logfile logFile;
30    
31    
32          public static readonly string queueNameIndbakke = "DAO.INDBAKKE";          public static readonly string queueNameIndbakke = "DAO.INDBAKKE";
33          public static readonly string queueNameDimaps = "DAO.SAMLET";          public static readonly string queueNameDimaps = "DAO.SAMLET";
34          public static readonly string queueNameMysql = "DAO.ALL";          public static readonly string queueNameMysql = "DAO.ALL";
35          public static readonly string queueNameStore = "DAO.STORE";          public static readonly string queueNameStore = "DAO.STORE";
36    
37            TimeSpan silentPeriodBegin;
38            TimeSpan silentPeriodEnd;
39    
40          protected FilterController()          protected FilterController()
41          {          {
42              initialize();              initialize();
43                logFile = new Logfile(LogfileType.LogEvents, "filter", logDirectory);
44                logFile.addSingleLogEntry("Starting service");
45          }          }
46    
47          private void initialize()          private void initialize()
# Line 80  namespace MQFilter Line 88  namespace MQFilter
88    
89              ////////////              ////////////
90    
91                string silentBeginStr = (string)key.GetValue("SilentPeriodBegin");
92                if (silentBeginStr == null || silentBeginStr.Length == 0)
93                {
94                    key.SetValue("SilentPeriodBegin", "", RegistryValueKind.String);
95                    throw new System.ArgumentException("SilentPeriodBegin cannot be null or empty");
96                }
97                silentPeriodBegin = TimeSpan.Parse(silentBeginStr);
98    
99                string silentEndStr = (string)key.GetValue("SilentPeriodEnd");
100                if (silentEndStr == null || silentEndStr.Length == 0)
101                {
102                    key.SetValue("SilentPeriodEnd", "", RegistryValueKind.String);
103                    throw new System.ArgumentException("SilentPeriodEnd cannot be null or empty");
104                }
105                silentPeriodEnd = TimeSpan.Parse(silentEndStr);
106    
107                ////////////
108    
109              String tmpFilterTransactions = (string)key.GetValue("FilterTransactions");              String tmpFilterTransactions = (string)key.GetValue("FilterTransactions");
110              if (tmpFilterTransactions == null || tmpFilterTransactions.Length == 0)              if (tmpFilterTransactions == null || tmpFilterTransactions.Length == 0)
111              {              {
# Line 101  namespace MQFilter Line 127  namespace MQFilter
127    
128    
129    
   
130          public void transportAllMessages()          public void transportAllMessages()
131          {          {
132                try
133                {
134                    transportMessagesWorker();
135                }
136                catch (Exception e)
137                {
138                    logFile.addSingleLogEntry("Error during transportAllMessages: " + e.Message);
139                    Console.WriteLine(e.StackTrace);
140                }
141            }
142    
143            private void transportMessagesWorker()
144            {
145              int messageCount = 0;              int messageCount = 0;
146    
147              MQQueueManager mqMgr = null;              MQQueueManager mqMgr = null;
# Line 111  namespace MQFilter Line 149  namespace MQFilter
149              MQQueue queueMysql = null;              MQQueue queueMysql = null;
150              MQQueue queueDimaps = null;              MQQueue queueDimaps = null;
151              MQQueue queueStore = null;              MQQueue queueStore = null;
152    
153                using (Logfile translog = new Logfile(LogfileType.LogTransactions, "filter", logDirectory))
154              try              try
155              {              {
156                  //MQ options                  //MQ options
# Line 143  namespace MQFilter Line 183  namespace MQFilter
183                          queueIndbakke.Get(mqMsg, mqGetMsgOpts);                          queueIndbakke.Get(mqMsg, mqGetMsgOpts);
184                          if (mqMsg.Format.CompareTo(MQC.MQFMT_STRING) == 0)                          if (mqMsg.Format.CompareTo(MQC.MQFMT_STRING) == 0)
185                          {                          {
186                                if (mqMsg.MessageLength == 0) //Skip empty transactions (so far only seen on my test server)
187                                    continue;
188    
189                                //System.Console.WriteLine("LEN>" + mqMsg.MessageLength);
190                              string salt2String = mqMsg.ReadString(mqMsg.MessageLength);                              string salt2String = mqMsg.ReadString(mqMsg.MessageLength);
191                              //System.Console.WriteLine(msgString);                              
192    
193    
194                              // validér at headeren er gyldig                              // validér at headeren er gyldig
195                              if ( Salt2Helper.validateSalt2Header(salt2String) == false)                              if ( Salt2Helper.validateSalt2Header(salt2String) == false)
196                              {                              {
197                                  string discarded_filename = Logfile.getLogFilename(LogfileType.LogTransactions, logDirectory, "filter");  
198                                  using (StreamWriter discardedlog = new StreamWriter(discarded_filename, true))  
199                                    using (Logfile discardedlog = new Logfile(LogfileType.LogDiscarded, "filter", logDirectory))
200                                  {                                  {
201                                      discardedlog.WriteLine(Logfile.getNowString() + " " + salt2String);                                      discardedlog.writeLogEntry(salt2String);
202                                  }                                  }
203                                  continue; //gå frem til at tage næste transaktion fra køen                                  continue; //gå frem til at tage næste transaktion fra køen
204                              }                              }
205    
206                                translog.writeLogEntry(salt2String);
207    
208                              MQPutMessageOptions pmo = new MQPutMessageOptions(); // accept the defaults,                              MQPutMessageOptions pmo = new MQPutMessageOptions(); // accept the defaults,
209                              // same as MQPMO_DEFAULT                              // same as MQPMO_DEFAULT
210    
# Line 177  namespace MQFilter Line 224  namespace MQFilter
224                                  queueDimaps.Put(msg, pmo);                                  queueDimaps.Put(msg, pmo);
225                              }                              }
226    
227                                
228    
229                              messageCount++;// increment per run message counter                              messageCount++;// increment per run message counter
230                              if (messageCount >= 10000) // if we have moved  10000 messages in this run - let it go                              if (messageCount >= TRANSACTIONS_PER_RUN) // if we have moved  TRANSACTIONS_PER_RUN messages in this run - let it go
231                              {                              {
232                                  isContinue = false;                                  isContinue = false;
233                              }                              }
# Line 232  namespace MQFilter Line 279  namespace MQFilter
279          private Boolean saveForLater(Salt2Header header)          private Boolean saveForLater(Salt2Header header)
280          {          {
281    
282              DateTime now = DateTime.Now;              TimeSpan now = DateTime.Now.TimeOfDay;
283              int hour = now.Hour;              
284              if (hour >= 14 && hour < 18)              if (now >= silentPeriodBegin && now < silentPeriodEnd)
285              {              {
286    
287                    if (header.afsender == "DAO") //DAO transaktioner må altid komme igennem
288                        return false;
289                                    
290                  if (contains(header.transaktionForkortelse, this.filterTranscations) ) //Så længe vi skal være .net3.0 kompatible er LINQ problematisk (LINQ kræver 3.5)                  if (contains(header.transaktionForkortelse, this.filterTranscations) ) //Så længe vi skal være .net3.0 kompatible er LINQ problematisk (LINQ kræver 3.5)
291                  {                  {

Legend:
Removed from v.2175  
changed lines
  Added in v.2183

  ViewVC Help
Powered by ViewVC 1.1.20