public IActionResult Publish() { DemoEvent demo = new DemoEvent($"event time {DateTime.Now}"); _dispatcher.Broadcast(demo); return(Ok(DateTime.Now)); }
public async Task StartAsync() { var request = new HttpRequestMessage(HttpMethod.Get, item.FileUrl); request.Headers.Add("Cookie", cookies); var response = await Client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead); var resStream = await response.Content.ReadAsStreamAsync(); var fStream = File.Create(downloadDestPath); var downloadCompleted = false; await resStream .CopyToAsync(fStream, 81920, tokenSource.Token) .ContinueWith(task => downloadCompleted = task.IsCompletedSuccessfully); resStream.Dispose(); fStream.Dispose(); DirectDownloadMethod.DirectDownloadTasks.TryRemove(item.Token, out _); if (downloadCompleted) { _ = dispatcher.Broadcast(new ItemDownloaded(item.Id)); } }
public ObjectResult TorrentDone([FromServices] IControllerHelperService helper, string hash) { logger.LogInformation("TorrentDone: " + hash); if (!helper.IsLocalCall(HttpContext)) { logger.LogWarning("Request not sent from the server"); return(StatusCode(403, null)); } var item = repository.FindAllUnarchived().FirstOrDefault(x => x.Hash == hash); if (item == null) { logger.LogInformation(hash + ": note found"); return(StatusCode(404, DownloadItemActionError.ItemNotFound)); } var authorizationResult = authorizationService.AuthorizeAsync(User, item, DownloadItemPolicies.TorrentDonePolicy).Result; if (!authorizationResult.Succeeded) { var requirement = authorizationResult.Failure.FailedRequirements.First() as DownloadItemBaseRequirement; return(StatusCode(requirement.HttpCode, requirement.Error)); } torrentDaemonService.StopTorrent(hash); _ = dispatcher.Broadcast(new ItemDownloaded(item.Id)); return(StatusCode(200, new { Processed = true })); }
public async Task <IActionResult> Create() { var post = new Post(); _logger.LogInformation($"Create - {post.Id}"); var blogPostCreated = new BlogPostCreated(post); await _dispatcher.Broadcast(blogPostCreated); _logger.LogInformation($"Broadcast - {post.Id}"); return(Ok()); }
public async Task Invoke() { await ProvideUserEvents(); if (_events.Count == 0) { return; } foreach (var userNotifyMessage in _events) { await _dispatcher.Broadcast(new NotifyUserEvent(userNotifyMessage)); } await CreateNewActions(); await UpdateActionsFollowUps(); }
/// <inheritdoc /> /// <summary> /// Starts a download /// </summary> /// <param name="item"></param> /// <param name="error"></param> /// <returns></returns> public bool StartDownload(DownloadItem item, out DownloadItemActionError error) { error = DownloadItemActionError.DownloadabilityFailure; var downloadMethod = ResolveDownloadMethod(item.FileUrl); if (downloadMethod == null) { logger.LogWarning("URL not handled: " + item.FileUrl); error = DownloadItemActionError.UrlNotHandled; return(false); } try { downloadMethod.Start(item); item.DownloadedSize = 0; item.StartedAt = DateTime.Now; item.Archived = false; item.State = DownloadState.Downloading; repository.Add(item); _ = dispatcher.Broadcast(new ItemStarted(item)); } catch (FileNotDownloadableException ex) { logger.LogWarning(ex.Message); error = DownloadItemActionError.DownloadabilityFailure; return(false); } catch (StartDownloadException ex) { logger.LogWarning(ex.Message); error = DownloadItemActionError.StartDownloadFailure; return(false); } return(true); }