public static void Replace(this IStorageTable table, ITableEntity entity) { if (table == null) { throw new ArgumentNullException("table"); } IStorageTableOperation operation = table.CreateReplaceOperation(entity); table.ExecuteAsync(operation, CancellationToken.None).GetAwaiter().GetResult(); }
public static TElement Retrieve <TElement>(this IStorageTable table, string partitionKey, string rowKey) where TElement : ITableEntity, new() { if (table == null) { throw new ArgumentNullException("table"); } IStorageTableOperation operation = table.CreateRetrieveOperation <TElement>(partitionKey, rowKey); TableResult result = table.ExecuteAsync(operation, CancellationToken.None).GetAwaiter().GetResult(); return((TElement)result.Result); }
public async Task <IValueProvider> BindAsync(TableEntityContext value, ValueBindingContext context) { IStorageTable table = value.Table; IStorageTableOperation retrieve = table.CreateRetrieveOperation <TElement>(value.PartitionKey, value.RowKey); TableResult result = await table.ExecuteAsync(retrieve, context.CancellationToken); TElement entity = (TElement)result.Result; if (entity == null) { return(new NullEntityValueProvider <TElement>(value)); } return(new TableEntityValueBinder(value, entity, typeof(TElement))); }
public async Task <IValueProvider> BindAsync(TableEntityContext value, ValueBindingContext context) { IStorageTable table = value.Table; IStorageTableOperation retrieve = table.CreateRetrieveOperation <DynamicTableEntity>( value.PartitionKey, value.RowKey); TableResult result = await table.ExecuteAsync(retrieve, context.CancellationToken); DynamicTableEntity entity = (DynamicTableEntity)result.Result; if (entity == null) { return(new NullEntityValueProvider <TElement>(value)); } TElement userEntity = Converter.Convert(entity); return(new PocoEntityValueBinder <TElement>(value, entity.ETag, userEntity)); }
public Task SetValueAsync(object value, CancellationToken cancellationToken) { // Not ByRef, so can ignore value argument. if (_value.PartitionKey != _entityContext.PartitionKey || _value.RowKey != _entityContext.RowKey) { throw new InvalidOperationException( "When binding to a table entity, the partition key and row key must not be changed."); } if (HasChanged) { IStorageTable table = _entityContext.Table; IStorageTableOperation operation = table.CreateReplaceOperation(_value); return(table.ExecuteAsync(operation, cancellationToken)); } return(Task.FromResult(0)); }
async Task <JObject> IAsyncConverter <TableAttribute, JObject> .ConvertAsync(TableAttribute attribute, CancellationToken cancellation) { IStorageTable table = GetTable(attribute); IStorageTableOperation retrieve = table.CreateRetrieveOperation <DynamicTableEntity>( attribute.PartitionKey, attribute.RowKey); TableResult result = await table.ExecuteAsync(retrieve, CancellationToken.None); DynamicTableEntity entity = (DynamicTableEntity)result.Result; if (entity == null) { return(null); } else { var obj = ConvertEntityToJObject(entity); return(obj); } }
public Task SetValueAsync(object value, CancellationToken cancellationToken) { // Not ByRef, so can ignore value argument. ITableEntity entity = _converter.Convert(_value); if (!_converter.ConvertsPartitionKey) { entity.PartitionKey = _entityContext.PartitionKey; } if (!_converter.ConvertsRowKey) { entity.RowKey = _entityContext.RowKey; } if (!_converter.ConvertsETag) { entity.ETag = _eTag; } if (entity.PartitionKey != _entityContext.PartitionKey) { throw new InvalidOperationException( "When binding to a table entity, the partition key must not be changed."); } if (entity.RowKey != _entityContext.RowKey) { throw new InvalidOperationException( "When binding to a table entity, the row key must not be changed."); } if (HasChanges(entity)) { IStorageTable table = _entityContext.Table; IStorageTableOperation operation = table.CreateReplaceOperation(entity); return(table.ExecuteAsync(operation, cancellationToken)); } return(Task.FromResult(0)); }