Esempio n. 1
0
        public void Run()
        {
            try
            {
                Method(this.Session, Script);
                if (Context.Job == null)
                {
                    return;
                }

                var output = new RunnerOutput
                {
                    Exception = null,
                    Output    = this.Session.Output.ToHtml(),
                    HasErrors = this.Session.Output.HasErrors,
                };

                Context.Job.Status.Result = output;
                JobContext.MessageQueue.PutMessage(new CompleteMessage {
                    RunnerOutput = output
                });
            }
            catch (ThreadAbortException ex)
            {
                TurboConsoleLog.Error("Script was aborted", ex);
                if (!Environment.HasShutdownStarted)
                {
                    Thread.ResetAbort();
                }
            }
            catch (Exception ex)
            {
                TurboConsoleLog.Error("Error while executing script.", ex);
                if (!Context.Job.IsNull())
                {
                    var output = new RunnerOutput()
                    {
                        Exception = ex,
                        Output    = String.Empty, //TODO: Implement
                        HasErrors = true
                    };
                    Context.Job.Status.Result = output;
                    var message = new CompleteMessage {
                        RunnerOutput = output
                    };
                    JobContext.MessageQueue.PutMessage(message);
                }
            }
        }
 private T TryGetSettingValue <T>(string fieldName, T defaultValue, Func <T> action)
 {
     try
     {
         var result = action();
         if (result != null && !String.IsNullOrEmpty(result.ToString()))
         {
             return(result);
         }
         return(defaultValue);
     }
     catch (Exception ex)
     {
         TurboConsoleLog.Error($"Error while restoring setting {fieldName}.", ex);
         return(defaultValue);
     }
 }
 public static void RemoveSession(String key)
 {
     lock (sessions)
     {
         if (sessions.Contains(key))
         {
             sessions.Remove(key);
         }
         if (HttpRuntime.Cache[key].IsNull())
         {
             return;
         }
         var session = HttpRuntime.Cache.Remove(key) as ScriptSession;
         if (!session.IsNull())
         {
             session.Dispose();
         }
         TurboConsoleLog.Debug($"Script session '{key}' disposed.");
     }
 }
        public static ScriptSession GetSession(String persistentId, String applicationType, Boolean personalizedSettings)
        {
            var autoDispose = String.IsNullOrEmpty(persistentId);

            if (autoDispose)
            {
                persistentId = Guid.NewGuid().ToString();
            }
            var sessionKey = GetSessionKey(persistentId);

            lock (sessions)
            {
                if (SessionExists(persistentId))
                {
                    return(HttpRuntime.Cache[sessionKey] as ScriptSession);
                }

                var session = new ScriptSession(applicationType, personalizedSettings)
                {
                    ID = persistentId
                };

                TurboConsoleLog.Debug($"New script session with key '{sessionKey}' created.");
                if (autoDispose)
                {
                    //this only should be set if new session has been created - do not change!
                    session.AutoDispose = true;
                }
                var expiration = Sitecore.Configuration.Settings.GetIntSetting(expirationSetting, 30);
                HttpRuntime.Cache.Add(sessionKey, session, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, expiration, 0), CacheItemPriority.Normal, CacheItemRemoved);
                sessions.Add(sessionKey);
                session.ID  = persistentId;
                session.Key = sessionKey;
                session.Initialize();
                return(session);
            }
        }