/// <summary> /// Can the given underlying entity be locked by the intended owner? /// </summary> protected override bool CanLockUnderlyingEntity(ILockableState entity, ILocState owner, out ILocState lockedBy) { if (base.CanLockUnderlyingEntity(entity, owner, out lockedBy)) { return(true); } return((entity == From) && entity.IsLockedBy(owner)); }
/// <summary> /// Should this state be excluded given the exclusion? /// </summary> private bool ExcludeMe(ILockableState exclusion) { if (exclusion == null) { return(false); } if (exclusion == this) { return(true); } var impl = exclusion as ILockableStateImpl; return((impl != null) && impl.UnderlyingLockableEntities.Contains(this)); }
/// <summary> /// Unlock this state from the given owner. /// Also unlock all underlying entities except those where the given predicate returns true. /// </summary> public void Unlock(ILockableState exclusion) { if (lockedBy != null) { // Unlock underlying entities foreach (var item in UnderlyingLockableEntities) { item.Unlock(exclusion); } // Unlock me if (!ExcludeMe(exclusion)) { lockedBy.RemoveLockedEntity(this); lockedBy = null; } OnActualStateChanged(); AfterUnlock(); } }
/// <summary> /// Validate that the given state is locked by the given loc. /// If not, throw an error. /// </summary> public static void AssertLockedBy(this ILockableState state, ILocState loc) { if (state.LockedBy != loc) { var current = state.LockedBy; if (current == null) { throw new InvalidOperationException( string.Format(Strings.ObjectXNotLockedByYNotLocked, state, loc)); } else { throw new InvalidOperationException( string.Format(Strings.ObjectXNotLockedByYButByZ, state, loc, current)); } } }
/// <summary> /// Can the given underlying entity be locked by the intended owner? /// </summary> protected virtual bool CanLockUnderlyingEntity(ILockableState entity, ILocState owner, out ILocState lockedBy) { return(entity.CanLock(owner, out lockedBy)); }
/// <summary> /// Is the given state locked by the given loc? /// </summary> public static bool IsLockedBy(this ILockableState state, ILocState loc) { return(state.LockedBy == loc); }
/// <summary> /// Is the given state locked? /// </summary> public static bool IsLocked(this ILockableState state) { return(state.LockedBy != null); }
/// <summary> /// Remove a state object from the list of entities locked by this locomotive. /// </summary> internal void RemoveLockedEntity(ILockableState entity) { lockedEntities.Remove(entity); }
/// <summary> /// Add a state object to the list of entities locked by this locomotive. /// </summary> internal void AddLockedEntity(ILockableState entity) { lockedEntities.Add(entity); }