Exemplo n.º 1
0
        private async Task CreateEntity(string entityName, IDictionary <string, string> properties)
        {
            var mutex = Semaphores.GetEntitySemaphore(entityName);
            await mutex.WaitAsync();

            try
            {
                if (await _setClient.SetContains(Constants.AllEntityNamesSetKeyName, entityName))
                {
                    throw new EntityAlreadyExistsException(entityName);
                }

                foreach (var property in properties)
                {
                    await _hashClient.SetHashField(Helpers.GetEntityPropertyTypesKey(entityName), property.Key, property.Value);
                }

                await _setClient.AddToSet(Constants.AllEntityNamesSetKeyName, entityName);

                await _stringClient.StoreValue(Helpers.GetEntityCountKey(entityName), 0.ToString());
            }
            finally
            {
                mutex.Release();
            }
        }
Exemplo n.º 2
0
        private async Task CheckEntityExistance(string entityName)
        {
            var mutex = Semaphores.GetEntitySemaphore(entityName);
            await mutex.WaitAsync();

            try
            {
                if (!await _setClient.SetContains(Constants.AllEntityNamesSetKeyName, entityName))
                {
                    throw new EntityNotFoundException(entityName);
                }
            }
            finally
            {
                mutex.Release();
            }
        }