Esempio n. 1
0
        protected override void ProcessRecord()
        {
            LogErrors(() =>
            {
                var message =
                    new ShowApplicationMessage(Application, Title, Icon, WidthString, HeightString, Modal.IsPresent,
                        Parameter);

                PutMessage(message);
            });
        }
Esempio n. 2
0
        protected override void ProcessRecord()
        {
            LogErrors(() =>
            {
                if (!CheckSessionCanDoInteractiveAction()) return;

                var message =
                    new ShowApplicationMessage(Application, Title, Icon, WidthString, HeightString, Modal.IsPresent,
                        Parameter);

                PutMessage(message);
            });
        }
        protected override void ProcessSession(ScriptSession session)
        {
            if (session.State == RunspaceAvailability.Busy)
            {
                WriteError(typeof(CmdletInvocationException),
                    $"The script session with Id '{session.ID}' cannot execute the script because it is Busy. Use Stop-ScriptSession or wait for the operation to complete.",
                    ErrorIds.ScriptSessionBusy, ErrorCategory.ResourceBusy, session.ID);
                return;
            }
            session.AutoDispose = AutoDispose;
            session.SetItemLocationContext(ContextItem);

            if (ArgumentList != null)
            {
                foreach (string argument in ArgumentList.Keys)
                {
                    session.SetVariable(argument, ArgumentList[argument]);
                }
            }

            var handle = string.IsNullOrEmpty(JobName) ? ID.NewID.ToString() : JobName;
            var jobOptions = new JobOptions(GetJobId(session.ID, handle), "PowerShell", "shell", this, "RunJob",
                new object[] { session, scriptBlock.ToString() })
            {
                AfterLife = new TimeSpan(0, 0, 1),
                ContextUser = Identity ?? Context.User,
                EnableSecurity = !DisableSecurity,
                ClientLanguage = Context.ContentLanguage
            };

            if (Interactive)
            {
                var appParams = new Hashtable();
                if (scriptItem != null)
                {
                    appParams.Add("scriptId", scriptItem.ID.ToString());
                    appParams.Add("scriptDb", scriptItem.Database.Name);
                }
                else
                {
                    session.JobScript = scriptBlock.ToString();
                    session.JobOptions = jobOptions;
                }
                appParams.Add("appMode", "1");
                appParams.Add("sessionKey", session.Key);

                var message = new ShowApplicationMessage("PowerShell/PowerShell Runner", "PowerShell", "", "500", "360",
                    false, appParams)
                {Title = " "};
                PutMessage(message);
            }
            else
            {
                Sitecore.Jobs.JobManager.Start(jobOptions);
            }
            WriteObject(session);
        }