public void TestConsolidateTorrentWithNullResponseResultParameter() { BaseResponse response = new Response(); response.Result = null; UTorrentClient.ConsolidateTorrent(response, string.Empty); }
public void TestConsolidateTorrentWithNoTorrentInResponseResult() { BaseResponse response = new Response(); response.Result = new Result(null); Assert.IsNull(UTorrentClient.ConsolidateTorrent(response, string.Empty)); }
public void TestConsolidateTorrentWithNullHashParameter() { BaseResponse response = new Response(); response.Result = new Result(null); Assert.ThrowsException <ArgumentNullException>(() => UTorrentClient.ConsolidateTorrent(response, null)); }
public void TestConsolidateTorrentWithNullResponseResultParameter() { BaseResponse response = new Response(); response.Result = null; Assert.ThrowsException <ArgumentNullException>(() => UTorrentClient.ConsolidateTorrent(response, string.Empty)); }
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); }
public void TestGetTorrentWithFiles() { try { UTorrentClient client = new UTorrentClient("admin", "password"); var response = client.GetList(); 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]; response = client.GetTorrent(torrent.Hash.ToLower()); 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); } catch (ServerUnavailableException) { Assert.Inconclusive("Serveur unavailable"); } catch (InvalidCredentialException) { Assert.Inconclusive("Invalid credential"); } }
public void TestAddAndRemoveTorrent() { try { UTorrentClient client = new UTorrentClient("admin", "password"); using (System.IO.FileStream file = System.IO.File.OpenRead("dummy.torrent")) { var addResponse = client.PostTorrent(file); Assert.IsNotNull(addResponse); Assert.IsNotNull(addResponse.Result); Assert.IsNull(addResponse.Result.Error); Assert.IsNotNull(addResponse.AddedTorrent); Torrent torrent = addResponse.AddedTorrent; var deleteResponse = client.DeleteTorrent(torrent.Hash); Assert.IsNotNull(deleteResponse); Assert.IsNotNull(deleteResponse.Result); Assert.IsNull(deleteResponse.Result.Error); } } catch (ServerUnavailableException) { Assert.Inconclusive("Serveur unavailable"); } catch (InvalidCredentialException) { Assert.Inconclusive("Invalid credential"); } }
public void TestConsolidateTorrentWithNullHashParameter() { BaseResponse response = new Response(); response.Result = new Result(null); UTorrentClient.ConsolidateTorrent(response, null); }
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); }
public UTorrentClientHandler(IConfiguration configuration, ILogger <UTorrentClientHandler> logger) { var username = configuration["uTorrent:Username"]; var password = configuration["uTorrent:Password"]; var ip = configuration["uTorrent:IP"]; var port = configuration.GetValue <int>("uTorrent:Port"); m_client = new UTorrentClient(ip, port, username, password); m_logger = logger; }
static void Main(string[] args) { _uTorrentClient = new UTorrentClient(Config.UTorrent.Ip, Config.UTorrent.Port, Config.UTorrent.Username, Config.UTorrent.Password); if (args.Length != 1) { Log.Error("Only Torrent hash id is expected as an argument"); Environment.Exit(-1); } try { var torrents = _uTorrentClient.GetList(); if (torrents.Error != null) { Log.Error(torrents.Error.Message); Environment.Exit(-1); } var torrent = torrents.Result.Torrents.SingleOrDefault(x => x.Hash == args[0]); if (torrent == null) { Log.ErrorFormat("Torrent with hash {0}, was not found", args[0]); Environment.Exit(-1); } switch (torrent.Label) { case "tv": CopyTorrentToFolder(torrent.Path, torrent.Hash, Config.UTorrent.TvDownloadFolder); if (Config.UTorrent.TorrentRatio == 0 || torrent.Ratio >= Config.UTorrent.TorrentRatio * 100) { _uTorrentClient.DeleteTorrent(torrent.Hash); } break; case "movies": CopyTorrentToFolder(torrent.Path, torrent.Hash, Config.UTorrent.MoviesDownloadFolder); if (Config.UTorrent.TorrentRatio == 0 || torrent.Ratio >= Config.UTorrent.TorrentRatio * 100) { _uTorrentClient.DeleteTorrent(torrent.Hash); } break; } } catch (ServerUnavailableException) { Log.Error("The utorrent server cannot be reach"); Environment.Exit(-1); } Environment.Exit(0); }
public void TestAddAndRemoveTorrent() { try { var dummyFile = "ZDEwOmNyZWF0ZWQgYnkx" + "Mzp1VG9ycmVudC8zMzAw" + "MTM6Y3JlYXRpb24gZGF0" + "ZWkxMzc1NTU5MjcyZTg6" + "ZW5jb2Rpbmc1OlVURi04" + "NDppbmZvZDY6bGVuZ3Ro" + "aTVlNDpuYW1lOTpkdW1t" + "eS50eHQxMjpwaWVjZSBs" + "ZW5ndGhpMTYzODRlNjpw" + "aWVjZXMyMDqCnDgEQBsH" + "J/cPc9RBXhYkAMvlezc6" + "cHJpdmF0ZWkxZWVl"; var bytes = Convert.FromBase64String(dummyFile); UTorrentClient client = new UTorrentClient("admin", "password"); using (var file = new MemoryStream(bytes)) { var addResponse = client.PostTorrent(file); Assert.IsNotNull(addResponse); Assert.IsNotNull(addResponse.Result); Assert.IsNull(addResponse.Result.Error); Assert.IsNotNull(addResponse.AddedTorrent); Torrent torrent = addResponse.AddedTorrent; var deleteResponse = client.DeleteTorrent(torrent.Hash); Assert.IsNotNull(deleteResponse); Assert.IsNotNull(deleteResponse.Result); Assert.IsNull(deleteResponse.Result.Error); } } catch (AggregateException ex) { if (ex.InnerException is ServerUnavailableException || ex.InnerException is InvalidCredentialException) { Assert.Inconclusive("Serveur unavailable"); } throw; } catch (ServerUnavailableException) { Assert.Inconclusive("Serveur unavailable"); } catch (InvalidCredentialException) { Assert.Inconclusive("Invalid credential"); } }
// setup uTorrent Client and validate connection public static bool SetupUtorrentConnection() { uTorrentUrl = Properties.Settings.Default.uTorrentUrl; if (!String.IsNullOrWhiteSpace(uTorrentUrl) && !String.IsNullOrWhiteSpace(Properties.Settings.Default.uTorrentUsername) && !String.IsNullOrWhiteSpace(Properties.Settings.Default.uTorrentPassword)) { client = new UTorrentClient(new System.Uri(uTorrentUrl), Properties.Settings.Default.uTorrentUsername, Properties.Settings.Default.uTorrentPassword); ConnectToUtorrent(); return(IsUtorrentConnected); } IsUtorrentConnected = false; return(IsUtorrentConnected); }
public void TestGetToken() { try { UTorrentClient client = new UTorrentClient("admin", "password"); var token = client.TestGetToken(); Assert.IsNotNull(token, "Invalid null token"); Assert.AreNotEqual(0, token.Length, "Invalid empty token"); } catch (ServerUnavailableException) { Assert.Inconclusive("Serveur unavailable"); } catch (InvalidCredentialException) { Assert.Inconclusive("Invalid credential"); } }
public void TestSetSettings() { try { UTorrentClient client = new UTorrentClient("admin", "password"); var response = client.GetSettings(); Assert.IsNull(response.Error); Assert.IsNotNull(response.Result); Assert.IsNotNull(response.Result.Settings); Assert.AreNotEqual(response.Result.Settings.Count, 0); var searchListSetting = response.Result.Settings.FirstOrDefault(s => s.Key == "search_list"); Assert.IsNotNull(searchListSetting); Assert.AreEqual(SettingType.String, searchListSetting.Type); Assert.AreEqual("Y", searchListSetting.Access); string value = searchListSetting.Value.ToString(); response = client.SetSetting("search_list", value + "\r\nUniut test|http://localhost?q="); Assert.IsNull(response.Error); response = client.GetSettings(); Assert.IsNull(response.Error); Assert.IsNotNull(response.Result); Assert.IsNotNull(response.Result.Settings); Assert.AreNotEqual(response.Result.Settings.Count, 0); searchListSetting = response.Result.Settings.FirstOrDefault(s => s.Key == "search_list"); Assert.IsNotNull(searchListSetting); Assert.AreEqual(SettingType.String, searchListSetting.Type); Assert.AreEqual("Y", searchListSetting.Access); string newValue = searchListSetting.Value.ToString(); Assert.AreEqual(value + "\r\nUniut test|http://localhost?q=", newValue); var resp = client.SetSetting("search_list", value); } catch (ServerUnavailableException) { Assert.Inconclusive("Serveur unavailable"); } }
public void TestGetAllTorrent() { try { UTorrentClient client = new UTorrentClient("admin", "password"); var response = client.GetList(); Assert.IsNull(response.Error); Assert.IsNotNull(response.Result); Assert.IsNotNull(response.Result.Torrents); } catch (ServerUnavailableException) { Assert.Inconclusive("Serveur unavailable"); } catch (InvalidCredentialException) { Assert.Inconclusive("Invalid credential"); } }
public void TestGetSettings() { try { UTorrentClient client = new UTorrentClient("admin", "password"); var response = client.GetSettings(); Assert.IsNull(response.Error); Assert.IsNotNull(response.Result); Assert.IsNotNull(response.Result.Settings); Assert.AreNotEqual(response.Result.Settings.Count, 0); var webuiEnableSetting = response.Result.Settings.FirstOrDefault(s => s.Key == "webui.enable"); Assert.IsNotNull(webuiEnableSetting); Assert.AreEqual(SettingType.Integer, webuiEnableSetting.Type); Assert.AreEqual(1, webuiEnableSetting.Value); Assert.AreEqual("Y", webuiEnableSetting.Access); } catch (ServerUnavailableException) { Assert.Inconclusive("Serveur unavailable"); } }
public void TestGetFilesWithNullHashAsync() { UTorrentClient client = new UTorrentClient("admin", "password"); client.GetFilesAsync(null); }
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); }
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); }
public void TestProcessRequestWithNullParameter() { UTorrentClient client = new UTorrentClient("admin", "password"); client.ProcessRequest <Response>(null); }
public void TestProcessRequestWithNullParameter() { UTorrentClient client = new UTorrentClient("admin", "password"); Assert.ThrowsException <ArgumentNullException>(() => client.ProcessRequest <Response>(null)); }
public void TestConsolidateTorrentWithNullResponseParameter() { Assert.ThrowsException <ArgumentNullException>(() => UTorrentClient.ConsolidateTorrent(null, string.Empty)); }
public void TestProcessRequestWithNullParameter() { UTorrentClient client = new UTorrentClient("admin", "password"); client.ProcessRequest<Response>(null); }
public void TestGetFilesWithNullHashAsync() { UTorrentClient client = new UTorrentClient("admin", "password"); Assert.ThrowsException <ArgumentNullException>(() => client.GetFilesAsync(null)); }
public void TestConsolidateTorrentWithNullResponseParameter() { UTorrentClient.ConsolidateTorrent(null, string.Empty); }