internal static void RunOnce() { // this code will execute once per request // we make sure that only one request will run the upgrade // we do not block the other requests while that one is running // and if the upgrade fails (throws)... have to restart the app // if for any reason the context is null, maybe that's a client-side // request (for an image, javascript, whatever) but anyway we cannot // do anything and have to wait for a proper request. if (UmbracoContext.Current == null) { return; } // sets to 1 and return the previous value - run only if zero if (Interlocked.Exchange(ref _ran, 1) > 0) { return; } var app = UmbracoContext.Current.HttpContext.ApplicationInstance; LogHelper.Info <YolApplication>("Run (once)."); YolManager.ExecuteInitialized(app, ApplicationContext.Current); LogHelper.Info <YolApplication>("Done running (once)."); }
/// <summary> /// Creates and registers an instance of the <see cref="YolManager"/> class with a name and a user login. /// </summary> /// <param name="name">The name of the manager.</param> /// <param name="login">The login of the user to impersonate while running the state machine.</param> /// <returns>The instance of the <see cref="YolManager"/> class.</returns> /// <exception cref="ArgumentException"><paramref name="name"/> and/or <paramref name="login"/> is <c>null</c> or empty.</exception> /// <exception cref="InvalidOperationException">A manager with that name has already been initialized.</exception> public static YolManager Create(string name, string login) { lock (Managers) { if (Managers.ContainsKey(name)) { throw new InvalidOperationException(string.Format("A manager named \"{0}\" has already been initialized.", name)); } return(Managers[name] = new YolManager(name, login)); } }