Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Client.Console/3.2/HiveClientConsole.cs @ 2115

Last change on this file since 2115 was 2101, checked in by whackl, 15 years ago

refactoring #663

File size: 21.5 KB
RevLine 
[717]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
[1511]24using System.Diagnostics;
[717]25using System.Drawing;
26using System.Linq;
[1511]27using System.Net;
28using System.ServiceModel;
[717]29using System.Windows.Forms;
[1511]30using Calendar;
31using HeuristicLab.Hive.Client.Console.ClientService;
[906]32using ZedGraph;
[1579]33using HeuristicLab.Hive.Contracts;
[2006]34using System.Xml.Serialization;
35using System.IO;
[717]36
[1511]37namespace HeuristicLab.Hive.Client.Console
38{
[752]39
[2101]40  #region Delegates
[1027]41
[2101]42  //delegate to write text in the textbox from another process
43  public delegate void AppendTextDelegate(String message);
[2062]44
[2101]45  //delegate to remove text in the textbox from another process
46  public delegate void RemoveTextDelegate(int newLength, int maxChars);
[752]47
[2101]48  //delegate fired, if a dialog is being closed
49  public delegate void OnDialogClosedDelegate(RecurrentEvent e);
[1027]50
[2101]51  #endregion
[752]52
[2101]53  public partial class HiveClientConsole : Form
54  {
[1027]55
[2101]56    #region Declarations
[1027]57
[2101]58    private const string ENDPOINTADRESS = "net.tcp://127.0.0.1:8000/ClientConsole/ClientConsoleCommunicator";
[2062]59
[2101]60    private static bool isfired = false;
61    //the logfilereader
62    private LogFileReader logFileReader;
[2062]63
[2101]64    //communication with the client
65    private ClientConsoleCommunicatorClient clientCommunicator;
[752]66
[2101]67    //the timer for refreshing the gui
68    private System.Windows.Forms.Timer refreshTimer;
[1138]69
[2101]70    //the list of appointments in the calender
71    [XmlArray("Appointments")]
72    [XmlArrayItem("Appointment", typeof(Appointment))]
73    public List<Appointment> onlineTimes = new List<Appointment>();
[1511]74
[2101]75    public OnDialogClosedDelegate dialogClosedDelegate;
[1002]76
[2101]77    #endregion
[1027]78
[2101]79    #region Constructor
[2006]80
[2101]81    public HiveClientConsole()
82    {
83      InitializeComponent();
84      InitTimer();
85      ConnectToClient();
86      RefreshGui();
87      InitCalender();
88      InitLogFileReader();
89    }
[2062]90
[2101]91    #endregion
[2062]92
[2101]93    #region Methods
[2062]94
[2101]95    #region Client connection
[1943]96
[2101]97    private void ConnectToClient()
98    {
99      try
100      {
101        clientCommunicator = new ClientConsoleCommunicatorClient(WcfSettings.GetBinding(), new EndpointAddress(ENDPOINTADRESS));
102        clientCommunicator.GetStatusInfosCompleted += new EventHandler<GetStatusInfosCompletedEventArgs>(clientCommunicator_GetStatusInfosCompleted);
103        clientCommunicator.GetCurrentConnectionCompleted += new EventHandler<GetCurrentConnectionCompletedEventArgs>(clientCommunicator_GetCurrentConnectionCompleted);
104        clientCommunicator.GetUptimeCalendarCompleted += new EventHandler<GetUptimeCalendarCompletedEventArgs>(clientCommunicator_GetUptimeCalendarCompleted);
105        clientCommunicator.SetUptimeCalendarCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(clientCommunicator_SetUptimeCalendarCompleted);
106      }
107      catch (Exception ex)
108      {
109        ManageFatalException("Connection Error, check if Hive Client is running!", "Connection Error", ex);
110      }
111    }
[1930]112
[2101]113    #endregion
[1930]114
[2101]115    #region Logging
[2024]116
[2101]117    private void InitLogFileReader()
118    {
119      logFileReader = new LogFileReader(Environment.CurrentDirectory + @"/Hive.log");
120      logFileReader.MoreData += new LogFileReader.MoreDataHandler(logFileReader_MoreData);
121      logFileReader.Start();
122    }
[1949]123
[2101]124    private void logFileReader_MoreData(object sender, string newData)
125    {
126      int maxChars = txtLog.MaxLength;
127      if (newData.Length > maxChars)
128      {
129        newData = newData.Remove(0, newData.Length - maxChars);
130      }
131      int newLength = this.txtLog.Text.Length + newData.Length;
132      if (newLength > maxChars)
133      {
134        RemoveText(newLength, maxChars);
135      }
136      AppendText(newData);
137    }
[906]138
[2101]139    private void RemoveText(int newLength, int maxChars)
140    {
141      if (this.txtLog.InvokeRequired)
142      {
143        this.txtLog.Invoke(new
144          RemoveTextDelegate(RemoveText), new object[] { newLength, maxChars });
145      }
146      else
147      {
148        this.txtLog.Text = this.txtLog.Text.Remove(0, newLength - (int)maxChars);
149      }
150    }
[2062]151
[2101]152    private void AppendText(string message)
153    {
154      if (this.txtLog.InvokeRequired)
155      {
156        this.txtLog.Invoke(new
157          AppendTextDelegate(AppendText), new object[] { message });
158      }
159      else
160      {
161        this.txtLog.AppendText(message);
162      }
163    }
[2062]164
[2101]165    #endregion
[2062]166
[2101]167    #region Gui Refresh
[973]168
[2101]169    private void InitTimer()
170    {
171      refreshTimer = new System.Windows.Forms.Timer();
172      refreshTimer.Interval = 1000;
173      refreshTimer.Tick += new EventHandler(refreshTimer_Tick);
174      refreshTimer.Start();
175    }
[2024]176
[2101]177    private void RefreshGui()
178    {
179      try
180      {
181        clientCommunicator.GetStatusInfosAsync();
182      }
183      catch (Exception ex)
184      {
185        ManageFatalException("Connection Error, check if Hive Client is running!", "Connection Error", ex);
186      }
187    }
[1027]188
[2101]189    private void UpdateGraph(JobStatus[] jobs)
190    {
191      ZedGraphControl zgc = new ZedGraphControl();
192      GraphPane myPane = zgc.GraphPane;
193      myPane.GraphObjList.Clear();
[1027]194
[2101]195      myPane.Title.IsVisible = false;  // no title
196      myPane.Border.IsVisible = false; // no border
197      myPane.Chart.Border.IsVisible = false; // no border around the chart
198      myPane.XAxis.IsVisible = false;  // no x-axis
199      myPane.YAxis.IsVisible = false;  // no y-axis
200      myPane.Legend.IsVisible = false; // no legend
[1027]201
[2101]202      myPane.Fill.Color = this.BackColor;
[1027]203
[2101]204      myPane.Chart.Fill.Type = FillType.None;
205      myPane.Fill.Type = FillType.Solid;
[2024]206
[2101]207      double allProgress = 0;
208      double done = 0;
[2024]209
[2101]210      if (jobs.Length == 0)
211      {
212        myPane.AddPieSlice(100, Color.Green, 0.1, "");
213      }
214      else
215      {
216        for (int i = 0; i < jobs.Length; i++)
217        {
218          allProgress += jobs[i].Progress;
219        }
[2024]220
[2101]221        done = allProgress / jobs.Length;
[2024]222
[2101]223        myPane.AddPieSlice(done, Color.Green, 0, "");
224        myPane.AddPieSlice(1 - done, Color.Red, 0, "");
225      }
226      //Hides the slice labels
227      PieItem.Default.LabelType = PieLabelType.None;
[2024]228
[2101]229      myPane.AxisChange();
[1027]230
[2101]231      pbGraph.Image = zgc.GetImage();
232    }
[2062]233
[2101]234    #region Events
[2062]235
[2101]236    private void refreshTimer_Tick(object sender, EventArgs e)
237    {
238      RefreshGui();
239    }
[2062]240
[2101]241    #endregion
[2062]242
243
[2101]244    #endregion
[2062]245
[2101]246    #region Calendar stuff
[1080]247
[2101]248    private void InitCalender()
249    {
250      dvOnline.StartDate = DateTime.Now;
251      dvOnline.OnNewAppointment += new EventHandler<NewAppointmentEventArgs>(dvOnline_OnNewAppointment);
252      dvOnline.OnResolveAppointments += new EventHandler<ResolveAppointmentsEventArgs>(dvOnline_OnResolveAppointments);
[1027]253
[2101]254      //get calender from client
255      clientCommunicator.GetUptimeCalendarAsync();
256    }
257
258    private bool CreateAppointment()
259    {
260      DateTime from, to;
261
262      if (!string.IsNullOrEmpty(dtpFrom.Text) && !string.IsNullOrEmpty(dtpTo.Text))
263      {
264        if (chbade.Checked)
[2062]265        {
[2101]266          //whole day appointment, only dates are visible
267          if (DateTime.TryParse(dtpFrom.Text, out from) && DateTime.TryParse(dtpTo.Text, out to) && from <= to)
268            onlineTimes.Add(CreateAppointment(from, to.AddDays(1), true));
269          else
270            MessageBox.Show("Incorrect date format", "Schedule Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
271        }
272        else if (!string.IsNullOrEmpty(txttimeFrom.Text) && !string.IsNullOrEmpty(txttimeTo.Text))
273        {
274          //Timeframe appointment
275          if (DateTime.TryParse(dtpFrom.Text + " " + txttimeFrom.Text, out from) && DateTime.TryParse(dtpTo.Text + " " + txttimeTo.Text, out to) && from < to)
276          {
277            if (from.Date == to.Date)
278              onlineTimes.Add(CreateAppointment(from, to, false));
[2062]279            else
280            {
[2101]281              //more than 1 day selected
282              while (from.Date != to.Date)
283              {
284                onlineTimes.Add(CreateAppointment(from, new DateTime(from.Year, from.Month, from.Day, to.Hour, to.Minute, 0, 0), false));
285                from = from.AddDays(1);
286              }
287              onlineTimes.Add(CreateAppointment(from, new DateTime(from.Year, from.Month, from.Day, to.Hour, to.Minute, 0, 0), false));
[2062]288            }
[2101]289          }
290          else
291            MessageBox.Show("Incorrect date format", "Schedule Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
[2062]292        }
[2101]293        dvOnline.Invalidate();
294        return true;
295      }
296      else
297      {
298        MessageBox.Show("Error in create appointment, please fill out all textboxes!", "Schedule Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
299        return false;
300      }
301    }
[2062]302
[2101]303    private Appointment CreateAppointment(DateTime startDate, DateTime endDate, bool allDay)
304    {
305      Appointment App = new Appointment();
306      App.StartDate = startDate;
307      App.EndDate = endDate;
308      App.AllDayEvent = allDay;
309      App.BorderColor = Color.Red;
310      App.Locked = true;
311      App.Subject = "Online";
312      App.Recurring = false;
313      return App;
314    }
[1027]315
[2101]316    private Appointment CreateAppointment(DateTime startDate, DateTime endDate, bool allDay, bool recurring, Guid recurringId)
317    {
318      Appointment App = new Appointment();
319      App.StartDate = startDate;
320      App.EndDate = endDate;
321      App.AllDayEvent = allDay;
322      App.BorderColor = Color.Red;
323      App.Locked = true;
324      App.Subject = "Online";
325      App.Recurring = recurring;
326      App.RecurringId = recurringId;
327      return App;
328    }
[1027]329
[2101]330    private void DeleteAppointment()
331    {
332      onlineTimes.Remove(dvOnline.SelectedAppointment);
333    }
[2023]334
[2101]335    private void DeleteRecurringAppointment(Guid recurringId)
336    {
337      onlineTimes.RemoveAll(a => a.RecurringId.ToString() == dvOnline.SelectedAppointment.RecurringId.ToString());
338    }
[1138]339
[2101]340    private void ChangeRecurrenceAppointment(Guid recurringId)
341    {
342      int hourfrom = int.Parse(txttimeFrom.Text.Substring(0, txttimeFrom.Text.IndexOf(':')));
343      int hourTo = int.Parse(txttimeTo.Text.Substring(0, txttimeTo.Text.IndexOf(':')));
344      List<Appointment> recurringAppointments = onlineTimes.Where(appointment => appointment.RecurringId == recurringId).ToList();
345      recurringAppointments.ForEach(appointment => appointment.StartDate = new DateTime(appointment.StartDate.Year, appointment.StartDate.Month, appointment.StartDate.Day, hourfrom, 0, 0));
346      recurringAppointments.ForEach(appointment => appointment.EndDate = new DateTime(appointment.EndDate.Year, appointment.EndDate.Month, appointment.EndDate.Day, hourTo, 0, 0));
[1511]347
[2101]348      DeleteRecurringAppointment(recurringId);
349      onlineTimes.AddRange(recurringAppointments);
350    }
[1511]351
[2101]352    public void DialogClosed(RecurrentEvent e)
353    {
354      CreateDailyRecurrenceAppointments(e.DateFrom, e.DateTo, e.AllDay, e.IncWeeks, e.WeekDays);
355    }
[1002]356
[2101]357    private void CreateDailyRecurrenceAppointments(DateTime dateFrom, DateTime dateTo, bool allDay, int incWeek, HashSet<DayOfWeek> daysOfWeek)
358    {
359      DateTime incDate = dateFrom;
360      Guid guid = Guid.NewGuid();
[1002]361
[2101]362      while (incDate.Date <= dateTo.Date)
363      {
364        if (daysOfWeek.Contains(incDate.Date.DayOfWeek))
365          onlineTimes.Add(CreateAppointment(incDate, new DateTime(incDate.Year, incDate.Month, incDate.Day, dateTo.Hour, dateTo.Minute, 0), allDay, true, guid));
366        incDate = incDate.AddDays(1);
367      }
[1002]368
[2101]369      dvOnline.Invalidate();
370    }
[2024]371
[2101]372    #region Calendar Events
[2024]373
[2101]374    private void btbDelete_Click(object sender, EventArgs e)
375    {
376      Appointment selectedAppointment = dvOnline.SelectedAppointment;
377      if (dvOnline.SelectedAppointment != null)
378      {
379        if (!selectedAppointment.Recurring)
380          DeleteAppointment();
381        else
[2024]382        {
[2101]383          DialogResult res = MessageBox.Show("Delete all events in this series?", "Delete recurrences", MessageBoxButtons.YesNo);
384          if (res != DialogResult.Yes)
385            DeleteAppointment();
386          else
387            DeleteRecurringAppointment(selectedAppointment.RecurringId);
[2024]388        }
[2101]389      }
390      dvOnline.Invalidate();
391    }
[1002]392
[2101]393    private void chbade_CheckedChanged(object sender, EventArgs e)
394    {
395      txttimeFrom.Visible = !chbade.Checked;
396      txttimeTo.Visible = !chbade.Checked;
397    }
[1087]398
[2101]399    private void dvOnline_OnSelectionChanged(object sender, EventArgs e)
400    {
401      //btCreate.Enabled = true;
402      if (dvOnline.Selection == SelectionType.DateRange)
403      {
404        dtpFrom.Text = dvOnline.SelectionStart.ToShortDateString();
405        dtpTo.Text = dvOnline.SelectionEnd.Date.ToShortDateString();
406        txttimeFrom.Text = dvOnline.SelectionStart.ToShortTimeString();
407        txttimeTo.Text = dvOnline.SelectionEnd.ToShortTimeString();
[1163]408
[2101]409        btCreate.Text = "Save";
410      }
[1511]411
[2101]412      if (dvOnline.Selection == SelectionType.Appointment)
413      {
[1511]414
[2101]415        dtpFrom.Text = dvOnline.SelectedAppointment.StartDate.ToShortDateString();
416        dtpTo.Text = dvOnline.SelectedAppointment.EndDate.ToShortDateString();
417        txttimeFrom.Text = dvOnline.SelectedAppointment.StartDate.ToShortTimeString();
418        txttimeTo.Text = dvOnline.SelectedAppointment.EndDate.ToShortTimeString();
[1511]419
[2101]420        if (dvOnline.SelectedAppointment.Recurring)
421          //btCreate.Enabled = false;
422          //also change the caption of the save button
423          btCreate.Text = "Save changes";
424      }
[1511]425
[2101]426      if (dvOnline.Selection == SelectionType.None)
427      {
428        //also change the caption of the save button
429        btCreate.Text = "Save";
430      }
[1511]431
[2101]432    }
[1511]433
[2101]434    private void mcOnline_DateChanged(object sender, DateRangeEventArgs e)
435    {
436      dvOnline.StartDate = mcOnline.SelectionStart;
437    }
[1163]438
[2101]439    private void btCreate_Click(object sender, EventArgs e)
440    {
441      if (dvOnline.Selection != SelectionType.Appointment)
442      {
443        CreateAppointment();
444      }
445      else
446      {
447        //now we want to change an existing appointment
448        if (!dvOnline.SelectedAppointment.Recurring)
[1511]449        {
[2101]450          if (CreateAppointment())
451            DeleteAppointment();
[1163]452        }
[2101]453        else
[1511]454        {
[2101]455          //change recurring appointment
456          //check, if only selected appointment has to change or whole recurrence
457          DialogResult res = MessageBox.Show("Change all events in this series?", "Change recurrences", MessageBoxButtons.YesNo);
458          if (res != DialogResult.Yes)
459          {
460            if (CreateAppointment())
461              DeleteAppointment();
462          }
463          else
464            ChangeRecurrenceAppointment(dvOnline.SelectedAppointment.RecurringId);
[2062]465        }
[2101]466      }
467      dvOnline.Invalidate();
468    }
[2024]469
[2101]470    private void btnRecurrence_Click(object sender, EventArgs e)
471    {
472      Recurrence recurrence = new Recurrence();
473      recurrence.dialogClosedDelegate = new OnDialogClosedDelegate(this.DialogClosed);
474      recurrence.Show();
475    }
[2024]476
[2101]477    private void btnSaveCal_Click(object sender, EventArgs e)
478    {
479      clientCommunicator.SetUptimeCalendarAsync(onlineTimes.ToArray());
480    }
[2024]481
[2101]482    private void dvOnline_OnResolveAppointments(object sender, ResolveAppointmentsEventArgs e)
483    {
484      List<Appointment> Apps = new List<Appointment>();
[1511]485
[2101]486      foreach (Appointment m_App in onlineTimes)
487        if ((m_App.StartDate >= e.StartDate) &&
488            (m_App.StartDate <= e.EndDate))
489          Apps.Add(m_App);
490      e.Appointments = Apps;
491    }
[1511]492
[2101]493    private void dvOnline_OnNewAppointment(object sender, NewAppointmentEventArgs e)
494    {
495      Appointment Appointment = new Appointment();
[1511]496
[2101]497      Appointment.StartDate = e.StartDate;
498      Appointment.EndDate = e.EndDate;
[1163]499
[2101]500      onlineTimes.Add(Appointment);
501    }
[2062]502
[2101]503    #endregion
[2062]504
[2101]505    #endregion
[2062]506
[2101]507    #region Client communicator events
[1138]508
[2101]509    void clientCommunicator_SetUptimeCalendarCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
510    {
511      if (e.Error == null)
512      {
513        MessageBox.Show("Calendar successfully saved!", "Calender", MessageBoxButtons.OK, MessageBoxIcon.Information);
514      }
515      else
516      {
517        MessageBox.Show("Error saving calender \n" + e.Error.ToString(), "Calender", MessageBoxButtons.OK, MessageBoxIcon.Error);
518      }
519    }
520
521    void clientCommunicator_GetUptimeCalendarCompleted(object sender, GetUptimeCalendarCompletedEventArgs e)
522    {
523      if (e.Error == null)
524      {
525        if (e.Result != null)
[2024]526        {
[2101]527          onlineTimes = e.Result.ToList<Appointment>();
528          onlineTimes.ForEach(a => a.BorderColor = Color.Red);
[2024]529        }
[2101]530        else
[2024]531        {
[2101]532          onlineTimes = new List<Appointment>();
[2062]533        }
[2101]534      }
535    }
[1163]536
[2101]537    private void clientCommunicator_GetCurrentConnectionCompleted(object sender, GetCurrentConnectionCompletedEventArgs e)
538    {
539      if (e.Error == null)
540      {
541        ConnectionContainer curConnection = e.Result;
542        tbIPAdress.Text = curConnection.IPAdress;
543        tbPort.Text = curConnection.Port.ToString();
544      }
545      else
546      {
547        ManageFatalException("Connection Error, check if Hive Client is running!", "Connection Error", null);
548      }
549    }
[2062]550
[2101]551    private void clientCommunicator_GetStatusInfosCompleted(object sender, GetStatusInfosCompletedEventArgs e)
552    {
553      if (e.Error == null)
554      {
555        StatusCommons sc = e.Result;
[2062]556
[2101]557        lbGuid.Text = sc.ClientGuid.ToString();
558        lbConnectionStatus.Text = sc.Status.ToString();
559        lbJobdone.Text = sc.JobsDone.ToString();
560        lbJobsAborted.Text = sc.JobsAborted.ToString();
561        lbJobsFetched.Text = sc.JobsFetched.ToString();
[2062]562
[2101]563        this.Text = "Client Console (" + sc.Status.ToString() + ")";
[2062]564
[2101]565        ListViewItem curJobStatusItem;
[2062]566
[2101]567        if (sc.Jobs != null)
568        {
569          lvJobDetail.Items.Clear();
570          double progress;
571          foreach (JobStatus curJob in sc.Jobs)
572          {
573            curJobStatusItem = new ListViewItem(curJob.JobId.ToString());
574            curJobStatusItem.SubItems.Add(curJob.Since.ToString());
575            progress = curJob.Progress * 100;
576            curJobStatusItem.SubItems.Add(progress.ToString());
577            lvJobDetail.Items.Add(curJobStatusItem);
578          }
579          lvJobDetail.Sort();
[2062]580        }
[1163]581
[2101]582        UpdateGraph(sc.Jobs);
[2062]583
[2101]584        if (sc.Status == NetworkEnumWcfConnState.Connected || sc.Status == NetworkEnumWcfConnState.Loggedin)
[2062]585        {
[2101]586          btConnect.Enabled = false;
587          btnDisconnect.Enabled = true;
588          lbCs.Text = sc.ConnectedSince.ToString();
589          clientCommunicator.GetCurrentConnectionAsync();
[2024]590        }
[2101]591        else if (sc.Status == NetworkEnumWcfConnState.Disconnected)
[2024]592        {
[2101]593          btConnect.Enabled = true;
594          btnDisconnect.Enabled = false;
595          lbCs.Text = String.Empty;
[2024]596        }
[2101]597        else if (sc.Status == NetworkEnumWcfConnState.Failed)
[2062]598        {
[2101]599          btConnect.Enabled = true;
600          btnDisconnect.Enabled = false;
601          lbCs.Text = String.Empty;
[2062]602        }
603
[2101]604        clientCommunicator.GetCurrentConnection();
605      }
606      else
607      {
608        ManageFatalException("Connection Error, check if Hive Client is running!", "Connection Error", null);
609      }
610    }
[2062]611
[2101]612    #endregion
[1511]613
[2101]614    #region Exception
615    private void ManageFatalException(string body, string caption, Exception e)
616    {
617      if (!isfired)
618      {
619        isfired = true;
620        refreshTimer.Stop();
621        DialogResult res = MessageBox.Show(body, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
622        if (res == DialogResult.OK)
623          this.Close();
624      }
[1511]625    }
[2101]626
627    #endregion
628
629    #endregion
630
631    #region GUI Events
632
633    private void btConnect_Click(object sender, EventArgs e)
634    {
635      IPAddress ipAdress;
636      int port;
637      ConnectionContainer cc = new ConnectionContainer();
638      if (IPAddress.TryParse(tbIPAdress.Text, out ipAdress) && int.TryParse(tbPort.Text, out port))
639      {
640        cc.IPAdress = tbIPAdress.Text;
641        cc.Port = port;
642        clientCommunicator.SetConnectionAsync(cc);
643      }
644      else
645      {
646        MessageBox.Show("IP Adress and/or Port Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
647      }
648    }
649
650    private void btnDisconnect_Click(object sender, EventArgs e)
651    {
652      clientCommunicator.DisconnectAsync();
653    }
654
655    private void btn_clientShutdown_Click(object sender, EventArgs e)
656    {
657      DialogResult res = MessageBox.Show("Do you really want to shutdown the Hive Client?", "Hive Client Console", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
658      if (res == DialogResult.Yes)
659      {
660        logFileReader.Stop();
661        clientCommunicator.ShutdownClient();
662        this.Close();
663      }
664    }
665
666    private void Connection_KeyPress(object sender, KeyPressEventArgs e)
667    {
668      if (e.KeyChar == (char)Keys.Return)
669        btConnect_Click(null, null);
670    }
671
672    #endregion
673
674  }
[752]675}
Note: See TracBrowser for help on using the repository browser.