예제 #1
0
 /// <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));
 }
예제 #2
0
        /// <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));
        }
예제 #3
0
 /// <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();
     }
 }
예제 #4
0
 /// <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));
         }
     }
 }
예제 #5
0
 /// <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));
 }
예제 #6
0
 /// <summary>
 /// Is the given state locked by the given loc?
 /// </summary>
 public static bool IsLockedBy(this ILockableState state, ILocState loc)
 {
     return(state.LockedBy == loc);
 }
예제 #7
0
 /// <summary>
 /// Is the given state locked?
 /// </summary>
 public static bool IsLocked(this ILockableState state)
 {
     return(state.LockedBy != null);
 }
예제 #8
0
 /// <summary>
 /// Remove a state object from the list of entities locked by this locomotive.
 /// </summary>
 internal void RemoveLockedEntity(ILockableState entity)
 {
     lockedEntities.Remove(entity);
 }
예제 #9
0
 /// <summary>
 /// Add a state object to the list of entities locked by this locomotive.
 /// </summary>
 internal void AddLockedEntity(ILockableState entity)
 {
     lockedEntities.Add(entity);
 }