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

Diff of /dao/DaoMqPump2/DaoMqGUI/MainForm.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 2058 by torben, Wed Aug 28 06:45:20 2013 UTC
# Line 7  using System.Text; Line 7  using System.Text;
7  using System.Windows.Forms;  using System.Windows.Forms;
8    
9  using DaoMqGUI.ServiceReference1;  using DaoMqGUI.ServiceReference1;
10    using System.ServiceModel;
11    using Microsoft.Win32;
12    
13  namespace DaoMqGUI  namespace DaoMqGUI
14  {  {
15      public partial class MainForm : Form      public partial class MainForm : Form
16      {      {
17          RemoteControlClient client = new RemoteControlClient();          RemoteControlClient client = null;
18    
19          List<string> transportNameList = new List<string>();          List<string> transportNameList = new List<string>();
20    
21            string hostname = "";
22    
23          public MainForm()          public MainForm()
24          {          {
25              InitializeComponent();              InitializeComponent();
26              loadTransports();  
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()          private string[] getSafeTransports()
# Line 42  namespace DaoMqGUI Line 64  namespace DaoMqGUI
64              return result;              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()          public void loadTransports()
76          {          {
77              int selected = transports.SelectedIndex;  
78                int selected = getSelectedTransportIndex();
79              if (selected == -1) //er der ikke valgt - vælger vi den første              if (selected == -1) //er der ikke valgt - vælger vi den første
80                  selected = 0;                  selected = 0;
81    
# Line 55  namespace DaoMqGUI Line 86  namespace DaoMqGUI
86              foreach (string t in transportNames)              foreach (string t in transportNames)
87              {              {
88                  transportNameList.Add(t);                  transportNameList.Add(t);
89                    StatusData statusData = client.GetTransportStatus(t);
90                  bool enabled = client.GetTransportEnabled(t);                  bool enabled = statusData.transportEnabled;
91                  string status = "";                  string status = "";
92                    Color bgColor;
93                  if (enabled)                  if (enabled)
94                  {                  {
95                      bool lastOk = client.GetTransportLastrunOk(t);                      bool lastOk = statusData.lastrunOk;                    
96                                            
97                      if (lastOk)                      if (lastOk)
98                      {                      {
99                          status = "running";                                                  status = "running";
100                            bgColor = Color.Green;
101                      }                      }
102                      else                      else
103                      {                      {
104                          status = "error";                          status = "error";
105                            bgColor = Color.Red;
106                      }                      }
107                  }                  }
108                  else                  else
109                  {                  {
110                      status = "stopped";                      status = "stopped";
111                        bgColor = Color.DarkOrange;                    
112                  }                  }
113    
114                  transports.Items.Add(t + " - " + status);                  ListViewItem item = new ListViewItem(t + " - " + status);
115                    item.ForeColor = bgColor;
116                    transports.Items.Add(item);
117              }              }
118    
119    
# Line 89  namespace DaoMqGUI Line 125  namespace DaoMqGUI
125                      selected = -1;                      selected = -1;
126              }              }
127    
128              transports.SelectedIndex = selected;              transports.SelectedIndices.Clear();
129                if (selected != -1)
130                    transports.SelectedIndices.Add(selected);
131                //transports.SelectedIndices[0] = selected;
132    
133          }          }
134    
# Line 131  namespace DaoMqGUI Line 170  namespace DaoMqGUI
170    
171          private void transports_SelectedIndexChanged(object sender, EventArgs e)          private void transports_SelectedIndexChanged(object sender, EventArgs e)
172          {          {
173              loadFormData();              showData();
174          }          }
175    
176          private void loadFormData()          private void loadStatusData()
177          {          {
178              if (transports.SelectedIndex == -1)              if (getSelectedTransportIndex() == -1)
179                  return;                  return;
180    
181              string transportName = transportNameList[transports.SelectedIndex];              string transportName = transportNameList[getSelectedTransportIndex() ];
   
             bool enabled = client.GetTransportEnabled(transportName);  
             bool lastOk = client.GetTransportLastrunOk(transportName);  
   
             string lastokTime = client.GetTransportLastOkTime(transportName);  
             string lastErrorTime = client.GetTransportLastErrorTime(transportName);  
182    
183              string errorMsg = client.GetTransportLastErrorMessage(transportName);              StatusData statusData = client.GetTransportStatus(transportName);
184    
185              int counter = client.GetTransportCounter(transportName);              bool enabled = statusData.transportEnabled;
186    
187              txtTransport.Text = transportName;              txtTransport.Text = transportName;
188              txtEnabled.Text = "" + enabled;              txtEnabled.Text = "" + enabled;
189              txtLastOK.Text = "" + lastOk;              txtLastOK.Text = "" + statusData.lastrunOk;
190    
191              txtOkTime.Text = lastokTime;              txtOkTime.Text = statusData.lastOkTime;
192              txtErrorTime.Text = lastErrorTime;              txtErrorTime.Text = statusData.lastErrorTime;
193                txtTransferTime.Text = statusData.lastTransferTime;
194    
195              txtErrorMsg.Text = errorMsg;              txtErrorMsg.Text = statusData.lastErrorMessage;
   
             txtCounter.Text = "" + counter;  
196    
197                txtCounter.Text = "" + statusData.counter;
198    
199                txtDiscarded.Text = "" + statusData.discardedCounter;
200    
201              btnDisableOne.Enabled = enabled;              btnDisableOne.Enabled = enabled;
202              btnEnableOne.Enabled = (!enabled);                          btnEnableOne.Enabled = (!enabled);            
# Line 171  namespace DaoMqGUI Line 205  namespace DaoMqGUI
205    
206          private void refreshTimer_Tick(object sender, EventArgs e)          private void refreshTimer_Tick(object sender, EventArgs e)
207          {          {
208              loadTransports();              loadTransports();
   
             if (transports.SelectedIndex == -1)  
                 return;  
209    
210              if (tabControl1.SelectedIndex != 0) //0 er status siden              if (getSelectedTransportIndex() == -1)
211                  return;                  return;
212    
213              loadFormData();              showData();
214          }          }
215    
216          private void loadLog()          private void loadLog()
217          {          {
218              if (transports.SelectedIndex == -1)              if (getSelectedTransportIndex() == -1)
219                  return;                  return;
220              string transportName = transportNameList[transports.SelectedIndex];              string transportName = transportNameList[getSelectedTransportIndex()];
221    
222              string[] logEntries = client.GetTransportLog(transportName);              string[] logEntries = client.GetTransportLog(transportName);
223    
# Line 201  namespace DaoMqGUI Line 232  namespace DaoMqGUI
232    
233          private void loadConfig()          private void loadConfig()
234          {          {
235              if (transports.SelectedIndex == -1)              if (getSelectedTransportIndex() == -1)
236                  return;                  return;
237              string transportName = transportNameList[transports.SelectedIndex];              string transportName = transportNameList[getSelectedTransportIndex()];
238    
239              string direction = client.GetTransportDirection(transportName);              string direction = client.GetTransportDirection(transportName);
240              string queue = client.GetTransportQueueName(transportName);              string queue = client.GetTransportQueueName(transportName);
# Line 219  namespace DaoMqGUI Line 250  namespace DaoMqGUI
250    
251          }          }
252    
253          private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)          private void showData()
254          {          {
255              if (transports.SelectedIndex == -1)              if (getSelectedTransportIndex() == -1)
256                  return;                  return;
257    
258              switch (tabControl1.SelectedIndex)              switch (tabControl1.SelectedIndex)
259              {              {
260                  case 0:                  case 0:
261                      loadFormData();                      loadStatusData();
262                      break;                      break;
263                  case 1:                  case 1:
264                      loadLog();                      loadLog();
# Line 238  namespace DaoMqGUI Line 269  namespace DaoMqGUI
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  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.20