コード例 #1
0
        public static async Task <TResult> FindLinkedDocumentAsync <TParentDoc, TLinkedDoc, TResult>(this AzureStorageRepository repo,
                                                                                                     TableQuery <TParentDoc> query,
                                                                                                     Func <TParentDoc, Guid> getLinkedId,
                                                                                                     Func <IDictionary <TParentDoc, TLinkedDoc>, TResult> found,
                                                                                                     Func <TResult> parentDocNotFound)
            where TParentDoc : class, ITableEntity, new()
            where TLinkedDoc : class, ITableEntity
        {
            var parentDocs = await repo.FindByQueryAsync(query);

            var results = await parentDocs
                          .Aggregate(
                (new Dictionary <TParentDoc, TLinkedDoc>()).ToTask(),
                async (docsTask, document) =>
            {
                var linkedDocId = getLinkedId(document);
                return(await await repo.FindByIdAsync(linkedDocId,
                                                      async(TLinkedDoc priceSheetDocument) =>
                {
                    var docs = await docsTask;
                    docs.Add(document, priceSheetDocument);
                    return docs;
                },
                                                      () => docsTask));
            });

            return(found(results));
        }
コード例 #2
0
        public static async Task <TResult> FindLinkedLinkedDocumentsAsync <TParentDoc, TMiddleDoc, TLinkedDoc, TResult>(this AzureStorageRepository repo,
                                                                                                                        Guid parentDocId,
                                                                                                                        Func <TParentDoc, Guid[]> getMiddleDocumentIds,
                                                                                                                        Func <TMiddleDoc, Guid[]> getLinkedIds,
                                                                                                                        Func <TParentDoc, IDictionary <TMiddleDoc, TLinkedDoc[]>, TResult> found,
                                                                                                                        Func <TResult> lookupDocNotFound)
            where TParentDoc : class, ITableEntity
            where TMiddleDoc : class, ITableEntity
            where TLinkedDoc : class, ITableEntity
        {
            var result = await await repo.FindByIdAsync(parentDocId,
                                                        async (TParentDoc parentDoc) =>
            {
                var middleDocIds        = getMiddleDocumentIds(parentDoc);
                var middleAndLinkedDocs = await middleDocIds
                                          .Select(
                    middleDocId =>
                    repo.FindLinkedDocumentsAsync(middleDocId,
                                                  (middleDoc) => getLinkedIds(middleDoc),
                                                  (TMiddleDoc middleDoc, TLinkedDoc[] linkedDocsByMiddleDoc) =>
                                                  new KeyValuePair <TMiddleDoc, TLinkedDoc[]>(middleDoc, linkedDocsByMiddleDoc),
                                                  () => default(KeyValuePair <TMiddleDoc, TLinkedDoc[]>?)))
                                          .WhenAllAsync()
                                          .SelectWhereHasValueAsync();
                return(found(parentDoc, middleAndLinkedDocs.ToDictionary()));
            },
                                                        () =>
            {
                // TODO: Log data inconsistency here
                return(lookupDocNotFound().ToTask());
            });

            return(result);
        }
コード例 #3
0
 public Sessions(AzureStorageRepository repository)
 {
     this.repository = repository;
 }
コード例 #4
0
        public static async Task <TResult> FindLinkedDocumentsAsync <TParentDoc, TLinkedDoc, TResult>(this AzureStorageRepository repo,
                                                                                                      Guid parentDocId, string partitionKey,
                                                                                                      Func <TParentDoc, Guid[]> getLinkedIds,
                                                                                                      Func <TParentDoc, TLinkedDoc[], TResult> found,
                                                                                                      Func <TResult> parentDocNotFound)
            where TParentDoc : class, ITableEntity
            where TLinkedDoc : class, ITableEntity
        {
            var result = await await repo.FindByIdAsync(parentDocId, partitionKey,
                                                        async (TParentDoc document) =>
            {
                var linkedDocIds        = getLinkedIds(document);
                var linkedDocsWithNulls = await linkedDocIds
                                          .Select(
                    linkedDocId =>
                {
                    return(repo.FindByIdAsync(linkedDocId,
                                              (TLinkedDoc priceSheetDocument) => priceSheetDocument,
                                              () =>
                    {
                        // TODO: Log data corruption
                        return default(TLinkedDoc);
                    }));
                })
                                          .WhenAllAsync();
                var linkedDocs = linkedDocsWithNulls
                                 .Where(doc => default(TLinkedDoc) != doc)
                                 .ToArray();
                return(found(document, linkedDocs));
            },
                                                        () => parentDocNotFound().ToTask());

            return(result);
        }
コード例 #5
0
 public CredentialMappings(AzureStorageRepository repository)
 {
     this.repository = repository;
 }
コード例 #6
0
 public BookController(AzureStorageRepository repository)
 {
     _repository = repository;
 }
コード例 #7
0
        public static async Task <TRollback> ExecuteDeleteJoinAsync <TRollback, TDocument>(this RollbackAsync <Guid?, TRollback> rollback,
                                                                                           Func <TRollback> onSuccess,
                                                                                           AzureStorageRepository repo)
            where TDocument : class, ITableEntity
        {
            var result = await await rollback.ExecuteAsync <Task <TRollback> >(
                async (joinIds) =>
            {
                var joinId = joinIds.First(joinIdCandidate => joinIdCandidate.HasValue);
                if (!joinId.HasValue)
                {
                    return(onSuccess());
                }
                return(await repo.DeleteIfAsync <TDocument, TRollback>(joinId.Value,
                                                                       async(doc, delete) =>
                {
                    await delete();
                    return onSuccess();
                },
                                                                       () =>
                {
                    // TODO: Log data inconsistency
                    return onSuccess();
                }));
            },
                (failureResult) => failureResult.ToTask());

            return(result);
        }
コード例 #8
0
        public static async Task <TResult> DeleteJoinAsync <TLink, TLinkDocument, TLinkedDocument, TResult>(this AzureStorageRepository repo,
                                                                                                            IEnumerable <TLink> links,
                                                                                                            Func <TLink, Guid> getLinkId,
                                                                                                            Func <TLink, Guid> getLinkedId,
                                                                                                            Action <TLinkedDocument> mutateAsync,
                                                                                                            Func <bool, TResult> success)
            where TLinkDocument : class, ITableEntity
            where TLinkedDocument : class, ITableEntity
        {
            var deletedCleans = await links
                                .Select(
                async link =>
            {
                var deleteSuccess = repo.DeleteIfAsync <TLinkDocument, bool>(getLinkId(link),
                                                                             async(doc, deleteAsync) =>
                {
                    await deleteAsync();
                    return(true);
                },
                                                                             () => false);
                var updateSuccess = await repo.UpdateAsync <TLinkedDocument, bool>(getLinkedId(link),
                                                                                   async(doc, updateAsync) =>
                {
                    mutateAsync(doc);
                    await updateAsync(doc);
                    return(true);
                },
                                                                                   () => false);
                return((await deleteSuccess) && (updateSuccess));
            })
                                .WhenAllAsync();

            var completeSuccess = deletedCleans.All(t => t);

            return(success(completeSuccess));
        }
 public AuthenticationRequests(DataContext context, AzureStorageRepository repository)
 {
     this.repository = repository;
     this.context    = context;
 }
コード例 #10
0
        public static void AddTaskUpdate <T, TRollback, TDocument>(this RollbackAsync <TRollback> rollback,
                                                                   Guid docId,
                                                                   Func <
                                                                       TDocument,
                                                                       Func <T, UpdateCallback <T> >, // Save + Success
                                                                       Func <UpdateCallback <T> >,    // No Save + Success
                                                                       Func <UpdateCallback <T> >,    // Reject
                                                                       UpdateCallback <T> > mutateUpdate,
                                                                   Func <T, TDocument, bool> mutateRollback,
                                                                   Func <TRollback> onMutateRejected,
                                                                   Func <TRollback> onNotFound,
                                                                   AzureStorageRepository repo)
            where TDocument : class, ITableEntity
        {
            rollback.AddTask(
                async(success, failure) =>
            {
                var r = await repo.UpdateAsync <TDocument, UpdateCallback <T> >(docId,
                                                                                async(doc, save) =>
                {
                    var passThrough = mutateUpdate(doc,
                                                   (passThroughSuccess) => UpdateCallback <T> .Save(passThroughSuccess),
                                                   () => UpdateCallback <T> .SuccessNoSave(),
                                                   () => UpdateCallback <T> .Reject());
                    if (passThrough.save)
                    {
                        await save(doc);
                    }
                    return(passThrough);
                },
                                                                                () => UpdateCallback <T> .NotFound());

                if (!r.found)
                {
                    return(failure(onNotFound()));
                }
                if (!r.success)
                {
                    return(failure(onMutateRejected()));
                }

                return(success(
                           async() =>
                {
                    if (r.save)
                    {
                        await repo.UpdateAsync <TDocument, bool>(docId,
                                                                 async(doc, save) =>
                        {
                            if (mutateRollback(r.t, doc))
                            {
                                await save(doc);
                            }
                            return true;
                        },
                                                                 () => false);
                    }

                    // If this was not saved, there is no reason to do anything on the rollback
                }));
            });
        }
        internal async Task <TResult> AddClaimsAsync <TResult>(ClaimDocument claimsDoc, AzureStorageRepository repository,
                                                               Func <TResult> success,
                                                               Func <TResult> failure)
        {
            var claimDocumentIdsCurrent = Claims.ToGuidsFromByteArray();
            var claimDocumentIds        = claimDocumentIdsCurrent.Concat(new Guid[] { claimsDoc.ClaimId });

            this.Claims = claimDocumentIds.ToByteArrayOfGuids();
            return(await repository.CreateAsync(claimsDoc.ClaimId, claimsDoc,
                                                () => success(),
                                                () => failure()));
        }
コード例 #12
0
 public Accesses(AzureStorageRepository repository)
 {
     this.repository = repository;
 }
コード例 #13
0
        internal static Task <TResult> CreateAsync <TResult>(Guid processId,
                                                             Guid processStageId,
                                                             Guid actorId, Guid resourceId, Type resourceType, DateTime createdOn,
                                                             Process.ProcessStageResource[] resources,
                                                             Guid?previousStepId, DateTime?confirmedWhen, Guid?confirmedBy,
                                                             Guid [] lookupActorIds,
                                                             Func <TResult> onSuccess,
                                                             Func <TResult> onAlreadyExists)
        {
            return(AzureStorageRepository.Connection(
                       azureStorageRepository =>
            {
                var rollback = new RollbackAsync <TResult>();

                var resourceTypeString = resourceType.AssemblyQualifiedName;
                var processDocument = new ProcessDocument()
                {
                    ProcessStage = processStageId,

                    Resource = resourceId,
                    ResourceType = resourceTypeString,
                    CreatedOn = createdOn,
                    Owner = actorId,

                    ConfirmedBy = confirmedBy,
                    PreviousStep = previousStepId,
                    ConfirmedWhen = confirmedWhen,
                };
                processDocument.SetResources(resources);
                rollback.AddTaskCreate(processId, processDocument,
                                       onAlreadyExists, azureStorageRepository);

                foreach (var lookupActorId in lookupActorIds.Distinct())
                {
                    rollback.AddTaskCreateOrUpdate <TResult, Documents.ProcessStepActorLookupDocument>(lookupActorId, resourceTypeString,
                                                                                                       (created, lookupDoc) => lookupDoc.AddLookupDocumentId(processId),
                                                                                                       actorDoc => actorDoc.RemoveLookupDocumentId(processId),
                                                                                                       azureStorageRepository);
                }

                rollback.AddTaskCreateOrUpdate <TResult, Documents.ProcessStepResourceLookupDocument>(resourceId, resourceTypeString,
                                                                                                      (created, lookupDoc) => lookupDoc.AddLookupDocumentId(processId),
                                                                                                      actorDoc => actorDoc.RemoveLookupDocumentId(processId),
                                                                                                      azureStorageRepository);

                bool[] updates = resources
                                 .Select(
                    resource =>
                {
                    if (!resource.resourceId.HasValue)
                    {
                        return true;
                    }
                    rollback.AddTaskCreateOrUpdate <TResult, Documents.ProcessStepResourceKeyLookupDocument>(
                        resource.resourceId.Value, resource.type.AssemblyQualifiedName,
                        (created, lookupDoc) => lookupDoc.AddLookupDocumentId(processId),
                        lookupDoc => lookupDoc.RemoveLookupDocumentId(processId),
                        azureStorageRepository);
                    return true;
                })
                                 .ToArray();

                return rollback.ExecuteAsync(onSuccess);
            }));
        }
コード例 #14
0
 internal Roles(DataContext dataContext)
 {
     this.dataContext            = dataContext;
     this.azureStorageRepository = dataContext.AzureStorageRepository;
 }
コード例 #15
0
        //public static async Task<TResult> FindLinkedLinkedDocumentAsync<TParentDoc, TMiddleDoc, TLinkedDoc, TResult>(this AzureStorageRepository repo,
        //    Guid parentDocId,
        //    Func<TParentDoc, Guid> getMiddleDocumentId,
        //    Func<TMiddleDoc, Guid> getLinkedId,
        //    Func<TParentDoc, TMiddleDoc, TLinkedDoc, TResult> found,
        //    Func<TResult> parentDocNotFound,
        //    Func<TParentDoc, TResult> middleDocNotFound,
        //    Func<TParentDoc, TMiddleDoc, TResult> linkedDocNotFound)
        //    where TParentDoc : class, ITableEntity
        //    where TMiddleDoc : class, ITableEntity
        //    where TLinkedDoc : class, ITableEntity
        //{
        //    var result = await await repo.FindByIdAsync(parentDocId,
        //        async (TParentDoc parentDoc) =>
        //        {
        //            var middleDocId = getMiddleDocumentId(parentDoc);
        //            var middleAndLinkedDocs = await repo.FindLinkedDocumentAsync(middleDocId,
        //                    (middleDoc) => getLinkedId(middleDoc),
        //                    (TMiddleDoc middleDoc, TLinkedDoc linkedDoc) =>
        //                found(parentDoc, middleDoc, linkedDoc),
        //                () => middleDocNotFound(parentDoc),
        //                (middleDoc) => linkedDocNotFound(parentDoc, middleDoc));
        //            return middleAndLinkedDocs;
        //        },
        //        parentDocNotFound.AsAsyncFunc());
        //    return result;
        //}

        //public static async Task<TResult> FindLinkedLinkedDocumentsAsync<TParentDoc, TMiddleDoc, TLinkedDoc, TResult>(this AzureStorageRepository repo,
        //    Guid parentDocId,
        //    Func<TParentDoc, Guid[]> getMiddleDocumentIds,
        //    Func<TMiddleDoc, Guid[]> getLinkedIds,
        //    Func<TParentDoc, IDictionary<TMiddleDoc, TLinkedDoc[]>, TResult> found,
        //    Func<TResult> lookupDocNotFound)
        //    where TParentDoc : class, ITableEntity
        //    where TMiddleDoc : class, ITableEntity
        //    where TLinkedDoc : class, ITableEntity
        //{
        //    var result = await await repo.FindByIdAsync(parentDocId,
        //        async (TParentDoc parentDoc) =>
        //        {
        //            var middleDocIds = getMiddleDocumentIds(parentDoc);
        //            var middleAndLinkedDocs = await middleDocIds
        //                .Select(
        //                    middleDocId =>
        //                        repo.FindLinkedDocumentsAsync(middleDocId,
        //                            (middleDoc) => getLinkedIds(middleDoc),
        //                            (TMiddleDoc middleDoc, TLinkedDoc[] linkedDocsByMiddleDoc) =>
        //                                new KeyValuePair<TMiddleDoc, TLinkedDoc[]>(middleDoc, linkedDocsByMiddleDoc),
        //                            () => default(KeyValuePair<TMiddleDoc, TLinkedDoc[]>?)))
        //                .WhenAllAsync()
        //                .SelectWhereHasValueAsync();
        //            return found(parentDoc, middleAndLinkedDocs.ToDictionary());
        //        },
        //        () =>
        //        {
        //            // TODO: Log data inconsistency here
        //            return lookupDocNotFound().AsTask();
        //        });
        //    return result;
        //}

        //public static Task<TResult> FindLinkedDocumentsAsync<TParentDoc, TLinkedDoc, TResult>(this AzureStorageRepository repo,
        //    Guid parentDocId,
        //    Func<TParentDoc, Guid[]> getLinkedIds,
        //    Func<TParentDoc, IEnumerableAsync<TLinkedDoc>, TResult> found,
        //    Func<TResult> parentDocNotFound)
        //    where TParentDoc : class, ITableEntity
        //    where TLinkedDoc : class, ITableEntity
        //{
        //    return repo.FindByIdAsync(parentDocId,
        //        (TParentDoc document) =>
        //        {
        //            var linkedDocIds = getLinkedIds(document);
        //            var linkedDocs = linkedDocIds
        //                .SelectAsyncOptional<Guid, TLinkedDoc>(
        //                    (linkedDocId, select, skip) =>
        //                    {
        //                        return repo.FindByIdAsync(linkedDocId,
        //                            (TLinkedDoc priceSheetDocument) => select(priceSheetDocument),
        //                            skip);
        //                    });
        //            return found(document, linkedDocs);
        //        },
        //        () => parentDocNotFound());
        //}

        //public static async Task<TResult> FindLinkedLinkedDocumentsAsync<TParentDoc, TMiddleDoc, TLinkedDoc, TResult>(this AzureStorageRepository repo,
        //    Guid parentDocId,
        //    Func<TParentDoc, Guid[]> getMiddleDocumentIds,
        //    Func<TMiddleDoc, Guid> getLinkedId,
        //    Func<TParentDoc, IDictionary<TMiddleDoc, TLinkedDoc>, TResult> found,
        //    Func<TResult> lookupDocNotFound)
        //    where TParentDoc : class, ITableEntity
        //    where TMiddleDoc : class, ITableEntity
        //    where TLinkedDoc : class, ITableEntity
        //{
        //    var result = await await repo.FindByIdAsync(parentDocId,
        //        async (TParentDoc parentDoc) =>
        //        {
        //            var middleDocIds = getMiddleDocumentIds(parentDoc);
        //            var middleAndLinkedDocs = await middleDocIds
        //                .Select(
        //                    middleDocId =>
        //                        repo.FindLinkedDocumentAsync(middleDocId,
        //                            (middleDoc) => getLinkedId(middleDoc),
        //                            (TMiddleDoc middleDoc, TLinkedDoc linkedDocsByMiddleDoc) =>
        //                                new KeyValuePair<TMiddleDoc, TLinkedDoc>(middleDoc, linkedDocsByMiddleDoc),
        //                            () => default(KeyValuePair<TMiddleDoc, TLinkedDoc>?),
        //                            (middleDoc) => default(KeyValuePair<TMiddleDoc, TLinkedDoc>?)))
        //                .WhenAllAsync()
        //                .SelectWhereHasValueAsync();
        //            return found(parentDoc, middleAndLinkedDocs.ToDictionary());
        //        },
        //        () =>
        //        {
        //            // TODO: Log data inconsistency here
        //            return lookupDocNotFound().AsTask();
        //        });
        //    return result;
        //}

        //public static async Task<TResult> FindLinkedLinkedDocumentsAsync<TParentDoc, TMiddleDoc, TLinkedDoc, TResult>(this AzureStorageRepository repo,
        //    Guid parentDocId,
        //    Func<TParentDoc, Guid> getMiddleDocumentId,
        //    Func<TMiddleDoc, Guid[]> getLinkedIds,
        //    Func<TParentDoc, TMiddleDoc, TLinkedDoc[], TResult> found,
        //    Func<TResult> parentDocNotFound,
        //    Func<TResult> middleDocNotFound,
        //    Func<TResult> linkedDocNotFound)
        //    where TParentDoc : class, ITableEntity
        //    where TMiddleDoc : class, ITableEntity
        //    where TLinkedDoc : class, ITableEntity
        //{
        //    var resultAll = await await repo.FindByIdAsync(parentDocId,
        //        async (TParentDoc parentDoc) =>
        //        {
        //            var middleDocId = getMiddleDocumentId(parentDoc);
        //            var result = await repo.FindLinkedDocumentsAsync(middleDocId,
        //                (middleDoc) => getLinkedIds(middleDoc),
        //                (TMiddleDoc middleDoc, TLinkedDoc[] linkedDocsByMiddleDocs) =>
        //                    found(parentDoc, middleDoc, linkedDocsByMiddleDocs),
        //                () => middleDocNotFound());
        //            return result;
        //        },
        //        () => parentDocNotFound().AsTask());
        //    return resultAll;
        //}

        //public static Guid? RemoveLinkedDocument<TJoin>(this TJoin[] joins, Guid joinId,
        //    Func<TJoin, Guid> idField,
        //    Func<TJoin, Guid> joinField,
        //    Action<TJoin[]> save)
        //{
        //    var joinsUpdated = joins
        //        .Where(join => joinField(join) != joinId)
        //        .ToArray();
        //    save(joinsUpdated);
        //    var match = joins.Where(join => joinField(join) == joinId).ToArray();
        //    if (match.Length > 0)
        //        return idField(match[0]);
        //    return default(Guid?);
        //}

        /// <summary>
        /// Starting with <paramref name="startingDocumentId"/>, searches for documents until <paramref name="getLinkedId"/>
        /// returns a Guid? without a value.
        /// </summary>
        /// <typeparam name="TDoc"></typeparam>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="repo"></param>
        /// <param name="startingDocumentId"></param>
        /// <param name="getLinkedId"></param>
        /// <param name="onFound">Passes an array of found documents in reverse order (document with id <paramref name="startingDocumentId"/> is last).</param>
        /// <param name="startDocNotFound"></param>
        /// <returns></returns>
        public static async Task <TResult> FindRecursiveDocumentsAsync <TDoc, TResult>(this AzureStorageRepository repo,
                                                                                       Guid startingDocumentId,
                                                                                       Func <TDoc, Guid?> getLinkedId,
                                                                                       Func <TDoc[], TResult> onFound,
                                                                                       Func <TResult> startDocNotFound)
            where TDoc : class, ITableEntity
        {
            var result = await await repo.FindByIdAsync(startingDocumentId,
                                                        async (TDoc document) =>
            {
                var linkedDocId = getLinkedId(document);
                if (!linkedDocId.HasValue)
                {
                    return(onFound(document.AsEnumerable().ToArray()));
                }
                return(await repo.FindRecursiveDocumentsAsync(linkedDocId.Value,
                                                              getLinkedId,
                                                              (linkedDocuments) => onFound(linkedDocuments.Append(document).ToArray()),
                                                              () => onFound(new TDoc[] { document }))); // TODO: Log data inconsistency
            },
                                                        () => startDocNotFound().AsTask());

            return(result);
        }
コード例 #16
0
        public static async Task <TResult> DeleteJoinAsync <TJoinDoc, TJoinedDoc1, TJoinedDoc2, TResult>(this AzureStorageRepository repo,
                                                                                                         Guid joinId,
                                                                                                         Func <TJoinDoc, Guid> joinedDoc1Id,
                                                                                                         Func <TJoinDoc, Guid> joinedDoc2Id,
                                                                                                         Func <TJoinDoc, TJoinedDoc1, Func <TJoinedDoc1, Task>, Task <bool> > onMutate1Async,
                                                                                                         Func <TJoinDoc, TJoinedDoc2, Func <TJoinedDoc2, Task>, Task <bool> > onMutate2Async,
                                                                                                         Func <TJoinDoc, bool, bool, TResult> onSuccess,
                                                                                                         Func <TResult> onNotFound)
            where TJoinDoc : class, ITableEntity
            where TJoinedDoc1 : class, ITableEntity
            where TJoinedDoc2 : class, ITableEntity
        {
            var result = await repo.DeleteIfAsync <TJoinDoc, TResult>(joinId,
                                                                      async (joinDoc, deleteJoinDoc) =>
            {
                var task            = deleteJoinDoc();
                var doc1SuccessTask = repo.UpdateAsync <TJoinedDoc1, bool>(joinedDoc1Id(joinDoc),
                                                                           async(joinedDoc, mutateJoinedDoc) =>
                {
                    var mutated = await onMutate1Async(joinDoc, joinedDoc, (joinedDocToMutate) => mutateJoinedDoc(joinedDocToMutate));
                    return(mutated);
                },
                                                                           () => false);
                var doc2SuccessTask = repo.UpdateAsync <TJoinedDoc2, bool>(joinedDoc2Id(joinDoc),
                                                                           async(joinedDoc, mutateJoinedDoc) =>
                {
                    var mutated = await onMutate2Async(joinDoc, joinedDoc, (joinedDocToMutate) => mutateJoinedDoc(joinedDocToMutate));
                    return(mutated);
                },
                                                                           () => false);
                await task;
                return(onSuccess(joinDoc, await doc1SuccessTask, await doc2SuccessTask));
            },
                                                                      onNotFound);

            return(result);
        }
コード例 #17
0
        //public static async Task<TResult> FindRecursiveDocumentsAsync<TDoc, TResult>(this AzureStorageRepository repo,
        //    Guid startingDocumentId, HashSet<Guid> skip,
        //    Func<TDoc, Guid?> getLinkedId,
        //    Func<TDoc[], TResult> onFound,
        //    Func<TResult> startDocNotFound)
        //    where TDoc : class, ITableEntity
        //{
        //    var result = await await repo.FindByIdAsync(startingDocumentId,
        //        async (TDoc document) =>
        //        {
        //            var linkedDocId = getLinkedId(document);
        //            if ((!linkedDocId.HasValue) || skip.Contains(linkedDocId.Value))
        //                return onFound(document.AsEnumerable().ToArray());
        //            return await repo.FindRecursiveDocumentsAsync(linkedDocId.Value,
        //                getLinkedId,
        //                (linkedDocuments) => onFound(linkedDocuments.Append(document).ToArray()),
        //                () => onFound(new TDoc[] { document })); // TODO: Log data inconsistency
        //        },
        //        () => startDocNotFound().AsTask());

        //    return result;
        //}

        public static async Task <TResult> FindRecursiveDocumentsAsync <TDoc, TResult>(this AzureStorageRepository repo,
                                                                                       Guid startingDocumentId,
                                                                                       Func <TDoc, Guid[]> getLinkedIds,
                                                                                       Func <TDoc[], TResult> onFound,
                                                                                       Func <TResult> startDocNotFound)
            where TDoc : class, ITableEntity
        {
            var result = await await repo.FindByIdAsync(startingDocumentId,
                                                        async (TDoc document) =>
            {
                var linkedDocIds = getLinkedIds(document);
                var docs         = await linkedDocIds.Select(
                    linkedDocId =>
                    repo.FindRecursiveDocumentsAsync(linkedDocId,
                                                     getLinkedIds,
                                                     (linkedDocuments) => linkedDocuments,
                                                     () => (new TDoc[] { })))
                                   .WhenAllAsync()
                                   .SelectManyAsync()
                                   .ToArrayAsync(); // TODO: Log data inconsistency
                return(onFound(docs.Append(document).ToArray()));
            },
                                                        () => startDocNotFound().AsTask());

            return(result);
        }
コード例 #18
0
        public static async Task <TResult> AddJoinAsync <TJoin, TDocJoin, TDoc1, TDoc2, TResult>(this AzureStorageRepository repo,
                                                                                                 Guid id, Guid id1, Guid id2, TDocJoin document,
                                                                                                 Func <TDoc1, TJoin[]> getJoins1,
                                                                                                 Func <TDoc2, TJoin[]> getJoins2,
                                                                                                 Func <TJoin, Guid> id1FromJoin,
                                                                                                 Func <TJoin, Guid> id2FromJoin,
                                                                                                 Action <TDoc1> mutateUpdate1,
                                                                                                 Action <TDoc1> mutateRollback1,
                                                                                                 Action <TDoc2> mutateUpdate2,
                                                                                                 Action <TDoc2> mutateRollback2,
                                                                                                 Func <TResult> onSuccess,
                                                                                                 Func <TResult> joinIdAlreadyExist,
                                                                                                 Func <TJoin, TResult> joinAlreadyExist,
                                                                                                 Func <TResult> doc1DoesNotExist,
                                                                                                 Func <TResult> doc2DoesNotExist)
            where TDocJoin : class, ITableEntity
            where TDoc1 : class, ITableEntity
            where TDoc2 : class, ITableEntity
        {
            var parallel = new RollbackAsync <TResult>();

            var duplicateJoin1 = default(TJoin);

            parallel.AddTaskUpdate <Guid, TResult, TDoc1>(id1,
                                                          (doc, successSave, successNoSave, reject) =>
            {
                var matches = getJoins1(doc).Where(join => id2FromJoin(join) == id2).ToArray();
                if (matches.Length > 0)
                {
                    duplicateJoin1 = matches[0];
                    return(reject());
                }
                mutateUpdate1(doc);
                return(successSave(id1));
            },
                                                          (id1Again, doc) => { mutateRollback1(doc); return(true); },
                                                          () => joinAlreadyExist(duplicateJoin1),
                                                          doc1DoesNotExist,
                                                          repo);

            var duplicateJoin2 = default(TJoin);

            parallel.AddTaskUpdate <Guid, TResult, TDoc2>(id2,
                                                          (doc, successSave, successNoSave, reject) =>
            {
                var matches = getJoins2(doc).Where(join => id1FromJoin(join) == id1).ToArray();
                if (matches.Length > 0)
                {
                    duplicateJoin2 = matches[0];
                    return(reject());
                }
                mutateUpdate2(doc);
                return(successSave(id2));
            },
                                                          (id1Again, doc) => { mutateRollback2(doc); return(true); },
                                                          () => joinAlreadyExist(duplicateJoin2),
                                                          doc2DoesNotExist,
                                                          repo);

            //parallel.AddTaskUpdate(id2,
            //    mutateUpdate2,
            //    mutateRollback2,
            //    doc2DoesNotExist,
            //    repo);

            parallel.AddTaskCreate(id, document,
                                   () => joinIdAlreadyExist(),
                                   repo);

            var result = await parallel.ExecuteAsync(
                () => onSuccess(),
                (failureResult) => failureResult);

            return(result);
        }
コード例 #19
0
        //public static async Task<TResult> FindLinkedDocumentAsync<TParentDoc, TLinkedDoc, TResult>(this AzureStorageRepository repo,
        //    TableQuery<TParentDoc> query,
        //    Func<TParentDoc, Guid> getLinkedId,
        //    Func<IDictionary<TParentDoc, TLinkedDoc>, TResult> found,
        //    Func<TResult> parentDocNotFound)
        //    where TParentDoc : class, ITableEntity, new()
        //    where TLinkedDoc : class, ITableEntity
        //{
        //    var parentDocs = await repo.FindByQueryAsync(query);
        //    var results = await parentDocs
        //        .Aggregate(
        //            (new Dictionary<TParentDoc, TLinkedDoc>()).AsTask(),
        //            async (docsTask, document) =>
        //            {
        //                var linkedDocId = getLinkedId(document);
        //                return await await repo.FindByIdAsync(linkedDocId,
        //                    async (TLinkedDoc priceSheetDocument) =>
        //                    {
        //                        var docs = await docsTask;
        //                        docs.Add(document, priceSheetDocument);
        //                        return docs;
        //                    },
        //                    () => docsTask);
        //        });

        //    return found(results);
        //}

        //public static Task<TResult> FindLinkedDocumentAsync<TParentDoc, TLinkedDoc, TResult>(this AzureStorageRepository repo,
        //    Guid parentDocRowKey, string parentDocPartitionKey,
        //    Func<TParentDoc, Guid> getLinkedId,
        //    Func<TParentDoc, TLinkedDoc, TResult> found,
        //    Func<TResult> parentDocNotFound,
        //    Func<TParentDoc, TResult> linkedDocNotFound)
        //    where TParentDoc : class, ITableEntity
        //    where TLinkedDoc : class, ITableEntity
        //{
        //    return repo.FindLinkedDocumentAsync(parentDocRowKey.AsRowKey(), parentDocPartitionKey,
        //        getLinkedId, found, parentDocNotFound, linkedDocNotFound);
        //}

        //public static async Task<TResult> FindLinkedDocumentAsync<TParentDoc, TLinkedDoc, TResult>(this AzureStorageRepository repo,
        //    string parentDocRowKey, string parentDocPartitionKey,
        //    Func<TParentDoc, Guid> getLinkedId,
        //    Func<TParentDoc, TLinkedDoc, TResult> found,
        //    Func<TResult> parentDocNotFound,
        //    Func<TParentDoc, TResult> linkedDocNotFound)
        //    where TParentDoc : class, ITableEntity
        //    where TLinkedDoc : class, ITableEntity
        //{
        //    var result = await await repo.FindByIdAsync(parentDocRowKey, parentDocPartitionKey,
        //        async (TParentDoc document) =>
        //        {
        //            var linkedDocId = getLinkedId(document);
        //            return await repo.FindByIdAsync(linkedDocId,
        //                (TLinkedDoc priceSheetDocument) => found(document, priceSheetDocument),
        //                () => linkedDocNotFound(document));
        //        },
        //        () => parentDocNotFound().AsTask());

        //    return result;
        //}

        public static async Task <TResult> FindLinkedDocumentAsync <TParentDoc, TLinkedDoc, TResult>(this AzureStorageRepository repo,
                                                                                                     Guid parentDocId,
                                                                                                     Func <TParentDoc, Guid> getLinkedId,
                                                                                                     Func <TParentDoc, TLinkedDoc, TResult> found,
                                                                                                     Func <TResult> parentDocNotFound,
                                                                                                     Func <TParentDoc, TResult> linkedDocNotFound,
                                                                                                     ILogger logger = default)
            where TParentDoc : class, ITableEntity
            where TLinkedDoc : class, ITableEntity
        {
            return(await await repo.FindByIdAsync(parentDocId,
                                                  async (TParentDoc document) =>
            {
                logger.Trace("Found parent doc");
                var linkedDocId = getLinkedId(document);
                return await repo.FindByIdAsync(linkedDocId,
                                                (TLinkedDoc linkedDoc) =>
                {
                    logger.Trace("Found linked doc");
                    return found(document, linkedDoc);
                },
                                                () =>
                {
                    logger.Trace($"Failed to find linked doc {linkedDocId}");
                    return linkedDocNotFound(document);
                });
            },
                                                  () =>
            {
                logger.Trace($"Failed to find parent doc {parentDocId}");
                return parentDocNotFound().AsTask();
            },
                                                  logger : logger));
        }
コード例 #20
0
 public Integrations(AzureStorageRepository repository, Security.SessionServer.Persistence.DataContext dataContext)
 {
     this.repository  = repository;
     this.dataContext = dataContext;
 }
コード例 #21
0
 public DeleteMediaCommandHandler(AzureStorageRepository repository)
 {
     _repository = repository ?? throw new ArgumentNullException(nameof(repository));
 }
コード例 #22
0
 public CreateFolderCommandHandler(AzureStorageRepository repository, MediaFolderConverter folderConverter)
 {
     _repository      = repository ?? throw new ArgumentNullException(nameof(repository));
     _folderConverter = folderConverter ?? throw new ArgumentNullException(nameof(folderConverter));
 }
コード例 #23
0
 public PasswordCredentials(DataContext context, AzureStorageRepository repository)
 {
     this.repository = repository;
     this.context    = context;
 }
コード例 #24
0
 public AzureMediaLibraryQuery(AzureStorageRepository repository)
 {
     _repository = repository ?? throw new ArgumentNullException(nameof(repository));
 }
コード例 #25
0
 public Claims(AzureStorageRepository repository)
 {
     this.repository = repository;
 }
コード例 #26
0
        public static async Task <TResult> FindLinkedDocumentsAsync <TParentDoc, TLinkedDoc, TResult>(this AzureStorageRepository repo,
                                                                                                      Guid parentDocId, string partitionKey,
                                                                                                      Func <TParentDoc, Guid[]> getLinkedIds,
                                                                                                      Func <TParentDoc, TLinkedDoc[], Guid [], TResult> found,
                                                                                                      Func <TResult> parentDocNotFound)
            where TParentDoc : class, ITableEntity
            where TLinkedDoc : class, ITableEntity
        {
            var result = await await repo.FindByIdAsync(parentDocId, partitionKey,
                                                        (TParentDoc document) =>
            {
                var linkedDocIds = getLinkedIds(document);
                return(linkedDocIds
                       .FlatMap(
                           new Guid[] { },
                           async(linkedDocId, missingIds, next, skip) =>
                {
                    return await await repo.FindByIdAsync(linkedDocId,
                                                          (TLinkedDoc priceSheetDocument) => next(priceSheetDocument, missingIds),
                                                          () => skip(missingIds.Append(linkedDocId).ToArray()));
                },
                           (TLinkedDoc[] linkedDocs, Guid[] missingIds) =>
                {
                    return found(document, linkedDocs, missingIds).ToTask();
                }));
            },
                                                        () => parentDocNotFound().ToTask());

            return(result);
        }
コード例 #27
0
 public StorageRepositoryTests()
 {
     var settings = Config.GetSettings();
     _storage = new AzureStorageRepository(settings.Account, settings.Key, settings.Table, false);
 }
コード例 #28
0
        public static async Task <TResult> FindLinkedLinkedDocumentAsync <TParentDoc, TMiddleDoc, TLinkedDoc, TResult>(this AzureStorageRepository repo,
                                                                                                                       Guid parentDocId,
                                                                                                                       Func <TParentDoc, Guid> getMiddleDocumentId,
                                                                                                                       Func <TMiddleDoc, Guid> getLinkedId,
                                                                                                                       Func <TParentDoc, TMiddleDoc, TLinkedDoc, TResult> found,
                                                                                                                       Func <TResult> parentDocNotFound,
                                                                                                                       Func <TParentDoc, TResult> middleDocNotFound,
                                                                                                                       Func <TParentDoc, TMiddleDoc, TResult> linkedDocNotFound)
            where TParentDoc : class, ITableEntity
            where TMiddleDoc : class, ITableEntity
            where TLinkedDoc : class, ITableEntity
        {
            var result = await await repo.FindByIdAsync(parentDocId,
                                                        async (TParentDoc parentDoc) =>
            {
                var middleDocId         = getMiddleDocumentId(parentDoc);
                var middleAndLinkedDocs = await repo.FindLinkedDocumentAsync(middleDocId,
                                                                             (middleDoc) => getLinkedId(middleDoc),
                                                                             (TMiddleDoc middleDoc, TLinkedDoc linkedDoc) =>
                                                                             found(parentDoc, middleDoc, linkedDoc),
                                                                             () => middleDocNotFound(parentDoc),
                                                                             (middleDoc) => linkedDocNotFound(parentDoc, middleDoc));
                return(middleAndLinkedDocs);
            },
                                                        parentDocNotFound.AsAsyncFunc());

            return(result);
        }
コード例 #29
0
        internal async Task <TResult> AddOrUpdateClaimsAsync <TResult>(ClaimDocument claimsDoc, AzureStorageRepository repository,
                                                                       Func <TResult> success,
                                                                       Func <TResult> failure)
        {
            var claimDocumentIdsCurrent        = Claims.ToGuidsFromByteArray();
            var updatedClaimDocumentIdsCurrent = claimDocumentIdsCurrent.AddIfNotExisting(claimsDoc.ClaimId);

            this.Claims = updatedClaimDocumentIdsCurrent.ToByteArrayOfGuids();
            var result = await repository.CreateOrUpdateAsync <ClaimDocument, TResult>(claimsDoc.ClaimId,
                                                                                       async (created, doc, save) =>
            {
                doc.ClaimId = claimsDoc.ClaimId;
                doc.Issuer  = claimsDoc.Issuer;
                doc.Type    = claimsDoc.Type;
                doc.Value   = claimsDoc.Value;
                await save(doc);
                return(success());
            });

            return(result);
        }
コード例 #30
0
 public static Task <TResult> FindLinkedDocumentsAsync <TParentDoc, TLinkedDoc, TResult>(this AzureStorageRepository repo,
                                                                                         Guid parentDocId,
                                                                                         Func <TParentDoc, Guid[]> getLinkedIds,
                                                                                         Func <TParentDoc, IEnumerableAsync <TLinkedDoc>, TResult> found,
                                                                                         Func <TResult> parentDocNotFound)
     where TParentDoc : class, ITableEntity
     where TLinkedDoc : class, ITableEntity
 {
     return(repo.FindByIdAsync(parentDocId,
                               (TParentDoc document) =>
     {
         var linkedDocIds = getLinkedIds(document);
         var linkedDocs = linkedDocIds
                          .SelectAsyncOptional <Guid, TLinkedDoc>(
             (linkedDocId, select, skip) =>
         {
             return repo.FindByIdAsync(linkedDocId,
                                       (TLinkedDoc priceSheetDocument) => select(priceSheetDocument),
                                       skip);
         });
         return found(document, linkedDocs);
     },
                               () => parentDocNotFound()));
 }
コード例 #31
0
 public Authorizations(AzureStorageRepository repository)
 {
     this.repository = repository;
 }