private Smock(IServiceLocator serviceLocator) { ArgumentChecker.NotNull(serviceLocator, () => serviceLocator); _setupExtractor = serviceLocator.Resolve <ISetupExtractor>(); _eventTargetExtractor = serviceLocator.Resolve <IEventTargetExtractor>(); _dependencyGraphBuilder = serviceLocator.Resolve <IDependencyGraphBuilder>(); _moduleFilterFactory = serviceLocator.Resolve <IModuleFilterFactory>(); _serviceLocator = serviceLocator; }
private Smock(Configuration configuration) { ArgumentChecker.NotNull(configuration, nameof(configuration)); _serviceLocator = CreateServiceLocator(configuration); _setupExtractor = _serviceLocator.Resolve <ISetupExtractor>(); _eventTargetExtractor = _serviceLocator.Resolve <IEventTargetExtractor>(); _dependencyGraphBuilder = _serviceLocator.Resolve <IDependencyGraphBuilder>(); _moduleFilterFactory = _serviceLocator.Resolve <IModuleFilterFactory>(); }
public void Pause(Object eventTarget) { if (GuiThreadHelper.IsInGuiThread()) { // Nothing to do return; } IEventTargetExtractor eventTargetExtractor = typeToEventTargetExtractorsDict.GetExtension(eventTarget.GetType()); if (eventTargetExtractor == null) { return; } eventTarget = eventTargetExtractor.ExtractEventTarget(eventTarget); if (eventTarget == null) { return; } PausedEventTargetItem etiKey = new PausedEventTargetItem(eventTarget); listenersWriteLock.Lock(); try { PausedEventTargetItem pauseETI = pausedTargets.Get(eventTarget); if (pauseETI == null) { pauseETI = new PausedEventTargetItem(eventTarget); pausedTargets.Put(eventTarget, pauseETI); } pauseETI.PauseCount++; } finally { listenersWriteLock.Unlock(); } }
public void UnregisterEventTargetExtractor(IEventTargetExtractor eventTargetExtractor, Type eventType) { typeToEventTargetExtractorsDict.Unregister(eventTargetExtractor, eventType); }
public void Resume(Object eventTarget) { if (GuiThreadHelper.IsInGuiThread()) { // Nothing to do return; } IEventTargetExtractor eventTargetExtractor = typeToEventTargetExtractorsDict.GetExtension(eventTarget.GetType()); if (eventTargetExtractor == null) { return; } eventTarget = eventTargetExtractor.ExtractEventTarget(eventTarget); if (eventTarget == null) { return; } IdentityLinkedSet <WaitForResumeItem> freeLatchMap = null; try { PausedEventTargetItem pauseETI; listenersWriteLock.Lock(); try { IdentityLinkedMap <Object, PausedEventTargetItem> pausedTargets = this.pausedTargets; pauseETI = pausedTargets.Get(eventTarget); if (pauseETI == null) { throw new System.Exception("No pause() active for target " + eventTarget); } pauseETI.PauseCount--; if (pauseETI.PauseCount > 0) { return; } pausedTargets.Remove(eventTarget); IList <Object> remainingPausedEventTargets = EvaluatePausedEventTargets(); IdentityHashSet <Object> remainingPausedEventTargetsSet = new IdentityHashSet <Object>(); Iterator <WaitForResumeItem> iter = waitForResumeSet.Iterator(); while (iter.MoveNext()) { WaitForResumeItem pauseItem = iter.Current; remainingPausedEventTargetsSet.AddAll(remainingPausedEventTargets); remainingPausedEventTargetsSet.RetainAll(pauseItem.PendingPauses); if (remainingPausedEventTargetsSet.Count == 0) { iter.Remove(); if (freeLatchMap == null) { freeLatchMap = new IdentityLinkedSet <WaitForResumeItem>(); } freeLatchMap.Add(pauseItem); } remainingPausedEventTargetsSet.Clear(); } } finally { listenersWriteLock.Unlock(); } } finally { if (freeLatchMap != null) { foreach (WaitForResumeItem wfrItem in freeLatchMap) { wfrItem.Latch.CountDown(); } foreach (WaitForResumeItem wfrItem in freeLatchMap) { try { wfrItem.ResultLatch.Await(); } catch (System.Exception e) { throw new System.Exception("Fatal state occured. This may result in a global deadlock", e); } } } } }