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 = session.GetExceptionString(ex);
                    if (job.Options.WriteToLog)
                    {
                        Log.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
                {
                    Log.Error("Script execution failed. Could not find command job.", ex, this);
                }
            }
            finally
            {
                if (session.AutoDispose)
                {
                    session.Dispose();
                }
            }
        }
        protected void RunJob(ScriptSession session, string command)
        {
            if (!WebServiceSettings.ServiceEnabledClient || !Sitecore.Context.IsLoggedIn)
            {
                return;
            }
            try
            {
                if (!string.IsNullOrEmpty(command))
                {
                    if (session.IsRunning)
                    {
                        session.ImmediateCommand = command;
                        var tries = 20;
                        while (!string.IsNullOrEmpty(session.ImmediateCommand) && tries > 0)
                        {
                            Thread.Sleep(100);
                            tries--;
                        }
                    }
                    else
                    {
                        session.ExecuteScriptPart(command);
                    }
                }
            }
            catch (Exception ex)
            {
                var job = Sitecore.Context.Job;
                if (job != null)
                {
                    job.Status.Failed = true;

                    var exceptionMessage = session.GetExceptionString(ex);
                    if (job.Options.WriteToLog)
                    {
                        Log.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
                {
                    Log.Error("Script execution failed. Could not find command job.", ex, this);
                }
            }
        }