本文整理汇总了C#中Api.GetTorrents方法的典型用法代码示例。如果您正苦于以下问题:C# Api.GetTorrents方法的具体用法?C# Api.GetTorrents怎么用?C# Api.GetTorrents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Api
的用法示例。
在下文中一共展示了Api.GetTorrents方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Functional
public Functional()
{
var appEnv = CallContextServiceLocator.Locator.ServiceProvider.GetService(typeof(IApplicationEnvironment)) as IApplicationEnvironment;
Debug.Assert(appEnv != null, "appEnv != null");
var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath);
builder.AddJsonFile("config.json");
builder.AddJsonFile("config.private.json", true);
var configuration = builder.Build();
var uri = new Uri(configuration["ServerCredentialUri"]);
var username = configuration["ServerCredentialUsername"];
var password = configuration["ServerCredentialPassword"];
_serverCredential = new ServerCredential(uri, username, password);
_freeMusicTorrentFile =
new HttpClient().GetByteArrayAsync(
new Uri("http://bt.etree.org/download.php/582271/hottuna2015-09-11.flac16.torrent")).Result;
_freeMusicTorrentHash = "9ecc7229ff971d27552dd399509e188847dbbbf1";
// Make sure there is no torrents before executing the tests
var api = new Api(_serverCredential);
var torrents = api.GetTorrents().Result;
if (torrents.Any())
{
var result = api.Perform(Action.Removedata, torrents.Select(t => t.InfoHash)).Result;
Assert.True(result);
}
}
示例2: BadCredential
public async Task BadCredential()
{
var api = new Api(new ServerCredential(_serverCredential.Uri, _serverCredential.Username, "WrongPassword"));
await Assert.ThrowsAsync<SecurityException>(async () =>
{
try
{
await api.GetTorrents();
}
catch (AggregateException aggregateException)
{
throw aggregateException.InnerException;
}
});
}
示例3: ScenarioTypicalUse
public async Task ScenarioTypicalUse()
{
var api = new Api(_serverCredential);
var resultAddTorrent = await api.AddTorrent(_freeMusicTorrentFile);
Assert.True(resultAddTorrent);
Thread.Sleep(60*1000);
var torrents = await api.GetTorrents();
Assert.True(torrents.Count == 1);
Assert.Equal(_freeMusicTorrentHash, torrents.First().InfoHash);
var properties = await api.GetProperties(_freeMusicTorrentHash);
properties.Label = "free-music";
var resultSetProperty = await api.SetProperties(_freeMusicTorrentHash, properties);
Assert.True(resultSetProperty);
Thread.Sleep(1500);
var torrentsAfterLabelChange = await api.GetTorrents();
Assert.Equal(properties.Label, torrentsAfterLabelChange.First().Label);
Thread.Sleep(1500);
var files = await api.GetFiles(_freeMusicTorrentHash);
var rnd = new Random();
var randomFileIndex = rnd.Next(files.Count);
var setFilePriorityResult = await api.SetFilePriority(_freeMusicTorrentHash, randomFileIndex, 0);
Assert.True(setFilePriorityResult);
// TODO : Investigate why peers are sometimes unavailable
//var peers = await api.GetPeers(_freeMusicTorrentHash);
//Assert.True(peers.Count > 0);
var deleteResult = await api.Perform(Action.Removedata, _freeMusicTorrentHash);
Assert.True(deleteResult);
Thread.Sleep(1500);
Assert.True((await api.GetTorrents()).Count == 0);
}
示例4: GetTorrents
public async Task GetTorrents()
{
var api = new Api(_serverCredential);
var torrents = await api.GetTorrents();
Assert.NotNull(torrents);
if (torrents.Any())
{
Assert.True(!string.IsNullOrWhiteSpace(torrents.First().Hash));
}
}
示例5: TestUpload
public async Task TestUpload()
{
var api = new Api(_serverCredential);
var initialTorrents = await api.GetTorrents();
var bytes = new[]
{
await
new HttpClient().GetByteArrayAsync(
new Uri("http://releases.ubuntu.com/16.04/ubuntu-16.04-desktop-amd64.iso.torrent")),
await
new HttpClient().GetByteArrayAsync(
new Uri("http://releases.ubuntu.com/16.04/ubuntu-16.04-desktop-i386.iso.torrent"))
};
await api.Upload(bytes);
await api.WaitForTorrentToStartByName("ubuntu-16.04-desktop-amd64.iso");
await api.WaitForTorrentToStartByName("ubuntu-16.04-desktop-i386.iso");
var afterUploadTorrents = await api.GetTorrents();
Assert.Equal(initialTorrents.Count + bytes.Length, afterUploadTorrents.Count);
var hashList =
afterUploadTorrents.Select(t => t.Hash)
.ToList()
.Except(initialTorrents.Select(t => t.Hash).ToList())
.ToList();
Assert.Equal(bytes.Length, hashList.Count());
var setCategoryResult = await api.SetCategory(hashList, "ubuntu");
await api.DeletePermanently(hashList);
var afterDeleteTorrents = await api.GetTorrents();
Assert.Equal(afterDeleteTorrents.Count, initialTorrents.Count);
}
示例6: TestDownloadFromUrls
public async Task TestDownloadFromUrls()
{
var api = new Api(_serverCredential);
var uris = new[]
{
new Uri(
"magnet:?xt=urn:btih:cd8158937344b2a066446bed7e7a0c45214f1245&dn=debian-8.2.0-amd64-DVD-1.iso&tr=http%3a%2f%2fbttracker.debian.org%3a6969%2fannounce"),
new Uri(
"magnet:?xt=urn:btih:e508e5f1c7ad6650eb41d38f29aa567923b3934f&dn=debian-8.2.0-amd64-DVD-2.iso&tr=http%3a%2f%2fbttracker.debian.org%3a6969%2fannounce")
};
var hashes = new[]
{
"cd8158937344b2a066446bed7e7a0c45214f1245",
"e508e5f1c7ad6650eb41d38f29aa567923b3934f"
};
var initialCount = (await api.GetTorrents()).Count;
await api.DownloadFromUrls(uris);
foreach(var hash in hashes)
{
//await api.WaitForTorrentToBePausedByHash(hash);
//await api.Resume(hash);
await api.WaitForTorrentToStartByHash(hash);
}
var after2AddCount = (await api.GetTorrents()).Count;
Assert.Equal(initialCount + 2, after2AddCount);
await api.DeletePermanently(hashes);
var after2Delete = (await api.GetTorrents()).Count;
Assert.Equal(initialCount, after2Delete);
}
示例7: GetTorrentsWithCategory
public async Task GetTorrentsWithCategory()
{
var api = new Api(_serverCredential);
var torrents = await api.GetTorrents(Filter.All, "test");
Assert.Equal(0, torrents.Count);
}