Example #1
0
        private static void OnTorrentAddAlert(Core.torrent_added_alert a)
        {
            Core.TorrentHandle th = a.handle;
            if (TorrentHandles.TryAdd(th.info_hash().ToString(), th))
            {
                using (Core.TorrentStatus ts = th.status())
                {
                    var stat = "Paused";
                    if (!ts.paused)
                    {
                        stat = Utils.GiveMeStateFromEnum(ts.state);
                    }
                    var evnt = new EventsArgs.OnTorrentAddedEventArgs
                    {
                        Hash          = th.info_hash().ToString(),
                        Name          = ts.name,
                        Progress      = ts.progress,
                        QueuePosition = ts.queue_position,
                        Status        = stat
                    };
                    //log.Debug("torrent added: name {0}; status {1}; hash {2}", ts.name, ts.state.ToString(), ts.info_hash.ToString());

                    // notify web that a new id must be requested via webapi
                    if (webServer != null)
                    {
                        var context = Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext <www.SignalRHub>();
                        context.Clients.All.notifyTorrentAdded(evnt.Hash);
                    }

                    TorrentAdded?.Invoke(null, evnt);
                }
            }
        }
        private static void OnTorrentAddAlert(Core.torrent_added_alert a)
        {
            Core.TorrentHandle th = a.handle;
            if (TorrentHandles.TryAdd(th.info_hash().ToString(), th))
            {
                using (Core.TorrentStatus ts = th.status())
                {
                    var stat = "Paused";
                    if (!ts.paused)
                    {
                        stat = Utils.GiveMeStateFromEnum(ts.state);
                    }
                    var evnt = new EventsArgs.OnTorrentAddedEventArgs
                    {
                        Hash = th.info_hash().ToString(),
                        Name = ts.name,
                        Progress = ts.progress,
                        QueuePosition = ts.queue_position,
                        Status = stat
                    };
                    //log.Debug("torrent added: name {0}; status {1}; hash {2}", ts.name, ts.state.ToString(), ts.info_hash.ToString());

                    // notify web that a new id must be requested via webapi
                    if (webServer != null)
                    {
                        var context = Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext<www.SignalRHub>();
                        context.Clients.All.notifyTorrentAdded(evnt.Hash);
                    }

                    TorrentAdded?.Invoke(null, evnt);
                }
            }
        }