示例#1
0
        public async Task <PendingDocumentResponse> Get(long?fromId,
                                                        [FromServices] IBlobProvider blobProvider,
                                                        CancellationToken token)
        {
            var query  = new PendingDocumentQuery(fromId, User.GetCountryClaim());
            var retVal = await _queryBus.QueryAsync(query, token);

            var  tasks   = new Lazy <List <Task> >();
            var  counter = 0;
            long?id      = null;

            foreach (var document in retVal)
            {
                id = document.Id;
                var files = await _blobProvider.FilesInDirectoryAsync("preview-0", document.Id.ToString(), token);

                var file = files.FirstOrDefault();
                if (file != null)
                {
                    document.Preview =
                        blobProvider.GeneratePreviewLink(file,
                                                         TimeSpan.FromMinutes(20));

                    counter++;
                }
                else
                {
                    var t = _queueProvider.InsertBlobReprocessAsync(document.Id);
                    tasks.Value.Add(t);
                }
                document.SiteLink = Url.RouteUrl("DocumentDownload", new { id = document.Id });

                if (counter >= 21)
                {
                    break;
                }
            }

            if (tasks.IsValueCreated)
            {
                await Task.WhenAll(tasks.Value);
            }

            string nextLink = null;

            if (id.HasValue)
            {
                nextLink = Url.RouteUrl("Pending", new
                {
                    fromId = id.Value
                });
            }

            return(new PendingDocumentResponse()
            {
                Documents = retVal,
                NextLink = nextLink
            });
        }
示例#2
0
 public async Task PendingDocumentEmptyQuery_Ok(long?documentId, string country)
 {
     var query = new PendingDocumentQuery(documentId, country);
     await _fixture.QueryBus.QueryAsync(query, default);
 }