Ejemplo n.º 1
0
 public static bool TryRemoveKnownSpell(this Biota biota, int spell, out BiotaPropertiesSpellBook entity, ReaderWriterLockSlim rwLock)
 {
     rwLock.EnterUpgradeableReadLock();
     try
     {
         entity = biota.BiotaPropertiesSpellBook.FirstOrDefault(x => x.Spell == spell);
         if (entity != null)
         {
             rwLock.EnterWriteLock();
             try
             {
                 biota.BiotaPropertiesSpellBook.Remove(entity);
                 entity.Object = null;
                 return(true);
             }
             finally
             {
                 rwLock.ExitWriteLock();
             }
         }
         return(false);
     }
     finally
     {
         rwLock.ExitUpgradeableReadLock();
     }
 }
Ejemplo n.º 2
0
        public static BiotaPropertiesSpellBook GetOrAddKnownSpell(this Biota biota, int spell, ReaderWriterLockSlim rwLock, out bool spellAdded)
        {
            rwLock.EnterUpgradeableReadLock();
            try
            {
                var entity = biota.BiotaPropertiesSpellBook.FirstOrDefault(x => x.Spell == spell);
                if (entity != null)
                {
                    spellAdded = false;
                    return(entity);
                }

                rwLock.EnterWriteLock();
                try
                {
                    entity = new BiotaPropertiesSpellBook {
                        ObjectId = biota.Id, Spell = spell, Object = biota
                    };
                    biota.BiotaPropertiesSpellBook.Add(entity);
                    spellAdded = true;
                    return(entity);
                }
                finally
                {
                    rwLock.ExitWriteLock();
                }
            }
            finally
            {
                rwLock.ExitUpgradeableReadLock();
            }
        }