System.Threading.ReaderWriterLockSlim.EnterReadLock()

Here are the examples of the csharp api System.Threading.ReaderWriterLockSlim.EnterReadLock() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

773 Examples 7

19 View Source File : BiotaExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static Dictionary<int, float> GetMatchingSpells(this Biota biota, HashSet<int> match, ReaderWriterLockSlim rwLock)
        {
            if (biota.PropertiesSpellBook == null)
                return new Dictionary<int, float>();

            rwLock.EnterReadLock();
            try
            {
                var results = new Dictionary<int, float>();

                foreach (var value in biota.PropertiesSpellBook)
                {
                    if (match.Contains(value.Key))
                        results[value.Key] = value.Value;
                }

                return results;
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : PropertiesAnimPartExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static int GetCount(this IList<PropertiesAnimPart> value, ReaderWriterLockSlim rwLock)
        {
            if (value == null)
                return 0;

            rwLock.EnterReadLock();
            try
            {
                return value.Count;
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : CharacterExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static int GetContractsCount(this Character character, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterReadLock();
            try
            {
                return character.CharacterPropertiesContractRegistry.Count;
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : BiotaExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static List<int> GetKnownSpellsIds(this Biota biota, ReaderWriterLockSlim rwLock)
        {
            if (biota.PropertiesSpellBook == null)
                return new List<int>();

            rwLock.EnterReadLock();
            try
            {
                if (biota.PropertiesSpellBook == null)
                    return new List<int>();

                return new List<int>(biota.PropertiesSpellBook.Keys);
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : BiotaExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static uint? GetProperty(this Biota biota, PropertyInstanceId property, ReaderWriterLockSlim rwLock)
        {
            if (biota.PropertiesIID == null)
                return null;

            rwLock.EnterReadLock();
            try
            {
                if (biota.PropertiesIID.TryGetValue(property, out var value))
                    return value;

                return null;
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : ShardDatabaseWithCaching.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public override bool SaveBiota(ACE.Enreplacedy.Models.Biota biota, ReaderWriterLockSlim rwLock)
        {
            CacheObject<Biota> cachedBiota;

            lock (biotaCacheMutex)
                biotaCache.TryGetValue(biota.Id, out cachedBiota);

            if (cachedBiota != null)
            {
                cachedBiota.LastSeen = DateTime.UtcNow;

                rwLock.EnterReadLock();
                try
                {
                    ACE.Database.Adapter.BiotaUpdater.UpdateDatabaseBiota(cachedBiota.Context, biota, cachedBiota.CachedObject);
                }
                finally
                {
                    rwLock.ExitReadLock();
                }

                return DoSaveBiota(cachedBiota.Context, cachedBiota.CachedObject);
            }

            // Biota does not exist in the cache

            var context = new ShardDbContext();

            var existingBiota = base.GetBiota(context, biota.Id);

            rwLock.EnterReadLock();
            try
            {
                if (existingBiota == null)
                {
                    existingBiota = ACE.Database.Adapter.BiotaConverter.ConvertFromEnreplacedyBiota(biota);

                    context.Biota.Add(existingBiota);
                }
                else
                {
                    ACE.Database.Adapter.BiotaUpdater.UpdateDatabaseBiota(context, biota, existingBiota);
                }
            }
            finally
            {
                rwLock.ExitReadLock();
            }

            if (DoSaveBiota(context, existingBiota))
            {
                TryAddToCache(context, existingBiota);

                return true;
            }

            return false;
        }

19 View Source File : BiotaExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static bool? GetHouseGuestStoragePermission(this Biota biota, uint guestGuid, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterReadLock();
            try
            {
                if (biota.HousePermissions == null)
                    return null;

                if (!biota.HousePermissions.TryGetValue(guestGuid, out var value))
                    return null;

                return value;
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : CharacterExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static bool HasAsFriend(this Character character, uint friendId, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterReadLock();
            try
            {
                foreach (var record in character.CharacterPropertiesFriendList)
                {
                    if (record.FriendId == friendId)
                        return true;
                }

                return false;
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

public static int GetPageCount(this IList<PropertiesBookPageData> value, ReaderWriterLockSlim rwLock)
        {
            if (value == null)
                return 0;

            rwLock.EnterReadLock();
            try
            {
                return value.Count;
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : CharacterExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static CharacterPropertiesQuestRegistry GetQuest(this Character character, string questName, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterReadLock();
            try
            {
                return character.CharacterPropertiesQuestRegistry.FirstOrDefault(q => q.QuestName.Equals(questName, StringComparison.OrdinalIgnoreCase));
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : BiotaExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static Dictionary<int, float> CloneSpells(this Biota biota, ReaderWriterLockSlim rwLock)
        {
            if (biota.PropertiesSpellBook == null)
                return new Dictionary<int, float>();

            rwLock.EnterReadLock();
            try
            {
                var results = new Dictionary<int, float>();

                foreach (var kvp in biota.PropertiesSpellBook)
                    results[kvp.Key] = kvp.Value;

                return results;
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : BiotaExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static long? GetProperty(this Biota biota, PropertyInt64 property, ReaderWriterLockSlim rwLock)
        {
            if (biota.PropertiesInt64 == null)
                return null;

            rwLock.EnterReadLock();
            try
            {
                if (biota.PropertiesInt64.TryGetValue(property, out var value))
                    return value;

                return null;
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : CharacterExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static List<CharacterPropertiesreplacedleBook> Getreplacedles(this Character character, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterReadLock();
            try
            {
                return character.CharacterPropertiesreplacedleBook.ToList();
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : BiotaExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static List<float> GetKnownSpellsProbabilities(this Biota biota, ReaderWriterLockSlim rwLock)
        {
            if (biota.PropertiesSpellBook == null)
                return new List<float>();

            rwLock.EnterReadLock();
            try
            {
                if (biota.PropertiesSpellBook == null)
                    return new List<float>();

                return new List<float>(biota.PropertiesSpellBook.Values);
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : CharacterExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static List<CharacterPropertiesFillCompBook> GetFillComponents(this Character character, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterReadLock();
            try
            {
                return character.CharacterPropertiesFillCompBook.ToList();
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : BiotaExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static Dictionary<uint, bool> CloneHousePermissions(this Biota biota, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterReadLock();
            try
            {
                if (biota.HousePermissions == null)
                    return new Dictionary<uint, bool>();

                return new Dictionary<uint, bool>(biota.HousePermissions);
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : ShardDatabase.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public bool RenameCharacter(Character character, string newName, ReaderWriterLockSlim rwLock)
        {
            if (CharacterContexts.TryGetValue(character, out var cachedContext))
            {
                rwLock.EnterReadLock();
                try
                {
                    Exception firstException = null;
                retry:

                    try
                    {
                        character.Name = newName;
                        cachedContext.SaveChanges();

                        if (firstException != null)
                            log.Debug($"[DATABASE] RenameCharacter 0x{character.Id:X8}:{character.Name} retry succeeded after initial exception of: {firstException.GetFullMessage()}");

                        return true;
                    }
                    catch (Exception ex)
                    {
                        if (firstException == null)
                        {
                            firstException = ex;
                            goto retry;
                        }

                        // Character name might be in use or some other fault
                        log.Error($"[DATABASE] RenameCharacter 0x{character.Id:X8}:{character.Name} failed first attempt with exception: {firstException.GetFullMessage()}");
                        log.Error($"[DATABASE] RenameCharacter 0x{character.Id:X8}:{character.Name} failed second attempt with exception: {ex.GetFullMessage()}");
                        return false;
                    }
                }
                finally
                {
                    rwLock.ExitReadLock();
                }
            }

            character.Name = newName;

            var context = new ShardDbContext();

            CharacterContexts.Add(character, context);

            rwLock.EnterReadLock();
            try
            {
                context.Character.Add(character);

                Exception firstException = null;
            retry:

                try
                {
                    context.SaveChanges();

                    if (firstException != null)
                        log.Debug($"[DATABASE] RenameCharacter 0x{character.Id:X8}:{character.Name} retry succeeded after initial exception of: {firstException.GetFullMessage()}");

                    return true;
                }
                catch (Exception ex)
                {
                    if (firstException == null)
                    {
                        firstException = ex;
                        goto retry;
                    }

                    // Character name might be in use or some other fault
                    log.Error($"[DATABASE] RenameCharacter 0x{character.Id:X8}:{character.Name} failed first attempt with exception: {firstException.GetFullMessage()}");
                    log.Error($"[DATABASE] RenameCharacter 0x{character.Id:X8}:{character.Name} failed second attempt with exception: {ex.GetFullMessage()}");
                    return false;
                }
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

public static Dictionary<uint, PropertiesAllegiance> GetBanList(this IDictionary<uint, PropertiesAllegiance> value, ReaderWriterLockSlim rwLock)
        {
            if (value == null)
                return new Dictionary<uint, PropertiesAllegiance>();

            rwLock.EnterReadLock();
            try
            {
                return value.Where(i => i.Value.Banned).ToDictionary(i => i.Key, i => i.Value);
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : ReaderCache.cs
License : Apache License 2.0
Project Creator : aadreja

internal static Action<object, IDbCommand> GetFromCacheDoNotUse(object param, IDbCommand cmd)
        {
            ParameterKey key = new ParameterKey(GetParameterHash(param), param);
            
            Action<object, IDbCommand> action;
            try
            {
                cacheLock.EnterReadLock();
                if (dynamicParameters.TryGetValue(key, out action)) return action;
            }
            finally
            {
                cacheLock.ExitReadLock();
            }
            
            action = AddParametersIL(param, cmd);

            try
            {
                cacheLock.EnterWriteLock();
                return dynamicParameters[key] = action;
            }
            finally
            {
                cacheLock.ExitWriteLock();
            }
        }

19 View Source File : PropertiesAnimPartExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static void CopyTo(this IList<PropertiesAnimPart> value, ICollection<PropertiesAnimPart> destination, ReaderWriterLockSlim rwLock)
        {
            if (value == null)
                return;

            rwLock.EnterReadLock();
            try
            {
                foreach (var entry in value)
                    destination.Add(entry);
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : BiotaExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static uint? GetProperty(this Biota biota, PropertyDataId property, ReaderWriterLockSlim rwLock)
        {
            if (biota.PropertiesDID == null)
                return null;

            rwLock.EnterReadLock();
            try
            {
                if (biota.PropertiesDID.TryGetValue(property, out var value))
                    return value;

                return null;
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : BiotaExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static double? GetProperty(this Biota biota, PropertyFloat property, ReaderWriterLockSlim rwLock)
        {
            if (biota.PropertiesFloat == null)
                return null;

            rwLock.EnterReadLock();
            try
            {
                if (biota.PropertiesFloat.TryGetValue(property, out var value))
                    return value;

                return null;
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : CharacterExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static List<uint> GetContractsIds(this Character character, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterReadLock();
            try
            {
                return character.CharacterPropertiesContractRegistry.Select(r => r.ContractId).ToList();
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : BiotaExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static int? GetProperty(this Biota biota, PropertyInt property, ReaderWriterLockSlim rwLock)
        {
            if (biota.PropertiesInt == null)
                return null;

            rwLock.EnterReadLock();
            try
            {
                if (biota.PropertiesInt.TryGetValue(property, out var value))
                    return value;

                return null;
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : CharacterExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static List<CharacterPropertiesShortcutBar> GetShortcuts(this Character character, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterReadLock();
            try
            {
                return character.CharacterPropertiesShortcutBar.ToList();
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : BiotaExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static Position GetPosition(this Biota biota, PositionType property, ReaderWriterLockSlim rwLock)
        {
            if (biota.PropertiesPosition == null)
                return null;

            rwLock.EnterReadLock();
            try
            {
                if (biota.PropertiesPosition.TryGetValue(property, out var value))
                    return new Position(value.ObjCellId, value.PositionX, value.PositionY, value.PositionZ, value.RotationX, value.RotationY, value.RotationZ, value.RotationW);

                return null;
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : BiotaExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static string GetProperty(this Biota biota, PropertyString property, ReaderWriterLockSlim rwLock)
        {
            if (biota.PropertiesString == null)
                return null;

            rwLock.EnterReadLock();
            try
            {
                if (biota.PropertiesString.TryGetValue(property, out var value))
                    return value;

                return null;
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : CharacterExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static List<CharacterPropertiesSquelch> GetSquelches(this Character character, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterReadLock();
            try
            {
                return character.CharacterPropertiesSquelch.ToList();
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : BiotaExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static bool HasKnownSpell(this Biota biota, ReaderWriterLockSlim rwLock)
        {
            if (biota.PropertiesSpellBook == null)
                return false;

            rwLock.EnterReadLock();
            try
            {
                return biota.PropertiesSpellBook.Count > 0;
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : CharacterExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static CharacterPropertiesFillCompBook GetFillComponent(this Character character, uint wcid, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterReadLock();
            try
            {
                return character.CharacterPropertiesFillCompBook.FirstOrDefault(i => i.SpellComponentId == wcid);
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : BiotaExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static List<int> GetKnownSpellsIdsWhere(this Biota biota, Func<int, bool> predicate, ReaderWriterLockSlim rwLock)
        {
            if (biota.PropertiesSpellBook == null)
                return new List<int>();

            rwLock.EnterReadLock();
            try
            {
                if (biota.PropertiesSpellBook == null)
                    return new List<int>();

                return biota.PropertiesSpellBook.Keys.Where(predicate).ToList();
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : ShardDatabase.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public virtual bool SaveBiota(ACE.Enreplacedy.Models.Biota biota, ReaderWriterLockSlim rwLock)
        {
            using (var context = new ShardDbContext())
            {
                var existingBiota = GetBiota(context, biota.Id);

                rwLock.EnterReadLock();
                try
                {
                    if (existingBiota == null)
                    {
                        existingBiota = ACE.Database.Adapter.BiotaConverter.ConvertFromEnreplacedyBiota(biota);

                        context.Biota.Add(existingBiota);
                    }
                    else
                    {
                        ACE.Database.Adapter.BiotaUpdater.UpdateDatabaseBiota(context, biota, existingBiota);
                    }
                }
                finally
                {
                    rwLock.ExitReadLock();
                }

                return DoSaveBiota(context, existingBiota);
            }
        }

19 View Source File : BiotaExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static bool SpellIsKnown(this Biota biota, int spell, ReaderWriterLockSlim rwLock)
        {
            if (biota.PropertiesSpellBook == null)
                return false;

            rwLock.EnterReadLock();
            try
            {
                return biota.PropertiesSpellBook.ContainsKey(spell);
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : ReaderCache.cs
License : Apache License 2.0
Project Creator : aadreja

internal static Func<IDataReader, T> GetFromCache(IDataReader reader)
        {
            int hash = GetReaderHash(reader);

            ReaderKey key = new ReaderKey(hash, reader);

            Func<IDataReader, T> func;
            try
            {
                cacheLock.EnterReadLock();
                if (readers.TryGetValue(key, out func)) return func;
            }
            finally
            {
                cacheLock.ExitReadLock();
            }
            func = ReaderToObject(reader);
            try
            {
                cacheLock.EnterWriteLock();
                return readers[key] = func;
            }
            finally
            {
                cacheLock.ExitWriteLock();
            }
        }

19 View Source File : BiotaExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static PropertiesSkill GetSkill(this Biota biota, Skill skill, ReaderWriterLockSlim rwLock)
        {
            if (biota.PropertiesSkill == null)
                return null;

            rwLock.EnterReadLock();
            try
            {
                if (biota.PropertiesSkill == null)
                    return null;

                biota.PropertiesSkill.TryGetValue(skill, out var value);
                return value;
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : ShardDatabase.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public bool SaveCharacter(Character character, ReaderWriterLockSlim rwLock)
        {
            if (CharacterContexts.TryGetValue(character, out var cachedContext))
            {
                rwLock.EnterReadLock();
                try
                {
                    Exception firstException = null;
                    retry:

                    try
                    {
                        cachedContext.SaveChanges();

                        if (firstException != null)
                            log.Debug($"[DATABASE] SaveCharacter-1 0x{character.Id:X8}:{character.Name} retry succeeded after initial exception of: {firstException.GetFullMessage()}");

                        return true;
                    }
                    catch (Exception ex)
                    {
                        if (firstException == null)
                        {
                            firstException = ex;
                            goto retry;
                        }

                        // Character name might be in use or some other fault
                        log.Error($"[DATABASE] SaveCharacter-1 0x{character.Id:X8}:{character.Name} failed first attempt with exception: {firstException.GetFullMessage()}");
                        log.Error($"[DATABASE] SaveCharacter-1 0x{character.Id:X8}:{character.Name} failed second attempt with exception: {ex.GetFullMessage()}");
                        return false;
                    }
                }
                finally
                {
                    rwLock.ExitReadLock();
                }
            }

            var context = new ShardDbContext();

            CharacterContexts.Add(character, context);

            rwLock.EnterReadLock();
            try
            {
                context.Character.Add(character);

                Exception firstException = null;
                retry:

                try
                {
                    context.SaveChanges();

                    if (firstException != null)
                        log.Debug($"[DATABASE] SaveCharacter-2 0x{character.Id:X8}:{character.Name} retry succeeded after initial exception of: {firstException.GetFullMessage()}");

                    return true;
                }
                catch (Exception ex)
                {
                    if (firstException == null)
                    {
                        firstException = ex;
                        goto retry;
                    }

                    // Character name might be in use or some other fault
                    log.Error($"[DATABASE] SaveCharacter-2 0x{character.Id:X8}:{character.Name} failed first attempt with exception: {firstException.GetFullMessage()}");
                    log.Error($"[DATABASE] SaveCharacter-2 0x{character.Id:X8}:{character.Name} failed second attempt with exception: {ex.GetFullMessage()}");
                    return false;
                }
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : BiotaExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static bool HasHouseGuest(this Biota biota, uint guestGuid, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterReadLock();
            try
            {
                if (biota.HousePermissions == null)
                    return false;

                return biota.HousePermissions.ContainsKey(guestGuid);
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : CharacterExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static List<CharacterPropertiesFriendList> GetFriends(this Character character, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterReadLock();
            try
            {
                return character.CharacterPropertiesFriendList.ToList();
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

public static Dictionary<uint, PropertiesAllegiance> GetApprovedVreplacedals(this IDictionary<uint, PropertiesAllegiance> value, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterReadLock();
            try
            {
                if (value == null)
                    return new Dictionary<uint, PropertiesAllegiance>();

                return value.Where(i => i.Value.ApprovedVreplacedal).ToDictionary(i => i.Key, i => i.Value);
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : CharacterExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static List<CharacterPropertiesContractRegistry> GetContracts(this Character character, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterReadLock();
            try
            {
                return character.CharacterPropertiesContractRegistry.ToList();
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

public static PropertiesAllegiance GetFirstOrDefaultByCharacterId(this IDictionary<uint, PropertiesAllegiance> value, uint characterId, ReaderWriterLockSlim rwLock)
        {
            if (value == null)
                return null;

            rwLock.EnterReadLock();
            try
            {
                value.TryGetValue(characterId, out var enreplacedy);

                return enreplacedy;
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : EntityCache.cs
License : Apache License 2.0
Project Creator : aadreja

internal static TableAttribute Get(Type enreplacedy)
        {
            TableAttribute result;

            try
            {
                cacheLock.EnterReadLock();
                if (Enreplacedies.TryGetValue(enreplacedy, out result)) return result;
            }
            finally
            {
                cacheLock.ExitReadLock();
            }

            result = PrepareTableAttribute(enreplacedy);
            
            try
            {
                cacheLock.EnterWriteLock();
                Enreplacedies[enreplacedy] = result;
            }
            finally
            {
                cacheLock.ExitWriteLock();
            }

            return result;
        }

19 View Source File : PropertiesAnimPartExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static List<PropertiesAnimPart> Clone(this IList<PropertiesAnimPart> value, ReaderWriterLockSlim rwLock)
        {
            if (value == null)
                return null;

            rwLock.EnterReadLock();
            try
            {
                return new List<PropertiesAnimPart>(value);
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : BiotaExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static bool? GetProperty(this Biota biota, PropertyBool property, ReaderWriterLockSlim rwLock)
        {
            if (biota.PropertiesBool == null)
                return null;

            rwLock.EnterReadLock();
            try
            {
                if (biota.PropertiesBool.TryGetValue(property, out var value))
                    return value;

                return null;
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : CharacterExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static List<CharacterPropertiesQuestRegistry> GetQuests(this Character character, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterReadLock();
            try
            {
                return character.CharacterPropertiesQuestRegistry.ToList();
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : RWLock.cs
License : MIT License
Project Creator : 0x0ade

public RLock Start() {
                Inner.EnterReadLock();
                return this;
            }

19 View Source File : Database.cs
License : Apache License 2.0
Project Creator : aadreja

public static Database Get(IDbConnection con)
        {
            string key = con.GetType().Name + "," + con.ConnectionString;

            Database db;

            try
            {
                cacheLock.EnterReadLock();
                if (dbs.TryGetValue(key, out db)) return db;
            }
            finally
            {
                cacheLock.ExitReadLock();
            }
            
            if (key.ToLowerInvariant().Contains("npgsqlconnection"))
                db = new PgSqlDatabase();
            else if (key.ToLowerInvariant().Contains("sqliteconnection"))
                db = new SQLiteDatabase();
            else
                db = new MsSqlDatabase();

            try 
            {
                cacheLock.EnterWriteLock();
                return dbs[key] = db;
            }
            finally
            {
                cacheLock.ExitWriteLock();
            }
        }

19 View Source File : CharacterExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static CharacterPropertiesContractRegistry GetContract(this Character character, uint contractId, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterReadLock();
            try
            {
                return character.CharacterPropertiesContractRegistry.FirstOrDefault(c => c.ContractId == contractId);
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : CharacterExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static List<CharacterPropertiesSpellBar> GetSpellsInBar(this Character character, int barNumber, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterReadLock();
            try
            {
                return character.CharacterPropertiesSpellBar.Where(x => x.SpellBarNumber == barNumber + 1).OrderBy(x => x.SpellBarIndex).ToList();
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : BiotaExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static PropertiesPosition GetProperty(this Biota biota, PositionType property, ReaderWriterLockSlim rwLock)
        {
            if (biota.PropertiesPosition == null)
                return null;

            rwLock.EnterReadLock();
            try
            {
                if (biota.PropertiesPosition.TryGetValue(property, out var value))
                    return value;

                return null;
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

See More Examples