public TableEntityValueBinder(TableEntityContext entityContext, ITableEntity entity, Type valueType) { _entityContext = entityContext; _value = entity; _valueType = valueType; _originalProperties = DeepClone(entity.WriteEntity(null)); }
internal static IEnumerable<ODataProperty> GetPropertiesWithKeys(ITableEntity entity, OperationContext operationContext, TableOperationType operationType, TableRequestOptions options) { if (operationType == TableOperationType.Insert) { if (entity.PartitionKey != null) { yield return new ODataProperty() { Name = TableConstants.PartitionKey, Value = entity.PartitionKey }; } if (entity.RowKey != null) { yield return new ODataProperty() { Name = TableConstants.RowKey, Value = entity.RowKey }; } } foreach (ODataProperty property in GetPropertiesFromDictionary(entity.WriteEntity(operationContext), options, entity.PartitionKey, entity.RowKey)) { yield return property; } }
internal static List<ODataProperty> GetPropertiesWithKeys(ITableEntity entity, OperationContext operationContext) { List<ODataProperty> retProps = GetPropertiesFromDictionary(entity.WriteEntity(operationContext)); if (entity.PartitionKey != null) { retProps.Add(new ODataProperty() { Name = TableConstants.PartitionKey, Value = entity.PartitionKey }); } if (entity.RowKey != null) { retProps.Add(new ODataProperty() { Name = TableConstants.RowKey, Value = entity.RowKey }); } return retProps; }
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 bool Evaluate(ITableEntity entity) { return(Evaluate(entity.PartitionKey, entity.RowKey, entity.WriteEntity(null))); }
internal static IEnumerable <KeyValuePair <string, object> > GetPropertiesWithKeys(ITableEntity entity, OperationContext operationContext, TableOperationType operationType, TableRequestOptions options, bool ignoreEncryption) { if (operationType == TableOperationType.Insert) { if (entity.PartitionKey != null) { yield return(new KeyValuePair <string, object>(TableConstants.PartitionKey, entity.PartitionKey)); } if (entity.RowKey != null) { yield return(new KeyValuePair <string, object>(TableConstants.RowKey, entity.RowKey)); } } foreach (KeyValuePair <string, object> property in GetPropertiesFromDictionary(entity.WriteEntity(operationContext), options, entity.PartitionKey, entity.RowKey, ignoreEncryption)) { yield return(property); } }
internal static IEnumerable <KeyValuePair <string, EntityProperty> > ToDictionary(ITableEntity entity) { return(entity.WriteEntity(new OperationContext())); }
private bool HasChanges(ITableEntity current) { return(TableEntityValueBinder.HasChanges(_originalProperties, current.WriteEntity(operationContext: null))); }
// Currently used by InMemoryTable. public static TElement CopyEntity <TElement>(ITableEntity entity) where TElement : ITableEntity, new() { // Copy mutable data in case both entities are DynamicTableEntity. // https://github.com/Azure/azure-storage-net/issues/154 // We could equally well do "new TElement" and use the setters directly. return((TElement)AzureTableAccessors.GetRetrieveResolver(TableOperation.Retrieve <TElement>("1", "1"))( entity.PartitionKey, entity.RowKey, entity.Timestamp, CopyPropertyDict(entity.WriteEntity(null)), entity.ETag)); }