private void PSWizHost_FormClosing(object sender, FormClosingEventArgs e) { Trace.WriteLine("Form Closing.", "Form"); if (PowershellHostControl1.isPowerShellRunning) { Trace.WriteLine("Powershell still running, prompt the user for cancel confirmation.", "Form"); e.Cancel = true; if (MessageBox.Show("Are you sure you want to quit?", this.Text, MessageBoxButtons.YesNo) == DialogResult.Yes) { Trace.WriteLine("User selected to confirm close, force any in-progress powershell script to stop.", "Form"); PowershellHostControl1.Stop(); } } }
private void ButtonN_Click(object sender, EventArgs e) { Trace.WriteLine("Button Click Next.", "Form"); if (PowershellHostControl1.isPowerShellRunning) { Trace.WriteLine("Validate any child elements.", "Form"); if (!this.ValidateChildren()) { Trace.WriteLine("Some input elements reported error.", "Form"); MessageBox.Show("Please fill out all missing elements."); return; } Trace.WriteLine("All form elements ready for processing.", "Form"); PowershellHostControl1.OnNavigationNextPrompt(); ButtonN.Enabled = false; } else { this.Close(); } }
private void PSWizHost_Load(object sender, EventArgs e) { #if DEBUG foreach (var Resources in Assembly.GetExecutingAssembly().GetManifestResourceNames()) { Trace.WriteLine(string.Format("Resource names {0}", Resources), "Form"); } #endif Trace.WriteLine("Load Powershell Script from embedded resource and start execution.", "Form"); foreach (string ResourceName in Assembly.GetExecutingAssembly().GetManifestResourceNames()) { if (ResourceName.ToLower().EndsWith(".ps1")) { Trace.WriteLine("Resource names {0}", ResourceName); Stream DataStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(ResourceName); PowershellHostControl1.Script += (new StreamReader(DataStream)).ReadToEnd(); } } PowershellHostControl1.Start(Environment.GetCommandLineArgs()); }