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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2000 - (show annotations) (download)
Mon Jul 8 14:23:01 2013 UTC (10 years, 10 months ago) by torben
File size: 8709 byte(s)
Client side parts of:
 Use one StatusData struct to transfer data
 Introduce EventLog file
 Add lastTransferTime to status data
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 void loadTransports()
68 {
69 int selected = transports.SelectedIndex;
70 if (selected == -1) //er der ikke valgt - vælger vi den første
71 selected = 0;
72
73 transports.Items.Clear();
74 transportNameList.Clear();
75
76 string[] transportNames = getSafeTransports();
77 foreach (string t in transportNames)
78 {
79 transportNameList.Add(t);
80 StatusData statusData = client.GetTransportStatus(t);
81 bool enabled = statusData.transportEnabled;
82 string status = "";
83
84 if (enabled)
85 {
86 bool lastOk = statusData.lastrunOk;
87
88 if (lastOk)
89 {
90 status = "running";
91 }
92 else
93 {
94 status = "error";
95 }
96 }
97 else
98 {
99 status = "stopped";
100 }
101
102 transports.Items.Add(t + " - " + status);
103 }
104
105
106 if (selected >= transports.Items.Count) //hvis at der før var flere transports end nu - kan ikke ske pt.
107 {
108 if (transports.Items.Count > 0) //hvis vi har nogen vælger vi den første
109 selected = 0;
110 else
111 selected = -1;
112 }
113
114 transports.SelectedIndex = selected;
115
116 }
117
118 private void stopAll_Click(object sender, EventArgs e)
119 {
120 string[] transportNames = getSafeTransports();
121 foreach (string t in transportNames)
122 {
123 client.SetTransportEnabled(t, false);
124 }
125
126 loadTransports();
127 }
128
129 private void startAll_Click(object sender, EventArgs e)
130 {
131 string[] transportNames = getSafeTransports();
132 foreach (string t in transportNames)
133 {
134 client.SetTransportEnabled(t, true);
135 }
136
137 loadTransports();
138 }
139
140 private void btnEnableOne_Click(object sender, EventArgs e)
141 {
142 string transportName = txtTransport.Text;
143 client.SetTransportEnabled(transportName, true);
144 loadTransports();
145 }
146
147 private void btnDisableOne_Click(object sender, EventArgs e)
148 {
149 string transportName = txtTransport.Text;
150 client.SetTransportEnabled(transportName, false);
151 loadTransports();
152 }
153
154 private void transports_SelectedIndexChanged(object sender, EventArgs e)
155 {
156 showData();
157 }
158
159 private void loadStatusData()
160 {
161 if (transports.SelectedIndex == -1)
162 return;
163
164 string transportName = transportNameList[transports.SelectedIndex];
165
166 StatusData statusData = client.GetTransportStatus(transportName);
167
168 bool enabled = statusData.transportEnabled;
169
170 txtTransport.Text = transportName;
171 txtEnabled.Text = "" + enabled;
172 txtLastOK.Text = "" + statusData.lastrunOk;
173
174 txtOkTime.Text = statusData.lastOkTime;
175 txtErrorTime.Text = statusData.lastErrorTime;
176 txtTransferTime.Text = statusData.lastTransferTime;
177
178 txtErrorMsg.Text = statusData.lastErrorMessage;
179
180 txtCounter.Text = "" + statusData.counter;
181
182
183
184 btnDisableOne.Enabled = enabled;
185 btnEnableOne.Enabled = (!enabled);
186
187 }
188
189 private void refreshTimer_Tick(object sender, EventArgs e)
190 {
191 loadTransports();
192
193 if (transports.SelectedIndex == -1)
194 return;
195
196 showData();
197 }
198
199 private void loadLog()
200 {
201 if (transports.SelectedIndex == -1)
202 return;
203 string transportName = transportNameList[transports.SelectedIndex];
204
205 string[] logEntries = client.GetTransportLog(transportName);
206
207 string str = "";
208 foreach (string entry in logEntries)
209 {
210 str += entry + "\r\n";
211 }
212 txtLog.Text = str;
213
214 }
215
216 private void loadConfig()
217 {
218 if (transports.SelectedIndex == -1)
219 return;
220 string transportName = transportNameList[transports.SelectedIndex];
221
222 string direction = client.GetTransportDirection(transportName);
223 string queue = client.GetTransportQueueName(transportName);
224 string insert = client.GetTransportInsertQuery(transportName);
225 string read = client.GetTransportReadQuery(transportName);
226 string update = client.GetTransportUpdateQuery(transportName);
227
228 txtDirection.Text = direction;
229 txtQueueName.Text = queue;
230 txtInsertQuery.Text = insert;
231 txtReadQuery.Text = read;
232 txtUpdateQuery.Text = update;
233
234 }
235
236 private void showData()
237 {
238 if (transports.SelectedIndex == -1)
239 return;
240
241 switch (tabControl1.SelectedIndex)
242 {
243 case 0:
244 loadStatusData();
245 break;
246 case 1:
247 loadLog();
248 break;
249 case 2:
250 loadConfig();
251 break;
252 }
253 }
254
255 private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
256 {
257 showData();
258 }
259
260 private void lnkServer_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
261 {
262 string tmp_hostname = Microsoft.VisualBasic.Interaction.InputBox("Indtast servernavn/ip", "MQ Gui", hostname);
263 if (tmp_hostname == null || tmp_hostname.Trim().Length == 0)
264 return;
265
266 hostname = tmp_hostname.Trim();
267
268 RegistryKey key = Registry.LocalMachine.CreateSubKey("Software\\DAO\\DaoMqGui");
269 key.SetValue("Hostname", hostname, RegistryValueKind.String);
270 key.Close();
271
272 initClient();
273 loadTransports();
274 }
275
276 private void MainForm_Shown(object sender, EventArgs e)
277 {
278 lnkServer.Text = "Connecting ...";
279 this.Refresh(); //force a redraw now () before we do the heavy work
280
281 initClient();
282 loadTransports();
283 }
284
285 }
286 }

  ViewVC Help
Powered by ViewVC 1.1.20