protected void Page_PreRender(object sender, EventArgs e)
    {
        if (hdnSelectedRow.Text != "")
        {
            gvScripts.Rows[Int32.Parse(hdnSelectedRow.Text)].Attributes.Remove("onmouseout");
            gvScripts.Rows[Int32.Parse(hdnSelectedRow.Text)].Style.Add("background", "lightblue");
            txtName.Text = hdnSelectedScriptName.Text;
            ddlScriptProcessor.SelectedValue = gvScripts.DataKeys[Int32.Parse(hdnSelectedRow.Text)]["script_processor_name"].ToString();
            hdnScript.Value = OSAEScriptManager.GetScript(gvScripts.DataKeys[Int32.Parse(hdnSelectedRow.Text)]["script_id"].ToString());
            loadLinkage(gvScripts.DataKeys[Int32.Parse(hdnSelectedRow.Text)]["script_id"].ToString());
            lblCopyScript.Text   = OSAEScriptManager.GetScriptByName(hdnSelectedScriptName.Text);
            lblExportScript.Text = OSAEScriptManager.ExportScript(hdnSelectedScriptName.Text);
        }
        if (hdnSelectedEventScriptRow.Text != "")
        {
            gvEventScripts.Rows[Int32.Parse(hdnSelectedEventScriptRow.Text)].Attributes.Remove("onmouseout");
            gvEventScripts.Rows[Int32.Parse(hdnSelectedEventScriptRow.Text)].Style.Add("background", "lightblue");
        }

        if (hdnSelectedObjTypeEventScriptRow.Text != "")
        {
            gvObjTypeScripts.Rows[Int32.Parse(hdnSelectedObjTypeEventScriptRow.Text)].Attributes.Remove("onmouseout");
            gvObjTypeScripts.Rows[Int32.Parse(hdnSelectedObjTypeEventScriptRow.Text)].Style.Add("background", "lightblue");
        }
    }
Exemple #2
0
        /// <summary>
        /// A Command to be processed bu the plugin
        /// </summary>
        /// <param name="method"></param>
        public override void ProcessCommand(OSAEMethod method)
        {
            try
            {
                string script = "";

                int scriptId;
                if (int.TryParse(method.Parameter1, out scriptId))
                {
                    script = OSAEScriptManager.GetScript(method.Parameter1);
                }
                else
                {
                    script = OSAEScriptManager.GetScriptByName(method.Parameter1);
                }

                this.Log.Debug("running script: " + script);

                if (!string.IsNullOrEmpty(script))
                {
                    RunScript(script, method);
                }
            }
            catch (Exception exc)
            {
                this.Log.Error("Error Processing Command ", exc);
            }
        }
        /// <summary>
        /// A Command to be processed bu the plugin
        /// </summary>
        /// <param name="method"></param>
        public override void ProcessCommand(OSAEMethod method)
        {
            try
            {
                string script = "";

                int scriptId;
                if (int.TryParse(method.Parameter1, out scriptId))
                {
                    script = OSAEScriptManager.GetScript(method.Parameter1);
                }
                else
                {
                    script = OSAEScriptManager.GetScriptByName(method.Parameter1);
                }

                logging.AddToLog("running script: " + script, false);

                if (!string.IsNullOrEmpty(script))
                {
                    RunScript(script, method);
                }
            }
            catch (Exception exc)
            {
                logging.AddToLog("Error Processing Command: " + exc.Message, true);
            }
        }
        private void RunNested()
        {
            Pipeline pipeline = null;

            try
            {
                pipeline = Runspace.DefaultRunspace.CreateNestedPipeline();
                string  script    = OSAEScriptManager.GetScriptByName(Name);
                Command psCommand = new Command(script, true);
                pipeline.Commands.Add(psCommand);

                pipeline.Commands.Add("Out-String");

                Collection <PSObject> results = pipeline.Invoke();

                StringBuilder stringBuilder = new StringBuilder();
                foreach (PSObject obj in results)
                {
                    stringBuilder.AppendLine(obj.ToString());
                }

                logging.AddToLog("Script return: \r\n" + stringBuilder.ToString(), false);
            }
            catch (Exception ex)
            {
                logging.AddToLog("An error occured while trying to run the script, details: \r\n" + ex.Message, true);
            }
            finally
            {
                if (pipeline != null)
                {
                    pipeline.Dispose();
                }
            }
        }
        private void RunNormal()
        {
            Pipeline pipeline = null;
            Runspace runspace = null;

            try
            {
                RunspaceConfiguration runConfig = RunspaceConfiguration.Create();

                PSSnapInException psEx   = null;
                string            script = OSAEScriptManager.GetScriptByName(Name);
                runConfig.AddPSSnapIn("OSA", out psEx);
                runspace = RunspaceFactory.CreateRunspace(runConfig);
                runspace.ThreadOptions = PSThreadOptions.UseCurrentThread;

                runspace.Open();

                runspace.SessionStateProxy.SetVariable("parameter2", Parameter2);

                pipeline = runspace.CreatePipeline();
                pipeline.Commands.AddScript(script);
                pipeline.Commands.Add("Out-String");

                Collection <PSObject> results = pipeline.Invoke();

                StringBuilder stringBuilder = new StringBuilder();
                foreach (PSObject obj in results)
                {
                    stringBuilder.AppendLine(obj.ToString());
                }

                logging.AddToLog("Script return: \r\n" + stringBuilder.ToString(), false);
            }
            catch (Exception ex)
            {
                logging.AddToLog("An error occured while trying to run the script, details: \r\n" + ex.Message, true);
            }
            finally
            {
                if (pipeline != null)
                {
                    pipeline.Dispose();
                }
                if (runspace != null)
                {
                    runspace.Close();
                    runspace.Dispose();
                }
            }
        }
 protected void btnScriptExport_Click(object sender, EventArgs e)
 {
     OSAEScriptManager.GetScriptByName(hdnSelectedObjTypeEventScriptID.Text);
 }