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(); } }
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(); } }
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(); } }
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); }