CodeRinseRepeat.Deluge.DelugeClient.GetTorrents C# (CSharp) Метод

GetTorrents() публичный Метод

public GetTorrents ( ) : IEnumerable
Результат IEnumerable
        public IEnumerable<Torrent> GetTorrents()
        {
            var result = DoServiceCall ("core.get_torrents_status", emptyFilterDict, emptyStringArray);
            var torrentsDict = (Dictionary<string, object>) result["result"];

            var torrents = new List<Torrent> (torrentsDict.Count);

            foreach (var hash in torrentsDict.Keys) {
                JsonObject data = (JsonObject) torrentsDict[hash];
                torrents.Add (Torrent.TorrentFromJsonObject (data));
            }

            return torrents;
        }

Usage Example

        public void refreshTorrents(bool compare = false)
        {
            _appSettings = getSettings ();

            if (_appSettings == null)
                return;

            if (string.IsNullOrEmpty(_appSettings.SettingsList[0].host) || string.IsNullOrEmpty(_appSettings.SettingsList[0].port.ToString()))
                return;

            var client = new DelugeClient (_appSettings.SettingsList[0].host, _appSettings.SettingsList[0].port);
            client.Login (_appSettings.SettingsList[0].pass);
            var torrents = client.GetTorrents ();

            var sortedTorrents = torrents.OrderBy(c => c.TrackerHost).ThenBy(c => c.TimeAdded);

            if (compare && curTorrents != null) {
                IEnumerable<CodeRinseRepeat.Deluge.Torrent> differenceQuery =
                    sortedTorrents.Except(curTorrents);

                //Console.WriteLine ("Difference: " + differenceQuery.Count<CodeRinseRepeat.Deluge.Torrent>().ToString());

                if (differenceQuery.Count<CodeRinseRepeat.Deluge.Torrent> () > 0) {
                    UILocalNotification notification = new UILocalNotification ();
                    notification.FireDate = DateTime.Now;
                    notification.AlertBody = "DelugeMobile: New torrents added!";
                    UIApplication.SharedApplication.ScheduleLocalNotification (notification);
                }
            }

            didRefreshData = true;

            curTorrents = sortedTorrents;

            // Save torrents to XML
            SaveTorrents ();
        }