/// <summary> /// Called when the user clicks the "Load" button. Spawns the two loader threads to /// do the dirty work and free up the UI thread. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnLoad_Click(object sender, EventArgs e) { try { EnableControls(false); btnCancel.Enabled = false; var tourStart = Convert.ToInt32(txtbxStartTour.Text); var tourEnd = Convert.ToInt32(txtbxEndTour.Text); _threadParam = new DataLoaderThreadParams(); // if a single pilot, add single pilot name to the list. if (cmbBoxSquadSelect.SelectedItem.ToString() == NotSelectedText) { _threadParam.PilotIdList.Add(txtbxPilotToLoad.Text.ToUpperFirstChar()); } else // its a squad - so add each member of the sqaud to the list. { var squad = Registry.GetSquad(cmbBoxSquadSelect.SelectedItem.ToString()); foreach (var squadMember in squad.Members.Where(squadMember => squadMember.StartTour <= tourStart && squadMember.EndTour >= tourStart)) { _threadParam.PilotIdList.Add(squadMember.PilotName.ToUpperFirstChar()); } } var tourType = cmboxTourType.SelectedItem.ToString(); // build the list of tours to load. for (var tourId = tourStart; tourId <= tourEnd; tourId++) { _threadParam.ToursToLoad.Add(Registry.TourDefinitions.FindTour(tourType, tourId)); } // Set the thread callbacks. _threadParam.CompletedCallBack = _loadCompletedCallBack; _threadParam.ProgressCallBack = _updateProgressCallBack; // Make sure they actually selected something sane. Shouldnt happen due to form validation. if (cmbBoxSquadSelect.SelectedItem.ToString() == NotSelectedText && string.IsNullOrEmpty(txtbxPilotToLoad.Text)) { throw new Exception(); } _threadParam.ProxySettings = _proxySettings; // Kick off the threads to do the dirty work. _loaderThread = new Thread(_loaderThreadStart); _loaderThread.Start(_threadParam); _totalStarted = 1; if (cmbBoxSquadSelect.SelectedItem.ToString() == NotSelectedText) { progressBarLoading.Maximum = (tourEnd - tourStart + 1) * 2; } else { //var squad = Registry.GetSquad(cmbBoxSquadSelect.SelectedItem.ToString()); progressBarLoading.Maximum = _threadParam.PilotIdList.Count * 2; } lblUnitsToLoad.Text = progressBarLoading.Maximum.ToString(); lblLoading.Visible = true; } catch (Exception) { // Silently ignore any exceptions in this thread. RestoreForm(); } }
/// <summary> /// Called when the user clicks the "Load" button. Spawns the two loader threads to /// do the dirty work and free up the UI thread. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnLoad_Click(object sender, EventArgs e) { try { EnableControls(false); this.btnCancel.Enabled = false; int tourStart = System.Convert.ToInt32(this.txtbxStartTour.Text); int tourEnd = System.Convert.ToInt32(this.txtbxEndTour.Text); _threadParam = new DataLoaderThreadParams(); // if a single pilot, add single pilot name to the list. if (cmbBoxSquadSelect.SelectedItem.ToString() == _notSelectedText) { _threadParam.pilotIdList.Add(CommonUtils.ToUpperFirstChar(this.txtbxPilotToLoad.Text)); } else // its a squad - so add each member of the sqaud to the list. { Squad squad = Registry.Instance.GetSquad(cmbBoxSquadSelect.SelectedItem.ToString()); foreach (Squad.SquadMember squadMember in squad.Members) { //only load this member if they were actually a member for that tour. if (squadMember.StartTour <= tourStart && squadMember.EndTour >= tourStart) { _threadParam.pilotIdList.Add(CommonUtils.ToUpperFirstChar(squadMember.PilotName)); } } } string tourType = this.cmboxTourType.SelectedItem.ToString(); // build the list of tours to load. for (int tourId = tourStart; tourId <= tourEnd; tourId++) { _threadParam.toursToLoad.Add(Registry.Instance.TourDefinitions.FindTour(tourType, tourId)); } // Set the thread callbacks. _threadParam.loadCompletedCallBack = _LoadCompletedCallBack; _threadParam.updateProgressCallBack = _UpdateProgressCallBack; // Make sure they actually selected something sane. Shouldnt happen due to form validation. if (cmbBoxSquadSelect.SelectedItem.ToString() == _notSelectedText && string.IsNullOrEmpty(txtbxPilotToLoad.Text)) { throw new Exception(); } _threadParam.proxySettings = _proxySettings; // Kick off the threads to do the dirty work. _LoaderThread = new Thread(_LoaderThreadStart); _LoaderThread.Start(_threadParam); _TotalStarted = 1; if (cmbBoxSquadSelect.SelectedItem.ToString() == _notSelectedText) this.progressBarLoading.Maximum = (tourEnd - tourStart + 1) * 2; else { Squad squad = Registry.Instance.GetSquad(cmbBoxSquadSelect.SelectedItem.ToString()); this.progressBarLoading.Maximum = _threadParam.pilotIdList.Count * 2; } this.lblUnitsToLoad.Text = this.progressBarLoading.Maximum.ToString(); this.lblLoading.Visible = true; } catch (Exception) { // Silently ignore any exceptions in this thread. RestoreForm(); } }