コード例 #1
0
 public static bool TryRemoveFriend(this Character character, uint friendId, out CharacterPropertiesFriendList entity, ReaderWriterLockSlim rwLock)
 {
     rwLock.EnterUpgradeableReadLock();
     try
     {
         entity = character.CharacterPropertiesFriendList.FirstOrDefault(x => x.FriendId == friendId);
         if (entity != null)
         {
             rwLock.EnterWriteLock();
             try
             {
                 character.CharacterPropertiesFriendList.Remove(entity);
                 entity.Character = null;
                 return(true);
             }
             finally
             {
                 rwLock.ExitWriteLock();
             }
         }
         return(false);
     }
     finally
     {
         rwLock.ExitUpgradeableReadLock();
     }
 }
コード例 #2
0
ファイル: BiotaExtensions.cs プロジェクト: Cloudxtreme/ACE-1
 public static bool TryRemoveFriend(this Biota biota, ObjectGuid friendGuid, out CharacterPropertiesFriendList entity, ReaderWriterLockSlim rwLock)
 {
     rwLock.EnterUpgradeableReadLock();
     try
     {
         entity = biota.CharacterPropertiesFriendList.FirstOrDefault(x => x.FriendId == friendGuid.Full);
         if (entity != null)
         {
             rwLock.EnterWriteLock();
             try
             {
                 biota.CharacterPropertiesFriendList.Remove(entity);
                 entity.Object = null;
                 return(true);
             }
             finally
             {
                 rwLock.ExitWriteLock();
             }
         }
         return(false);
     }
     finally
     {
         rwLock.ExitUpgradeableReadLock();
     }
 }
コード例 #3
0
        public static CharacterPropertiesFriendList AddFriend(this Character character, uint friendId, ReaderWriterLockSlim rwLock, out bool friendAlreadyExists)
        {
            rwLock.EnterUpgradeableReadLock();
            try
            {
                var entity = character.CharacterPropertiesFriendList.FirstOrDefault(x => x.FriendId == friendId);
                if (entity != null)
                {
                    friendAlreadyExists = true;
                    return(entity);
                }

                rwLock.EnterWriteLock();
                try
                {
                    entity = new CharacterPropertiesFriendList {
                        CharacterId = character.Id, FriendId = friendId, Character = character
                    };
                    character.CharacterPropertiesFriendList.Add(entity);
                    friendAlreadyExists = false;
                    return(entity);
                }
                finally
                {
                    rwLock.ExitWriteLock();
                }
            }
            finally
            {
                rwLock.ExitUpgradeableReadLock();
            }
        }
コード例 #4
0
ファイル: CharacterExtensions.cs プロジェクト: Zegeger/ACE
        public static bool TryRemoveFriend(this Character character, ObjectGuid friendGuid, out CharacterPropertiesFriendList entity)
        {
            entity = character.CharacterPropertiesFriendList.FirstOrDefault(x => x.FriendId == friendGuid.Full);

            if (entity != null)
            {
                character.CharacterPropertiesFriendList.Remove(entity);
                entity.Character = null;
                return(true);
            }

            return(false);
        }