Esempio 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;
            }
        }
 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();
 }