/// <summary> /// Event fired when the Next button is pushed /// </summary> private async void NextBtn_Click(object sender, EventArgs e) { // Get our next step switch (pageControl1.SelectedTab.Name) { case "tabPageSelect": // Make sure we are going to redirect something... if (!Bf2webCheckbox.Checked && !GpcmCheckbox.Checked) { MessageBox.Show( "Please select at least 1 redirect option", "Select an Option", MessageBoxButtons.OK, MessageBoxIcon.Information ); return; } // Show loading status so the user sees progress StatusPic.Visible = StatusText.Visible = true; NextBtn.Enabled = false; // Validate hostnames, and convert them to IPAddresses bool IsValid = await GetRedirectAddressesAsync(); if (IsValid) { Step = pageControl1.TabPages.IndexOf(tabPageRedirectType); } // Hide status icon and next StatusPic.Visible = StatusText.Visible = false; break; case "tabPageRedirectType": if (IcsRadio.Checked) { Step = pageControl1.TabPages.IndexOf(tabPageVerifyIcs); } else if (HostsRadio.Checked) { Step = pageControl1.TabPages.IndexOf(tabPageVerifyHosts); } else { Step = pageControl1.TabPages.IndexOf(tabPageDiagnostic); } // Set new redirect options Redirector.SetRedirectMode(SelectedMode); Redirector.StatsServerAddress = StatsServerAddress; Redirector.GamespyServerAddress = GamespyServerAddress; break; case "tabPageVerifyIcs": case "tabPageVerifyHosts": // Reset diag page Status1.Image = Status2.Image = Status4.Image = Status5.Image = null; Address1.Text = Address2.Text = Address4.Text = Address5.Text = "Queued"; // Get our next page index Step = pageControl1.TabPages.IndexOf(tabPageDiagnostic); break; case "tabPageDiagnostic": // All processing is done in the after select Step = pageControl1.TabPages.IndexOf(tabPageSuccess); break; case "tabPageError": case "tabPageSuccess": this.DialogResult = DialogResult.OK; this.Close(); break; } // Make sure we have a change before changing our index if (Step == pageControl1.SelectedIndex) { return; } // Set the new index pageControl1.SelectedIndex = Step; }
/// <summary> /// When the Step is changed, this method handles the processing of /// the next step /// </summary> protected async void AfterSelectProcessing() { // Disable buttons until processing is complete NextBtn.Enabled = false; PrevBtn.Enabled = false; bool IsErrorFree; // Do processing // Get our previous step switch (pageControl1.SelectedTab.Name) { case "tabPageSelect": // We dont do anything here NextBtn.Enabled = true; break; case "tabPageRedirectType": // We dont do much here PrevBtn.Enabled = NextBtn.Enabled = true; break; case "tabPageVerifyHosts": case "tabPageVerifyIcs": // Create new progress SyncProgress <TaskStep> Myprogress = new SyncProgress <TaskStep>(RedirectStatusUpdate); // Apply redirects IsErrorFree = await Redirector.ApplyRedirectsAsync(Myprogress); if (IsErrorFree) { NextBtn.Enabled = true; } else { // Remove redirect if there are errors await Task.Delay(ERRORPAGE_DELAY); ShowHostsErrorPage(); } break; case "tabPageDiagnostic": // Run in a new thread of course bool DiagnosticResult = await Task.Run <bool>(() => VerifyDnsCache()); // Switch page if (DiagnosticResult) { NextBtn.Enabled = true; } else { // Remove redirect if there are errors Redirector.RemoveRedirects(); await Task.Delay(ERRORPAGE_DELAY); // Show Error Page ShowDnsErrorPage(); } break; case "tabPageSuccess": PrevBtn.Visible = false; CancelBtn.Visible = false; NextBtn.Text = "Finish"; NextBtn.Enabled = true; NextBtn.Location = CancelBtn.Location; return; case "tabPageError": break; } // Unlock the previos button if (pageControl1.SelectedTab != tabPageSelect) { PrevBtn.Enabled = true; } }