コード例 #1
0
        public Task <TResult> GetLookupInfoAsync <TResult>(
            MemberInfo memberInfo, Driver.AzureTableDriverDynamic repository,
            KeyValuePair <MemberInfo, object>[] queries,
            Func <string, DateTime, int, TResult> onEtagLastModifedFound,
            Func <TResult> onNoLookupInfo)
        {
            var tableName           = GetLookupTableName(memberInfo);
            var lookupGeneratorAttr = (IGenerateLookupKeys)this;

            return(lookupGeneratorAttr
                   .GetLookupKeys(memberInfo, queries,
                                  lookupKeys =>
            {
                var lookupRef = lookupKeys.First();
                return repository.FindByIdAsync <StorageLookupTable, TResult>(
                    lookupRef.RowKey, lookupRef.PartitionKey,
                    (dictEntity, tableResult) =>
                {
                    return onEtagLastModifedFound(tableResult.Etag,
                                                  dictEntity.lastModified,
                                                  dictEntity.rowAndPartitionKeys
                                                  .NullToEmpty().Count());
                },
                    () => onNoLookupInfo(),
                    tableName: tableName);
            },
                                  why => throw new Exception(why)));
        }
コード例 #2
0
        public Task <TResult> GetLookupInfoAsync <TResult>(
            MemberInfo memberInfo, Driver.AzureTableDriverDynamic repository,
            KeyValuePair <MemberInfo, object>[] queries,
            Func <string, DateTime, int, TResult> onEtagLastModifedFound,
            Func <TResult> onNoLookupInfo)
        {
            if (queries.IsDefaultNullOrEmpty())
            {
                throw new ArgumentException("Exactly one query param is required for StorageLinkAttribute.");
            }
            if (queries.Length != 1)
            {
                throw new ArgumentException("Exactly one query param is valid for StorageLinkAttribute.");
            }

            var tableName       = GetLookupTableName(memberInfo);
            var memberValue     = queries.First().Value;
            var queryMemberInfo = queries.First().Key;
            var rowKey          = queryMemberInfo.StorageComputeRowKey(memberValue,
                                                                       onMissing: () => new RowKeyAttribute());
            var partitionKey = queryMemberInfo.StorageComputePartitionKey(memberValue, rowKey,
                                                                          onMissing: () => new RowKeyPrefixAttribute());

            return(repository.FindByIdAsync <StorageLookupTable, TResult>(
                       rowKey, partitionKey,
                       (dictEntity, tableResult) =>
            {
                return onEtagLastModifedFound(tableResult.Etag,
                                              dictEntity.lastModified,
                                              dictEntity.rowAndPartitionKeys
                                              .NullToEmpty().Count());
            },
                       () => onNoLookupInfo(),
                       tableName: tableName));
        }
コード例 #3
0
        public IEnumerableAsync <IRefAst> GetKeys(object memberValueObj,
                                                  MemberInfo memberInfo, Driver.AzureTableDriverDynamic repository,
                                                  KeyValuePair <MemberInfo, object>[] queries)
        {
            if (!queries.IsDefaultNullOrEmpty())
            {
                throw new ArgumentException("Exactly one query param is valid for DateTimeLookupAttribute.");
            }

            var memberValue        = (DateTime)memberValueObj;
            var tableName          = GetLookupTableName(memberInfo);
            var lookupRowKey       = ComputeLookupKey(memberValue, TimeSpan.FromSeconds(this.Row));
            var lookupPartitionKey = ComputeLookupKey(memberValue, TimeSpan.FromSeconds(this.Partition));

            return(repository
                   .FindByIdAsync <DateTimeLookupTable, IEnumerableAsync <IRefAst> >(lookupRowKey, lookupPartitionKey,
                                                                                     (dictEntity) =>
            {
                var rowAndParitionKeys = dictEntity.rows
                                         .NullToEmpty()
                                         .Zip(dictEntity.partitions,
                                              (row, partition) => row.AsAstRef(partition))
                                         .AsAsync();
                return rowAndParitionKeys;
            },
                                                                                     () => EnumerableAsync.Empty <IRefAst>(),
                                                                                     tableName: tableName)
                   .FoldTask());
        }
コード例 #4
0
        public IEnumerableAsync <IRefAst> GetKeys(object memberValue,
                                                  MemberInfo memberInfo, Driver.AzureTableDriverDynamic repository,
                                                  KeyValuePair <MemberInfo, object>[] queries)
        {
            if (!queries.IsDefaultNullOrEmpty())
            {
                throw new ArgumentException("Exactly one query param is valid for StorageLinkAttribute.");
            }

            var tableName = GetLookupTableName(memberInfo);

            var rowKey = memberInfo.StorageComputeRowKey(memberValue,
                                                         onMissing: () => new RowKeyAttribute());
            var partitionKey = memberInfo.StorageComputePartitionKey(memberValue, rowKey,
                                                                     onMissing: () => new RowKeyPrefixAttribute());

            return(repository
                   .FindByIdAsync <StorageLookupTable, IEnumerableAsync <IRefAst> >(rowKey, partitionKey,
                                                                                    (dictEntity) =>
            {
                var rowAndParitionKeys = dictEntity.rowAndPartitionKeys
                                         .NullToEmpty()
                                         .Select(rowParitionKeyKvp => rowParitionKeyKvp.Key.AsAstRef(rowParitionKeyKvp.Value))
                                         .AsAsync();
                return rowAndParitionKeys;
            },
                                                                                    () => EnumerableAsync.Empty <IRefAst>(),
                                                                                    tableName: tableName)
                   .FoldTask());
        }
コード例 #5
0
        public TResult GetKeys <TResult>(
            MemberInfo memberInfo, Driver.AzureTableDriverDynamic repository,
            KeyValuePair <MemberInfo, object>[] queries,
            Func <IEnumerableAsync <IRefAst>, TResult> onQueriesMatched,
            Func <TResult> onQueriesDidNotMatch,
            ILogger logger = default)
        {
            var tableName    = GetLookupTableName(memberInfo);
            var scopedLogger = logger.CreateScope("GetKeys");

            return(this.GetLookupKeys(memberInfo, queries,
                                      lookupKeys =>
            {
                var lookupRefs = lookupKeys.ToArray();
                scopedLogger.Trace($"Found {lookupRefs.Length} lookupRefs [{lookupRefs.Select(lr => $"{lr.PartitionKey}/{lr.RowKey}").Join(",")}]");
                var items = lookupRefs
                            .Select(
                    lookupRef =>
                {
                    scopedLogger.Trace($"Fetching... {lookupRef.PartitionKey}/{lookupRef.RowKey}");
                    return repository.FindByIdAsync <StorageLookupTable, IRefAst[]>(
                        lookupRef.RowKey, lookupRef.PartitionKey,
                        (dictEntity, tableResult) =>
                    {
                        scopedLogger.Trace($"Fetched {lookupRef.PartitionKey}/{lookupRef.RowKey}");
                        var rowAndPartitionKeys = dictEntity.rowAndPartitionKeys
                                                  .NullToEmpty()
                                                  .Where(rowPartitionKeyKvp => rowPartitionKeyKvp.Key.HasBlackSpace() && rowPartitionKeyKvp.Value.HasBlackSpace())
                                                  .Distinct(rowPartitionKeyKvp => $"{rowPartitionKeyKvp.Key}{rowPartitionKeyKvp.Value}")
                                                  .Select(rowPartitionKeyKvp => rowPartitionKeyKvp.Key.AsAstRef(rowPartitionKeyKvp.Value))
                                                  .ToArray();
                        scopedLogger.Trace($"{lookupRef.PartitionKey}/{lookupRef.RowKey} = {rowAndPartitionKeys.Length} lookups");
                        return rowAndPartitionKeys;
                    },
                        () =>
                    {
                        scopedLogger.Trace($"Fetch FAILED for {lookupRef.PartitionKey}/{lookupRef.RowKey}");
                        return new IRefAst[] { };
                    },
                        tableName: tableName);
                })
                            .AsyncEnumerable(startAllTasks: true)
                            .SelectMany(logger: scopedLogger);
                return onQueriesMatched(items);
            },
                                      why => onQueriesDidNotMatch()));
        }
コード例 #6
0
        public IEnumerableAsync <IRefAst> GetKeys(object memberValue,
                                                  MemberInfo memberInfo, Driver.AzureTableDriverDynamic repository,
                                                  KeyValuePair <MemberInfo, object>[] queries)
        {
            var tableName          = GetLookupTableName(memberInfo);
            var lookupRowKey       = ComputeLookupRowKey(memberValue, memberInfo);
            var lookupPartitionKey = ComputeLookupPartitionKey(memberValue, memberInfo, lookupRowKey);
            var lookupKey          = queries
                                     .NullToEmpty()
                                     .OrderBy(kvp => kvp.Key.Name)
                                     .Aggregate(
                lookupRowKey.AsAstRef(lookupPartitionKey),
                (lookupKeyCurrent, kvp) =>
            {
                var scopings = kvp.Key
                               .GetAttributesInterface <IScope>()
                               .Where(attr => attr.Scope == this.Scope);
                if (!scopings.Any())
                {
                    // TODO: Error here if scope is set?
                    return(lookupKeyCurrent);
                }
                var scoping = scopings.First();
                return(scoping.MutateReference(lookupKeyCurrent, kvp.Key, kvp.Value));
            });

            return(repository
                   .FindByIdAsync <StorageLookupTable, IEnumerableAsync <IRefAst> >(lookupKey.RowKey, lookupKey.PartitionKey,
                                                                                    (dictEntity) =>
            {
                var rowAndParitionKeys = dictEntity.rowAndPartitionKeys
                                         .NullToEmpty()
                                         .Select(rowParitionKeyKvp => rowParitionKeyKvp.Key.AsAstRef(rowParitionKeyKvp.Value))
                                         .AsAsync();
                return rowAndParitionKeys;
            },
                                                                                    () => EnumerableAsync.Empty <IRefAst>(),
                                                                                    tableName: tableName)
                   .FoldTask());
        }
コード例 #7
0
        public TResult GetKeys <TResult>(
            MemberInfo memberInfo, Driver.AzureTableDriverDynamic repository,
            KeyValuePair <MemberInfo, object>[] queries,
            Func <IEnumerableAsync <IRefAst>, TResult> onQueriesMatched,
            Func <TResult> onQueriesDidNotMatch,
            ILogger logger = default)
        {
            if (queries.IsDefaultNullOrEmpty())
            {
                throw new ArgumentException("Exactly one query param is required for StorageLinkAttribute.");
            }
            if (queries.Length != 1)
            {
                throw new ArgumentException("Exactly one query param is valid for StorageLinkAttribute.");
            }

            var tableName       = GetLookupTableName(memberInfo);
            var memberValue     = queries.First().Value;
            var queryMemberInfo = queries.First().Key;
            var rowKey          = queryMemberInfo.StorageComputeRowKey(memberValue,
                                                                       onMissing: () => new RowKeyAttribute());
            var partitionKey = queryMemberInfo.StorageComputePartitionKey(memberValue, rowKey,
                                                                          onMissing: () => new RowKeyPrefixAttribute());

            return(onQueriesMatched(repository
                                    .FindByIdAsync <StorageLookupTable, IEnumerableAsync <IRefAst> >(rowKey, partitionKey,
                                                                                                     (dictEntity, tableResult) =>
            {
                var rowAndParitionKeys = dictEntity.rowAndPartitionKeys
                                         .NullToEmpty()
                                         .Select(rowParitionKeyKvp => rowParitionKeyKvp.Key.AsAstRef(rowParitionKeyKvp.Value))
                                         .AsAsync();
                return rowAndParitionKeys;
            },
                                                                                                     () => EnumerableAsync.Empty <IRefAst>(),
                                                                                                     tableName: tableName)
                                    .FoldTask()));
        }
コード例 #8
0
        public TResult GetKeys <TResult>(
            MemberInfo memberInfo, Driver.AzureTableDriverDynamic repository,
            KeyValuePair <MemberInfo, object>[] queries,
            Func <IEnumerableAsync <IRefAst>, TResult> onQueriesMatched,
            Func <TResult> onQueriesDidNotMatch,
            ILogger logger = default)
        {
            var tableName           = GetLookupTableName(memberInfo);
            var lookupGeneratorAttr = (IGenerateLookupKeys)this;

            return(lookupGeneratorAttr
                   .GetLookupKeys(memberInfo, queries,
                                  lookupKeys =>
            {
                var astRefs = lookupKeys
                              .ToArray()
                              .Select(
                    lookupRef =>
                {
                    return repository.FindByIdAsync <StorageLookupTable, IEnumerable <IRefAst> >(
                        lookupRef.RowKey, lookupRef.PartitionKey,
                        (dictEntity, tableResult) =>
                    {
                        var rowAndParitionKeys = dictEntity.rowAndPartitionKeys
                                                 .NullToEmpty()
                                                 .Select(rowParitionKeyKvp => rowParitionKeyKvp.Key.AsAstRef(rowParitionKeyKvp.Value));
                        return rowAndParitionKeys;
                    },
                        () => Enumerable.Empty <IRefAst>(),
                        tableName: tableName);
                })
                              .AsyncEnumerable(true)
                              .SelectMany();
                return onQueriesMatched(astRefs);
            },
                                  why => onQueriesDidNotMatch()));
        }