private void Handle(TorrentAddedAlert alert) { var torrent = Torrent.CreateFromHandle(alert.Handle, _metadataRepository); if (_muted.Contains(torrent.InfoHash)) { return; } _messageBus.Publish(new TorrentAddedMessage(torrent)); }
private void Handle(TorrentAddedAlert alert) { var msg = new TorrentAddedMessage(new Torrent { InfoHash = alert.Handle.InfoHash.ToHex(), Name = alert.Handle.TorrentFile.Name, Size = alert.Handle.TorrentFile.TotalSize, State = alert.Handle.QueryStatus().State }); _eventAggregator.PublishOnBackgroundThread(msg); }
private void Handle(TorrentAddedAlert alert) { var torrent = Torrent.CreateFromHandle(alert.Handle, _metadataRepository); if (_muted.Contains(torrent.InfoHash)) return; _messageBus.Publish(new TorrentAddedMessage(torrent)); }
private void Session_OnTorrentAddedAlert(object sender, TorrentAddedAlert e) { }
private void monitor() { var timeout = TimeSpan.FromSeconds(0.5); int last_tick = Environment.TickCount; while (true) { if ((Environment.TickCount - last_tick) > 1000) { ses.PostTorrentUpdates(); last_tick = Environment.TickCount; } var foundAlerts = ses.Alerts.PeekWait(timeout); if (!foundAlerts) { if (running) { continue; } else { return; } } var alerts = ses.Alerts.PopAll(); foreach (var alert in alerts) { Type alert_type = alert.GetType(); if (alert_type == typeof(SaveResumeDataAlert)) { SaveResumeDataAlert srda = (SaveResumeDataAlert)alert; ResumeDataArrived(srda.Handle, srda.ResumeData); continue; } if (alert_type == typeof(TorrentAddedAlert)) { TorrentAddedAlert taa = (TorrentAddedAlert)alert; main_thread_dispatcher.Invoke(() => TorrentAdded(taa.Handle)); continue; } if (alert_type == typeof(StateChangedAlert)) { StateChangedAlert taa = (StateChangedAlert)alert; main_thread_dispatcher.Invoke(() => TorrentStateChanged(taa.Handle, taa.PreviousState, taa.State)); continue; } if (alert_type == typeof(StateUpdateAlert)) { StateUpdateAlert sua = (StateUpdateAlert)alert; foreach (var s in sua.Statuses) { main_thread_dispatcher.Invoke(() => TorrentStatsUpdated(s)); } continue; } if (alert_type == typeof(TorrentFinishedAlert)) { TorrentFinishedAlert tfa = (TorrentFinishedAlert)alert; main_thread_dispatcher.Invoke(() => TorrentFinished(tfa.Handle)); continue; } if (alert_type == typeof(MetadataReceivedAlert)) { MetadataReceivedAlert mra = (MetadataReceivedAlert)alert; MetadataReceived(mra.Handle); continue; } /* * case typeof(Ragnar.FileCompletedAlert): * case typeof(Ragnar.FileRenamedAlert): * * case typeof(Ragnar.PeerAlert): * case typeof(Ragnar.PeerBanAlert): * case typeof(Ragnar.PeerConnectAlert): * case typeof(Ragnar.PeerUnsnubbedAlert): * case typeof(Ragnar.PieceFinishedAlert): * * case typeof(Ragnar.ScrapeReplyAlert): * case typeof(Ragnar.StorageMovedAlert): * * case typeof(Ragnar.TorrentCheckedAlert): * case typeof(Ragnar.TorrentErrorAlert): * * case typeof(Ragnar.TorrentPausedAlert): * case typeof(Ragnar.TorrentRemovedAlert): * case typeof(Ragnar.TorrentResumedAlert): * * case typeof(Ragnar.UnwantedBlockAlert): */ System.Diagnostics.Debug.WriteLine(alert.Message); System.Threading.Thread.Sleep(150); } } }