コード例 #1
0
        public async Task <List <TorrentInfo> > GetTorrents()
        {
            try
            {
                Task <TransmissionTorrents> getTorrentsTask = client.TorrentGetAsync(TorrentFields.ALL_FIELDS);
                Task delayTask = Task.Delay(TimeSpan.FromSeconds(Properties.Settings.Default.MaxRequestDuration));
                await Task.WhenAny(getTorrentsTask, delayTask);

                if (!requestCancelled)
                {
                    if (delayTask.IsCompleted)
                    {
                        return(null);
                    }
                    else
                    {
                        TransmissionTorrents torrentsList = getTorrentsTask.Result;
                        return(torrentsList != null && torrentsList.Torrents != null?torrentsList.Torrents.ToList() : new List <TorrentInfo>());
                    }
                }
                else
                {
                    return(null);
                }
            }
            catch (AggregateException)
            {
                return(null);
            }
        }
コード例 #2
0
        /// <summary>
        /// Parse transmission torrents data.
        /// </summary>
        /// <param name="data"></param>
        private void ProcessParsingTransmissionResponse(TransmissionTorrents data)
        {
            if (!IsConnected)
            {
                return;
            }

            lock (_syncTorrentList)
            {
                //1: 'check pending',
                //2: 'checking',

                //5: 'seed pending',
                //6: 'seeding',
                switch (_filterCategory)
                {
                //3: 'download pending',
                //4: 'downloading',
                case Enums.Categories.Downloading:
                    data.Torrents = data.Torrents.Where(x => x.Status == 3 || x.Status == 4).ToArray();
                    break;

                //4: 'downloading',
                //6: 'seeding',
                //2: 'checking',
                case Enums.Categories.Active:
                    data.Torrents = data.Torrents.Where(x => x.Status == 4 || x.Status == 6 || x.Status == 2)
                                    .ToArray();
                    data.Torrents = data.Torrents.Where(x => x.RateDownload > 1 || x.RateUpload > 1).ToArray();
                    break;

                //0: 'stopped' and is error,
                case Enums.Categories.Stopped:
                    data.Torrents = data.Torrents.Where(x => x.Status == 0 && string.IsNullOrEmpty(x.ErrorString))
                                    .ToArray();
                    break;

                case Enums.Categories.Error:
                    data.Torrents = data.Torrents.Where(x => !string.IsNullOrEmpty(x.ErrorString)).ToArray();
                    break;


                //6: 'seeding',
                //1: 'checking queue',
                case Enums.Categories.Inactive:
                    //var array1 = data.Torrents.Where(x=> x.Status == 1).ToArray();
                    var array2 = data.Torrents.Where(x => x.RateDownload <= 0 && x.RateUpload <= 0 && x.Status != 2)
                                 .ToArray();

                    //int array1OriginalLength = array1.Length;
                    //Array.Resize<TorrentInfo>(ref array1, array1OriginalLength + array2.Length);
                    //Array.Copy(array2, 0, array1, array1OriginalLength, array2.Length);
                    data.Torrents = array2;
                    break;

                //6: 'seeding',
                case Enums.Categories.Ended:
                    data.Torrents = data.Torrents.Where(x => x.Status == 6).ToArray();
                    break;
                }

                if (!string.IsNullOrEmpty(FilterText))
                {
                    //var txtfilter = FilterText;
                    if (FilterText.Contains("{p}:"))
                    {
                        var splited   = FilterText.Split("{p}:");
                        var filterKey = splited[^ 1];