public Task <TResult> ExecuteInsertOrReplaceAsync <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 existingRowKey       = GetRowKey(memberInfo, value);
            var existingPartitionKey = GetPartitionKey(memberInfo, value);
            var tableName            = GetLookupTableName(memberInfo);

            return(repository.FindByIdAsync <DateTimeLookupTable, TResult>(existingRowKey, existingPartitionKey,
                                                                           (lookup) =>
            {
                var rowAndParitionKeys = lookup.rows
                                         .NullToEmpty()
                                         .Zip(lookup.partitions.NullToEmpty(), (k, v) => k.PairWithValue(v))
                                         .ToArray();
                var rowKeyFound = rowAndParitionKeys
                                  .NullToEmpty()
                                  .Where(kvp => kvp.Key == rowKeyRef)
                                  .Any();
                var partitionKeyFound = rowAndParitionKeys
                                        .NullToEmpty()
                                        .Where(kvp => kvp.Value == partitionKeyRef)
                                        .Any();
                if (rowKeyFound && partitionKeyFound)
                {
                    return onSuccessWithRollback(() => true.AsTask());
                }
                return onFailure();
            },
                                                                           onNotFound: () => onFailure(),
                                                                           tableName: tableName));
        }
Exemple #2
0
        public async Task <TResult> ExecuteInsertOrReplaceAsync <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 existingRowKeys = GetKeys(memberInfo, value);
            var tableName       = GetLookupTableName(memberInfo);
            var missingRows     = existingRowKeys
                                  .Select(
                async astKey =>
            {
                var isGood = await repository.FindByIdAsync <StorageLookupTable, bool>(astKey.RowKey, astKey.PartitionKey,
                                                                                       (lookup, tableResult) =>
                {
                    var rowAndParitionKeys = lookup.rowAndPartitionKeys;
                    var rowKeyFound        = rowAndParitionKeys
                                             .NullToEmpty()
                                             .Where(kvp => kvp.Key == rowKeyRef)
                                             .Any();
                    var partitionKeyFound = rowAndParitionKeys
                                            .NullToEmpty()
                                            .Where(kvp => kvp.Value == partitionKeyRef)
                                            .Any();
                    if (rowKeyFound && partitionKeyFound)
                    {
                        return(true);
                    }
                    return(false);
                },
                                                                                       onNotFound: () => false,
                                                                                       tableName: tableName);
                return(isGood);
            })
                                  .AsyncEnumerable()
                                  .Where(item => !item);

            if (await missingRows.AnyAsync())
            {
                return(onFailure());
            }
            return(onSuccessWithRollback(() => 1.AsTask()));
        }