Example #1
0
        public void FromXml(string configurationString)
        {
            XmlDocument config = new XmlDocument();

            config.LoadXml(configurationString);
            Entries.Clear();
            XmlElement root = config.DocumentElement;

            foreach (XmlElement powerShellScriptRunnerNode in root.SelectNodes("powerShellScripts/powerShellScriptRunner"))
            {
                PowerShellScriptRunnerEntry entry = new PowerShellScriptRunnerEntry();
                entry.Name = powerShellScriptRunnerNode.ReadXmlElementAttr("name", "");
                entry.ReturnCheckSequence = CollectorAgentReturnValueCompareEngine.CheckSequenceTypeFromString(powerShellScriptRunnerNode.ReadXmlElementAttr("returnCheckSequence", "gwe"));
                XmlNode testScriptNode = powerShellScriptRunnerNode.SelectSingleNode("testScript");
                entry.TestScript = testScriptNode.InnerText;

                XmlNode goodScriptNode = powerShellScriptRunnerNode.SelectSingleNode("goodScript");
                entry.GoodResultMatchType = CollectorAgentReturnValueCompareEngine.MatchTypeFromString(goodScriptNode.ReadXmlElementAttr("resultMatchType", "match"));
                entry.GoodScriptText      = goodScriptNode.InnerText;

                XmlNode warningScriptNode = powerShellScriptRunnerNode.SelectSingleNode("warningScript");
                entry.WarningResultMatchType = CollectorAgentReturnValueCompareEngine.MatchTypeFromString(warningScriptNode.ReadXmlElementAttr("resultMatchType", "match"));
                entry.WarningScriptText      = warningScriptNode.InnerText;

                XmlNode errorScriptNode = powerShellScriptRunnerNode.SelectSingleNode("errorScript");
                entry.ErrorResultMatchType = CollectorAgentReturnValueCompareEngine.MatchTypeFromString(errorScriptNode.ReadXmlElementAttr("resultMatchType", "match"));
                entry.ErrorScriptText      = errorScriptNode.InnerText;

                Entries.Add(entry);
            }
        }
Example #2
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();
 }
Example #6
0
        private void cmdOK_Click(object sender, EventArgs e)
        {
            if (SelectedEntry == null)
            {
                SelectedEntry = new PowerShellScriptRunnerEntry();
            }
            PowerShellScriptRunnerEntry selectedEntry = (PowerShellScriptRunnerEntry)SelectedEntry;

            selectedEntry.Name = txtName.Text;

            selectedEntry.ReturnCheckSequence    = optGWE.Checked ? CollectorAgentReturnValueCheckSequence.GWE : CollectorAgentReturnValueCheckSequence.EWG;
            selectedEntry.TestScript             = txtScript.Text;
            selectedEntry.GoodScriptText         = txtSuccess.Text;
            selectedEntry.GoodResultMatchType    = (CollectorAgentReturnValueCompareMatchType)cboSuccessMatchType.SelectedIndex;
            selectedEntry.WarningScriptText      = txtWarning.Text;
            selectedEntry.WarningResultMatchType = (CollectorAgentReturnValueCompareMatchType)cboWarningMatchType.SelectedIndex;
            selectedEntry.ErrorScriptText        = txtError.Text;
            selectedEntry.ErrorResultMatchType   = (CollectorAgentReturnValueCompareMatchType)cboErrorMatchType.SelectedIndex;
            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
Example #7
0
        private void PowerShellScriptRunnerCollectorEditEntry_Load(object sender, EventArgs e)
        {
            if (SelectedEntry == null)
            {
                SelectedEntry = new PowerShellScriptRunnerEntry();
            }
            PowerShellScriptRunnerEntry selectedEntry = (PowerShellScriptRunnerEntry)SelectedEntry;

            #region Load Match types
            cboSuccessMatchType.Items.Clear();
            cboSuccessMatchType.Items.AddRange(CollectorAgentReturnValueCompareEngine.ReturnValueCompareMatchTypesToList().ToArray());
            if (cboSuccessMatchType.Items.Count > 0)
            {
                cboSuccessMatchType.SelectedIndex = 0;
            }
            cboWarningMatchType.Items.Clear();
            cboWarningMatchType.Items.AddRange(CollectorAgentReturnValueCompareEngine.ReturnValueCompareMatchTypesToList().ToArray());
            if (cboWarningMatchType.Items.Count > 0)
            {
                cboWarningMatchType.SelectedIndex = 0;
            }
            cboErrorMatchType.Items.Clear();
            cboErrorMatchType.Items.AddRange(CollectorAgentReturnValueCompareEngine.ReturnValueCompareMatchTypesToList().ToArray());
            if (cboErrorMatchType.Items.Count > 0)
            {
                cboErrorMatchType.SelectedIndex = 0;
            }
            #endregion

            txtName.Text    = selectedEntry.Name;
            optEWG.Checked  = selectedEntry.ReturnCheckSequence == CollectorAgentReturnValueCheckSequence.EWG;
            txtScript.Text  = selectedEntry.TestScript;
            txtSuccess.Text = selectedEntry.GoodScriptText;
            cboSuccessMatchType.SelectedIndex = (int)selectedEntry.GoodResultMatchType;
            txtWarning.Text = selectedEntry.WarningScriptText;
            cboWarningMatchType.SelectedIndex = (int)selectedEntry.WarningResultMatchType;
            txtError.Text = selectedEntry.ErrorScriptText;
            cboErrorMatchType.SelectedIndex = (int)selectedEntry.ErrorResultMatchType;
        }
Example #8
0
        public void FromXml(string configurationString)
        {
            XmlDocument config = new XmlDocument();

            config.LoadXml(configurationString);
            Entries.Clear();
            XmlElement root = config.DocumentElement;

            //Old format
            foreach (XmlElement powerShellScriptRunnerNode in root.SelectNodes("powerShellScripts/powerShellScriptRunner"))
            {
                PowerShellScriptRunnerEntry entry = new PowerShellScriptRunnerEntry();
                entry.Name = powerShellScriptRunnerNode.ReadXmlElementAttr("name", "");

                entry.ReturnCheckSequence = CollectorAgentReturnValueCompareEngine.CheckSequenceTypeFromString(powerShellScriptRunnerNode.ReadXmlElementAttr("returnCheckSequence", "gwe"));

                XmlNode testScriptNode = powerShellScriptRunnerNode.SelectSingleNode("testScript");
                entry.TestScript = testScriptNode.InnerText;

                XmlNode goodScriptNode = powerShellScriptRunnerNode.SelectSingleNode("goodScript");
                entry.GoodResultMatchType = CollectorAgentReturnValueCompareEngine.MatchTypeFromString(goodScriptNode.ReadXmlElementAttr("resultMatchType", "match"));
                entry.GoodScriptText      = goodScriptNode.InnerText;

                XmlNode warningScriptNode = powerShellScriptRunnerNode.SelectSingleNode("warningScript");
                entry.WarningResultMatchType = CollectorAgentReturnValueCompareEngine.MatchTypeFromString(warningScriptNode.ReadXmlElementAttr("resultMatchType", "match"));
                entry.WarningScriptText      = warningScriptNode.InnerText;

                XmlNode errorScriptNode = powerShellScriptRunnerNode.SelectSingleNode("errorScript");
                entry.ErrorResultMatchType = CollectorAgentReturnValueCompareEngine.MatchTypeFromString(errorScriptNode.ReadXmlElementAttr("resultMatchType", "match"));
                entry.ErrorScriptText      = errorScriptNode.InnerText;

                Entries.Add(entry);
            }
            //New format
            foreach (XmlElement carvceEntryNode in root.SelectNodes("carvcesEntries/carvceEntry"))
            {
                PowerShellScriptRunnerEntry entry = new PowerShellScriptRunnerEntry();
                entry.Name            = carvceEntryNode.ReadXmlElementAttr("name", "");
                entry.PrimaryUIValue  = carvceEntryNode.ReadXmlElementAttr("primaryUIValue", false);
                entry.OutputValueUnit = carvceEntryNode.ReadXmlElementAttr("outputValueUnit", "");
                XmlNode testScriptNode = carvceEntryNode.SelectSingleNode("dataSource");
                entry.TestScript = testScriptNode.InnerText;

                XmlNode testConditionsNode = carvceEntryNode.SelectSingleNode("testConditions");
                entry.ReturnCheckSequence = CollectorAgentReturnValueCompareEngine.CheckSequenceTypeFromString(testConditionsNode.ReadXmlElementAttr("testSequence", "gwe"));

                XmlNode goodScriptNode = testConditionsNode.SelectSingleNode("success");
                entry.GoodResultMatchType = CollectorAgentReturnValueCompareEngine.MatchTypeFromString(goodScriptNode.ReadXmlElementAttr("testType", "match"));
                entry.GoodScriptText      = goodScriptNode.InnerText;

                XmlNode warningScriptNode = testConditionsNode.SelectSingleNode("warning");
                entry.WarningResultMatchType = CollectorAgentReturnValueCompareEngine.MatchTypeFromString(warningScriptNode.ReadXmlElementAttr("testType", "match"));
                entry.WarningScriptText      = warningScriptNode.InnerText;

                XmlNode errorScriptNode = testConditionsNode.SelectSingleNode("error");
                entry.ErrorResultMatchType = CollectorAgentReturnValueCompareEngine.MatchTypeFromString(errorScriptNode.ReadXmlElementAttr("testType", "match"));
                entry.ErrorScriptText      = errorScriptNode.InnerText;

                Entries.Add(entry);
            }
        }