System.Threading.ReaderWriterLockSlim.EnterWriteLock()

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

944 Examples 7

19 Source : RWLock.cs
with MIT License
from 0x0ade

public WLock Start() {
                Inner.EnterWriteLock();
                return this;
            }

19 Source : EntityCache.cs
with Apache License 2.0
from 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 Source : ReaderCache.cs
with Apache License 2.0
from 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 Source : Database.cs
with Apache License 2.0
from 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 Source : ReaderCache.cs
with Apache License 2.0
from 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 Source : CharacterExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static CharacterPropertiesContractRegistry GetOrCreateContract(this Character character, uint contractId, ReaderWriterLockSlim rwLock, out bool contractWasCreated)
        {
            rwLock.EnterWriteLock();
            try
            {
                var enreplacedy = character.CharacterPropertiesContractRegistry.FirstOrDefault(c => c.ContractId == contractId);

                if (enreplacedy == null)
                {
                    enreplacedy = new CharacterPropertiesContractRegistry
                    {
                        ContractId = contractId
                    };

                    character.CharacterPropertiesContractRegistry.Add(enreplacedy);

                    contractWasCreated = true;
                }
                else
                    contractWasCreated = false;

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

19 Source : CharacterExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static bool EraseContract(this Character character, uint contractId, out CharacterPropertiesContractRegistry contractErased, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterWriteLock();
            try
            {
                contractErased = character.CharacterPropertiesContractRegistry.FirstOrDefault(c => c.ContractId == contractId);

                if (contractErased == null)
                    return false;

                character.CharacterPropertiesContractRegistry.Remove(contractErased);

                return true;
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : CharacterExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static void EraseAllContracts(this Character character, out List<CharacterPropertiesContractRegistry> contractsErased, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterWriteLock();
            try
            {
                contractsErased = character.CharacterPropertiesContractRegistry.ToList();

                character.CharacterPropertiesContractRegistry.Clear();
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : CharacterExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static CharacterPropertiesFillCompBook AddFillComponent(this Character character, uint wcid, uint amount, ReaderWriterLockSlim rwLock, out bool alreadyExists)
        {
            rwLock.EnterUpgradeableReadLock();
            try
            {
                var enreplacedy = character.CharacterPropertiesFillCompBook.FirstOrDefault(i => i.SpellComponentId == wcid);
                if (enreplacedy != null)
                {
                    alreadyExists = true;
                    return enreplacedy;
                }

                rwLock.EnterWriteLock();
                try
                {
                    enreplacedy = new CharacterPropertiesFillCompBook { CharacterId = character.Id, SpellComponentId = (int)wcid, QuanreplacedyToRebuy = (int)amount };
                    character.CharacterPropertiesFillCompBook.Add(enreplacedy);
                    alreadyExists = false;
                    return enreplacedy;
                }
                finally
                {
                    rwLock.ExitWriteLock();
                }
            }
            finally
            {
                rwLock.ExitUpgradeableReadLock();
            }
        }

19 Source : CharacterExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static bool TryRemoveFillComponent(this Character character, uint wcid, out CharacterPropertiesFillCompBook enreplacedy, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterUpgradeableReadLock();
            try
            {
                enreplacedy = character.CharacterPropertiesFillCompBook.FirstOrDefault(i => i.SpellComponentId == wcid);
                if (enreplacedy != null)
                {
                    rwLock.EnterWriteLock();
                    try
                    {
                        character.CharacterPropertiesFillCompBook.Remove(enreplacedy);
                        enreplacedy.Character = null;
                        return true;
                    }
                    finally
                    {
                        rwLock.ExitWriteLock();
                    }
                }
                return false;
            }
            finally
            {
                rwLock.ExitUpgradeableReadLock();
            }
        }

19 Source : CharacterExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static CharacterPropertiesFriendList AddFriend(this Character character, uint friendId, ReaderWriterLockSlim rwLock, out bool friendAlreadyExists)
        {
            rwLock.EnterUpgradeableReadLock();
            try
            {
                var enreplacedy = character.CharacterPropertiesFriendList.FirstOrDefault(x => x.FriendId == friendId);
                if (enreplacedy != null)
                {
                    friendAlreadyExists = true;
                    return enreplacedy;
                }

                rwLock.EnterWriteLock();
                try
                {
                    enreplacedy = new CharacterPropertiesFriendList { CharacterId = character.Id, FriendId = friendId, Character = character};
                    character.CharacterPropertiesFriendList.Add(enreplacedy);
                    friendAlreadyExists = false;
                    return enreplacedy;
                }
                finally
                {
                    rwLock.ExitWriteLock();
                }
            }
            finally
            {
                rwLock.ExitUpgradeableReadLock();
            }
        }

19 Source : CharacterExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static bool TryRemoveFriend(this Character character, uint friendId, out CharacterPropertiesFriendList enreplacedy, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterUpgradeableReadLock();
            try
            {
                enreplacedy = character.CharacterPropertiesFriendList.FirstOrDefault(x => x.FriendId == friendId);
                if (enreplacedy != null)
                {
                    rwLock.EnterWriteLock();
                    try
                    {
                        character.CharacterPropertiesFriendList.Remove(enreplacedy);
                        enreplacedy.Character = null;
                        return true;
                    }
                    finally
                    {
                        rwLock.ExitWriteLock();
                    }
                }
                return false;
            }
            finally
            {
                rwLock.ExitUpgradeableReadLock();
            }
        }

19 Source : CharacterExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static CharacterPropertiesQuestRegistry GetOrCreateQuest(this Character character, string questName, ReaderWriterLockSlim rwLock, out bool questRegistryWasCreated)
        {
            rwLock.EnterWriteLock();
            try
            {
                var enreplacedy = character.CharacterPropertiesQuestRegistry.FirstOrDefault(q => q.QuestName.Equals(questName, StringComparison.OrdinalIgnoreCase));

                if (enreplacedy == null)
                {
                    enreplacedy = new CharacterPropertiesQuestRegistry
                    {
                        QuestName = questName
                    };

                    character.CharacterPropertiesQuestRegistry.Add(enreplacedy);

                    questRegistryWasCreated = true;
                }
                else
                    questRegistryWasCreated = false;

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

19 Source : CharacterExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static bool EraseQuest(this Character character, string questName, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterWriteLock();
            try
            {
                var enreplacedy = character.CharacterPropertiesQuestRegistry.FirstOrDefault(q => q.QuestName.Equals(questName, StringComparison.OrdinalIgnoreCase));

                if (enreplacedy == null)
                    return false;

                character.CharacterPropertiesQuestRegistry.Remove(enreplacedy);

                return true;
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : CharacterExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static void EraseAllQuests(this Character character, out List<string> questNamesErased, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterWriteLock();
            try
            {
                questNamesErased = character.CharacterPropertiesQuestRegistry.Select(r => r.QuestName).ToList();

                character.CharacterPropertiesQuestRegistry.Clear();
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : CharacterExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

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

19 Source : CharacterExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static bool TryRemoveShortcut(this Character character, uint index, out CharacterPropertiesShortcutBar enreplacedy, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterUpgradeableReadLock();
            try
            {
                enreplacedy = character.CharacterPropertiesShortcutBar.FirstOrDefault(x => x.ShortcutBarIndex == index + 1);

                if (enreplacedy != null)
                {
                    rwLock.EnterWriteLock();
                    try
                    {
                        character.CharacterPropertiesShortcutBar.Remove(enreplacedy);
                        enreplacedy.Character = null;
                        return true;
                    }
                    finally
                    {
                        rwLock.ExitWriteLock();
                    }
                }
                return false;
            }
            finally
            {
                rwLock.ExitUpgradeableReadLock();
            }
        }

19 Source : CharacterExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static void AddSpellToBar(this Character character, uint barNumber, uint indexInBar, uint spell, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterWriteLock();
            try
            {
                var spellCountInThisBar = character.CharacterPropertiesSpellBar.Count(x => x.SpellBarNumber == barNumber + 1);

                //Console.WriteLine($"Character.AddSpellToBar.Entry: barNumber = {barNumber} ({barNumber + 1}) | indexInBar = {indexInBar} ({indexInBar + 1}) | spell = {spell} | spellCountInThisBar = {spellCountInThisBar}");

                if (indexInBar > spellCountInThisBar)
                    indexInBar = (uint)(spellCountInThisBar);

                // We must increment the position of existing spells in the bar that exist on or after this position
                foreach (var property in character.CharacterPropertiesSpellBar.OrderBy(x => x.SpellBarIndex))
                {
                    if (property.SpellBarNumber == barNumber + 1 && property.SpellBarIndex >= indexInBar + 1)
                    {
                        property.SpellBarIndex++;
                        //Console.WriteLine($"Character.AddSpellToBar.Adjust: SpellBarNumber = {property.SpellBarNumber} | SpellBarIndex = {property.SpellBarIndex} ({property.SpellBarIndex - 1}) | SpellId = {property.SpellId}");
                    }
                }

                var enreplacedy = new CharacterPropertiesSpellBar { CharacterId = character.Id, SpellBarNumber = barNumber + 1, SpellBarIndex = indexInBar + 1, SpellId = spell, Character = character };

                character.CharacterPropertiesSpellBar.Add(enreplacedy);

                //Console.WriteLine($"Character.AddSpellToBar.Add: barNumber = {barNumber + 1} | indexInBar = {indexInBar + 1} | spell = {spell}");
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : CharacterExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static bool TryRemoveSpellFromBar(this Character character, uint barNumber, uint spell, out CharacterPropertiesSpellBar enreplacedy, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterUpgradeableReadLock();
            try
            {
                //Console.WriteLine($"Character.TryRemoveSpellFromBar.Entry: barNumber = {barNumber} ({barNumber + 1}) | spell = {spell}");
                enreplacedy = character.CharacterPropertiesSpellBar.FirstOrDefault(x => x.SpellBarNumber == barNumber + 1 && x.SpellId == spell);
                if (enreplacedy != null)
                {
                    rwLock.EnterWriteLock();
                    try
                    {
                        //Console.WriteLine($"Character.TryRemoveSpellFromBar.Remove: SpellBarNumber = {enreplacedy.SpellBarNumber} | SpellBarIndex = {enreplacedy.SpellBarIndex} | SpellId = {enreplacedy.SpellId}");
                        character.CharacterPropertiesSpellBar.Remove(enreplacedy);
                        enreplacedy.Character = null;

                        // We must decrement the position of existing spells in the bar that exist after this position
                        foreach (var property in character.CharacterPropertiesSpellBar.OrderBy(x => x.SpellBarIndex))
                        {
                            if (property.SpellBarNumber == barNumber + 1 && property.SpellBarIndex > enreplacedy.SpellBarIndex)
                            {
                                property.SpellBarIndex--;
                                //Console.WriteLine($"Character.TryRemoveSpellFromBar.Adjust: SpellBarNumber = {property.SpellBarNumber} | SpellBarIndex = {property.SpellBarIndex} ({property.SpellBarIndex + 1}) | SpellId = {property.SpellId}");
                            }
                        }

                        return true;
                    }
                    finally
                    {
                        rwLock.ExitWriteLock();
                    }
                }
                return false;
            }
            finally
            {
                rwLock.ExitUpgradeableReadLock();
            }
        }

19 Source : CharacterExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static void AddOrUpdateSquelch(this Character character, uint squelchCharacterId, uint squelchAccountId, uint type, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterUpgradeableReadLock();
            try
            {
                var enreplacedy = character.CharacterPropertiesSquelch.FirstOrDefault(x => x.SquelchCharacterId == squelchCharacterId);
                rwLock.EnterWriteLock();
                try
                {
                    if (enreplacedy == null)
                    {
                        enreplacedy = new CharacterPropertiesSquelch { CharacterId = character.Id, SquelchCharacterId = squelchCharacterId, SquelchAccountId = squelchAccountId, Type = type, Character = character };
                        character.CharacterPropertiesSquelch.Add(enreplacedy);
                    }
                    else
                    {
                        enreplacedy.SquelchAccountId = squelchAccountId;
                        enreplacedy.Type = type;
                    }
                }
                finally
                {
                    rwLock.ExitWriteLock();
                }
            }
            finally
            {
                rwLock.ExitUpgradeableReadLock();
            }
        }

19 Source : CharacterExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static bool TryRemoveSquelch(this Character character, uint squelchCharacterId, uint squelchAccountId, out CharacterPropertiesSquelch enreplacedy, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterUpgradeableReadLock();
            try
            {
                enreplacedy = character.CharacterPropertiesSquelch.FirstOrDefault(x => x.SquelchCharacterId == squelchCharacterId && x.SquelchAccountId == squelchAccountId);

                if (enreplacedy != null)
                {
                    rwLock.EnterWriteLock();
                    try
                    {
                        character.CharacterPropertiesSquelch.Remove(enreplacedy);
                        enreplacedy.Character = null;
                        return true;
                    }
                    finally
                    {
                        rwLock.ExitWriteLock();
                    }
                }
                return false;
            }
            finally
            {
                rwLock.ExitUpgradeableReadLock();
            }
        }

19 Source : CharacterExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static void AddreplacedleToRegistry(this Character character, uint replacedle, ReaderWriterLockSlim rwLock, out bool replacedleAlreadyExists, out int numCharacterreplacedles)
        {
            rwLock.EnterUpgradeableReadLock();
            try
            {
                var enreplacedy = character.CharacterPropertiesreplacedleBook.FirstOrDefault(x => x.replacedleId == replacedle);
                if (enreplacedy != null)
                {
                    replacedleAlreadyExists = true;
                    numCharacterreplacedles = character.CharacterPropertiesreplacedleBook.Count;
                    return;
                }

                rwLock.EnterWriteLock();
                try
                {
                    enreplacedy = new CharacterPropertiesreplacedleBook { CharacterId = character.Id, replacedleId = replacedle, Character = character };
                    character.CharacterPropertiesreplacedleBook.Add(enreplacedy);
                    replacedleAlreadyExists = false;
                    numCharacterreplacedles = character.CharacterPropertiesreplacedleBook.Count;
                }
                finally
                {
                    rwLock.ExitWriteLock();
                }
            }
            finally
            {
                rwLock.ExitUpgradeableReadLock();
            }
        }

19 Source : BiotaExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static void SetProperty(this Biota biota, PropertyBool property, bool value, ReaderWriterLockSlim rwLock, out bool changed)
        {
            rwLock.EnterWriteLock();
            try
            {
                if (biota.PropertiesBool == null)
                    biota.PropertiesBool = new Dictionary<PropertyBool, bool>();

                changed = (!biota.PropertiesBool.TryGetValue(property, out var existing) || value != existing);

                if (changed)
                    biota.PropertiesBool[property] = value;
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : BiotaExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static void SetProperty(this Biota biota, PropertyDataId property, uint value, ReaderWriterLockSlim rwLock, out bool changed)
        {
            rwLock.EnterWriteLock();
            try
            {
                if (biota.PropertiesDID == null)
                    biota.PropertiesDID = new Dictionary<PropertyDataId, uint>();

                changed = (!biota.PropertiesDID.TryGetValue(property, out var existing) || value != existing);

                if (changed)
                    biota.PropertiesDID[property] = value;
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : BiotaExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static void SetProperty(this Biota biota, PropertyFloat property, double value, ReaderWriterLockSlim rwLock, out bool changed)
        {
            rwLock.EnterWriteLock();
            try
            {
                if (biota.PropertiesFloat == null)
                    biota.PropertiesFloat = new Dictionary<PropertyFloat, double>();

                changed = (!biota.PropertiesFloat.TryGetValue(property, out var existing) || value != existing);

                if (changed)
                    biota.PropertiesFloat[property] = value;
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : BiotaExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static void SetProperty(this Biota biota, PropertyInstanceId property, uint value, ReaderWriterLockSlim rwLock, out bool changed)
        {
            rwLock.EnterWriteLock();
            try
            {
                if (biota.PropertiesIID == null)
                    biota.PropertiesIID = new Dictionary<PropertyInstanceId, uint>();

                changed = (!biota.PropertiesIID.TryGetValue(property, out var existing) || value != existing);

                if (changed)
                    biota.PropertiesIID[property] = value;
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : BiotaExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static void SetProperty(this Biota biota, PropertyInt property, int value, ReaderWriterLockSlim rwLock, out bool changed)
        {
            rwLock.EnterWriteLock();
            try
            {
                if (biota.PropertiesInt == null)
                    biota.PropertiesInt = new Dictionary<PropertyInt, int>();

                changed = (!biota.PropertiesInt.TryGetValue(property, out var existing) || value != existing);

                if (changed)
                    biota.PropertiesInt[property] = value;
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : BiotaExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static void SetProperty(this Biota biota, PropertyInt64 property, long value, ReaderWriterLockSlim rwLock, out bool changed)
        {
            rwLock.EnterWriteLock();
            try
            {
                if (biota.PropertiesInt64 == null)
                    biota.PropertiesInt64 = new Dictionary<PropertyInt64, long>();

                changed = (!biota.PropertiesInt64.TryGetValue(property, out var existing) || value != existing);

                if (changed)
                    biota.PropertiesInt64[property] = value;
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : BiotaExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static void SetProperty(this Biota biota, PropertyString property, string value, ReaderWriterLockSlim rwLock, out bool changed)
        {
            rwLock.EnterWriteLock();
            try
            {
                if (biota.PropertiesString == null)
                    biota.PropertiesString = new Dictionary<PropertyString, string>();

                changed = (!biota.PropertiesString.TryGetValue(property, out var existing) || value != existing);

                if (changed)
                    biota.PropertiesString[property] = value;
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : BiotaExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static void SetProperty(this Biota biota, PositionType property, PropertiesPosition value, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterWriteLock();
            try
            {
                if (biota.PropertiesPosition == null)
                    biota.PropertiesPosition = new Dictionary<PositionType, PropertiesPosition>();

                biota.PropertiesPosition[property] = value;
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : BiotaExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static void SetPosition(this Biota biota, PositionType property, Position value, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterWriteLock();
            try
            {
                if (biota.PropertiesPosition == null)
                    biota.PropertiesPosition = new Dictionary<PositionType, PropertiesPosition>();

                var enreplacedy = new PropertiesPosition { ObjCellId = value.Cell, PositionX = value.PositionX, PositionY = value.PositionY, PositionZ = value.PositionZ, RotationW = value.RotationW, RotationX = value.RotationX, RotationY = value.RotationY, RotationZ = value.RotationZ };

                biota.PropertiesPosition[property] = enreplacedy;
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : BiotaExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

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

            rwLock.EnterWriteLock();
            try
            {
                return biota.PropertiesBool.Remove(property);
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : BiotaExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static bool TryRemoveProperty(this Biota biota, PropertyDataId property, ReaderWriterLockSlim rwLock)
        {
            if (biota.PropertiesDID == null)
                return false;

            rwLock.EnterWriteLock();
            try
            {
                return biota.PropertiesDID.Remove(property);
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : BiotaExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static bool TryRemoveProperty(this Biota biota, PropertyFloat property, ReaderWriterLockSlim rwLock)
        {
            if (biota.PropertiesFloat == null)
                return false;

            rwLock.EnterWriteLock();
            try
            {
                return biota.PropertiesFloat.Remove(property);
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : BiotaExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static bool TryRemoveProperty(this Biota biota, PropertyInstanceId property, ReaderWriterLockSlim rwLock)
        {
            if (biota.PropertiesIID == null)
                return false;

            rwLock.EnterWriteLock();
            try
            {
                return biota.PropertiesIID.Remove(property);
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : BiotaExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static bool TryRemoveProperty(this Biota biota, PropertyInt property, ReaderWriterLockSlim rwLock)
        {
            if (biota.PropertiesInt == null)
                return false;

            rwLock.EnterWriteLock();
            try
            {
                return biota.PropertiesInt.Remove(property);
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : BiotaExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static bool TryRemoveProperty(this Biota biota, PropertyInt64 property, ReaderWriterLockSlim rwLock)
        {
            if (biota.PropertiesInt64 == null)
                return false;

            rwLock.EnterWriteLock();
            try
            {
                return biota.PropertiesInt64.Remove(property);
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : BiotaExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

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

            rwLock.EnterWriteLock();
            try
            {
                return biota.PropertiesString.Remove(property);
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : BiotaExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

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

            rwLock.EnterWriteLock();
            try
            {
                return biota.PropertiesPosition.Remove(property);
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : BiotaExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static float GetOrAddKnownSpell(this Biota biota, int spell, ReaderWriterLockSlim rwLock, out bool spellAdded, float probability = 2.0f)
        {
            rwLock.EnterWriteLock();
            try
            {
                if (biota.PropertiesSpellBook != null && biota.PropertiesSpellBook.TryGetValue(spell, out var value))
                {
                    spellAdded = false;
                    return value;
                }

                if (biota.PropertiesSpellBook == null)
                    biota.PropertiesSpellBook = new Dictionary<int, float>();

                biota.PropertiesSpellBook[spell] = probability;
                spellAdded = true;

                return probability;
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : BiotaExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

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

            rwLock.EnterWriteLock();
            try
            {
                return biota.PropertiesSpellBook.Remove(spell);
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : BiotaExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static void ClearSpells(this Biota biota, ReaderWriterLockSlim rwLock)
        {
            if (biota.PropertiesSpellBook == null)
                return;

            rwLock.EnterWriteLock();
            try
            {
                biota.PropertiesSpellBook?.Clear();
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : BiotaExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static PropertiesSkill GetOrAddSkill(this Biota biota, Skill skill, ReaderWriterLockSlim rwLock, out bool skillAdded)
        {
            rwLock.EnterWriteLock();
            try
            {
                if (biota.PropertiesSkill != null && biota.PropertiesSkill.TryGetValue(skill, out var value))
                {
                    skillAdded = false;
                    return value;
                }

                if (biota.PropertiesSkill == null)
                    biota.PropertiesSkill = new Dictionary<Skill, PropertiesSkill>();

                var enreplacedy = new PropertiesSkill();
                biota.PropertiesSkill[skill] = enreplacedy;
                skillAdded = true;

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

19 Source : BiotaExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static void AddOrUpdateHouseGuest(this Biota biota, uint guestGuid, bool storage, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterWriteLock();
            try
            {
                if (biota.HousePermissions == null)
                    biota.HousePermissions = new Dictionary<uint, bool>();

                biota.HousePermissions[guestGuid] = storage;
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : BiotaExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

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

                return biota.HousePermissions.Remove(guestGuid);
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : PropertiesAllegianceExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static void AddOrUpdateAllegiance(this IDictionary<uint, PropertiesAllegiance> value, uint characterId, bool isBanned, bool approvedVreplacedal, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterWriteLock();
            try
            {
                if (!value.TryGetValue(characterId, out var enreplacedy))
                {
                    enreplacedy = new PropertiesAllegiance { Banned = isBanned, ApprovedVreplacedal = approvedVreplacedal };

                    value.Add(characterId, enreplacedy);
                }

                enreplacedy.Banned = isBanned;
                enreplacedy.ApprovedVreplacedal = approvedVreplacedal;
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : PropertiesAllegianceExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

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

            rwLock.EnterWriteLock();
            try
            {
                return value.Remove(characterId);
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : PropertiesBookPageDataExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static void AddPage(this IList<PropertiesBookPageData> value, PropertiesBookPageData page, out int index, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterWriteLock();
            try
            {
                value.Add(page);

                index = value.Count;
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : PropertiesBookPageDataExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static bool RemovePage(this IList<PropertiesBookPageData> value, int index, ReaderWriterLockSlim rwLock)
        {
            if (value == null)
                return false;

            rwLock.EnterWriteLock();
            try
            {
                if (value.Count <= index)
                    return false;

                value.RemoveAt(index);

                return true;
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

19 Source : PropertiesEnchantmentRegistryExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator

public static void AddEnchantment(this ICollection<PropertiesEnchantmentRegistry> value, PropertiesEnchantmentRegistry enreplacedy, ReaderWriterLockSlim rwLock)
        {
            rwLock.EnterWriteLock();
            try
            {
                value.Add(enreplacedy);
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }

See More Examples