/[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 2167 by torben, Fri May 16 19:03:46 2014 UTC revision 2168 by torben, Fri May 16 20:56:22 2014 UTC
# Line 1  Line 1 
1  using System;  using System;
2    using System.Collections;
3  using System.Collections.Generic;  using System.Collections.Generic;
4  using System.IO;  using System.IO;
5  using System.Text.RegularExpressions;  using System.Text.RegularExpressions;
6    
7    using IBM.WMQ;
8    
9  using Microsoft.Win32;  using Microsoft.Win32;
10    
11    using DaoCommon;
12    
13    
14  namespace MQFilter  namespace MQFilter
15  {  {
16      class FilterController      class FilterController
# Line 19  namespace MQFilter Line 25  namespace MQFilter
25          public string[] filterTranscations { get; private set; }          public string[] filterTranscations { get; private set; }
26    
27    
28            public static readonly string queueNameIndbakke = "DAO.INDBAKKE";
29            public static readonly string queueNameDimaps = "DAO.SAMLET";
30            public static readonly string queueNameMysql = "DAO.ALL";
31            public static readonly string queueNameStore = "DAO.STORE";
32    
33    
34          protected FilterController()          protected FilterController()
35          {          {
36              initialize();              initialize();
# Line 43  namespace MQFilter Line 55  namespace MQFilter
55              if (mqQueueManager == null || mqQueueManager.Length == 0)              if (mqQueueManager == null || mqQueueManager.Length == 0)
56                  throw new System.ArgumentException("MQQueueManager cannot be null or empty");                  throw new System.ArgumentException("MQQueueManager cannot be null or empty");
57    
58              //Læser øvrige parametre              ////////////
59    
60              logDirectory = (string)key.GetValue("LogDirectory");              logDirectory = (string)key.GetValue("LogDirectory");
61              if (logDirectory == null || logDirectory.Length == 0)              if (logDirectory == null || logDirectory.Length == 0)
62                  throw new System.ArgumentException("LogDirectory cannot be null or empty");                  throw new System.ArgumentException("LogDirectory cannot be null or empty");
63    
64                if (Directory.Exists(logDirectory) == false)
65                {
66                    Directory.CreateDirectory(logDirectory);
67                }
68    
69                ////////////
70    
71              String tmpFilterTransactions = (string)key.GetValue("FilterTransactions");              String tmpFilterTransactions = (string)key.GetValue("FilterTransactions");
72              if (tmpFilterTransactions == null || tmpFilterTransactions.Length == 0)              if (tmpFilterTransactions == null || tmpFilterTransactions.Length == 0)
73                  throw new System.ArgumentException("LogDirectory cannot be null or empty");                  throw new System.ArgumentException("FilterTransactions cannot be null or empty");
74              filterTranscations = Regex.Split( tmpFilterTransactions, "," );              filterTranscations = Regex.Split(tmpFilterTransactions, ",");
75    
76              for (int i = 0; i < filterTranscations.Length; i++)              for (int i = 0; i < filterTranscations.Length; i++)
77              {              {
78                  filterTranscations[i] = filterTranscations[i].Trim();                  filterTranscations[i] = filterTranscations[i].Trim();
79              }              }
80    
81                ////////////
             if (Directory.Exists(logDirectory) == false)  
             {  
                 Directory.CreateDirectory(logDirectory);  
             }  
82    
83          }          }
84    
85    
86            private Hashtable getConnectionProperties()
87            {
88                Hashtable connProperties = new Hashtable();
89                connProperties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT);
90                connProperties.Add(MQC.HOST_NAME_PROPERTY, mqHost);
91                connProperties.Add(MQC.CHANNEL_PROPERTY, mqChannel);
92                return connProperties;
93            }
94    
95    
96          public void transportAllMessages()          public void transportAllMessages()
97          {          {
98                int messageCount = 0;
99    
100                MQQueueManager mqMgr = null;
101                MQQueue queueIndbakke = null;
102                MQQueue queueMysql = null;
103                MQQueue queueDimaps = null;
104                MQQueue queueStore = null;
105                try
106                {
107                    //MQ options
108                    Hashtable connProps = getConnectionProperties();
109                    int openInputOptions = MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING;
110                    int openOutputOptions = MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING;
111    
112    
113                    //MQ objects i v6 implementerer ikke IDisposable og kan derfor ikke bruges med "using" statement
114                    mqMgr = new MQQueueManager(mqQueueManager, connProps);//stage 1 connect to mq
115    
116                    queueIndbakke = mqMgr.AccessQueue(queueNameIndbakke, openInputOptions);
117    
118                    queueMysql = mqMgr.AccessQueue(queueNameMysql, openOutputOptions);
119                    queueDimaps = mqMgr.AccessQueue(queueNameDimaps, openOutputOptions);
120                    queueStore = mqMgr.AccessQueue(queueNameStore, openOutputOptions);
121    
122    
123                    bool isContinue = true;
124                    while (isContinue)
125                    {
126    
127                        MQMessage mqMsg = new MQMessage();
128                        MQGetMessageOptions mqGetMsgOpts = new MQGetMessageOptions();
129    
130    
131                        try
132                        {
133                            queueIndbakke.Get(mqMsg, mqGetMsgOpts);
134                            if (mqMsg.Format.CompareTo(MQC.MQFMT_STRING) == 0)
135                            {
136                                string msgString = mqMsg.ReadString(mqMsg.MessageLength);
137                                //System.Console.WriteLine(msgString);
138    
139    
140                                // Hvis transaktionen starter med et ? er det ikke en gyldig transaktion
141                                // validér ligeledes at headeren er gyldig
142                                if (msgString.StartsWith("?") || DaoUtil.validateSalt2Header(msgString) == false)
143                                {
144                                    string discarded_filename = Logfile.getLogFilename(LogfileType.LogTransactions, logDirectory, "filter");
145                                    using (StreamWriter discardedlog = new StreamWriter(discarded_filename, true))
146                                    {
147                                        discardedlog.WriteLine(Logfile.getNowString() + " " + msgString);
148                                    }
149                                    continue; //gå frem til at tage næste transaktion fra køen
150                                }
151    
152    
153    
154    
155    
156    
157    
158    
159                                messageCount++;// increment per run message counter
160                                if (messageCount >= 10000) // if we have moved  10000 messages in this run - let it go
161                                {
162                                    isContinue = false;
163                                }
164    
165    
166    
167    
168                            }
169                            else
170                            {
171                                System.Console.WriteLine("Non-text message");
172                            }
173                        }
174                        catch (MQException mqe)
175                        {
176                            isContinue = false;
177    
178                            // report reason, if any
179                            if (mqe.Reason == MQC.MQRC_NO_MSG_AVAILABLE)
180                            {
181                                // special report for normal end
182                                System.Console.WriteLine("no more messages");
183                            }
184                            else
185                            {
186                                // general report for other reasons
187                                System.Console.WriteLine("MQQueue::Get ended with " + mqe.Message); ;
188    
189                            }
190    
191                        }
192    
193                    }
194    
195    
196    
197                }
198                finally
199                {
200                    closeQueue(queueIndbakke);
201                    closeQueue(queueMysql);
202                    closeQueue(queueDimaps);
203                    closeQueue(queueStore);
204    
205    
206                    if (mqMgr != null && mqMgr.IsOpen)
207                    {
208                        try
209                        {
210                            mqMgr.Close();
211                        }
212                        catch (Exception e)
213                        {
214                            Console.WriteLine("Error cleaning up qmgr " + e.Message);
215                        }
216                    }
217                }
218            }
219    
220            private void closeQueue(MQQueue queue)
221            {
222                if (queue != null && queue.IsOpen)
223                {
224                    try
225                    {
226                        queue.Close();
227                    }
228                    catch (Exception e)
229                    {
230                        Console.WriteLine("Error cleaning up queue " + e.Message);
231                    }
232                }
233    
234          }          }
235    
236    

Legend:
Removed from v.2167  
changed lines
  Added in v.2168

  ViewVC Help
Powered by ViewVC 1.1.20