Changeset 4107 for branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Client.Console/3.3/HiveClientConsole.cs
- Timestamp:
- 07/26/10 18:17:16 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Client.Console/3.3/HiveClientConsole.cs
r3931 r4107 28 28 using System.ServiceModel; 29 29 using System.Windows.Forms; 30 using Calendar;30 using HeuristicLab.Calendar; 31 31 using HeuristicLab.Hive.Client.Console.ClientService; 32 32 using ZedGraph; … … 35 35 using System.IO; 36 36 37 namespace HeuristicLab.Hive.Client.Console 38 { 37 namespace HeuristicLab.Hive.Client.Console { 39 38 40 39 #region Delegates … … 51 50 #endregion 52 51 53 public partial class HiveClientConsole : Form 54 { 52 public partial class HiveClientConsole : Form { 55 53 56 54 #region Declarations … … 79 77 #region Constructor 80 78 81 public HiveClientConsole() 82 { 79 public HiveClientConsole() { 83 80 InitializeComponent(); 84 81 InitTimer(); … … 95 92 #region Client connection 96 93 97 private void ConnectToClient() 98 { 99 try 100 { 94 private void ConnectToClient() { 95 try { 101 96 clientCommunicator = new ClientConsoleCommunicatorClient(WcfSettings.GetBinding(), new EndpointAddress(ENDPOINTADRESS)); 102 97 clientCommunicator.GetStatusInfosCompleted += new EventHandler<GetStatusInfosCompletedEventArgs>(clientCommunicator_GetStatusInfosCompleted); … … 104 99 clientCommunicator.GetUptimeCalendarCompleted += new EventHandler<GetUptimeCalendarCompletedEventArgs>(clientCommunicator_GetUptimeCalendarCompleted); 105 100 clientCommunicator.SetUptimeCalendarCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(clientCommunicator_SetUptimeCalendarCompleted); 106 } 107 catch (Exception ex) 108 { 101 } catch (Exception ex) { 109 102 ManageFatalException("Connection Error, check if Hive Client is running!", "Connection Error", ex); 110 103 } … … 115 108 #region Logging 116 109 117 private void InitLogFileReader() 118 { 110 private void InitLogFileReader() { 119 111 logFileReader = new LogFileReader(Environment.CurrentDirectory + @"/Hive.log"); 120 112 logFileReader.MoreData += new LogFileReader.MoreDataHandler(logFileReader_MoreData); … … 122 114 } 123 115 124 private void logFileReader_MoreData(object sender, string newData) 125 { 116 private void logFileReader_MoreData(object sender, string newData) { 126 117 int maxChars = txtLog.MaxLength; 127 if (newData.Length > maxChars) 128 { 118 if (newData.Length > maxChars) { 129 119 newData = newData.Remove(0, newData.Length - maxChars); 130 120 } 131 121 int newLength = this.txtLog.Text.Length + newData.Length; 132 if (newLength > maxChars) 133 { 122 if (newLength > maxChars) { 134 123 RemoveText(newLength, maxChars); 135 124 } … … 137 126 } 138 127 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) { 143 130 this.txtLog.Invoke(new 144 131 RemoveTextDelegate(RemoveText), new object[] { newLength, maxChars }); 145 } 146 else 147 { 132 } else { 148 133 this.txtLog.Text = this.txtLog.Text.Remove(0, newLength - (int)maxChars); 149 134 } 150 135 } 151 136 152 private void AppendText(string message) 153 { 154 if (this.txtLog.InvokeRequired) 155 { 137 private void AppendText(string message) { 138 if (this.txtLog.InvokeRequired) { 156 139 this.txtLog.Invoke(new 157 140 AppendTextDelegate(AppendText), new object[] { message }); 158 } 159 else 160 { 141 } else { 161 142 this.txtLog.AppendText(message); 162 143 } … … 167 148 #region Gui Refresh 168 149 169 private void InitTimer() 170 { 150 private void InitTimer() { 171 151 refreshTimer = new System.Windows.Forms.Timer(); 172 152 refreshTimer.Interval = 1000; … … 175 155 } 176 156 177 private void RefreshGui() 178 { 179 try 180 { 157 private void RefreshGui() { 158 try { 181 159 clientCommunicator.GetStatusInfosAsync(); 182 } 183 catch (Exception ex) 184 { 160 } catch (Exception ex) { 185 161 ManageFatalException("Connection Error, check if Hive Client is running!", "Connection Error", ex); 186 162 } 187 163 } 188 164 189 private void UpdateGraph(StatusCommons sc) 190 { 165 private void UpdateGraph(StatusCommons sc) { 191 166 ZedGraphControl zgc = new ZedGraphControl(); 192 167 GraphPane myPane = zgc.GraphPane; … … 208 183 double done = 0; 209 184 210 185 211 186 /*if (jobs.Length == 0) 212 187 { … … 220 195 } */ 221 196 222 223 224 myPane.AddPieSlice((sc.FreeCores / (double) 197 //done = allProgress / jobs.Length; 198 199 myPane.AddPieSlice((sc.FreeCores / (double)sc.TotalCores), Color.Red, 0, ""); 225 200 myPane.AddPieSlice(((sc.TotalCores - sc.FreeCores) / (double)sc.TotalCores), Color.Green, 0, ""); 226 // }201 // } 227 202 //Hides the slice labels 228 203 PieItem.Default.LabelType = PieLabelType.None; … … 235 210 #region Events 236 211 237 private void refreshTimer_Tick(object sender, EventArgs e) 238 { 212 private void refreshTimer_Tick(object sender, EventArgs e) { 239 213 RefreshGui(); 240 214 } … … 247 221 #region Calendar stuff 248 222 249 private void InitCalender() 250 { 223 private void InitCalender() { 251 224 dvOnline.StartDate = DateTime.Now; 252 225 dvOnline.OnNewAppointment += new EventHandler<NewAppointmentEventArgs>(dvOnline_OnNewAppointment); … … 257 230 } 258 231 259 private bool CreateAppointment() 260 { 232 private bool CreateAppointment() { 261 233 DateTime from, to; 262 234 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) { 267 237 //whole day appointment, only dates are visible 268 238 if (DateTime.TryParse(dtpFrom.Text, out from) && DateTime.TryParse(dtpTo.Text, out to) && from <= to) … … 270 240 else 271 241 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)) { 275 243 //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) { 278 245 if (from.Date == to.Date) 279 246 onlineTimes.Add(CreateAppointment(from, to, false)); 280 else 281 { 247 else { 282 248 //more than 1 day selected 283 while (from.Date != to.Date) 284 { 249 while (from.Date != to.Date) { 285 250 onlineTimes.Add(CreateAppointment(from, new DateTime(from.Year, from.Month, from.Day, to.Hour, to.Minute, 0, 0), false)); 286 251 from = from.AddDays(1); … … 288 253 onlineTimes.Add(CreateAppointment(from, new DateTime(from.Year, from.Month, from.Day, to.Hour, to.Minute, 0, 0), false)); 289 254 } 290 } 291 else 255 } else 292 256 MessageBox.Show("Incorrect date format", "Schedule Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 293 257 } 294 258 dvOnline.Invalidate(); 295 259 return true; 296 } 297 else 298 { 260 } else { 299 261 MessageBox.Show("Error in create appointment, please fill out all textboxes!", "Schedule Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 300 262 return false; … … 302 264 } 303 265 304 private Appointment CreateAppointment(DateTime startDate, DateTime endDate, bool allDay) 305 { 266 private Appointment CreateAppointment(DateTime startDate, DateTime endDate, bool allDay) { 306 267 Appointment App = new Appointment(); 307 268 App.StartDate = startDate; … … 315 276 } 316 277 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) { 319 279 Appointment App = new Appointment(); 320 280 App.StartDate = startDate; … … 329 289 } 330 290 331 private void DeleteAppointment() 332 { 291 private void DeleteAppointment() { 333 292 onlineTimes.Remove(dvOnline.SelectedAppointment); 334 293 } 335 294 336 private void DeleteRecurringAppointment(Guid recurringId) 337 { 295 private void DeleteRecurringAppointment(Guid recurringId) { 338 296 onlineTimes.RemoveAll(a => a.RecurringId.ToString() == dvOnline.SelectedAppointment.RecurringId.ToString()); 339 297 } 340 298 341 private void ChangeRecurrenceAppointment(Guid recurringId) 342 { 299 private void ChangeRecurrenceAppointment(Guid recurringId) { 343 300 int hourfrom = int.Parse(txttimeFrom.Text.Substring(0, txttimeFrom.Text.IndexOf(':'))); 344 301 int hourTo = int.Parse(txttimeTo.Text.Substring(0, txttimeTo.Text.IndexOf(':'))); … … 351 308 } 352 309 353 public void DialogClosed(RecurrentEvent e) 354 { 310 public void DialogClosed(RecurrentEvent e) { 355 311 CreateDailyRecurrenceAppointments(e.DateFrom, e.DateTo, e.AllDay, e.IncWeeks, e.WeekDays); 356 312 } 357 313 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) { 360 315 DateTime incDate = dateFrom; 361 316 Guid guid = Guid.NewGuid(); 362 317 363 while (incDate.Date <= dateTo.Date) 364 { 318 while (incDate.Date <= dateTo.Date) { 365 319 if (daysOfWeek.Contains(incDate.Date.DayOfWeek)) 366 320 onlineTimes.Add(CreateAppointment(incDate, new DateTime(incDate.Year, incDate.Month, incDate.Day, dateTo.Hour, dateTo.Minute, 0), allDay, true, guid)); … … 373 327 #region Calendar Events 374 328 375 private void btbDelete_Click(object sender, EventArgs e) 376 { 329 private void btbDelete_Click(object sender, EventArgs e) { 377 330 Appointment selectedAppointment = dvOnline.SelectedAppointment; 378 if (dvOnline.SelectedAppointment != null) 379 { 331 if (dvOnline.SelectedAppointment != null) { 380 332 if (!selectedAppointment.Recurring) 381 333 DeleteAppointment(); 382 else 383 { 334 else { 384 335 DialogResult res = MessageBox.Show("Delete all events in this series?", "Delete recurrences", MessageBoxButtons.YesNo); 385 336 if (res != DialogResult.Yes) … … 392 343 } 393 344 394 private void chbade_CheckedChanged(object sender, EventArgs e) 395 { 345 private void chbade_CheckedChanged(object sender, EventArgs e) { 396 346 txttimeFrom.Visible = !chbade.Checked; 397 347 txttimeTo.Visible = !chbade.Checked; 398 348 } 399 349 400 private void dvOnline_OnSelectionChanged(object sender, EventArgs e) 401 { 350 private void dvOnline_OnSelectionChanged(object sender, EventArgs e) { 402 351 //btCreate.Enabled = true; 403 if (dvOnline.Selection == SelectionType.DateRange) 404 { 352 if (dvOnline.Selection == SelectionType.DateRange) { 405 353 dtpFrom.Text = dvOnline.SelectionStart.ToShortDateString(); 406 354 dtpTo.Text = dvOnline.SelectionEnd.Date.ToShortDateString(); … … 411 359 } 412 360 413 if (dvOnline.Selection == SelectionType.Appointment) 414 { 361 if (dvOnline.Selection == SelectionType.Appointment) { 415 362 416 363 dtpFrom.Text = dvOnline.SelectedAppointment.StartDate.ToShortDateString(); … … 425 372 } 426 373 427 if (dvOnline.Selection == SelectionType.None) 428 { 374 if (dvOnline.Selection == SelectionType.None) { 429 375 //also change the caption of the save button 430 376 btCreate.Text = "Save"; … … 433 379 } 434 380 435 private void mcOnline_DateChanged(object sender, DateRangeEventArgs e) 436 { 381 private void mcOnline_DateChanged(object sender, DateRangeEventArgs e) { 437 382 dvOnline.StartDate = mcOnline.SelectionStart; 438 383 } 439 384 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) { 444 387 CreateAppointment(); 445 } 446 else 447 { 388 } else { 448 389 //now we want to change an existing appointment 449 if (!dvOnline.SelectedAppointment.Recurring) 450 { 390 if (!dvOnline.SelectedAppointment.Recurring) { 451 391 if (CreateAppointment()) 452 392 DeleteAppointment(); 453 } 454 else 455 { 393 } else { 456 394 //change recurring appointment 457 395 //check, if only selected appointment has to change or whole recurrence 458 396 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) { 461 398 if (CreateAppointment()) 462 399 DeleteAppointment(); 463 } 464 else 400 } else 465 401 ChangeRecurrenceAppointment(dvOnline.SelectedAppointment.RecurringId); 466 402 } … … 469 405 } 470 406 471 private void btnRecurrence_Click(object sender, EventArgs e) 472 { 407 private void btnRecurrence_Click(object sender, EventArgs e) { 473 408 Recurrence recurrence = new Recurrence(); 474 409 recurrence.dialogClosedDelegate = new OnDialogClosedDelegate(this.DialogClosed); … … 476 411 } 477 412 478 private void btnSaveCal_Click(object sender, EventArgs e) 479 { 413 private void btnSaveCal_Click(object sender, EventArgs e) { 480 414 clientCommunicator.SetUptimeCalendarAsync(onlineTimes.ToArray()); 481 415 } 482 416 483 private void dvOnline_OnResolveAppointments(object sender, ResolveAppointmentsEventArgs e) 484 { 417 private void dvOnline_OnResolveAppointments(object sender, ResolveAppointmentsEventArgs e) { 485 418 List<Appointment> Apps = new List<Appointment>(); 486 419 … … 496 429 } 497 430 498 private void dvOnline_OnNewAppointment(object sender, NewAppointmentEventArgs e) 499 { 431 private void dvOnline_OnNewAppointment(object sender, NewAppointmentEventArgs e) { 500 432 Appointment Appointment = new Appointment(); 501 433 … … 512 444 #region Client communicator events 513 445 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) { 518 448 MessageBox.Show("Calendar successfully saved!", "Calender", MessageBoxButtons.OK, MessageBoxIcon.Information); 519 } 520 else 521 { 449 } else { 522 450 MessageBox.Show("Error saving calender \n" + e.Error.ToString(), "Calender", MessageBoxButtons.OK, MessageBoxIcon.Error); 523 451 } 524 452 } 525 453 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) { 532 457 onlineTimes = e.Result.ToList<Appointment>(); 533 458 onlineTimes.ForEach(a => a.BorderColor = Color.Red); 534 459 dvOnline.Invalidate(); 535 460 536 } 537 else 538 { 461 } else { 539 462 onlineTimes = new List<Appointment>(); 540 463 } … … 542 465 } 543 466 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) { 548 469 ConnectionContainer curConnection = e.Result; 549 470 tbIPAdress.Text = curConnection.IPAdress; 550 471 tbPort.Text = curConnection.Port.ToString(); 551 } 552 else 553 { 472 } else { 554 473 ManageFatalException("Connection Error, check if Hive Client is running!", "Connection Error", null); 555 474 } 556 475 } 557 476 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) { 562 479 StatusCommons sc = e.Result; 563 480 … … 572 489 ListViewItem curJobStatusItem; 573 490 574 if (sc.Jobs != null) 575 { 491 if (sc.Jobs != null) { 576 492 lvJobDetail.Items.Clear(); 577 493 double progress; 578 foreach (JobStatus curJob in sc.Jobs) 579 { 494 foreach (JobStatus curJob in sc.Jobs) { 580 495 curJobStatusItem = new ListViewItem(curJob.JobId.ToString()); 581 496 curJobStatusItem.SubItems.Add(curJob.Since.ToString()); … … 589 504 UpdateGraph(sc); 590 505 591 if (sc.Status == NetworkEnumWcfConnState.Connected || sc.Status == NetworkEnumWcfConnState.Loggedin) 592 { 506 if (sc.Status == NetworkEnumWcfConnState.Connected || sc.Status == NetworkEnumWcfConnState.Loggedin) { 593 507 btConnect.Enabled = false; 594 508 btnDisconnect.Enabled = true; 595 509 lbCs.Text = sc.ConnectedSince.ToString(); 596 510 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) { 600 516 btConnect.Enabled = true; 601 517 btnDisconnect.Enabled = false; 602 518 lbCs.Text = String.Empty; 603 519 } 604 else if (sc.Status == NetworkEnumWcfConnState.Failed)605 {606 btConnect.Enabled = true;607 btnDisconnect.Enabled = false;608 lbCs.Text = String.Empty;609 }610 520 611 521 clientCommunicator.GetCurrentConnection(); 612 } 613 else 614 { 522 } else { 615 523 ManageFatalException("Connection Error, check if Hive Client is running!", "Connection Error", null); 616 524 } … … 620 528 621 529 #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) { 626 532 isfired = true; 627 533 refreshTimer.Stop(); … … 638 544 #region GUI Events 639 545 640 private void btConnect_Click(object sender, EventArgs e) 641 { 546 private void btConnect_Click(object sender, EventArgs e) { 642 547 IPAddress ipAdress; 643 548 int port; 644 549 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)) { 647 551 cc.IPAdress = tbIPAdress.Text; 648 552 cc.Port = port; 649 553 clientCommunicator.SetConnectionAsync(cc); 650 } 651 else 652 { 554 } else { 653 555 MessageBox.Show("IP Adress and/or Port Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 654 556 } 655 557 } 656 558 657 private void btnDisconnect_Click(object sender, EventArgs e) 658 { 559 private void btnDisconnect_Click(object sender, EventArgs e) { 659 560 clientCommunicator.DisconnectAsync(); 660 561 } 661 562 662 private void btn_clientShutdown_Click(object sender, EventArgs e) 663 { 563 private void btn_clientShutdown_Click(object sender, EventArgs e) { 664 564 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) { 667 566 logFileReader.Stop(); 668 567 clientCommunicator.ShutdownClient(); … … 671 570 } 672 571 673 private void Connection_KeyPress(object sender, KeyPressEventArgs e) 674 { 572 private void Connection_KeyPress(object sender, KeyPressEventArgs e) { 675 573 if (e.KeyChar == (char)Keys.Return) 676 574 btConnect_Click(null, null);
Note: See TracChangeset
for help on using the changeset viewer.