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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1994 - (hide annotations) (download)
Fri Jul 5 08:43:21 2013 UTC (10 years, 10 months ago) by torben
File size: 8705 byte(s)
load transport list in shown event instead of Form contstructor
1 torben 1986 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 torben 1992 using System.ServiceModel;
11     using Microsoft.Win32;
12 torben 1986
13     namespace DaoMqGUI
14     {
15     public partial class MainForm : Form
16     {
17 torben 1992 RemoteControlClient client = null;
18 torben 1986
19     List<string> transportNameList = new List<string>();
20    
21 torben 1992 string hostname = "";
22    
23 torben 1986 public MainForm()
24     {
25     InitializeComponent();
26 torben 1992
27 torben 1994 //initClient(); is now called on shown() event
28     // loadTransports(); is now called on shown() event
29 torben 1992
30 torben 1986 }
31    
32 torben 1992 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 torben 1986 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    
81     bool enabled = client.GetTransportEnabled(t);
82     string status = "";
83    
84     if (enabled)
85     {
86     bool lastOk = client.GetTransportLastrunOk(t);
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     loadFormData();
157     }
158    
159     private void loadFormData()
160     {
161     if (transports.SelectedIndex == -1)
162     return;
163    
164     string transportName = transportNameList[transports.SelectedIndex];
165    
166     bool enabled = client.GetTransportEnabled(transportName);
167     bool lastOk = client.GetTransportLastrunOk(transportName);
168    
169     string lastokTime = client.GetTransportLastOkTime(transportName);
170     string lastErrorTime = client.GetTransportLastErrorTime(transportName);
171    
172     string errorMsg = client.GetTransportLastErrorMessage(transportName);
173    
174     int counter = client.GetTransportCounter(transportName);
175    
176     txtTransport.Text = transportName;
177     txtEnabled.Text = "" + enabled;
178     txtLastOK.Text = "" + lastOk;
179    
180     txtOkTime.Text = lastokTime;
181     txtErrorTime.Text = lastErrorTime;
182    
183     txtErrorMsg.Text = errorMsg;
184    
185     txtCounter.Text = "" + counter;
186    
187    
188    
189     btnDisableOne.Enabled = enabled;
190     btnEnableOne.Enabled = (!enabled);
191    
192     }
193    
194     private void refreshTimer_Tick(object sender, EventArgs e)
195     {
196     loadTransports();
197    
198     if (transports.SelectedIndex == -1)
199     return;
200    
201     if (tabControl1.SelectedIndex != 0) //0 er status siden
202     return;
203    
204     loadFormData();
205     }
206    
207     private void loadLog()
208     {
209     if (transports.SelectedIndex == -1)
210     return;
211     string transportName = transportNameList[transports.SelectedIndex];
212    
213     string[] logEntries = client.GetTransportLog(transportName);
214    
215     string str = "";
216     foreach (string entry in logEntries)
217     {
218     str += entry + "\r\n";
219     }
220     txtLog.Text = str;
221    
222     }
223    
224     private void loadConfig()
225     {
226     if (transports.SelectedIndex == -1)
227     return;
228     string transportName = transportNameList[transports.SelectedIndex];
229    
230     string direction = client.GetTransportDirection(transportName);
231     string queue = client.GetTransportQueueName(transportName);
232     string insert = client.GetTransportInsertQuery(transportName);
233     string read = client.GetTransportReadQuery(transportName);
234     string update = client.GetTransportUpdateQuery(transportName);
235    
236     txtDirection.Text = direction;
237     txtQueueName.Text = queue;
238     txtInsertQuery.Text = insert;
239     txtReadQuery.Text = read;
240     txtUpdateQuery.Text = update;
241    
242     }
243    
244     private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
245     {
246     if (transports.SelectedIndex == -1)
247     return;
248    
249     switch (tabControl1.SelectedIndex)
250     {
251     case 0:
252     loadFormData();
253     break;
254     case 1:
255     loadLog();
256     break;
257     case 2:
258     loadConfig();
259     break;
260     }
261     }
262    
263 torben 1992 private void lnkServer_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
264     {
265     string tmp_hostname = Microsoft.VisualBasic.Interaction.InputBox("Indtast servernavn/ip", "MQ Gui", hostname);
266     if (tmp_hostname == null || tmp_hostname.Trim().Length == 0)
267     return;
268    
269     hostname = tmp_hostname.Trim();
270    
271     RegistryKey key = Registry.LocalMachine.CreateSubKey("Software\\DAO\\DaoMqGui");
272     key.SetValue("Hostname", hostname, RegistryValueKind.String);
273     key.Close();
274    
275     initClient();
276     loadTransports();
277     }
278    
279 torben 1994 private void MainForm_Shown(object sender, EventArgs e)
280     {
281     initClient();
282     loadTransports();
283     }
284    
285 torben 1986 }
286     }

  ViewVC Help
Powered by ViewVC 1.1.20