示例#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 <IEnumerable <UserDocumentsDto> > GetUserInfo(long id, int page, [FromServices] IBlobProvider blobProvider,
                                                                        CancellationToken token)
        {
            var country = User.GetCountryClaim();
            var query   = new UserDocumentsQuery(id, page, country);


            var retVal = (await _queryBus.QueryAsync(query, token)).ToList();
            var tasks  = new Lazy <List <Task> >();

            foreach (var document in retVal)
            {
                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));

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

            return(retVal);
        }