--- dao/DaoMqPump2/MQFilter/FilterController.cs 2014/05/17 10:53:58 2172 +++ dao/DaoMqPump2/MQFilter/FilterController.cs 2014/05/19 19:51:47 2177 @@ -24,6 +24,8 @@ public string[] filterTranscations { get; private set; } + Logfile logFile; + public static readonly string queueNameIndbakke = "DAO.INDBAKKE"; public static readonly string queueNameDimaps = "DAO.SAMLET"; @@ -34,6 +36,8 @@ protected FilterController() { initialize(); + logFile = new Logfile(LogfileType.LogEvents, "filter", logDirectory); + logFile.addSingleLogEntry("Starting service"); } private void initialize() @@ -45,21 +49,33 @@ //Læser globale MQ Parametre mqHost = (string)key.GetValue("MQHost"); if (mqHost == null || mqHost.Length == 0) + { + key.SetValue("MQHost", "", RegistryValueKind.String); throw new System.ArgumentException("MQHost cannot be null or empty"); + } mqChannel = (string)key.GetValue("MQChannel"); if (mqChannel == null || mqChannel.Length == 0) + { + key.SetValue("MQChannel", "", RegistryValueKind.String); throw new System.ArgumentException("MQChannel cannot be null or empty"); + } mqQueueManager = (string)key.GetValue("MQQueueManager"); if (mqQueueManager == null || mqQueueManager.Length == 0) + { + key.SetValue("MQQueueManager", "", RegistryValueKind.String); throw new System.ArgumentException("MQQueueManager cannot be null or empty"); + } //////////// logDirectory = (string)key.GetValue("LogDirectory"); if (logDirectory == null || logDirectory.Length == 0) + { + key.SetValue("LogDirectory", "", RegistryValueKind.String); throw new System.ArgumentException("LogDirectory cannot be null or empty"); + } if (Directory.Exists(logDirectory) == false) { @@ -70,12 +86,16 @@ String tmpFilterTransactions = (string)key.GetValue("FilterTransactions"); if (tmpFilterTransactions == null || tmpFilterTransactions.Length == 0) + { + key.SetValue("FilterTransactions", "", RegistryValueKind.String); throw new System.ArgumentException("FilterTransactions cannot be null or empty"); + } + tmpFilterTransactions = tmpFilterTransactions.Replace(';', ','); filterTranscations = Regex.Split(tmpFilterTransactions, ","); for (int i = 0; i < filterTranscations.Length; i++) { - filterTranscations[i] = filterTranscations[i].Trim(); + filterTranscations[i] = filterTranscations[i].Trim().ToUpper(); } //////////// @@ -85,9 +105,20 @@ - public void transportAllMessages() { + try + { + transportMessagesWorker(); + } + catch (Exception e) + { + logFile.addSingleLogEntry("Error during transportAllMessages: " + e.Message); + } + } + + private void transportMessagesWorker() + { int messageCount = 0; MQQueueManager mqMgr = null; @@ -95,6 +126,8 @@ MQQueue queueMysql = null; MQQueue queueDimaps = null; MQQueue queueStore = null; + + using (Logfile translog = new Logfile(LogfileType.LogTransactions, "filter", logDirectory)) try { //MQ options @@ -106,11 +139,12 @@ //MQ objects i v6 implementerer ikke IDisposable og kan derfor ikke bruges med "using" statement mqMgr = new MQQueueManager(mqQueueManager, connProps);//stage 1 connect to mq - queueIndbakke = mqMgr.AccessQueue(queueNameIndbakke, openInputOptions); - queueMysql = mqMgr.AccessQueue(queueNameMysql, openOutputOptions); - queueDimaps = mqMgr.AccessQueue(queueNameDimaps, openOutputOptions); - queueStore = mqMgr.AccessQueue(queueNameStore, openOutputOptions); + queueIndbakke = MQHelper.openQueueHelper(queueNameIndbakke, mqMgr, openInputOptions); + + queueMysql = MQHelper.openQueueHelper(queueNameMysql, mqMgr, openOutputOptions); + queueDimaps = MQHelper.openQueueHelper(queueNameDimaps, mqMgr, openOutputOptions); + queueStore = MQHelper.openQueueHelper(queueNameStore, mqMgr, openOutputOptions); bool isContinue = true; @@ -133,14 +167,17 @@ // validér at headeren er gyldig if ( Salt2Helper.validateSalt2Header(salt2String) == false) { - string discarded_filename = Logfile.getLogFilename(LogfileType.LogTransactions, logDirectory, "filter"); - using (StreamWriter discardedlog = new StreamWriter(discarded_filename, true)) + + + using (Logfile discardedlog = new Logfile(LogfileType.LogDiscarded, "filter", logDirectory)) { - discardedlog.WriteLine(Logfile.getNowString() + " " + salt2String); + discardedlog.writeLogEntry(salt2String); } continue; //gå frem til at tage næste transaktion fra køen } + translog.writeLogEntry(salt2String); + MQPutMessageOptions pmo = new MQPutMessageOptions(); // accept the defaults, // same as MQPMO_DEFAULT @@ -160,7 +197,7 @@ queueDimaps.Put(msg, pmo); } - + messageCount++;// increment per run message counter if (messageCount >= 10000) // if we have moved 10000 messages in this run - let it go @@ -214,12 +251,13 @@ private Boolean saveForLater(Salt2Header header) { + DateTime now = DateTime.Now; int hour = now.Hour; if (hour >= 14 && hour < 18) { - 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) { return true; }