コード例 #1
0
        /// <summary>
        /// Handles clicks on Save button, including copying data back to Program.Settings
        /// and forcing list selection index update to revert to non-edit mode
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            // Find the old one if it exists so that we can replace/update as necessary.
            WSHScript oldW = Program.Settings.WSHScripts.Find(WSHScript => WSHScript.Name == (string)listQueries.SelectedItem);
            WSHScript W    = new WSHScript();

            W.Name       = txtName.Text;
            W.ScriptPath = txtPath.Text;
            W.Parameters = txtParams.Text;
            W.Timeout    = Convert.ToInt32(numTimeout.Value);
            // Remove the old one if needed
            if (oldW != null)
            {
                Program.Settings.WSHScripts.Remove(oldW);
            }
            Program.Settings.WSHScripts.Add(W);

            // Now work out what we have to do to the list of objects
            if ((oldW != null) && (oldW.Name != W.Name))
            {
                listQueries.Items.RemoveAt(listQueries.SelectedIndex);
            }
            else if ((oldW == null) || (oldW.Name != W.Name))
            {
                listQueries.Items.Add(txtName.Text);
            }

            // Update so the right item is selected (and force refresh if it didn't move)
            listQueries.SelectedIndex = listQueries.Items.IndexOf(txtName.Text);
            listQueries_SelectedIndexChanged(sender, e);
        }
コード例 #2
0
 /// <summary>
 /// Handles selection changes in the list of scripts. Enforces editing/not editing mode, preloads
 /// data to each field based on selected ID.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void listQueries_SelectedIndexChanged(object sender, EventArgs e)
 {
     txtName.Enabled    = false; txtName.ReadOnly = true;
     txtPath.Enabled    = false; txtPath.ReadOnly = true;
     txtParams.Enabled  = false; txtParams.ReadOnly = true;
     numTimeout.Enabled = false; numTimeout.ReadOnly = true;
     if (listQueries.SelectedItem != null)
     {
         WSHScript W = Program.Settings.WSHScripts.Find(WSHScript => WSHScript.Name == (string)listQueries.SelectedItem);
         btnEdit.Enabled   = true;
         btnDelete.Enabled = true;
         txtName.Text      = W.Name;
         txtPath.Text      = W.ScriptPath;
         txtParams.Text    = W.Parameters;
         numTimeout.Value  = W.Timeout;
     }
     else
     {
         btnEdit.Enabled   = false;
         btnDelete.Enabled = false;
         txtName.Text      = WSHScript.Defaults.Name;
         txtPath.Text      = WSHScript.Defaults.ScriptPath;
         txtParams.Text    = WSHScript.Defaults.Parameters;
         numTimeout.Value  = WSHScript.Defaults.Timeout;
     }
 }
コード例 #3
0
        /// <summary>
        /// Handles clicks on Delete button, including edit mode enable/disable, removing
        /// old item from the Program.Settings collection
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, EventArgs e)
        {
            WSHScript W = Program.Settings.WSHScripts.Find(WSHScript => WSHScript.Name == (string)listQueries.SelectedItem);

            Program.Settings.WSHScripts.Remove(W);
            listQueries.Items.RemoveAt(listQueries.SelectedIndex);
        }
コード例 #4
0
ファイル: RenderForm.cs プロジェクト: ninjanody/WPInfo
        /// <summary>
        /// Executes and returns the output of the WSH Script nominated by ID. The list of known IDs is
        /// stored in Program.Settings so it can be saved and restored
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        private string[] ExecScript(string ID)
        {
            WSHScript        S          = Program.Settings.WSHScripts.Find(WSHScript => WSHScript.Name == ID);
            DateTime         dtDeadLine = DateTime.Now.AddSeconds(S.Timeout);
            ProcessStartInfo psi        = new ProcessStartInfo();

            psi.RedirectStandardOutput = true;
            psi.RedirectStandardError  = true;
            psi.FileName        = "wscript.exe";
            psi.WindowStyle     = ProcessWindowStyle.Hidden;
            psi.Arguments       = S.Name + " " + S.Parameters;
            psi.UseShellExecute = false;
            Process p = Process.Start(psi);

            while ((DateTime.Now <= dtDeadLine) && (!p.HasExited))
            {
                Thread.Sleep(1000);
            }
            if (!p.HasExited)
            {
                p.Kill();
                return(new string[] { "Runtime exceeded for script " + ID });
            }
            using (StreamReader sr = p.StandardOutput)
            {
                List <string> l = new List <string>();
                while (!sr.EndOfStream)
                {
                    l.Add(sr.ReadLine());
                }
                return(l.ToArray());
            }
        }
コード例 #5
0
ファイル: WSHScript.cs プロジェクト: shabbirh/WPInfo
        /// <summary>
        /// Implement the ICloneable interface
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            WSHScript clone = new WSHScript();
            clone.Name = Name.Clone() as string;
            clone.ScriptPath = ScriptPath.Clone() as string;
            clone.Parameters = Parameters.Clone() as string;
            clone.Timeout = Timeout;

            return clone;
        }
コード例 #6
0
ファイル: WSHScript.cs プロジェクト: ninjanody/WPInfo
        /// <summary>
        /// Implement the ICloneable interface
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            WSHScript clone = new WSHScript();

            clone.Name       = Name.Clone() as string;
            clone.ScriptPath = ScriptPath.Clone() as string;
            clone.Parameters = Parameters.Clone() as string;
            clone.Timeout    = Timeout;

            return(clone);
        }
コード例 #7
0
ファイル: WSHScriptForm.cs プロジェクト: shabbirh/WPInfo
        /// <summary>
        /// Handles clicks on Save button, including copying data back to Program.Settings
        /// and forcing list selection index update to revert to non-edit mode
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            // Find the old one if it exists so that we can replace/update as necessary.
            WSHScript oldW = Program.Settings.WSHScripts.Find(WSHScript => WSHScript.Name == (string)listQueries.SelectedItem);
            WSHScript W = new WSHScript();
            W.Name = txtName.Text;
            W.ScriptPath = txtPath.Text;
            W.Parameters = txtParams.Text;
            W.Timeout = Convert.ToInt32(numTimeout.Value);
            // Remove the old one if needed
            if (oldW != null) Program.Settings.WSHScripts.Remove(oldW);
            Program.Settings.WSHScripts.Add(W);

            // Now work out what we have to do to the list of objects
            if ((oldW != null) && (oldW.Name != W.Name))
                listQueries.Items.RemoveAt(listQueries.SelectedIndex);
            else if ((oldW == null) || (oldW.Name != W.Name))
                listQueries.Items.Add(txtName.Text);

            // Update so the right item is selected (and force refresh if it didn't move)
            listQueries.SelectedIndex = listQueries.Items.IndexOf(txtName.Text);
            listQueries_SelectedIndexChanged(sender, e);
        }