예제 #1
0
        protected void RunJob(ScriptSession session, string command)
        {
            try
            {
                session.JobResultsStore = null;
                session.JobResultsStore = session.ExecuteScriptPart(command, false, false, false);
            }
            catch (Exception ex)
            {
                var jobManager = TypeResolver.ResolveFromCache <IJobManager>();
                var job        = jobManager.GetContextJob();
                if (job != null)
                {
                    job.StatusFailed = true;

                    var exceptionMessage = ScriptSession.GetExceptionString(ex);
                    if (job.Options.WriteToLog)
                    {
                        PowerShellLog.Error("Error while executing PowerShell Extensions script.", ex);
                    }
                    job.AddStatusMessage(exceptionMessage);
                    job.AddStatusMessage(
                        "Uh oh, looks like the command you ran is invalid or something else went wrong. Is it something we should know about?");
                    job.AddStatusMessage(
                        "Please submit a support ticket here https://git.io/spe with error details, screenshots, and anything else that might help.");
                    job.AddStatusMessage(
                        "We also have a user guide here https://doc.sitecorepowershell.com/.");
                }
                else
                {
                    PowerShellLog.Error("Script execution failed. Could not find command job.", ex);
                }
            }
            finally
            {
                if (session.AutoDispose)
                {
                    session.Dispose();
                }
            }
        }
예제 #2
0
        protected void RunJob(ScriptSession session, string command)
        {
            try
            {
                session.JobResultsStore = null;
                session.JobResultsStore = session.ExecuteScriptPart(command, false, false, false);
            }
            catch (Exception ex)
            {
                var job = Sitecore.Context.Job;
                if (job != null)
                {
                    job.Status.Failed = true;

                    var exceptionMessage = ScriptSession.GetExceptionString(ex);
                    if (job.Options.WriteToLog)
                    {
                        LogUtils.Error(exceptionMessage, this);
                    }
                    job.Status.Messages.Add(exceptionMessage);
                    job.Status.Messages.Add(
                        "Uh oh, looks like the command you ran is invalid or something else went wrong. Is it something we should know about?");
                    job.Status.Messages.Add(
                        "Please submit a support ticket here https://git.io/spe with error details, screenshots, and anything else that might help.");
                    job.Status.Messages.Add(
                        "We also have a user guide here http://sitecorepowershell.gitbooks.io/sitecore-powershell-extensions/.");
                }
                else
                {
                    LogUtils.Error("Script execution failed. Could not find command job.", ex, this);
                }
            }
            finally
            {
                if (session.AutoDispose)
                {
                    session.Dispose();
                }
            }
        }