Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/26/10 18:17:16 (14 years ago)
Author:
cneumuel
Message:

migration from 3.2 to 3.3 completed. Hive Server and Client are now executable and as functional as they were in 3.2. (#1096)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Client.Console/3.3/HiveClientConsole.cs

    r3931 r4107  
    2828using System.ServiceModel;
    2929using System.Windows.Forms;
    30 using Calendar;
     30using HeuristicLab.Calendar;
    3131using HeuristicLab.Hive.Client.Console.ClientService;
    3232using ZedGraph;
     
    3535using System.IO;
    3636
    37 namespace HeuristicLab.Hive.Client.Console
    38 {
     37namespace HeuristicLab.Hive.Client.Console {
    3938
    4039  #region Delegates
     
    5150  #endregion
    5251
    53   public partial class HiveClientConsole : Form
    54   {
     52  public partial class HiveClientConsole : Form {
    5553
    5654    #region Declarations
     
    7977    #region Constructor
    8078
    81     public HiveClientConsole()
    82     {
     79    public HiveClientConsole() {
    8380      InitializeComponent();
    8481      InitTimer();
     
    9592    #region Client connection
    9693
    97     private void ConnectToClient()
    98     {
    99       try
    100       {
     94    private void ConnectToClient() {
     95      try {
    10196        clientCommunicator = new ClientConsoleCommunicatorClient(WcfSettings.GetBinding(), new EndpointAddress(ENDPOINTADRESS));
    10297        clientCommunicator.GetStatusInfosCompleted += new EventHandler<GetStatusInfosCompletedEventArgs>(clientCommunicator_GetStatusInfosCompleted);
     
    10499        clientCommunicator.GetUptimeCalendarCompleted += new EventHandler<GetUptimeCalendarCompletedEventArgs>(clientCommunicator_GetUptimeCalendarCompleted);
    105100        clientCommunicator.SetUptimeCalendarCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(clientCommunicator_SetUptimeCalendarCompleted);
    106       }
    107       catch (Exception ex)
    108       {
     101      } catch (Exception ex) {
    109102        ManageFatalException("Connection Error, check if Hive Client is running!", "Connection Error", ex);
    110103      }
     
    115108    #region Logging
    116109
    117     private void InitLogFileReader()
    118     {
     110    private void InitLogFileReader() {
    119111      logFileReader = new LogFileReader(Environment.CurrentDirectory + @"/Hive.log");
    120112      logFileReader.MoreData += new LogFileReader.MoreDataHandler(logFileReader_MoreData);
     
    122114    }
    123115
    124     private void logFileReader_MoreData(object sender, string newData)
    125     {
     116    private void logFileReader_MoreData(object sender, string newData) {
    126117      int maxChars = txtLog.MaxLength;
    127       if (newData.Length > maxChars)
    128       {
     118      if (newData.Length > maxChars) {
    129119        newData = newData.Remove(0, newData.Length - maxChars);
    130120      }
    131121      int newLength = this.txtLog.Text.Length + newData.Length;
    132       if (newLength > maxChars)
    133       {
     122      if (newLength > maxChars) {
    134123        RemoveText(newLength, maxChars);
    135124      }
     
    137126    }
    138127
    139     private void RemoveText(int newLength, int maxChars)
    140     {
    141       if (this.txtLog.InvokeRequired)
    142       {
     128    private void RemoveText(int newLength, int maxChars) {
     129      if (this.txtLog.InvokeRequired) {
    143130        this.txtLog.Invoke(new
    144131          RemoveTextDelegate(RemoveText), new object[] { newLength, maxChars });
    145       }
    146       else
    147       {
     132      } else {
    148133        this.txtLog.Text = this.txtLog.Text.Remove(0, newLength - (int)maxChars);
    149134      }
    150135    }
    151136
    152     private void AppendText(string message)
    153     {
    154       if (this.txtLog.InvokeRequired)
    155       {
     137    private void AppendText(string message) {
     138      if (this.txtLog.InvokeRequired) {
    156139        this.txtLog.Invoke(new
    157140          AppendTextDelegate(AppendText), new object[] { message });
    158       }
    159       else
    160       {
     141      } else {
    161142        this.txtLog.AppendText(message);
    162143      }
     
    167148    #region Gui Refresh
    168149
    169     private void InitTimer()
    170     {
     150    private void InitTimer() {
    171151      refreshTimer = new System.Windows.Forms.Timer();
    172152      refreshTimer.Interval = 1000;
     
    175155    }
    176156
    177     private void RefreshGui()
    178     {
    179       try
    180       {
     157    private void RefreshGui() {
     158      try {
    181159        clientCommunicator.GetStatusInfosAsync();
    182       }
    183       catch (Exception ex)
    184       {
     160      } catch (Exception ex) {
    185161        ManageFatalException("Connection Error, check if Hive Client is running!", "Connection Error", ex);
    186162      }
    187163    }
    188164
    189     private void UpdateGraph(StatusCommons sc)
    190     {
     165    private void UpdateGraph(StatusCommons sc) {
    191166      ZedGraphControl zgc = new ZedGraphControl();
    192167      GraphPane myPane = zgc.GraphPane;
     
    208183      double done = 0;
    209184
    210      
     185
    211186      /*if (jobs.Length == 0)
    212187      {
     
    220195        } */
    221196
    222         //done = allProgress / jobs.Length;
    223 
    224       myPane.AddPieSlice((sc.FreeCores / (double) sc.TotalCores), Color.Red, 0, "");
     197      //done = allProgress / jobs.Length;
     198
     199      myPane.AddPieSlice((sc.FreeCores / (double)sc.TotalCores), Color.Red, 0, "");
    225200      myPane.AddPieSlice(((sc.TotalCores - sc.FreeCores) / (double)sc.TotalCores), Color.Green, 0, "");
    226      // }
     201      // }
    227202      //Hides the slice labels
    228203      PieItem.Default.LabelType = PieLabelType.None;
     
    235210    #region Events
    236211
    237     private void refreshTimer_Tick(object sender, EventArgs e)
    238     {
     212    private void refreshTimer_Tick(object sender, EventArgs e) {
    239213      RefreshGui();
    240214    }
     
    247221    #region Calendar stuff
    248222
    249     private void InitCalender()
    250     {
     223    private void InitCalender() {
    251224      dvOnline.StartDate = DateTime.Now;
    252225      dvOnline.OnNewAppointment += new EventHandler<NewAppointmentEventArgs>(dvOnline_OnNewAppointment);
     
    257230    }
    258231
    259     private bool CreateAppointment()
    260     {
     232    private bool CreateAppointment() {
    261233      DateTime from, to;
    262234
    263       if (!string.IsNullOrEmpty(dtpFrom.Text) && !string.IsNullOrEmpty(dtpTo.Text))
    264       {
    265         if (chbade.Checked)
    266         {
     235      if (!string.IsNullOrEmpty(dtpFrom.Text) && !string.IsNullOrEmpty(dtpTo.Text)) {
     236        if (chbade.Checked) {
    267237          //whole day appointment, only dates are visible
    268238          if (DateTime.TryParse(dtpFrom.Text, out from) && DateTime.TryParse(dtpTo.Text, out to) && from <= to)
     
    270240          else
    271241            MessageBox.Show("Incorrect date format", "Schedule Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    272         }
    273         else if (!string.IsNullOrEmpty(txttimeFrom.Text) && !string.IsNullOrEmpty(txttimeTo.Text))
    274         {
     242        } else if (!string.IsNullOrEmpty(txttimeFrom.Text) && !string.IsNullOrEmpty(txttimeTo.Text)) {
    275243          //Timeframe appointment
    276           if (DateTime.TryParse(dtpFrom.Text + " " + txttimeFrom.Text, out from) && DateTime.TryParse(dtpTo.Text + " " + txttimeTo.Text, out to) && from < to)
    277           {
     244          if (DateTime.TryParse(dtpFrom.Text + " " + txttimeFrom.Text, out from) && DateTime.TryParse(dtpTo.Text + " " + txttimeTo.Text, out to) && from < to) {
    278245            if (from.Date == to.Date)
    279246              onlineTimes.Add(CreateAppointment(from, to, false));
    280             else
    281             {
     247            else {
    282248              //more than 1 day selected
    283               while (from.Date != to.Date)
    284               {
     249              while (from.Date != to.Date) {
    285250                onlineTimes.Add(CreateAppointment(from, new DateTime(from.Year, from.Month, from.Day, to.Hour, to.Minute, 0, 0), false));
    286251                from = from.AddDays(1);
     
    288253              onlineTimes.Add(CreateAppointment(from, new DateTime(from.Year, from.Month, from.Day, to.Hour, to.Minute, 0, 0), false));
    289254            }
    290           }
    291           else
     255          } else
    292256            MessageBox.Show("Incorrect date format", "Schedule Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    293257        }
    294258        dvOnline.Invalidate();
    295259        return true;
    296       }
    297       else
    298       {
     260      } else {
    299261        MessageBox.Show("Error in create appointment, please fill out all textboxes!", "Schedule Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    300262        return false;
     
    302264    }
    303265
    304     private Appointment CreateAppointment(DateTime startDate, DateTime endDate, bool allDay)
    305     {
     266    private Appointment CreateAppointment(DateTime startDate, DateTime endDate, bool allDay) {
    306267      Appointment App = new Appointment();
    307268      App.StartDate = startDate;
     
    315276    }
    316277
    317     private Appointment CreateAppointment(DateTime startDate, DateTime endDate, bool allDay, bool recurring, Guid recurringId)
    318     {
     278    private Appointment CreateAppointment(DateTime startDate, DateTime endDate, bool allDay, bool recurring, Guid recurringId) {
    319279      Appointment App = new Appointment();
    320280      App.StartDate = startDate;
     
    329289    }
    330290
    331     private void DeleteAppointment()
    332     {
     291    private void DeleteAppointment() {
    333292      onlineTimes.Remove(dvOnline.SelectedAppointment);
    334293    }
    335294
    336     private void DeleteRecurringAppointment(Guid recurringId)
    337     {
     295    private void DeleteRecurringAppointment(Guid recurringId) {
    338296      onlineTimes.RemoveAll(a => a.RecurringId.ToString() == dvOnline.SelectedAppointment.RecurringId.ToString());
    339297    }
    340298
    341     private void ChangeRecurrenceAppointment(Guid recurringId)
    342     {
     299    private void ChangeRecurrenceAppointment(Guid recurringId) {
    343300      int hourfrom = int.Parse(txttimeFrom.Text.Substring(0, txttimeFrom.Text.IndexOf(':')));
    344301      int hourTo = int.Parse(txttimeTo.Text.Substring(0, txttimeTo.Text.IndexOf(':')));
     
    351308    }
    352309
    353     public void DialogClosed(RecurrentEvent e)
    354     {
     310    public void DialogClosed(RecurrentEvent e) {
    355311      CreateDailyRecurrenceAppointments(e.DateFrom, e.DateTo, e.AllDay, e.IncWeeks, e.WeekDays);
    356312    }
    357313
    358     private void CreateDailyRecurrenceAppointments(DateTime dateFrom, DateTime dateTo, bool allDay, int incWeek, HashSet<DayOfWeek> daysOfWeek)
    359     {
     314    private void CreateDailyRecurrenceAppointments(DateTime dateFrom, DateTime dateTo, bool allDay, int incWeek, HashSet<DayOfWeek> daysOfWeek) {
    360315      DateTime incDate = dateFrom;
    361316      Guid guid = Guid.NewGuid();
    362317
    363       while (incDate.Date <= dateTo.Date)
    364       {
     318      while (incDate.Date <= dateTo.Date) {
    365319        if (daysOfWeek.Contains(incDate.Date.DayOfWeek))
    366320          onlineTimes.Add(CreateAppointment(incDate, new DateTime(incDate.Year, incDate.Month, incDate.Day, dateTo.Hour, dateTo.Minute, 0), allDay, true, guid));
     
    373327    #region Calendar Events
    374328
    375     private void btbDelete_Click(object sender, EventArgs e)
    376     {
     329    private void btbDelete_Click(object sender, EventArgs e) {
    377330      Appointment selectedAppointment = dvOnline.SelectedAppointment;
    378       if (dvOnline.SelectedAppointment != null)
    379       {
     331      if (dvOnline.SelectedAppointment != null) {
    380332        if (!selectedAppointment.Recurring)
    381333          DeleteAppointment();
    382         else
    383         {
     334        else {
    384335          DialogResult res = MessageBox.Show("Delete all events in this series?", "Delete recurrences", MessageBoxButtons.YesNo);
    385336          if (res != DialogResult.Yes)
     
    392343    }
    393344
    394     private void chbade_CheckedChanged(object sender, EventArgs e)
    395     {
     345    private void chbade_CheckedChanged(object sender, EventArgs e) {
    396346      txttimeFrom.Visible = !chbade.Checked;
    397347      txttimeTo.Visible = !chbade.Checked;
    398348    }
    399349
    400     private void dvOnline_OnSelectionChanged(object sender, EventArgs e)
    401     {
     350    private void dvOnline_OnSelectionChanged(object sender, EventArgs e) {
    402351      //btCreate.Enabled = true;
    403       if (dvOnline.Selection == SelectionType.DateRange)
    404       {
     352      if (dvOnline.Selection == SelectionType.DateRange) {
    405353        dtpFrom.Text = dvOnline.SelectionStart.ToShortDateString();
    406354        dtpTo.Text = dvOnline.SelectionEnd.Date.ToShortDateString();
     
    411359      }
    412360
    413       if (dvOnline.Selection == SelectionType.Appointment)
    414       {
     361      if (dvOnline.Selection == SelectionType.Appointment) {
    415362
    416363        dtpFrom.Text = dvOnline.SelectedAppointment.StartDate.ToShortDateString();
     
    425372      }
    426373
    427       if (dvOnline.Selection == SelectionType.None)
    428       {
     374      if (dvOnline.Selection == SelectionType.None) {
    429375        //also change the caption of the save button
    430376        btCreate.Text = "Save";
     
    433379    }
    434380
    435     private void mcOnline_DateChanged(object sender, DateRangeEventArgs e)
    436     {
     381    private void mcOnline_DateChanged(object sender, DateRangeEventArgs e) {
    437382      dvOnline.StartDate = mcOnline.SelectionStart;
    438383    }
    439384
    440     private void btCreate_Click(object sender, EventArgs e)
    441     {
    442       if (dvOnline.Selection != SelectionType.Appointment)
    443       {
     385    private void btCreate_Click(object sender, EventArgs e) {
     386      if (dvOnline.Selection != SelectionType.Appointment) {
    444387        CreateAppointment();
    445       }
    446       else
    447       {
     388      } else {
    448389        //now we want to change an existing appointment
    449         if (!dvOnline.SelectedAppointment.Recurring)
    450         {
     390        if (!dvOnline.SelectedAppointment.Recurring) {
    451391          if (CreateAppointment())
    452392            DeleteAppointment();
    453         }
    454         else
    455         {
     393        } else {
    456394          //change recurring appointment
    457395          //check, if only selected appointment has to change or whole recurrence
    458396          DialogResult res = MessageBox.Show("Change all events in this series?", "Change recurrences", MessageBoxButtons.YesNo);
    459           if (res != DialogResult.Yes)
    460           {
     397          if (res != DialogResult.Yes) {
    461398            if (CreateAppointment())
    462399              DeleteAppointment();
    463           }
    464           else
     400          } else
    465401            ChangeRecurrenceAppointment(dvOnline.SelectedAppointment.RecurringId);
    466402        }
     
    469405    }
    470406
    471     private void btnRecurrence_Click(object sender, EventArgs e)
    472     {
     407    private void btnRecurrence_Click(object sender, EventArgs e) {
    473408      Recurrence recurrence = new Recurrence();
    474409      recurrence.dialogClosedDelegate = new OnDialogClosedDelegate(this.DialogClosed);
     
    476411    }
    477412
    478     private void btnSaveCal_Click(object sender, EventArgs e)
    479     {
     413    private void btnSaveCal_Click(object sender, EventArgs e) {
    480414      clientCommunicator.SetUptimeCalendarAsync(onlineTimes.ToArray());
    481415    }
    482416
    483     private void dvOnline_OnResolveAppointments(object sender, ResolveAppointmentsEventArgs e)
    484     {
     417    private void dvOnline_OnResolveAppointments(object sender, ResolveAppointmentsEventArgs e) {
    485418      List<Appointment> Apps = new List<Appointment>();
    486419
     
    496429    }
    497430
    498     private void dvOnline_OnNewAppointment(object sender, NewAppointmentEventArgs e)
    499     {
     431    private void dvOnline_OnNewAppointment(object sender, NewAppointmentEventArgs e) {
    500432      Appointment Appointment = new Appointment();
    501433
     
    512444    #region Client communicator events
    513445
    514     void clientCommunicator_SetUptimeCalendarCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
    515     {
    516       if (e.Error == null)
    517       {
     446    void clientCommunicator_SetUptimeCalendarCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) {
     447      if (e.Error == null) {
    518448        MessageBox.Show("Calendar successfully saved!", "Calender", MessageBoxButtons.OK, MessageBoxIcon.Information);
    519       }
    520       else
    521       {
     449      } else {
    522450        MessageBox.Show("Error saving calender \n" + e.Error.ToString(), "Calender", MessageBoxButtons.OK, MessageBoxIcon.Error);
    523451      }
    524452    }
    525453
    526     void clientCommunicator_GetUptimeCalendarCompleted(object sender, GetUptimeCalendarCompletedEventArgs e)
    527     {
    528       if (e.Error == null)
    529       {
    530         if (e.Result != null)
    531         {
     454    void clientCommunicator_GetUptimeCalendarCompleted(object sender, GetUptimeCalendarCompletedEventArgs e) {
     455      if (e.Error == null) {
     456        if (e.Result != null) {
    532457          onlineTimes = e.Result.ToList<Appointment>();
    533458          onlineTimes.ForEach(a => a.BorderColor = Color.Red);
    534459          dvOnline.Invalidate();
    535460
    536         }
    537         else
    538         {
     461        } else {
    539462          onlineTimes = new List<Appointment>();
    540463        }
     
    542465    }
    543466
    544     private void clientCommunicator_GetCurrentConnectionCompleted(object sender, GetCurrentConnectionCompletedEventArgs e)
    545     {
    546       if (e.Error == null)
    547       {
     467    private void clientCommunicator_GetCurrentConnectionCompleted(object sender, GetCurrentConnectionCompletedEventArgs e) {
     468      if (e.Error == null) {
    548469        ConnectionContainer curConnection = e.Result;
    549470        tbIPAdress.Text = curConnection.IPAdress;
    550471        tbPort.Text = curConnection.Port.ToString();
    551       }
    552       else
    553       {
     472      } else {
    554473        ManageFatalException("Connection Error, check if Hive Client is running!", "Connection Error", null);
    555474      }
    556475    }
    557476
    558     private void clientCommunicator_GetStatusInfosCompleted(object sender, GetStatusInfosCompletedEventArgs e)
    559     {
    560       if (e.Error == null)
    561       {
     477    private void clientCommunicator_GetStatusInfosCompleted(object sender, GetStatusInfosCompletedEventArgs e) {
     478      if (e.Error == null) {
    562479        StatusCommons sc = e.Result;
    563480
     
    572489        ListViewItem curJobStatusItem;
    573490
    574         if (sc.Jobs != null)
    575         {
     491        if (sc.Jobs != null) {
    576492          lvJobDetail.Items.Clear();
    577493          double progress;
    578           foreach (JobStatus curJob in sc.Jobs)
    579           {
     494          foreach (JobStatus curJob in sc.Jobs) {
    580495            curJobStatusItem = new ListViewItem(curJob.JobId.ToString());
    581496            curJobStatusItem.SubItems.Add(curJob.Since.ToString());
     
    589504        UpdateGraph(sc);
    590505
    591         if (sc.Status == NetworkEnumWcfConnState.Connected || sc.Status == NetworkEnumWcfConnState.Loggedin)
    592         {
     506        if (sc.Status == NetworkEnumWcfConnState.Connected || sc.Status == NetworkEnumWcfConnState.Loggedin) {
    593507          btConnect.Enabled = false;
    594508          btnDisconnect.Enabled = true;
    595509          lbCs.Text = sc.ConnectedSince.ToString();
    596510          clientCommunicator.GetCurrentConnectionAsync();
    597         }
    598         else if (sc.Status == NetworkEnumWcfConnState.Disconnected)
    599         {
     511        } else if (sc.Status == NetworkEnumWcfConnState.Disconnected) {
     512          btConnect.Enabled = true;
     513          btnDisconnect.Enabled = false;
     514          lbCs.Text = String.Empty;
     515        } else if (sc.Status == NetworkEnumWcfConnState.Failed) {
    600516          btConnect.Enabled = true;
    601517          btnDisconnect.Enabled = false;
    602518          lbCs.Text = String.Empty;
    603519        }
    604         else if (sc.Status == NetworkEnumWcfConnState.Failed)
    605         {
    606           btConnect.Enabled = true;
    607           btnDisconnect.Enabled = false;
    608           lbCs.Text = String.Empty;
    609         }
    610520
    611521        clientCommunicator.GetCurrentConnection();
    612       }
    613       else
    614       {
     522      } else {
    615523        ManageFatalException("Connection Error, check if Hive Client is running!", "Connection Error", null);
    616524      }
     
    620528
    621529    #region Exception
    622     private void ManageFatalException(string body, string caption, Exception e)
    623     {
    624       if (!isfired)
    625       {
     530    private void ManageFatalException(string body, string caption, Exception e) {
     531      if (!isfired) {
    626532        isfired = true;
    627533        refreshTimer.Stop();
     
    638544    #region GUI Events
    639545
    640     private void btConnect_Click(object sender, EventArgs e)
    641     {
     546    private void btConnect_Click(object sender, EventArgs e) {
    642547      IPAddress ipAdress;
    643548      int port;
    644549      ConnectionContainer cc = new ConnectionContainer();
    645       if (IPAddress.TryParse(tbIPAdress.Text, out ipAdress) && int.TryParse(tbPort.Text, out port))
    646       {
     550      if (IPAddress.TryParse(tbIPAdress.Text, out ipAdress) && int.TryParse(tbPort.Text, out port)) {
    647551        cc.IPAdress = tbIPAdress.Text;
    648552        cc.Port = port;
    649553        clientCommunicator.SetConnectionAsync(cc);
    650       }
    651       else
    652       {
     554      } else {
    653555        MessageBox.Show("IP Adress and/or Port Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    654556      }
    655557    }
    656558
    657     private void btnDisconnect_Click(object sender, EventArgs e)
    658     {
     559    private void btnDisconnect_Click(object sender, EventArgs e) {
    659560      clientCommunicator.DisconnectAsync();
    660561    }
    661562
    662     private void btn_clientShutdown_Click(object sender, EventArgs e)
    663     {
     563    private void btn_clientShutdown_Click(object sender, EventArgs e) {
    664564      DialogResult res = MessageBox.Show("Do you really want to shutdown the Hive Client?", "Hive Client Console", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
    665       if (res == DialogResult.Yes)
    666       {
     565      if (res == DialogResult.Yes) {
    667566        logFileReader.Stop();
    668567        clientCommunicator.ShutdownClient();
     
    671570    }
    672571
    673     private void Connection_KeyPress(object sender, KeyPressEventArgs e)
    674     {
     572    private void Connection_KeyPress(object sender, KeyPressEventArgs e) {
    675573      if (e.KeyChar == (char)Keys.Return)
    676574        btConnect_Click(null, null);
Note: See TracChangeset for help on using the changeset viewer.