public async Task <ActionResult> DownloadAsync(long id, [FromServices] ICommandBus commandBus, [FromServices] IBlobProvider blobProvider2, CancellationToken token) { var user = _userManager.GetLongUserId(User); var query = new DocumentById(id, user); var tItem = _queryBus.QueryAsync(query, token); var tFiles = _blobProvider.FilesInDirectoryAsync("file-", id.ToString(), token); await Task.WhenAll(tItem, tFiles); var item = tItem.Result; if (item == null) { return(NotFound()); } if (item.Document.DocumentType == DocumentType.Video) { return(Unauthorized()); } if (!item.IsPurchased) { return(Unauthorized()); } var files = tFiles.Result; var uri = files.First(); var file = uri.Segments.Last(); Task followTask = Task.CompletedTask; //blob.core.windows.net/spitball-files/files/6160/file-82925b5c-e3ba-4f88-962c-db3244eaf2b2-advanced-linux-programming.pdf if (item.Document.User.Id != user) { var command = new DownloadDocumentCommand(item.Document.Id, user); //var command = new FollowUserCommand(item.Document.User.Id, user); followTask = commandBus.DispatchAsync(command, token); } var messageTask = _queueProvider.InsertMessageAsync(new UpdateDocumentNumberOfDownloads(id), token); await Task.WhenAll(followTask, messageTask); var nameToDownload = item.Document.Title; var extension = Path.GetExtension(file); var url = blobProvider2.GenerateDownloadLink(uri, TimeSpan.FromMinutes(30), nameToDownload + extension); return(Redirect(url.AbsoluteUri)); }
public void ExecuteCommand() { log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); try { if (Command != null) { Me = (DownloadDocumentCommand)Command; } DownloadDocument(); } catch (Exception ex) { Page.DisplayErrorAlert(ex); log.Error(ex); } }