Ejemplo n.º 1
0
        private void cmdRunScript_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                PowerShellScriptRunnerEntry testEntry = new PowerShellScriptRunnerEntry();
                testEntry.Name = txtName.Text;
                testEntry.ReturnCheckSequence    = optGWE.Checked ? CollectorAgentReturnValueCheckSequence.GWE : CollectorAgentReturnValueCheckSequence.EWG;
                testEntry.TestScript             = txtScript.Text;
                testEntry.GoodScriptText         = txtSuccess.Text;
                testEntry.GoodResultMatchType    = (CollectorAgentReturnValueCompareMatchType)cboSuccessMatchType.SelectedIndex;
                testEntry.WarningScriptText      = txtWarning.Text;
                testEntry.WarningResultMatchType = (CollectorAgentReturnValueCompareMatchType)cboWarningMatchType.SelectedIndex;
                testEntry.ErrorScriptText        = txtError.Text;
                testEntry.ErrorResultMatchType   = (CollectorAgentReturnValueCompareMatchType)cboErrorMatchType.SelectedIndex;

                string         scriptResult = testEntry.RunScript();
                CollectorState state        = testEntry.GetState(scriptResult);

                MessageBox.Show(scriptResult, "Test script", MessageBoxButtons.OK, state == CollectorState.Good ? MessageBoxIcon.Information : state == CollectorState.Warning ? MessageBoxIcon.Warning : MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                Cursor.Current = Cursors.Default;
                MessageBox.Show(ex.Message, "Run script", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
 private void cmdRunScript_Click(object sender, EventArgs e)
 {
     try
     {
         Cursor.Current          = Cursors.WaitCursor;
         txtPSScriptResults.Text = PowerShellScriptRunnerEntry.RunScript(txtPSScript.Text);
     }
     catch (Exception ex)
     {
         Cursor.Current = Cursors.Default;
         MessageBox.Show(ex.Message, "Run script", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     finally
     {
         Cursor.Current = Cursors.Default;
     }
 }
        private void ShowScriptDetails()
        {
            if (lvwScripts.SelectedItems.Count > 0)
            {
                StringBuilder sb        = new StringBuilder();
                StringBuilder sbps      = new StringBuilder();
                bool          multiples = lvwScripts.SelectedItems.Count > 1;
                Cursor.Current = Cursors.WaitCursor;
                foreach (ListViewItem lvi in lvwScripts.SelectedItems)
                {
                    PowerShellScriptRunnerEntry pssrEntry = (PowerShellScriptRunnerEntry)lvi.Tag;
                    try
                    {
                        sbps.AppendLine(pssrEntry.TestScript);
                        if (multiples)
                        {
                            sb.AppendLine("-----------------------------");
                            sb.AppendLine("Name: " + pssrEntry.Name);
                            sb.AppendLine("-----------------------------");

                            sbps.AppendLine("#----------------------------");
                        }

                        string scriptResult = pssrEntry.RunScript();
                        sb.AppendLine(scriptResult);
                    }
                    catch (Exception ex)
                    {
                        sb.AppendLine(ex.Message);
                    }
                    txtPSScript.Text        = sbps.ToString();
                    txtPSScriptResults.Text = sb.ToString();
                }
            }
            else
            {
                txtPSScript.Text        = "";
                txtPSScriptResults.Text = "";
            }
            Cursor.Current = Cursors.Default;
        }
 public override void RefreshDisplayData()
 {
     try
     {
         lvwScripts.BeginUpdate();
         Cursor.Current = Cursors.WaitCursor;
         foreach (ListViewItem lvi in lvwScripts.Items)
         {
             PowerShellScriptRunnerEntry pssrEntry = (PowerShellScriptRunnerEntry)lvi.Tag;
             string         scriptResult           = pssrEntry.RunScript();
             CollectorState currentState           = pssrEntry.GetState(scriptResult);
             if (currentState == CollectorState.Good)
             {
                 lvi.ImageIndex = 1;
             }
             else if (currentState == CollectorState.Warning)
             {
                 lvi.ImageIndex = 2;
             }
             else if (currentState == CollectorState.Error)
             {
                 lvi.ImageIndex = 3;
             }
             else
             {
                 lvi.ImageIndex = 0;
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Refresh", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     finally
     {
         Cursor.Current = Cursors.Default;
         lvwScripts.EndUpdate();
     }
     ShowScriptDetails();
     base.RefreshDisplayData();
 }