예제 #1
0
        public async Task Hold(string partitionKey, string rowKey)
        {
            await this.mutex.AcquireAsync();

            var entity = await tableStorageProvider.Get <T>(partitionKey, rowKey);

            this.Entity = entity.Result;

            if (this.Entity == null)
            {
                IsNew = true;

                this.Entity = Activator.CreateInstance <T>();
                this.Entity.PartitionKey = tableStorageProvider.ToKey(partitionKey);
                this.Entity.RowKey       = tableStorageProvider.ToKey(rowKey);
            }

            this.Entity.ETag = "*"; // ML - Ensure clobbering happens as we have a lock
        }
        public async Task <IActorTableEntityClientState <T> > GetLocked <T>(string partitionKey, string rowKey) where T : class, ITableEntity, new()
        {
            partitionKey.CheckNotNull(nameof(partitionKey));
            rowKey.CheckNotNull(nameof(rowKey));

            /* This will throw a storage exception if it fails to acquire the lock */

            Mutex = DistributedLockFactory.Get(tableStorageProvider.ToKey(partitionKey + rowKey));

            var state = new ActorTableEntityClientState <T>(Mutex, tableStorageProvider);
            await state.Hold(partitionKey, rowKey);

            return(state);
        }