/[projects]/dao/DaoMqPump2/DaoMqPump2/Transport.cs
ViewVC logotype

Diff of /dao/DaoMqPump2/DaoMqPump2/Transport.cs

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

revision 1986 by torben, Wed Jul 3 07:56:52 2013 UTC revision 1999 by torben, Mon Jul 8 14:22:33 2013 UTC
# Line 12  namespace DaoMqPump2 Line 12  namespace DaoMqPump2
12  {  {
13      public class Transport      public class Transport
14      {      {
15    
16            enum LogfileType {
17                LogTransactions,
18                LogEvents
19            }
20    
21          public static string SQL2MQ = "sql2mq";          public static string SQL2MQ = "sql2mq";
22          public static string MQ2SQL = "mq2sql";          public static string MQ2SQL = "mq2sql";
23    
24            private bool enabled;        
         public bool enabled { get; set; }  
25    
26          TransportController controller;          TransportController controller;
27    
28            StatusData statusData = new StatusData();
29    
30          public string name { get; private set; }          public string name { get; private set; }
31          public string direction { get; private set; }          public string direction { get; private set; }
32          public string queueName { get; private set; }          public string queueName { get; private set; }
# Line 27  namespace DaoMqPump2 Line 34  namespace DaoMqPump2
34          public string sql2mqReadQuery { get; private set; }          public string sql2mqReadQuery { get; private set; }
35          public string sql2mqUpdateQuery { get; private set; }          public string sql2mqUpdateQuery { get; private set; }
36    
37          public bool lastrunOk { get; private set; }          //public bool lastrunOk { get; private set; }
38          public string lastErrorMessage { get; private set; }          //public string lastErrorMessage { get; private set; }
39    
40            //public string lastOkTime { get; private set; }
41            //public string lastErrorTime { get; private set; }
42            //public string lastTransferTime { get; private set; }
43    
44            //public int counter { get; private set; }
45    
46            public StatusData TransportStatusData
47            {
48                get
49                {
50                    return this.statusData;
51                }
52            }
53    
54    
55          public string lastOkTime { get; private set; }          public bool Enabled
56          public string lastErrorTime { get; private set; }          {
57                get {
58                    return this.enabled;
59                }
60                set
61                {
62                    this.enabled = value;
63                    if (value == true)
64                    {
65                        this.addLogEntry("Transport enabled");
66                    }
67                    else
68                    {
69                        this.addLogEntry("Transport disabled");
70                    }
71                }
72            }
73    
         public int counter { get; private set; }  
74    
75          private LinkedList<string> logEntries = new LinkedList<string>();          private LinkedList<string> logEntries = new LinkedList<string>();
76    
# Line 49  namespace DaoMqPump2 Line 86  namespace DaoMqPump2
86              this.sql2mqUpdateQuery = sql2mqUpdateQuery;              this.sql2mqUpdateQuery = sql2mqUpdateQuery;
87    
88              this.enabled = enabled;              this.enabled = enabled;
89                
90                
91              lastrunOk = true;              statusData.lastrunOk = true;
92              counter = 0;              statusData.counter = 0;
93              lastErrorMessage = lastOkTime = lastErrorTime = "";              statusData.lastErrorMessage = statusData.lastOkTime = statusData.lastErrorTime = "";
94    
95              addLogEntry( "Starting ... " );              addLogEntry( "Starting ... " );
96          }          }
97    
98            ~Transport()
99            {
100                addLogEntry("Stopping ... ");
101            }
102    
103    
104          public void transportMessages()          public void transportMessages()
105          {          {
106              if (enabled == false)              if (enabled == false)
107                  return;                  return;
108    
109              Console.WriteLine(name + " -> transportMessages() ");              Console.WriteLine(name + " -> transportMessages() ");
110              lastrunOk = true;              statusData.lastrunOk = true;
111    
112                int startCounter = statusData.counter;
113    
114              if (direction == SQL2MQ)              if (direction == SQL2MQ)
115              {              {
# Line 75  namespace DaoMqPump2 Line 120  namespace DaoMqPump2
120                  transportMq2Sql();                  transportMq2Sql();
121              }              }
122    
123              if (lastrunOk == true)              if (statusData.lastrunOk == true)
124              {              {
125                  lastOkTime = getNowString();                  statusData.lastOkTime = getNowString();
126    
127                    if (statusData.counter != startCounter)
128                    {
129                        //Vi har transporteret beskeder - så gemmer vi lige transfer tidspunktet
130                        statusData.lastTransferTime = getNowString();
131                    }
132              }              }
133              else              else
134              {              {
135                  addLogEntry(lastErrorMessage);                  addLogEntry(statusData.lastErrorMessage);
136                  lastErrorTime = getNowString();                  statusData.lastErrorTime = getNowString();
137              }              }
138          }          }
139    
140          private void transportSql2Mq()          private void transportSql2Mq()
141          {          {
142              string filename = getTransactionlogFilename();              string filename = getLogFilename(LogfileType.LogTransactions);
143              using (StreamWriter translog = new StreamWriter(filename, true) )              using (StreamWriter translog = new StreamWriter(filename, true) )
144              try              try
145              {              {
# Line 137  namespace DaoMqPump2 Line 188  namespace DaoMqPump2
188                      {                      {
189                          break;                          break;
190                      }                      }
191                      counter++;                      statusData.counter++;
192                  }                  }
193                                    
194    
# Line 149  namespace DaoMqPump2 Line 200  namespace DaoMqPump2
200              }              }
201              catch (Exception e)              catch (Exception e)
202              {              {
203                  lastrunOk = false;                  statusData.lastrunOk = false;
204                  lastErrorMessage = name + ".transportSql2Mq error: " + e.Message;                  statusData.lastErrorMessage = name + ".transportSql2Mq error: " + e.Message;
205                  Console.WriteLine(lastErrorMessage);                  Console.WriteLine(statusData.lastErrorMessage);
206                  EventLog.WriteEntry("DaoMqPump2", lastErrorMessage, EventLogEntryType.Warning);                  EventLog.WriteEntry("DaoMqPump2", statusData.lastErrorMessage, EventLogEntryType.Warning);
207              }              }
208          }          }
209    
210          private void transportMq2Sql()          private void transportMq2Sql()
211          {          {
212              string filename = getTransactionlogFilename();              string filename = getLogFilename(LogfileType.LogTransactions);
213              using (StreamWriter translog = new StreamWriter(filename, true))              using (StreamWriter translog = new StreamWriter(filename, true))
214              try              try
215              {              {
# Line 203  namespace DaoMqPump2 Line 254  namespace DaoMqPump2
254                              {                              {
255                                  translog.WriteLine(getNowString() + " " + msgString + "\n");                                  translog.WriteLine(getNowString() + " " + msgString + "\n");
256                                  mqMgr.Commit();                                  mqMgr.Commit();
257                                  counter++;                                  statusData.counter++;
258                              }                              }
259                              else                              else
260                              {                              {
# Line 231  namespace DaoMqPump2 Line 282  namespace DaoMqPump2
282                          {                          {
283                              // general report for other reasons                              // general report for other reasons
284                              System.Console.WriteLine("MQQueue::Get ended with " + mqe.Message);;                              System.Console.WriteLine("MQQueue::Get ended with " + mqe.Message);;
285                              lastrunOk = false;                              statusData.lastrunOk = false;
286                          }                          }
287    
288                      }                      }
# Line 248  namespace DaoMqPump2 Line 299  namespace DaoMqPump2
299              }              }
300              catch (Exception e)              catch (Exception e)
301              {              {
302                  lastrunOk = false;                  statusData.lastrunOk = false;
303    
304                  lastErrorMessage = name + ".transportMq2Sql error: " + e.Message;                  statusData.lastErrorMessage = name + ".transportMq2Sql error: " + e.Message;
305                  Console.WriteLine(lastErrorMessage);                  Console.WriteLine(statusData.lastErrorMessage);
306                  EventLog.WriteEntry("DaoMqPump2", lastErrorMessage, EventLogEntryType.Warning);                  EventLog.WriteEntry("DaoMqPump2", statusData.lastErrorMessage, EventLogEntryType.Warning);
307              }              }
308          }          }
309    
# Line 277  namespace DaoMqPump2 Line 328  namespace DaoMqPump2
328              return connProperties;              return connProperties;
329          }          }
330    
331          private string getTransactionlogFilename()  
332    
333            private string getLogFilename(LogfileType type)
334          {          {
335    
336              DateTime now = DateTime.Now;              DateTime now = DateTime.Now;
337              string filename = controller.logDirectory + "\\";              string filename = controller.logDirectory + "\\";
338    
339                switch (type)
340                {
341                    case LogfileType.LogEvents:
342                        filename += "eventlog_";
343                        break;
344    
345                    case LogfileType.LogTransactions:
346                        filename += "transactionlog_";
347                        break;
348                }
349    
350    
351              filename += "transactionlog_" + name + "_" + now.Year.ToString("D4") + now.Month.ToString("D2") + ".log";              filename += "transactionlog_" + name + "_" + now.Year.ToString("D4") + now.Month.ToString("D2") + ".log";
352    
353              return filename;              return filename;
# Line 304  namespace DaoMqPump2 Line 370  namespace DaoMqPump2
370                  if (logEntries.Count > 20)                  if (logEntries.Count > 20)
371                  {                  {
372                      logEntries.RemoveLast();                      logEntries.RemoveLast();
373                  }                  }                
374                                }
375    
376                string filename = getLogFilename(LogfileType.LogEvents);
377                using (StreamWriter eventlog = new StreamWriter(filename, true))
378                {
379                    eventlog.WriteLine(msg);
380              }              }
381          }          }
382    

Legend:
Removed from v.1986  
changed lines
  Added in v.1999

  ViewVC Help
Powered by ViewVC 1.1.20