public MainDomSemaphoreLock(ILogger logger) { var lockName = "UMBRACO-" + MainDom.GetMainDomId() + "-MAINDOM-LCK"; _systemLock = new SystemLock(lockName); var eventName = "UMBRACO-" + MainDom.GetMainDomId() + "-MAINDOM-EVT"; _signal = new EventWaitHandle(false, EventResetMode.AutoReset, eventName); _logger = logger; }
private void AcquireMainDom(MainDom mainDom) { using (var timer = ProfilingLogger.DebugDuration <CoreRuntime>("Acquiring MainDom.", "Acquired.")) { try { mainDom.Acquire(); } catch { timer.Fail(); throw; } } }
/// <summary> /// Boots the runtime within a timer. /// </summary> protected virtual IFactory Boot(IRegister register, DisposableTimer timer) { Composition composition = null; try { // throws if not full-trust new AspNetHostingPermission(AspNetHostingPermissionLevel.Unrestricted).Demand(); // application caches var appCaches = GetAppCaches(); var runtimeCache = appCaches.RuntimeCache; // database factory var databaseFactory = GetDatabaseFactory(); // configs var configs = GetConfigs(); // type loader var localTempStorage = configs.Global().LocalTempStorageLocation; var typeLoader = new TypeLoader(runtimeCache, localTempStorage, ProfilingLogger); // runtime state // beware! must use '() => _factory.GetInstance<T>()' and NOT '_factory.GetInstance<T>' // as the second one captures the current value (null) and therefore fails _state = new RuntimeState(Logger, configs.Settings(), configs.Global(), new Lazy <IMainDom>(() => _factory.GetInstance <IMainDom>()), new Lazy <IServerRegistrar>(() => _factory.GetInstance <IServerRegistrar>())) { Level = RuntimeLevel.Boot }; // main dom var mainDom = new MainDom(Logger); // create the composition composition = new Composition(register, typeLoader, ProfilingLogger, _state, configs); composition.RegisterEssentials(Logger, Profiler, ProfilingLogger, mainDom, appCaches, databaseFactory, typeLoader, _state); // register runtime-level services // there should be none, really - this is here "just in case" Compose(composition); // acquire the main domain, determine our runtime level AcquireMainDom(mainDom); DetermineRuntimeLevel(databaseFactory, ProfilingLogger); // get composers, and compose var composerTypes = ResolveComposerTypes(typeLoader); composition.WithCollectionBuilder <ComponentCollectionBuilder>(); var composers = new Composers(composition, composerTypes, ProfilingLogger); composers.Compose(); // create the factory _factory = Current.Factory = composition.CreateFactory(); // create & initialize the components _components = _factory.GetInstance <ComponentCollection>(); _components.Initialize(); } catch (Exception e) { var bfe = e as BootFailedException ?? new BootFailedException("Boot failed.", e); if (_state != null) { _state.Level = RuntimeLevel.BootFailed; _state.BootFailedException = bfe; } timer.Fail(exception: bfe); // be sure to log the exception - even if we repeat ourselves // if something goes wrong above, we may end up with no factory // meaning nothing can get the runtime state, etc - so let's try // to make sure we have a factory if (_factory == null) { try { _factory = Current.Factory = composition?.CreateFactory(); } catch { /* yea */ } } Debugger.Break(); // throwing here can cause w3wp to hard-crash and we want to avoid it. // instead, we're logging the exception and setting level to BootFailed. // various parts of Umbraco such as UmbracoModule and UmbracoDefaultOwinStartup // understand this and will nullify themselves, while UmbracoModule will // throw a BootFailedException for every requests. } return(_factory); }