Ejemplo n.º 1
0
        protected virtual void JobExecuteScript(ClientPipelineArgs args, string scriptToExecute,
                                                ScriptSession scriptSession, bool autoDispose, bool debug)
        {
            ScriptRunning = true;
            UpdateRibbon();

            PowerShellLog.Info($"Arbitrary script execution in ISE by user: '******'");

            scriptSession.SetExecutedScript(ScriptItem);
            var parameters = new object[]
            {
                scriptSession,
                scriptToExecute
            };

            var progressBoxRunner = new ScriptRunner(ExecuteInternal, scriptSession, scriptToExecute, autoDispose);

            var rnd = new Random();

            Context.ClientPage.ClientResponse.SetInnerHtml(
                "ScriptResult",
                string.Format(
                    "<div id='PleaseWait'>" +
                    "<img src='../../../../../sitecore modules/PowerShell/Assets/working.gif' alt='" +
                    Texts.PowerShellIse_JobExecuteScript_Working +
                    "' />" +
                    "<div>" +
                    Texts.PowerShellIse_JobExecuteScript_Please_wait___0_ +
                    "</div>" +
                    "</div>" +
                    "<pre ID='ScriptResultCode'></pre>",
                    ExecutionMessages.PleaseWaitMessages[
                        rnd.Next(ExecutionMessages.PleaseWaitMessages.Length - 1)]));

            Context.ClientPage.ClientResponse.Eval("if(cognifide.powershell.preventCloseWhenRunning){cognifide.powershell.preventCloseWhenRunning(true);}");

            scriptSession.Debugging = debug;
            Monitor.Start($"{DefaultSessionName}", "ISE", progressBoxRunner.Run,
                          LanguageManager.IsValidLanguageName(CurrentLanguage)
                    ? LanguageManager.GetLanguage(CurrentLanguage)
                    : Context.Language,
                          User.Exists(CurrentUser)
                    ? User.FromName(CurrentUser, true)
                    : Context.User);

            Monitor.SessionID = scriptSession.ID;
            SheerResponse.Eval("cognifide.powershell.restoreResults();");

            var settings = ApplicationSettings.GetInstance(ApplicationNames.ISE);

            if (settings.SaveLastScript)
            {
                settings.Load();
                settings.LastScript = Editor.Value;
                settings.Save();
            }
        }
Ejemplo n.º 2
0
        protected virtual void JobExecuteScript(ClientPipelineArgs args, string scriptToExecute,
                                                ScriptSession scriptSession, bool autoDispose, bool debug)
        {
            ScriptRunning = true;
            UpdateRibbon();

            scriptSession.SetExecutedScript(ScriptItem);
            var parameters = new object[]
            {
                scriptSession,
                scriptToExecute
            };

            var progressBoxRunner = new ScriptRunner(ExecuteInternal, scriptSession, scriptToExecute, autoDispose);

            var rnd = new Random();

            Context.ClientPage.ClientResponse.SetInnerHtml(
                "ScriptResult",
                string.Format(
                    "<div id='PleaseWait'>" +
                    "<img src='../../../../../sitecore modules/PowerShell/Assets/working.gif' alt='Working' />" +
                    "<div>Please wait, {0}</div>" +
                    "</div>" +
                    "<pre ID='ScriptResultCode'></pre>",
                    ExecutionMessages.PleaseWaitMessages[
                        rnd.Next(ExecutionMessages.PleaseWaitMessages.Length - 1)]));

            Context.ClientPage.ClientResponse.Eval("if(cognifide.powershell.preventCloseWhenRunning){cognifide.powershell.preventCloseWhenRunning(true);}");

            scriptSession.Debugging = debug;
            Monitor.Start("ScriptExecution", "UI", progressBoxRunner.Run);

            Monitor.SessionID = scriptSession.ID;
            SheerResponse.Eval("cognifide.powershell.restoreResults();");

            var settings = ApplicationSettings.GetInstance(ApplicationNames.IseConsole);

            if (settings.SaveLastScript)
            {
                settings.Load();
                settings.LastScript = Editor.Value;
                settings.Save();
            }
        }
Ejemplo n.º 3
0
        private void ExecuteScriptJob(Item scriptItem, ScriptSession scriptSession, Message message, bool autoDispose)
        {
            var script = (scriptItem.Fields[ScriptItemFieldNames.Script] != null)
                ? scriptItem.Fields[ScriptItemFieldNames.Script].Value
                : string.Empty;

            SetVariables(scriptSession, message);

            scriptSession.SetExecutedScript(scriptItem);
            scriptSession.Interactive = true;
            ScriptSessionId           = scriptSession.ID;

            var progressBoxRunner = new ScriptRunner(ExecuteInternal, scriptSession, script, autoDispose);

            Monitor.Start("ScriptExecution", "UI", progressBoxRunner.Run);
            LvProgressOverlay.Visible = false;
            Monitor.SessionID         = scriptSession.ID;
        }
Ejemplo n.º 4
0
        private void ExecuteScriptJob(Item scriptItem, ScriptSession scriptSession, Message message, bool autoDispose)
        {
            if (!scriptItem.IsPowerShellScript())
            {
                SessionElevationErrors.OperationFailedWrongDataTemplate();
                return;
            }

            var script = scriptItem[Templates.Script.Fields.ScriptBody] ?? string.Empty;

            SetVariables(scriptSession, message);
            scriptSession.SetExecutedScript(scriptItem);
            scriptSession.Interactive = true;
            ScriptSessionId           = scriptSession.ID;

            var progressBoxRunner = new ScriptRunner(ExecuteInternal, scriptSession, script, autoDispose);

            Monitor.Start($"SPE - \"{ListViewer?.Data?.Title}\" - \"{scriptItem?.Name}\"", "UI", progressBoxRunner.Run);
            LvProgressOverlay.Visible = false;
            Monitor.SessionID         = scriptSession.ID;
        }