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

Contents of /dao/DaoMqPump2/DaoMqPump2/TransportController.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1986 - (show annotations) (download)
Wed Jul 3 07:56:52 2013 UTC (10 years, 10 months ago) by torben
File size: 6921 byte(s)
Add files
1 using System;
2 using System.Collections.Generic;
3 using System.IO;
4
5 using Microsoft.Win32;
6
7 namespace DaoMqPump2
8 {
9 public class TransportController
10 {
11 List<Transport> transports = new List<Transport>();
12
13 public string mysqlHost { get; private set; }
14 public string mysqlPort { get; private set; }
15 public string mysqlUser { get; private set; }
16 public string mysqlPassword { get; private set; }
17
18 public string mqHost { get; private set; }
19 public string mqChannel { get; private set; }
20 public string mqQueueManager { get; private set; }
21
22 public string logDirectory { get; private set; }
23
24
25
26 protected TransportController()
27 {
28 initialize();
29 }
30
31 private void initialize()
32 {
33 Console.WriteLine("TransportController: Loading config");
34 RegistryKey key = Registry.LocalMachine.CreateSubKey("Software\\DAO\\DaoMqPump2");
35
36 //Læser globale MySQL Parametre
37 mysqlHost = (string) key.GetValue("MysqlHost");
38 if (mysqlHost == null || mysqlHost.Length == 0)
39 throw new System.ArgumentException("MysqlHost cannot be null or empty");
40
41 mysqlPort = (string) key.GetValue("MysqlPort");
42 if (mysqlPort == null || mysqlPort.Length == 0)
43 throw new System.ArgumentException("MysqlPort cannot be null or empty");
44
45 mysqlUser = (string) key.GetValue("MysqlUser");
46 if (mysqlUser == null || mysqlUser.Length == 0)
47 throw new System.ArgumentException("MysqlUser cannot be null or empty");
48
49 mysqlPassword = (string) key.GetValue("MysqlPassword");
50 if (mysqlPassword == null ||mysqlPassword.Length == 0)
51 throw new System.ArgumentException("MysqlPassword cannot be null or empty");
52
53
54 //Læser globale MQ Parametre
55 mqHost = (string)key.GetValue("MQHost");
56 if (mqHost == null || mqHost.Length == 0)
57 throw new System.ArgumentException("MQHost cannot be null or empty");
58
59 mqChannel = (string)key.GetValue("MQChannel");
60 if (mqChannel == null || mqChannel.Length == 0)
61 throw new System.ArgumentException("MQChannel cannot be null or empty");
62
63 mqQueueManager = (string)key.GetValue("MQQueueManager");
64 if (mqQueueManager == null || mqQueueManager.Length == 0)
65 throw new System.ArgumentException("MQQueueManager cannot be null or empty");
66
67 //Læser øvrige parametre
68
69 logDirectory = (string)key.GetValue("LogDirectory");
70 if (logDirectory == null || logDirectory.Length == 0)
71 throw new System.ArgumentException("LogDirectory cannot be null or empty");
72
73 if (Directory.Exists(logDirectory) == false)
74 {
75 Directory.CreateDirectory(logDirectory);
76 }
77
78 //Læs alle transport indstillingerne
79 string[] transportNames = key.GetSubKeyNames();
80 foreach (string name in transportNames)
81 {
82 Console.WriteLine("Reading Transport: " + name);
83 RegistryKey subKey = key.OpenSubKey(name);
84
85 string direction = (string)subKey.GetValue("Direction");
86 if (direction == null || direction.Length == 0)
87 throw new System.ArgumentException(name + ".direction cannot be null or empty");
88 direction = direction.ToLower();
89
90 if (direction.Equals(Transport.MQ2SQL) == false && direction.Equals(Transport.SQL2MQ) == false)
91 throw new System.ArgumentException(name + ".direction invalid value (sql2mq OR mq2sql) : " + direction);
92
93
94 string queueName = (string)subKey.GetValue("MQQueueName");
95 if (queueName == null || queueName.Length == 0)
96 throw new System.ArgumentException(name + ".MQQueueName cannot be null or empty");
97
98 Object tmpEnabled = subKey.GetValue("Enabled");
99 if (tmpEnabled == null)
100 throw new System.ArgumentException(name + ".Enabled cannot be null or empty");
101 bool enabled = ((int)tmpEnabled > 0);
102
103
104 string mq2sqlInsertQuery = "";
105 string sql2mqReadQuery = "";
106 string sql2mqUpdateQuery = "";
107
108
109 if (direction == "mq2sql")
110 {
111 mq2sqlInsertQuery = (string)subKey.GetValue("Mq2sqlInsertQuery");
112 if (mq2sqlInsertQuery == null || mq2sqlInsertQuery.Length == 0)
113 throw new System.ArgumentException(name + ".Mq2sqlInsertQuery cannot be null or empty");
114 }
115 else // sql2mq
116 {
117 sql2mqReadQuery = (string)subKey.GetValue("Sql2mqReadQuery");
118 if (sql2mqReadQuery == null || sql2mqReadQuery.Length == 0)
119 throw new System.ArgumentException(name + ".Sql2mqReadQuery cannot be null or empty");
120
121 sql2mqUpdateQuery = (string)subKey.GetValue("Sql2mqUpdateQuery");
122 if (sql2mqUpdateQuery == null || sql2mqUpdateQuery.Length == 0)
123 throw new System.ArgumentException(name + ".Sql2mqUpdateQuery cannot be null or empty");
124 }
125
126 Transport trans = new Transport(this, name, direction, queueName, mq2sqlInsertQuery, sql2mqReadQuery, sql2mqUpdateQuery, enabled);
127
128 transports.Add(trans);
129 }
130
131
132 }
133
134 public void transportAllMessages()
135 {
136 Console.WriteLine("transportAllMessages()");
137 foreach (Transport trans in transports)
138 {
139 trans.transportMessages();
140 }
141 }
142
143 public string[] getTransportNames()
144 {
145 List<string> names = new List<string>();
146
147 foreach (Transport t in transports)
148 {
149 names.Add(t.name);
150 }
151
152 return names.ToArray();
153 }
154
155 public Transport getTransport(string name)
156 {
157 foreach (Transport t in transports)
158 {
159 if (t.name == name)//found requested Transport object
160 {
161 return t;
162 }
163 }
164 return null;
165 }
166
167
168 /* Singleton */
169 private static TransportController instance = null;
170 public static TransportController getInstance()
171 {
172 if (instance == null)
173 instance = new TransportController();
174
175 return instance;
176 }
177
178 }
179 }

  ViewVC Help
Powered by ViewVC 1.1.20