Esempio n. 1
0
        private void GetTorrentsAndLabelsCached()
        {
            UpdatedTorrentsAndLabels UpdatedTorrents = ServiceClient.GetUpdatedTorrentsAndLabels(_cacheID.ToString(), _token);

            RemovedTorrentsList removedTorrents = null;

            if (UpdatedTorrents.RemovedTorrents != null && UpdatedTorrents.RemovedTorrents.Any())
            {
                removedTorrents = new RemovedTorrentsList()
                {
                    UpdatedTorrents.RemovedTorrents
                }
            }
            ;
            ChangedTorrentsList updatedTorrents = null;

            if (UpdatedTorrents.ChangedTorrents != null && UpdatedTorrents.ChangedTorrents.Any())
            {
                updatedTorrents = new ChangedTorrentsList()
                {
                    UpdatedTorrents.ChangedTorrents
                }
            }
            ;

            _torrents.Parse(UpdatedTorrents.Torrents, removedTorrents, updatedTorrents);
            _labels.Parse(UpdatedTorrents.Labels);
            SetCache(UpdatedTorrents.CacheID);
        }
Esempio n. 2
0
 internal void Parse(TorrentsList TorrentsToParse, RemovedTorrentsList RemovedTorrentsToParse, ChangedTorrentsList ChangedTorrentsToParse)
 {
     if (RemovedTorrentsToParse == null || ChangedTorrentsToParse == null)
     {
         if (TorrentsToParse != null)
         {
             Parse(TorrentsToParse, false);
         }
     }
     else
     {
         List <Torrent> RemovedTorrents = new List <Torrent>();
         foreach (string[] TorrentArray in RemovedTorrentsToParse)
         {
             if (TorrentArray.Length == 0)
             {
                 throw new FormatException("The array of torrent data was not in the expected format, it contains 0 elements.");
             }
             RemovedTorrents.Clear();
             RemovedTorrents.AddRange(RemoveByHashCode(TorrentArray[0]));
             foreach (Torrent RemovedTorrent in RemovedTorrents)
             {
                 CallCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, RemovedTorrent));
             }
         }
         foreach (string[] TorrentArray in ChangedTorrentsToParse)
         {
             if (TorrentArray.Length == 0)
             {
                 throw new FormatException("The array of torrent data was not in the expected format, it contains 0 elements.");
             }
             Torrent NewTorrent = GetByHashCode(TorrentArray[0]);
             if (NewTorrent == null)
             {
                 NewTorrent = new Torrent(TorrentArray, this);
                 _torrentCollectionInternal.Add(NewTorrent);
                 ParentClient.CallEvent(UTorrentWebClient.EventType.Added, NewTorrent);
                 CallCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, NewTorrent));
             }
             else
             {
                 NewTorrent.UpdateValuesFromStringArray(TorrentArray);
             }
         }
     }
 }
        private void GetTorrentsAndLabelsCached()
        {
            UpdatedTorrentsAndLabels UpdatedTorrents = ServiceClient.GetUpdatedTorrentsAndLabels(_cacheID.ToString(), _token);

            RemovedTorrentsList removedTorrents = null;
            if (UpdatedTorrents.RemovedTorrents.Any())
                removedTorrents = new RemovedTorrentsList() { UpdatedTorrents.RemovedTorrents };
            ChangedTorrentsList updatedTorrents = null;
            if (UpdatedTorrents.ChangedTorrents.Any())
                updatedTorrents = new ChangedTorrentsList() { UpdatedTorrents.ChangedTorrents };

            _torrents.Parse(UpdatedTorrents.Torrents, removedTorrents, updatedTorrents);
            _labels.Parse(UpdatedTorrents.Labels);
            SetCache(UpdatedTorrents.CacheID);
        }