- Timestamp:
- 06/18/09 17:04:22 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Hive.Client.Console/3.2/HiveClientConsole.cs
r2024 r2062 39 39 40 40 #region Delegates 41 41 42 //delegate to write text in the textbox from another process 42 43 public delegate void AppendTextDelegate(String message); 44 45 //delegate to remove text in the textbox from another process 43 46 public delegate void RemoveTextDelegate(int newLength, int maxChars); 47 48 //delegate fired, if a dialog is being closed 44 49 public delegate void OnDialogClosedDelegate(RecurrentEvent e); 45 50 … … 52 57 53 58 private const string ENDPOINTADRESS = "net.tcp://127.0.0.1:8000/ClientConsole/ClientConsoleCommunicator"; 54 //private const string EVENTLOGNAME = "Hive Client"; 55 56 //private EventLog HiveClientEventLog; 59 60 //the logfilereader 57 61 private LogFileReader logFileReader; 58 private ClientConsoleCommunicatorClient cccc; 62 63 //communication with the client 64 private ClientConsoleCommunicatorClient clientCommunicator; 65 66 //the timer for refreshing the gui 59 67 private System.Windows.Forms.Timer refreshTimer; 60 //private ListViewColumnSorterDate lvwColumnSorter; 61 68 69 //the list of appointments in the calender 62 70 [XmlArray("Appointments")] 63 71 [XmlArrayItem("Appointment", typeof(Appointment))] … … 80 88 } 81 89 82 private void InitTestCalenderEntries()83 {84 DateTime date = DateTime.Now;85 while (date.Year == 2009)86 {87 88 onlineTimes.Add(CreateAppointment(date.AddHours(1), date.AddHours(3), false));89 date = date.AddDays(1);90 }91 }92 93 90 #endregion 94 91 95 92 #region Methods 93 94 #region Client connection 95 96 private void ConnectToClient() 97 { 98 try 99 { 100 clientCommunicator = new ClientConsoleCommunicatorClient(WcfSettings.GetBinding(), new EndpointAddress(ENDPOINTADRESS)); 101 clientCommunicator.GetStatusInfosCompleted += new EventHandler<GetStatusInfosCompletedEventArgs>(clientCommunicator_GetStatusInfosCompleted); 102 clientCommunicator.GetCurrentConnectionCompleted += new EventHandler<GetCurrentConnectionCompletedEventArgs>(clientCommunicator_GetCurrentConnectionCompleted); 103 clientCommunicator.GetUptimeCalendarCompleted += new EventHandler<GetUptimeCalendarCompletedEventArgs>(clientCommunicator_GetUptimeCalendarCompleted); 104 clientCommunicator.SetUptimeCalendarCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(clientCommunicator_SetUptimeCalendarCompleted); 105 } 106 catch (Exception) 107 { 108 refreshTimer.Stop(); 109 DialogResult res = MessageBox.Show("Connection Error, check if Hive Client is running!", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 110 if (res == DialogResult.OK) 111 this.Close(); 112 } 113 } 114 115 #endregion 116 117 #region Logging 96 118 97 119 private void InitLogFileReader() … … 129 151 } 130 152 } 153 154 private void AppendText(string message) 155 { 156 if (this.txtLog.InvokeRequired) 157 { 158 this.txtLog.Invoke(new 159 AppendTextDelegate(AppendText), new object[] { message }); 160 } 161 else 162 { 163 this.txtLog.AppendText(message); 164 } 165 } 166 167 #endregion 168 169 #region Gui Refresh 131 170 132 171 private void InitTimer() … … 142 181 try 143 182 { 144 c ccc.GetStatusInfosAsync();183 clientCommunicator.GetStatusInfosAsync(); 145 184 } 146 185 catch (Exception ex) 147 186 { 148 187 refreshTimer.Stop(); 149 DialogResult res = MessageBox.Show("Connection Error, check if Hive Client is running!" , "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);188 DialogResult res = MessageBox.Show("Connection Error, check if Hive Client is running!" + ex.Message, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 150 189 if (res == DialogResult.OK) 151 190 this.Close(); 152 191 } 153 }154 155 private void ConnectToClient()156 {157 try158 {159 //changed by MB, 16.04.09160 //cccc = new ClientConsoleCommunicatorClient(new NetTcpBinding(), new EndpointAddress(ENDPOINTADRESS));161 cccc = new ClientConsoleCommunicatorClient(WcfSettings.GetBinding(), new EndpointAddress(ENDPOINTADRESS));162 cccc.GetStatusInfosCompleted += new EventHandler<GetStatusInfosCompletedEventArgs>(cccc_GetStatusInfosCompleted);163 cccc.GetCurrentConnectionCompleted += new EventHandler<GetCurrentConnectionCompletedEventArgs>(cccc_GetCurrentConnectionCompleted);164 cccc.GetUptimeCalendarCompleted += new EventHandler<GetUptimeCalendarCompletedEventArgs>(cccc_GetUptimeCalendarCompleted);165 cccc.SetUptimeCalendarCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(cccc_SetUptimeCalendarCompleted);166 }167 catch (Exception)168 {169 refreshTimer.Stop();170 DialogResult res = MessageBox.Show("Connection Error, check if Hive Client is running!", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);171 if (res == DialogResult.OK)172 this.Close();173 }174 }175 176 void cccc_SetUptimeCalendarCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)177 {178 if (e.Error == null)179 {180 MessageBox.Show("Calendar successfully saved!", "Calender", MessageBoxButtons.OK, MessageBoxIcon.Information);181 }182 else183 {184 MessageBox.Show("Error saving calender \n" + e.Error.ToString(), "Calender", MessageBoxButtons.OK, MessageBoxIcon.Error);185 }186 }187 188 void cccc_GetUptimeCalendarCompleted(object sender, GetUptimeCalendarCompletedEventArgs e)189 {190 if (e.Error == null)191 {192 if (e.Result != null)193 {194 onlineTimes = e.Result.ToList<Appointment>();195 onlineTimes.ForEach(a => a.BorderColor = Color.Red);196 }197 else198 {199 onlineTimes = new List<Appointment>();200 }201 }202 //InitTestCalenderEntries();203 192 } 204 193 … … 248 237 } 249 238 239 #region Events 240 241 private void refreshTimer_Tick(object sender, EventArgs e) 242 { 243 RefreshGui(); 244 } 245 246 #endregion 247 248 249 #endregion 250 251 #region Calendar stuff 252 250 253 private void InitCalender() 251 254 { 252 255 dvOnline.StartDate = DateTime.Now; 253 dvOnline.OnNewAppointment += new EventHandler<NewAppointmentEventArgs>( DvOnline_OnNewAppointment);254 dvOnline.OnResolveAppointments += new EventHandler<ResolveAppointmentsEventArgs>( DvOnline_OnResolveAppointments);256 dvOnline.OnNewAppointment += new EventHandler<NewAppointmentEventArgs>(dvOnline_OnNewAppointment); 257 dvOnline.OnResolveAppointments += new EventHandler<ResolveAppointmentsEventArgs>(dvOnline_OnResolveAppointments); 255 258 256 259 //get calender from client 257 cccc.GetUptimeCalendarAsync(); 258 } 259 260 private Appointment CreateAppointment(DateTime startDate, DateTime endDate, bool allDay) 261 { 262 Appointment App = new Appointment(); 263 App.StartDate = startDate; 264 App.EndDate = endDate; 265 App.AllDayEvent = allDay; 266 App.BorderColor = Color.Red; 267 App.Locked = true; 268 App.Subject = "Online"; 269 App.Recurring = false; 270 return App; 271 } 272 273 private Appointment CreateAppointment(DateTime startDate, DateTime endDate, bool allDay, bool recurring, Guid recurringId) 274 { 275 Appointment App = new Appointment(); 276 App.StartDate = startDate; 277 App.EndDate = endDate; 278 App.AllDayEvent = allDay; 279 App.BorderColor = Color.Red; 280 App.Locked = true; 281 App.Subject = "Online"; 282 App.Recurring = recurring; 283 App.RecurringId = recurringId; 284 return App; 285 } 286 287 private void DeleteAppointment() 288 { 289 onlineTimes.Remove(dvOnline.SelectedAppointment); 290 } 291 292 private void DeleteRecurringAppointment(Guid recurringId) 293 { 294 onlineTimes.RemoveAll(a => a.RecurringId.ToString() == dvOnline.SelectedAppointment.RecurringId.ToString()); 295 } 296 297 #endregion 298 299 #region Events 300 301 private void refreshTimer_Tick(object sender, EventArgs e) 302 { 303 RefreshGui(); 304 } 305 306 private void cccc_GetCurrentConnectionCompleted(object sender, GetCurrentConnectionCompletedEventArgs e) 307 { 308 if (e.Error == null) 309 { 310 ConnectionContainer curConnection = e.Result; 311 tbIPAdress.Text = curConnection.IPAdress; 312 tbPort.Text = curConnection.Port.ToString(); 313 } 314 else 315 { 316 refreshTimer.Stop(); 317 DialogResult res = MessageBox.Show("Connection Error, check if Hive Client is running! - " + e.Error.Message, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 318 if (res == DialogResult.OK) 319 this.Close(); 320 } 321 } 322 323 private void cccc_GetStatusInfosCompleted(object sender, GetStatusInfosCompletedEventArgs e) 324 { 325 326 if (e.Error == null) 327 { 328 StatusCommons sc = e.Result; 329 330 lbGuid.Text = sc.ClientGuid.ToString(); 331 lbConnectionStatus.Text = sc.Status.ToString(); 332 lbJobdone.Text = sc.JobsDone.ToString(); 333 lbJobsAborted.Text = sc.JobsAborted.ToString(); 334 lbJobsFetched.Text = sc.JobsFetched.ToString(); 335 336 this.Text = "Client Console (" + sc.Status.ToString() + ")"; 337 338 ListViewItem curJobStatusItem; 339 340 if (sc.Jobs != null) 341 { 342 lvJobDetail.Items.Clear(); 343 double progress; 344 foreach (JobStatus curJob in sc.Jobs) 345 { 346 curJobStatusItem = new ListViewItem(curJob.JobId.ToString()); 347 curJobStatusItem.SubItems.Add(curJob.Since.ToString()); 348 progress = curJob.Progress * 100; 349 curJobStatusItem.SubItems.Add(progress.ToString()); 350 lvJobDetail.Items.Add(curJobStatusItem); 351 } 352 lvJobDetail.Sort(); 353 } 354 355 UpdateGraph(sc.Jobs); 356 357 if (sc.Status == NetworkEnumWcfConnState.Connected || sc.Status == NetworkEnumWcfConnState.Loggedin) 358 { 359 btConnect.Enabled = false; 360 btnDisconnect.Enabled = true; 361 lbCs.Text = sc.ConnectedSince.ToString(); 362 cccc.GetCurrentConnectionAsync(); 363 } 364 else if (sc.Status == NetworkEnumWcfConnState.Disconnected) 365 { 366 btConnect.Enabled = true; 367 btnDisconnect.Enabled = false; 368 lbCs.Text = String.Empty; 369 } 370 else if (sc.Status == NetworkEnumWcfConnState.Failed) 371 { 372 btConnect.Enabled = true; 373 btnDisconnect.Enabled = false; 374 lbCs.Text = String.Empty; 375 } 376 377 cccc.GetCurrentConnection(); 378 } 379 else 380 { 381 refreshTimer.Stop(); 382 DialogResult res = MessageBox.Show("Connection Error, check if Hive Client is running! - " + e.Error.Message, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 383 if (res == DialogResult.OK) 384 this.Close(); 385 } 386 } 387 388 private void HiveClientConsole_Load(object sender, EventArgs e) 389 { 390 //nothing to do 391 } 392 393 private void AppendText(string message) 394 { 395 if (this.txtLog.InvokeRequired) 396 { 397 this.txtLog.Invoke(new 398 AppendTextDelegate(AppendText), new object[] { message }); 399 } 400 else 401 { 402 this.txtLog.AppendText(message); 403 } 404 } 405 406 private void btConnect_Click(object sender, EventArgs e) 407 { 408 IPAddress ipAdress; 409 int port; 410 ConnectionContainer cc = new ConnectionContainer(); 411 if (IPAddress.TryParse(tbIPAdress.Text, out ipAdress) && int.TryParse(tbPort.Text, out port)) 412 { 413 cc.IPAdress = tbIPAdress.Text; 414 cc.Port = port; 415 cccc.SetConnectionAsync(cc); 416 } 417 else 418 { 419 MessageBox.Show("IP Adress and/or Port Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 420 } 421 } 422 423 private void btnDisconnect_Click(object sender, EventArgs e) 424 { 425 cccc.DisconnectAsync(); 426 } 427 428 private void btn_clientShutdown_Click(object sender, EventArgs e) 429 { 430 DialogResult res = MessageBox.Show("Do you really want to shutdown the Hive Client?", "Hive Client Console", MessageBoxButtons.YesNo, MessageBoxIcon.Question); 431 if (res == DialogResult.Yes) 432 { 433 logFileReader.Stop(); 434 cccc.ShutdownClient(); 435 this.Close(); 436 } 437 } 438 439 private void btbDelete_Click(object sender, EventArgs e) 440 { 441 Appointment selectedAppointment = dvOnline.SelectedAppointment; 442 if (dvOnline.SelectedAppointment != null) 443 { 444 if (!selectedAppointment.Recurring) 445 DeleteAppointment(); 446 else 447 { 448 DialogResult res = MessageBox.Show("Delete all events in this series?", "Delete recurrences", MessageBoxButtons.YesNo); 449 if (res != DialogResult.Yes) 450 DeleteAppointment(); 451 else 452 DeleteRecurringAppointment(selectedAppointment.RecurringId); 453 } 454 } 455 dvOnline.Invalidate(); 456 } 457 458 private void chbade_CheckedChanged(object sender, EventArgs e) 459 { 460 txttimeFrom.Visible = !chbade.Checked; 461 txttimeTo.Visible = !chbade.Checked; 462 } 463 464 private void dvOnline_OnSelectionChanged(object sender, EventArgs e) 465 { 466 //btCreate.Enabled = true; 467 if (dvOnline.Selection == SelectionType.DateRange) 468 { 469 dtpFrom.Text = dvOnline.SelectionStart.ToShortDateString(); 470 dtpTo.Text = dvOnline.SelectionEnd.Date.ToShortDateString(); 471 txttimeFrom.Text = dvOnline.SelectionStart.ToShortTimeString(); 472 txttimeTo.Text = dvOnline.SelectionEnd.ToShortTimeString(); 473 474 btCreate.Text = "Save"; 475 } 476 477 if (dvOnline.Selection == SelectionType.Appointment) 478 { 479 480 dtpFrom.Text = dvOnline.SelectedAppointment.StartDate.ToShortDateString(); 481 dtpTo.Text = dvOnline.SelectedAppointment.EndDate.ToShortDateString(); 482 txttimeFrom.Text = dvOnline.SelectedAppointment.StartDate.ToShortTimeString(); 483 txttimeTo.Text = dvOnline.SelectedAppointment.EndDate.ToShortTimeString(); 484 485 if (dvOnline.SelectedAppointment.Recurring) 486 //btCreate.Enabled = false; 487 //also change the caption of the save button 488 btCreate.Text = "Save changes"; 489 } 490 491 if (dvOnline.Selection == SelectionType.None) 492 { 493 //also change the caption of the save button 494 btCreate.Text = "Save"; 495 } 496 497 } 498 499 private void Connection_KeyPress(object sender, KeyPressEventArgs e) 500 { 501 if (e.KeyChar == (char)Keys.Return) 502 btConnect_Click(null, null); 503 } 504 505 private void mcOnline_DateChanged(object sender, DateRangeEventArgs e) 506 { 507 dvOnline.StartDate = mcOnline.SelectionStart; 260 clientCommunicator.GetUptimeCalendarAsync(); 508 261 } 509 262 … … 553 306 } 554 307 308 private Appointment CreateAppointment(DateTime startDate, DateTime endDate, bool allDay) 309 { 310 Appointment App = new Appointment(); 311 App.StartDate = startDate; 312 App.EndDate = endDate; 313 App.AllDayEvent = allDay; 314 App.BorderColor = Color.Red; 315 App.Locked = true; 316 App.Subject = "Online"; 317 App.Recurring = false; 318 return App; 319 } 320 321 private Appointment CreateAppointment(DateTime startDate, DateTime endDate, bool allDay, bool recurring, Guid recurringId) 322 { 323 Appointment App = new Appointment(); 324 App.StartDate = startDate; 325 App.EndDate = endDate; 326 App.AllDayEvent = allDay; 327 App.BorderColor = Color.Red; 328 App.Locked = true; 329 App.Subject = "Online"; 330 App.Recurring = recurring; 331 App.RecurringId = recurringId; 332 return App; 333 } 334 335 private void DeleteAppointment() 336 { 337 onlineTimes.Remove(dvOnline.SelectedAppointment); 338 } 339 340 private void DeleteRecurringAppointment(Guid recurringId) 341 { 342 onlineTimes.RemoveAll(a => a.RecurringId.ToString() == dvOnline.SelectedAppointment.RecurringId.ToString()); 343 } 344 345 private void ChangeRecurrenceAppointment(Guid recurringId) 346 { 347 int hourfrom = int.Parse(txttimeFrom.Text.Substring(0, txttimeFrom.Text.IndexOf(':'))); 348 int hourTo = int.Parse(txttimeTo.Text.Substring(0, txttimeTo.Text.IndexOf(':'))); 349 List<Appointment> recurringAppointments = onlineTimes.Where(appointment => appointment.RecurringId == recurringId).ToList(); 350 recurringAppointments.ForEach(appointment => appointment.StartDate = new DateTime(appointment.StartDate.Year, appointment.StartDate.Month, appointment.StartDate.Day, hourfrom, 0, 0)); 351 recurringAppointments.ForEach(appointment => appointment.EndDate = new DateTime(appointment.EndDate.Year, appointment.EndDate.Month, appointment.EndDate.Day, hourTo, 0, 0)); 352 353 DeleteRecurringAppointment(recurringId); 354 onlineTimes.AddRange(recurringAppointments); 355 } 356 357 public void DialogClosed(RecurrentEvent e) 358 { 359 CreateDailyRecurrenceAppointments(e.DateFrom, e.DateTo, e.AllDay, e.IncWeeks, e.WeekDays); 360 } 361 362 private void CreateDailyRecurrenceAppointments(DateTime dateFrom, DateTime dateTo, bool allDay, int incWeek, HashSet<DayOfWeek> daysOfWeek) 363 { 364 DateTime incDate = dateFrom; 365 Guid guid = Guid.NewGuid(); 366 367 while (incDate.Date <= dateTo.Date) 368 { 369 if (daysOfWeek.Contains(incDate.Date.DayOfWeek)) 370 onlineTimes.Add(CreateAppointment(incDate, new DateTime(incDate.Year, incDate.Month, incDate.Day, dateTo.Hour, dateTo.Minute, 0), allDay, true, guid)); 371 incDate = incDate.AddDays(1); 372 } 373 374 dvOnline.Invalidate(); 375 } 376 377 #region Calendar Events 378 379 private void btbDelete_Click(object sender, EventArgs e) 380 { 381 Appointment selectedAppointment = dvOnline.SelectedAppointment; 382 if (dvOnline.SelectedAppointment != null) 383 { 384 if (!selectedAppointment.Recurring) 385 DeleteAppointment(); 386 else 387 { 388 DialogResult res = MessageBox.Show("Delete all events in this series?", "Delete recurrences", MessageBoxButtons.YesNo); 389 if (res != DialogResult.Yes) 390 DeleteAppointment(); 391 else 392 DeleteRecurringAppointment(selectedAppointment.RecurringId); 393 } 394 } 395 dvOnline.Invalidate(); 396 } 397 398 private void chbade_CheckedChanged(object sender, EventArgs e) 399 { 400 txttimeFrom.Visible = !chbade.Checked; 401 txttimeTo.Visible = !chbade.Checked; 402 } 403 404 private void dvOnline_OnSelectionChanged(object sender, EventArgs e) 405 { 406 //btCreate.Enabled = true; 407 if (dvOnline.Selection == SelectionType.DateRange) 408 { 409 dtpFrom.Text = dvOnline.SelectionStart.ToShortDateString(); 410 dtpTo.Text = dvOnline.SelectionEnd.Date.ToShortDateString(); 411 txttimeFrom.Text = dvOnline.SelectionStart.ToShortTimeString(); 412 txttimeTo.Text = dvOnline.SelectionEnd.ToShortTimeString(); 413 414 btCreate.Text = "Save"; 415 } 416 417 if (dvOnline.Selection == SelectionType.Appointment) 418 { 419 420 dtpFrom.Text = dvOnline.SelectedAppointment.StartDate.ToShortDateString(); 421 dtpTo.Text = dvOnline.SelectedAppointment.EndDate.ToShortDateString(); 422 txttimeFrom.Text = dvOnline.SelectedAppointment.StartDate.ToShortTimeString(); 423 txttimeTo.Text = dvOnline.SelectedAppointment.EndDate.ToShortTimeString(); 424 425 if (dvOnline.SelectedAppointment.Recurring) 426 //btCreate.Enabled = false; 427 //also change the caption of the save button 428 btCreate.Text = "Save changes"; 429 } 430 431 if (dvOnline.Selection == SelectionType.None) 432 { 433 //also change the caption of the save button 434 btCreate.Text = "Save"; 435 } 436 437 } 438 439 private void mcOnline_DateChanged(object sender, DateRangeEventArgs e) 440 { 441 dvOnline.StartDate = mcOnline.SelectionStart; 442 } 443 555 444 private void btCreate_Click(object sender, EventArgs e) 556 445 { … … 584 473 } 585 474 586 private void ChangeRecurrenceAppointment(Guid recurringId)587 { 588 int hourfrom = int.Parse(txttimeFrom.Text.Substring(0, txttimeFrom.Text.IndexOf(':')));589 int hourTo = int.Parse(txttimeTo.Text.Substring(0, txttimeTo.Text.IndexOf(':')));590 List<Appointment> recurringAppointments = onlineTimes.Where(appointment => appointment.RecurringId == recurringId).ToList();591 recurringAppointments.ForEach(appointment => appointment.StartDate = new DateTime(appointment.StartDate.Year, appointment.StartDate.Month, appointment.StartDate.Day, hourfrom, 0, 0));592 recurringAppointments.ForEach(appointment => appointment.EndDate = new DateTime(appointment.EndDate.Year, appointment.EndDate.Month, appointment.EndDate.Day, hourTo, 0, 0)); 593 594 DeleteRecurringAppointment(recurringId);595 onlineTimes.AddRange(recurringAppointments);596 } 597 598 private void DvOnline_OnResolveAppointments(object sender, ResolveAppointmentsEventArgs e)475 private void btnRecurrence_Click(object sender, EventArgs e) 476 { 477 Recurrence recurrence = new Recurrence(); 478 recurrence.dialogClosedDelegate = new OnDialogClosedDelegate(this.DialogClosed); 479 recurrence.Show(); 480 } 481 482 private void btnSaveCal_Click(object sender, EventArgs e) 483 { 484 clientCommunicator.SetUptimeCalendarAsync(onlineTimes.ToArray()); 485 } 486 487 private void dvOnline_OnResolveAppointments(object sender, ResolveAppointmentsEventArgs e) 599 488 { 600 489 List<Appointment> Apps = new List<Appointment>(); … … 607 496 } 608 497 609 private void DvOnline_OnNewAppointment(object sender, NewAppointmentEventArgs e)498 private void dvOnline_OnNewAppointment(object sender, NewAppointmentEventArgs e) 610 499 { 611 500 Appointment Appointment = new Appointment(); … … 617 506 } 618 507 619 private void btnRecurrence_Click(object sender, EventArgs e) 620 { 621 Recurrence recurrence = new Recurrence(); 622 recurrence.dialogClosedDelegate = new OnDialogClosedDelegate(this.DialogClosed); 623 recurrence.Show(); 624 } 625 626 public void DialogClosed(RecurrentEvent e) 627 { 628 CreateDailyRecurrenceAppointments(e.DateFrom, e.DateTo, e.AllDay, e.IncWeeks, e.WeekDays); 629 } 630 631 private void CreateDailyRecurrenceAppointments(DateTime dateFrom, DateTime dateTo, bool allDay, int incWeek, HashSet<DayOfWeek> daysOfWeek) 632 { 633 DateTime incDate = dateFrom; 634 Guid guid = Guid.NewGuid(); 635 636 while (incDate.Date <= dateTo.Date) 637 { 638 if (daysOfWeek.Contains(incDate.Date.DayOfWeek)) 639 onlineTimes.Add(CreateAppointment(incDate, new DateTime(incDate.Year, incDate.Month, incDate.Day, dateTo.Hour, dateTo.Minute, 0), allDay, true, guid)); 640 incDate = incDate.AddDays(1); 641 } 642 643 dvOnline.Invalidate(); 644 } 645 646 private void btnSaveCal_Click(object sender, EventArgs e) 647 { 648 cccc.SetUptimeCalendarAsync(onlineTimes.ToArray()); 508 #endregion 509 510 #endregion 511 512 #region Client communicator events 513 514 void clientCommunicator_SetUptimeCalendarCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) 515 { 516 if (e.Error == null) 517 { 518 MessageBox.Show("Calendar successfully saved!", "Calender", MessageBoxButtons.OK, MessageBoxIcon.Information); 519 } 520 else 521 { 522 MessageBox.Show("Error saving calender \n" + e.Error.ToString(), "Calender", MessageBoxButtons.OK, MessageBoxIcon.Error); 523 } 524 } 525 526 void clientCommunicator_GetUptimeCalendarCompleted(object sender, GetUptimeCalendarCompletedEventArgs e) 527 { 528 if (e.Error == null) 529 { 530 if (e.Result != null) 531 { 532 onlineTimes = e.Result.ToList<Appointment>(); 533 onlineTimes.ForEach(a => a.BorderColor = Color.Red); 534 } 535 else 536 { 537 onlineTimes = new List<Appointment>(); 538 } 539 } 540 //InitTestCalenderEntries(); 541 } 542 543 private void clientCommunicator_GetCurrentConnectionCompleted(object sender, GetCurrentConnectionCompletedEventArgs e) 544 { 545 if (e.Error == null) 546 { 547 ConnectionContainer curConnection = e.Result; 548 tbIPAdress.Text = curConnection.IPAdress; 549 tbPort.Text = curConnection.Port.ToString(); 550 } 551 else 552 { 553 refreshTimer.Stop(); 554 DialogResult res = MessageBox.Show("Connection Error, check if Hive Client is running! - " + e.Error.Message, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 555 if (res == DialogResult.OK) 556 this.Close(); 557 } 558 } 559 560 private void clientCommunicator_GetStatusInfosCompleted(object sender, GetStatusInfosCompletedEventArgs e) 561 { 562 563 if (e.Error == null) 564 { 565 StatusCommons sc = e.Result; 566 567 lbGuid.Text = sc.ClientGuid.ToString(); 568 lbConnectionStatus.Text = sc.Status.ToString(); 569 lbJobdone.Text = sc.JobsDone.ToString(); 570 lbJobsAborted.Text = sc.JobsAborted.ToString(); 571 lbJobsFetched.Text = sc.JobsFetched.ToString(); 572 573 this.Text = "Client Console (" + sc.Status.ToString() + ")"; 574 575 ListViewItem curJobStatusItem; 576 577 if (sc.Jobs != null) 578 { 579 lvJobDetail.Items.Clear(); 580 double progress; 581 foreach (JobStatus curJob in sc.Jobs) 582 { 583 curJobStatusItem = new ListViewItem(curJob.JobId.ToString()); 584 curJobStatusItem.SubItems.Add(curJob.Since.ToString()); 585 progress = curJob.Progress * 100; 586 curJobStatusItem.SubItems.Add(progress.ToString()); 587 lvJobDetail.Items.Add(curJobStatusItem); 588 } 589 lvJobDetail.Sort(); 590 } 591 592 UpdateGraph(sc.Jobs); 593 594 if (sc.Status == NetworkEnumWcfConnState.Connected || sc.Status == NetworkEnumWcfConnState.Loggedin) 595 { 596 btConnect.Enabled = false; 597 btnDisconnect.Enabled = true; 598 lbCs.Text = sc.ConnectedSince.ToString(); 599 clientCommunicator.GetCurrentConnectionAsync(); 600 } 601 else if (sc.Status == NetworkEnumWcfConnState.Disconnected) 602 { 603 btConnect.Enabled = true; 604 btnDisconnect.Enabled = false; 605 lbCs.Text = String.Empty; 606 } 607 else if (sc.Status == NetworkEnumWcfConnState.Failed) 608 { 609 btConnect.Enabled = true; 610 btnDisconnect.Enabled = false; 611 lbCs.Text = String.Empty; 612 } 613 614 clientCommunicator.GetCurrentConnection(); 615 } 616 else 617 { 618 refreshTimer.Stop(); 619 DialogResult res = MessageBox.Show("Connection Error, check if Hive Client is running! - " + e.Error.Message, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 620 if (res == DialogResult.OK) 621 this.Close(); 622 } 623 } 624 625 #endregion 626 627 #endregion 628 629 #region GUI Events 630 631 private void btConnect_Click(object sender, EventArgs e) 632 { 633 IPAddress ipAdress; 634 int port; 635 ConnectionContainer cc = new ConnectionContainer(); 636 if (IPAddress.TryParse(tbIPAdress.Text, out ipAdress) && int.TryParse(tbPort.Text, out port)) 637 { 638 cc.IPAdress = tbIPAdress.Text; 639 cc.Port = port; 640 clientCommunicator.SetConnectionAsync(cc); 641 } 642 else 643 { 644 MessageBox.Show("IP Adress and/or Port Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 645 } 646 } 647 648 private void btnDisconnect_Click(object sender, EventArgs e) 649 { 650 clientCommunicator.DisconnectAsync(); 651 } 652 653 private void btn_clientShutdown_Click(object sender, EventArgs e) 654 { 655 DialogResult res = MessageBox.Show("Do you really want to shutdown the Hive Client?", "Hive Client Console", MessageBoxButtons.YesNo, MessageBoxIcon.Question); 656 if (res == DialogResult.Yes) 657 { 658 logFileReader.Stop(); 659 clientCommunicator.ShutdownClient(); 660 this.Close(); 661 } 662 } 663 664 private void Connection_KeyPress(object sender, KeyPressEventArgs e) 665 { 666 if (e.KeyChar == (char)Keys.Return) 667 btConnect_Click(null, null); 649 668 } 650 669
Note: See TracChangeset
for help on using the changeset viewer.