/[projects]/dao/DaoMqPump2/DaoMqGUI/MainForm.cs
ViewVC logotype

Contents of /dao/DaoMqPump2/DaoMqGUI/MainForm.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2058 - (show annotations) (download)
Wed Aug 28 06:45:20 2013 UTC (10 years, 8 months ago) by torben
File size: 9453 byte(s)
Add a support for discarding transactions and writing those to a seperate log + use a counter for keeping track of how many were discarded in current session/instance
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Text;
7 using System.Windows.Forms;
8
9 using DaoMqGUI.ServiceReference1;
10 using System.ServiceModel;
11 using Microsoft.Win32;
12
13 namespace DaoMqGUI
14 {
15 public partial class MainForm : Form
16 {
17 RemoteControlClient client = null;
18
19 List<string> transportNameList = new List<string>();
20
21 string hostname = "";
22
23 public MainForm()
24 {
25 InitializeComponent();
26
27 //initClient(); is now called on shown() event
28 // loadTransports(); is now called on shown() event
29
30 }
31
32 private void initClient()
33 {
34 RegistryKey key = Registry.LocalMachine.CreateSubKey("Software\\DAO\\DaoMqGui");
35
36 hostname = (string) key.GetValue("Hostname", "localhost");
37 hostname = hostname.Trim();
38
39 lnkServer.Text = hostname;
40
41 //Step 1 - initialize client
42 BasicHttpBinding binding = new BasicHttpBinding();
43 EndpointAddress endpoint = new EndpointAddress(new Uri("http://" + hostname + ":8000/RemoteControl/RemoteControl"));
44 client = new RemoteControlClient(binding, endpoint);
45 }
46
47 private string[] getSafeTransports()
48 {
49 string[] result = new string[] { };
50 try
51 {
52 result = client.GetTransports();
53
54 startAll.Enabled = true;
55 stopAll.Enabled = true;
56 }
57 catch (Exception e)
58 {
59 MessageBox.Show(e.Message);
60 startAll.Enabled = false;
61 stopAll.Enabled = false;
62 }
63
64 return result;
65 }
66
67 public int getSelectedTransportIndex()
68 {
69 if (transports.SelectedIndices.Count == 0)
70 return -1;
71 else
72 return transports.SelectedIndices[0];
73 }
74
75 public void loadTransports()
76 {
77
78 int selected = getSelectedTransportIndex();
79 if (selected == -1) //er der ikke valgt - vælger vi den første
80 selected = 0;
81
82 transports.Items.Clear();
83 transportNameList.Clear();
84
85 string[] transportNames = getSafeTransports();
86 foreach (string t in transportNames)
87 {
88 transportNameList.Add(t);
89 StatusData statusData = client.GetTransportStatus(t);
90 bool enabled = statusData.transportEnabled;
91 string status = "";
92 Color bgColor;
93 if (enabled)
94 {
95 bool lastOk = statusData.lastrunOk;
96
97 if (lastOk)
98 {
99 status = "running";
100 bgColor = Color.Green;
101 }
102 else
103 {
104 status = "error";
105 bgColor = Color.Red;
106 }
107 }
108 else
109 {
110 status = "stopped";
111 bgColor = Color.DarkOrange;
112 }
113
114 ListViewItem item = new ListViewItem(t + " - " + status);
115 item.ForeColor = bgColor;
116 transports.Items.Add(item);
117 }
118
119
120 if (selected >= transports.Items.Count) //hvis at der før var flere transports end nu - kan ikke ske pt.
121 {
122 if (transports.Items.Count > 0) //hvis vi har nogen vælger vi den første
123 selected = 0;
124 else
125 selected = -1;
126 }
127
128 transports.SelectedIndices.Clear();
129 if (selected != -1)
130 transports.SelectedIndices.Add(selected);
131 //transports.SelectedIndices[0] = selected;
132
133 }
134
135 private void stopAll_Click(object sender, EventArgs e)
136 {
137 string[] transportNames = getSafeTransports();
138 foreach (string t in transportNames)
139 {
140 client.SetTransportEnabled(t, false);
141 }
142
143 loadTransports();
144 }
145
146 private void startAll_Click(object sender, EventArgs e)
147 {
148 string[] transportNames = getSafeTransports();
149 foreach (string t in transportNames)
150 {
151 client.SetTransportEnabled(t, true);
152 }
153
154 loadTransports();
155 }
156
157 private void btnEnableOne_Click(object sender, EventArgs e)
158 {
159 string transportName = txtTransport.Text;
160 client.SetTransportEnabled(transportName, true);
161 loadTransports();
162 }
163
164 private void btnDisableOne_Click(object sender, EventArgs e)
165 {
166 string transportName = txtTransport.Text;
167 client.SetTransportEnabled(transportName, false);
168 loadTransports();
169 }
170
171 private void transports_SelectedIndexChanged(object sender, EventArgs e)
172 {
173 showData();
174 }
175
176 private void loadStatusData()
177 {
178 if (getSelectedTransportIndex() == -1)
179 return;
180
181 string transportName = transportNameList[getSelectedTransportIndex() ];
182
183 StatusData statusData = client.GetTransportStatus(transportName);
184
185 bool enabled = statusData.transportEnabled;
186
187 txtTransport.Text = transportName;
188 txtEnabled.Text = "" + enabled;
189 txtLastOK.Text = "" + statusData.lastrunOk;
190
191 txtOkTime.Text = statusData.lastOkTime;
192 txtErrorTime.Text = statusData.lastErrorTime;
193 txtTransferTime.Text = statusData.lastTransferTime;
194
195 txtErrorMsg.Text = statusData.lastErrorMessage;
196
197 txtCounter.Text = "" + statusData.counter;
198
199 txtDiscarded.Text = "" + statusData.discardedCounter;
200
201 btnDisableOne.Enabled = enabled;
202 btnEnableOne.Enabled = (!enabled);
203
204 }
205
206 private void refreshTimer_Tick(object sender, EventArgs e)
207 {
208 loadTransports();
209
210 if (getSelectedTransportIndex() == -1)
211 return;
212
213 showData();
214 }
215
216 private void loadLog()
217 {
218 if (getSelectedTransportIndex() == -1)
219 return;
220 string transportName = transportNameList[getSelectedTransportIndex()];
221
222 string[] logEntries = client.GetTransportLog(transportName);
223
224 string str = "";
225 foreach (string entry in logEntries)
226 {
227 str += entry + "\r\n";
228 }
229 txtLog.Text = str;
230
231 }
232
233 private void loadConfig()
234 {
235 if (getSelectedTransportIndex() == -1)
236 return;
237 string transportName = transportNameList[getSelectedTransportIndex()];
238
239 string direction = client.GetTransportDirection(transportName);
240 string queue = client.GetTransportQueueName(transportName);
241 string insert = client.GetTransportInsertQuery(transportName);
242 string read = client.GetTransportReadQuery(transportName);
243 string update = client.GetTransportUpdateQuery(transportName);
244
245 txtDirection.Text = direction;
246 txtQueueName.Text = queue;
247 txtInsertQuery.Text = insert;
248 txtReadQuery.Text = read;
249 txtUpdateQuery.Text = update;
250
251 }
252
253 private void showData()
254 {
255 if (getSelectedTransportIndex() == -1)
256 return;
257
258 switch (tabControl1.SelectedIndex)
259 {
260 case 0:
261 loadStatusData();
262 break;
263 case 1:
264 loadLog();
265 break;
266 case 2:
267 loadConfig();
268 break;
269 }
270 }
271
272 private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
273 {
274 showData();
275 }
276
277 private void lnkServer_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
278 {
279 string tmp_hostname = Microsoft.VisualBasic.Interaction.InputBox("Indtast servernavn/ip", "MQ Gui", hostname);
280 if (tmp_hostname == null || tmp_hostname.Trim().Length == 0)
281 return;
282
283 hostname = tmp_hostname.Trim();
284
285 RegistryKey key = Registry.LocalMachine.CreateSubKey("Software\\DAO\\DaoMqGui");
286 key.SetValue("Hostname", hostname, RegistryValueKind.String);
287 key.Close();
288
289 initClient();
290 loadTransports();
291 }
292
293 private void MainForm_Shown(object sender, EventArgs e)
294 {
295 lnkServer.Text = "Connecting ...";
296 this.Refresh(); //force a redraw now () before we do the heavy work
297
298 initClient();
299 loadTransports();
300 }
301
302 }
303 }

  ViewVC Help
Powered by ViewVC 1.1.20