Example #1
0
        private void Handle(StateUpdateAlert alert)
        {
            for (var i = 0; i < alert.Statuses.Count; i++)
            {
                var status  = alert.Statuses[i];
                var torrent = new Torrent
                {
                    InfoHash     = status.InfoHash.ToHex(),
                    Name         = status.Name,
                    Progress     = status.Progress,
                    DownloadRate = status.DownloadRate,
                    UploadRate   = status.UploadRate,
                    State        = status.State
                };

                _eventAggregator.PublishOnBackgroundThread(new TorrentUpdatedMessage(torrent));
            }
        }
 private void Session_OnStateUpdateAlert(object sender, StateUpdateAlert e)
 {
     this.Status = e.Statuses;
 }
Example #3
0
 private void Session_OnStateUpdateAlert(object sender, StateUpdateAlert e)
 {
     this.Status = e.Statuses;
 }
Example #4
0
        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);
                }
            }
        }