Esempio n. 1
0
 public static void AddOrUpdateShortcut(this Character character, uint index, uint objectId, ReaderWriterLockSlim rwLock)
 {
     rwLock.EnterUpgradeableReadLock();
     try
     {
         var entity = character.CharacterPropertiesShortcutBar.FirstOrDefault(x => x.ShortcutBarIndex == index + 1);
         rwLock.EnterWriteLock();
         try
         {
             if (entity == null)
             {
                 entity = new CharacterPropertiesShortcutBar {
                     CharacterId = character.Id, ShortcutObjectId = objectId, ShortcutBarIndex = index + 1, Character = character
                 };
                 character.CharacterPropertiesShortcutBar.Add(entity);
             }
             else
             {
                 entity.ShortcutObjectId = objectId;
             }
         }
         finally
         {
             rwLock.ExitWriteLock();
         }
     }
     finally
     {
         rwLock.ExitUpgradeableReadLock();
     }
 }
Esempio n. 2
0
        public static bool TryRemoveShortcut(this Character character, uint index, out CharacterPropertiesShortcutBar entity, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterUpgradeableReadLock();
            try
            {
                entity = character.CharacterPropertiesShortcutBar.FirstOrDefault(x => x.ShortcutBarIndex == index + 1);

                if (entity != null)
                {
                    rwLock.EnterWriteLock();
                    try
                    {
                        character.CharacterPropertiesShortcutBar.Remove(entity);
                        entity.Character = null;
                        return(true);
                    }
                    finally
                    {
                        rwLock.ExitWriteLock();
                    }
                }
                return(false);
            }
            finally
            {
                rwLock.ExitUpgradeableReadLock();
            }
        }
Esempio n. 3
0
 public static CharacterPropertiesShortcutBar AddShortcut(this Character character, uint index, uint objectId, ReaderWriterLockSlim rwLock)
 {
     rwLock.EnterWriteLock();
     try
     {
         var entity = new CharacterPropertiesShortcutBar {
             CharacterId = character.Id, ShortcutBarIndex = index, ShortcutObjectId = objectId, Character = character
         };
         character.CharacterPropertiesShortcutBar.Add(entity);
         return(entity);
     }
     finally
     {
         rwLock.ExitWriteLock();
     }
 }