public Task <Func <Task> > CascadeDeleteAsync <TEntity>(MemberInfo memberInfo, string rowKeyRef, string partitionKeyRef, TEntity memberValue, IDictionary <string, EntityProperty> dictionary, AzureTableDriverDynamic repository) { var tableName = GetLookupTableName(memberInfo); return(repository .DeleteAsync <StorageLookupTable, Func <Task> >(rowKeyRef, partitionKeyRef, async(lookupTable, deleteAsync) => { var lookupEntity = await deleteAsync(); var rollbacks = await lookupTable .rowAndPartitionKeys .NullToEmpty() .Select(rowParitionKeyKvp => repository.DeleteAsync <Func <Task> >(rowParitionKeyKvp.Key, rowParitionKeyKvp.Value, memberInfo.DeclaringType, (entity, data) => () => (Task)repository.CreateAsync(entity, memberInfo.DeclaringType, (x) => true, () => false), () => () => 1.AsTask())) .AsyncEnumerable() .Append( () => repository.CreateAsync(lookupEntity, tableName, x => true, () => false)) .ToArrayAsync(); Func <Task> rollbacksAll = () => Task.WhenAll(rollbacks.Select(rollback => rollback())); return rollbacksAll; }, () => () => 0.AsTask(), tableName: tableName)); }
public async Task <TResult> ExecuteDeleteAsync <TEntity, TResult>(MemberInfo memberInfo, string rowKeyRef, string partitionKeyRef, TEntity value, IDictionary <string, EntityProperty> dictionary, AzureTableDriverDynamic repository, Func <Func <Task>, TResult> onSuccessWithRollback, Func <TResult> onFailure) { if (IsIgnored(memberInfo, value)) { return(onSuccessWithRollback(() => true.AsTask())); } var hashRowKey = GetHashRowKey(memberInfo, value, out string discard); var hashPartitionKey = memberInfo.DeclaringType.Name; var tableName = GetLookupTableName(memberInfo); return(await repository.DeleteAsync <StorageLookupTable, TResult>( hashRowKey, hashPartitionKey, async (entity, deleteAsync) => { await deleteAsync(); return onSuccessWithRollback( () => repository.CreateAsync(entity, (discardAgain, discard2x) => true, () => false)); }, () => onSuccessWithRollback(() => 1.AsTask()), (codes, why) => onSuccessWithRollback(() => 1.AsTask()), tableName : tableName)); }
public virtual Task <TResult> ExecuteCreateAsync <TEntity, TResult>(MemberInfo memberInfo, string rowKey, string partitionKey, TEntity value, IDictionary <string, EntityProperty> dictionary, AzureTableDriverDynamic repository, Func <Func <Task>, TResult> onSuccessWithRollback, Func <TResult> onFailure) { var to = (IModifyAzureStorageTablePartitionKey)Activator.CreateInstance(this.To); var toPartitionKey = to.GeneratePartitionKey(rowKey, value, memberInfo); var typeWrapper = new TypeWrapper(rowKey, toPartitionKey, dictionary); return(repository.CreateAsync <TEntity, TResult>(typeWrapper, (entity) => onSuccessWithRollback( () => repository.DeleteAsync <TEntity, bool>(entity, () => true, () => true)), () => onSuccessWithRollback(() => false.AsTask()))); }
public async Task <TResult> ExecuteCreateAsync <TEntity, TResult>(MemberInfo memberInfo, string rowKeyRef, string partitionKeyRef, TEntity value, IDictionary <string, EntityProperty> dictionary, AzureTableDriverDynamic repository, Func <Func <Task>, TResult> onSuccessWithRollback, Func <TResult> onFailure) { var memberType = typeof(TEntity); var taskValue = value.ExecuteFunction(out Type taskType); var resultValue = await taskValue.CastAsTaskObjectAsync(out Type typeToSave); var rawValues = Serialize(resultValue, typeToSave); var subtableEntity = new SubtableEntity(rowKeyRef, partitionKeyRef, rawValues); var tableName = StorageLookupAttribute.GetMemberTableName(memberInfo); var tableRef = repository.TableClient.GetTableReference(tableName); return(await repository.CreateAsync(subtableEntity, new E5CloudTable(tableRef), (discard, discard2) => onSuccessWithRollback(() => 1.AsTask()), onAlreadyExists : () => onFailure())); }
public Task <TResult> ExecuteDeleteAsync <TEntity, TResult>(MemberInfo memberInfo, string rowKey, string partitionKey, TEntity value, IDictionary <string, EntityProperty> dictionary, AzureTableDriverDynamic repository, Func <Func <Task>, TResult> onSuccessWithRollback, Func <TResult> onFailure) { var to = (IModifyAzureStorageTablePartitionKey)Activator.CreateInstance(this.To); var toPartitionKey = to.GeneratePartitionKey(rowKey, value, memberInfo); var typeWrapper = new TypeWrapper(rowKey, toPartitionKey, dictionary); return(repository.DeleteAsync <TEntity, TResult>(typeWrapper, () => onSuccessWithRollback( () => { return repository.CreateAsync <TEntity, bool>(typeWrapper, (createdEntity) => true, () => true); }), () => onSuccessWithRollback( () => 1.AsTask()), () => throw new Exception("Delete with ETAG = * failed due to modification."))); }