コード例 #1
0
        public void TestGetAllTorrentAsync()
        {
            UTorrentClient  client = new UTorrentClient("admin", "password");
            Task <Response> task   = client.GetListAsync();

            try
            {
                task.Wait();
            }
            catch (AggregateException ex)
            {
                if (ex.InnerExceptions.Count == 1 &&
                    ex.InnerExceptions[0].GetType() == typeof(ServerUnavailableException))
                {
                    Assert.Inconclusive("Serveur unavailable");
                }
                if (ex.InnerExceptions.Count == 1 &&
                    ex.InnerExceptions[0].GetType() == typeof(InvalidCredentialException))
                {
                    Assert.Inconclusive("Invalid credential");
                }
            }

            var response = task.Result;

            Assert.IsNull(response.Error);
            Assert.IsNotNull(response.Result);
            Assert.IsNotNull(response.Result.Torrents);
        }
コード例 #2
0
        public void TestGetTorrentWithFilesAsync()
        {
            UTorrentClient  client = new UTorrentClient("admin", "password");
            Task <Response> task   = client.GetListAsync();

            try
            {
                task.Wait();
            }
            catch (AggregateException ex)
            {
                if (ex.InnerExceptions.Count == 1 &&
                    ex.InnerExceptions[0].GetType() == typeof(ServerUnavailableException))
                {
                    Assert.Inconclusive("Serveur unavailable");
                }
                if (ex.InnerExceptions.Count == 1 &&
                    ex.InnerExceptions[0].GetType() == typeof(InvalidCredentialException))
                {
                    Assert.Inconclusive("Invalid credential");
                }
            }
            var response = task.Result;

            Assert.IsNull(response.Error);
            Assert.IsNotNull(response.Result);
            Assert.IsNotNull(response.Result.Torrents);
            Assert.AreNotEqual(response.Result.Torrents.Count, 0);

            var torrent = response.Result.Torrents[0];

            task = client.GetTorrentAsync(torrent.Hash.ToLower());
            try
            {
                task.Wait();
            }
            catch (AggregateException ex)
            {
                if (ex.InnerExceptions.Count == 1 &&
                    ex.InnerExceptions[0].GetType() == typeof(ServerUnavailableException))
                {
                    Assert.Inconclusive("Serveur unavailable");
                }
                if (ex.InnerExceptions.Count == 1 &&
                    ex.InnerExceptions[0].GetType() == typeof(InvalidCredentialException))
                {
                    Assert.Inconclusive("Invalid credential");
                }
            }
            response = task.Result;
            Assert.IsNull(response.Error);
            Assert.IsNotNull(response.Result);

            torrent = UTorrentClient.ConsolidateTorrent(response, torrent.Hash);
            Assert.IsNotNull(torrent);
            Assert.IsNotNull(torrent.Files);
            Assert.AreNotEqual(torrent.Files.Count, 0);
        }
コード例 #3
0
        private async Task <List <TorrentDescriptor> > GetCompletedTorrents(GetCompletedTorrents request)
        {
            var completed = new List <TorrentDescriptor>();

            var list = await m_client.GetListAsync();

            if (list.Error != null)
            {
                m_logger.LogError(list.Error, "Could not acquire list of torrents");
                throw list.Error;
            }
            var torrents = list.Result.Torrents;

            m_logger.LogInformation("Found {count} torrents", torrents.Count);
            foreach (var torrent in torrents)
            {
                if (torrent.Progress == 1000.0)
                {
                    // Log( "Label " + torrent.Label.ToString() );

                    if (torrent.Label == "TV" && request.Type == TorrentMediaType.TV)
                    {
                        m_logger.LogInformation("Torrent TV {name} is completed", torrent.Name);
                        completed.Add(ToDescriptor(torrent));
                    }
                    else if (torrent.Label.Contains("Movie") && request.Type == TorrentMediaType.Movie)
                    {
                        m_logger.LogInformation("Torrent Movie {name} is completed", torrent.Name);
                        completed.Add(ToDescriptor(torrent));
                    }
                    else
                    {
                        m_logger.LogInformation("Torrent {name} has label {label} which didnt match", torrent.Name, torrent.Label);
                    }
                }
            }

            return(completed);
        }
コード例 #4
0
        public void TestGetTorrentWithFilesAsync()
        {
            UTorrentClient client = new UTorrentClient("admin", "password");
            Task<Response> task = client.GetListAsync();
            try
            {
                task.Wait();
            }
            catch (AggregateException ex)
            {
                if (ex.InnerExceptions.Count == 1 &&
                    ex.InnerExceptions[0].GetType() == typeof(ServerUnavailableException))
                    Assert.Inconclusive("Serveur unavailable");
                if (ex.InnerExceptions.Count == 1 &&
                    ex.InnerExceptions[0].GetType() == typeof(InvalidCredentialException))
                    Assert.Inconclusive("Invalid credential");
            }
            var response = task.Result;
            Assert.IsNull(response.Error);
            Assert.IsNotNull(response.Result);
            Assert.IsNotNull(response.Result.Torrents);
            Assert.AreNotEqual(response.Result.Torrents.Count, 0);

            var torrent = response.Result.Torrents[0];
            task = client.GetTorrentAsync(torrent.Hash.ToLower());
            try
            {
                task.Wait();
            }
            catch (AggregateException ex)
            {
                if (ex.InnerExceptions.Count == 1 &&
                    ex.InnerExceptions[0].GetType() == typeof(ServerUnavailableException))
                    Assert.Inconclusive("Serveur unavailable");
                if (ex.InnerExceptions.Count == 1 &&
                    ex.InnerExceptions[0].GetType() == typeof(InvalidCredentialException))
                    Assert.Inconclusive("Invalid credential");
            }
            response = task.Result;
            Assert.IsNull(response.Error);
            Assert.IsNotNull(response.Result);

            torrent = UTorrentClient.ConsolidateTorrent(response, torrent.Hash);
            Assert.IsNotNull(torrent);
            Assert.IsNotNull(torrent.Files);
            Assert.AreNotEqual(torrent.Files.Count, 0);
        }
コード例 #5
0
        public void TestGetAllTorrentAsync()
        {
            UTorrentClient client = new UTorrentClient("admin", "password");
            Task<Response> task = client.GetListAsync();
            try
            {
                task.Wait();
            }
            catch (AggregateException ex)
            {
                if (ex.InnerExceptions.Count == 1 &&
                    ex.InnerExceptions[0].GetType() == typeof(ServerUnavailableException))
                    Assert.Inconclusive("Serveur unavailable");
                if (ex.InnerExceptions.Count == 1 &&
                    ex.InnerExceptions[0].GetType() == typeof(InvalidCredentialException))
                    Assert.Inconclusive("Invalid credential");
            }

            var response = task.Result;
            Assert.IsNull(response.Error);
            Assert.IsNotNull(response.Result);
            Assert.IsNotNull(response.Result.Torrents);
        }