/// <inheritdoc /> public void Add(IStorageTableOperation operation) { TableOperation sdkOperation = ((StorageTableOperation)operation).SdkObject; _sdk.Add(sdkOperation); _items.Add(operation); }
public TableResult Execute(string tableName, IStorageTableOperation operation) { if (!_items.ContainsKey(tableName)) { return(new TableResult { HttpStatusCode = 404 }); } return(_items[tableName].Execute(operation)); }
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) { var table = _bindingProvider.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 { return(ConvertEntityToJObject(entity)); } }
private async Task <JObject> BuildJObject(TableAttribute attribute) { 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)); }
public void Add(IStorageTableOperation operation) { _items.Add(operation); }
/// <inheritdoc /> public void Add(IStorageTableOperation operation) { TableOperation sdkOperation = ((StorageTableOperation)operation).SdkObject; _sdk.Add(sdkOperation); _items.Add(operation); }
/// <inheritdoc /> public Task <TableResult> ExecuteAsync(IStorageTableOperation operation, CancellationToken cancellationToken) { TableOperation sdkOperation = ((StorageTableOperation)operation).SdkObject; return(_sdk.ExecuteAsync(sdkOperation, cancellationToken)); }
public TableResult Execute(IStorageTableOperation operation) { TableOperationType operationType = operation.OperationType; ITableEntity entity = operation.Entity; Tuple <string, string> key; IDictionary <string, EntityProperty> writeProperties; if (operation.OperationType != TableOperationType.Retrieve) { key = new Tuple <string, string>(entity.PartitionKey, entity.RowKey); writeProperties = entity.WriteEntity(operationContext: null); } else { key = new Tuple <string, string>(operation.RetrievePartitionKey, operation.RetrieveRowKey); writeProperties = null; } switch (operation.OperationType) { case TableOperationType.Retrieve: TableItem item = _entities[key]; return(new TableResult { Result = operation.RetrieveEntityResolver.Resolve(operation.RetrievePartitionKey, operation.RetrieveRowKey, item.Timestamp, item.CloneProperties(), eTag: item.ETag) }); case TableOperationType.Insert: if (!_entities.TryAdd(key, new TableItem(writeProperties))) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "Entity PK='{0}',RK='{1}' already exists.", entity.PartitionKey, entity.RowKey)); } return(new TableResult()); case TableOperationType.Replace: if (entity.ETag == null) { throw new InvalidOperationException("Replace requires an ETag."); } else if (!_entities.TryUpdate(key, new TableItem(writeProperties), new TableItem(entity.ETag))) { if (entity.ETag == "*") { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "Entity PK='{0}',RK='{1}' does not exist.", entity.PartitionKey, entity.RowKey)); } else { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "Entity PK='{0}',RK='{1}' does not match eTag '{2}'.", entity.PartitionKey, entity.RowKey, entity.ETag)); } } return(new TableResult()); default: throw new InvalidOperationException( "Unsupported operation type " + operationType.ToString()); } }
public Task <TableResult> ExecuteAsync(IStorageTableOperation operation, CancellationToken cancellationToken) { return(Task.FromResult(_store.Execute(_tableName, operation))); }
public void Add(IStorageTableOperation operation) { _items.Add(operation); }
/// <inheritdoc /> public Task <TableResult> ExecuteAsync(IStorageTableOperation operation, CancellationToken cancellationToken) { TableOperation sdkOperation = ((StorageTableOperation)operation).SdkObject; return(_sdk.ExecuteAsync(sdkOperation, requestOptions: null, operationContext: null, cancellationToken: cancellationToken)); }