public Aria2Status[] GetTorrents(Aria2Settings settings) { _logger.Debug("> aria2.tellActive"); var client = BuildClient(settings); var actives = ExecuteRequest(() => client.GetActives(GetToken(settings))); _logger.Debug("< aria2.tellActive"); _logger.Debug("> aria2.tellWaiting"); var waitings = ExecuteRequest(() => client.GetWaitings(GetToken(settings), 1, 10 * 1024)); _logger.Debug("< aria2.tellWaiting"); _logger.Debug("> aria2.tellStopped"); var stoppeds = ExecuteRequest(() => client.GetStoppeds(GetToken(settings), 1, 10 * 1024)); _logger.Debug("< aria2.tellStopped"); var ret = new List <Aria2Status>(); ret.AddRange(actives); ret.AddRange(waitings); ret.AddRange(stoppeds); return(ret.ToArray()); }
public List <Aria2Status> GetTorrents(Aria2Settings settings) { _logger.Trace("> aria2.tellActive"); var client = BuildClient(settings); var active = ExecuteRequest(() => client.GetActive(GetToken(settings))); _logger.Trace("< aria2.tellActive"); _logger.Trace("> aria2.tellWaiting"); var waiting = ExecuteRequest(() => client.GetWaiting(GetToken(settings), 0, 10 * 1024)); _logger.Trace("< aria2.tellWaiting"); _logger.Trace("> aria2.tellStopped"); var stopped = ExecuteRequest(() => client.GetStopped(GetToken(settings), 0, 10 * 1024)); _logger.Trace("< aria2.tellStopped"); var items = new List <Aria2Status>(); items.AddRange(active); items.AddRange(waiting); items.AddRange(stopped); return(items); }
public bool RemoveCompletedTorrent(Aria2Settings settings, string gid) { var response = ExecuteRequest(settings, "aria2.removeDownloadResult", GetToken(settings), gid); var result = response.GetStringResponse(); return(result == "OK"); }
public bool RemoveTorrent(Aria2Settings settings, string gid) { var response = ExecuteRequest(settings, "aria2.forceRemove", GetToken(settings), gid); var gidres = response.GetStringResponse(); return(gid == gidres); }
public string AddTorrent(Aria2Settings settings, byte[] torrent) { var response = ExecuteRequest(settings, "aria2.addTorrent", GetToken(settings), torrent); var gid = response.GetStringResponse(); return(gid); }
private IAria2 BuildClient(Aria2Settings settings) { var client = XmlRpcProxyGen.Create <IAria2>(); client.Url = GetURL(settings); return(client); }
public Aria2Status GetFromGID(Aria2Settings settings, string gid) { var response = ExecuteRequest(settings, "aria2.tellStatus", GetToken(settings), gid); var element = response.XPathSelectElement("./methodResponse/params/param/value"); return(new Aria2Status(element)); }
public string GetVersion(Aria2Settings settings) { var response = ExecuteRequest(settings, "aria2.getVersion", GetToken(settings)); var element = response.XPathSelectElement("./methodResponse/params/param/value"); var version = new Aria2Version(element); return(version.Version); }
public Dictionary <string, string> GetGlobals(Aria2Settings settings) { var response = ExecuteRequest(settings, "aria2.getGlobalOption", GetToken(settings)); var element = response.XPathSelectElement("./methodResponse/params/param/value"); var result = new Aria2Dict(element); return(result.Dict); }
public string AddMagnet(Aria2Settings settings, string magnet) { var response = ExecuteRequest(settings, "aria2.addUri", GetToken(settings), new List <string> { magnet }); var gid = response.GetStringResponse(); return(gid); }
public bool RemoveTorrent(Aria2Settings settings, string gid) { _logger.Debug("> aria2.forceRemove"); var client = BuildClient(settings); var gidres = ExecuteRequest(() => client.Remove(GetToken(settings), gid)); _logger.Debug("< aria2.forceRemove"); return(gid == gidres); }
public string AddUri(Aria2Settings settings, string magnet) { _logger.Debug("> aria2.addUri"); var client = BuildClient(settings); var gid = ExecuteRequest(() => client.AddUri(GetToken(settings), new[] { magnet })); _logger.Debug("< aria2.addUri"); return(gid); }
public bool RemoveCompletedTorrent(Aria2Settings settings, string gid) { _logger.Trace("> aria2.removeDownloadResult"); var client = BuildClient(settings); var result = ExecuteRequest(() => client.RemoveResult(GetToken(settings), gid)); _logger.Trace("< aria2.removeDownloadResult"); return(result == "OK"); }
public string GetVersion(Aria2Settings settings) { _logger.Debug("> aria2.getVersion"); var client = BuildClient(settings); var version = ExecuteRequest(() => client.GetVersion(GetToken(settings))); _logger.Debug("< aria2.getVersion"); return(version.Version); }
public Aria2Status GetFromGID(Aria2Settings settings, string gid) { _logger.Debug("> aria2.tellStatus"); var client = BuildClient(settings); var found = ExecuteRequest(() => client.GetFromGid(GetToken(settings), gid)); _logger.Debug("< aria2.tellStatus"); return(found); }
public string AddTorrent(Aria2Settings settings, byte[] torrent) { _logger.Debug("> aria2.addTorrent"); var client = BuildClient(settings); var gid = ExecuteRequest(() => client.AddTorrent(GetToken(settings), torrent)); _logger.Debug("< aria2.addTorrent"); return(gid); }
public List <Aria2Status> GetTorrents(Aria2Settings settings) { var active = GetTorrentsMethod(settings, "aria2.tellActive"); var waiting = GetTorrentsMethod(settings, "aria2.tellWaiting", 0, 10 * 1024); var stopped = GetTorrentsMethod(settings, "aria2.tellStopped", 0, 10 * 1024); var items = new List <Aria2Status>(); items.AddRange(active); items.AddRange(waiting); items.AddRange(stopped); return(items); }
public Dictionary <string, string> GetGlobals(Aria2Settings settings) { _logger.Debug("> aria2.getGlobalOption"); var client = BuildClient(settings); var options = ExecuteRequest(() => client.GetGlobalOption(GetToken(settings))); _logger.Debug("< aria2.getGlobalOption"); var ret = new Dictionary <string, string>(); foreach (DictionaryEntry option in options) { ret.Add(option.Key.ToString(), option.Value?.ToString()); } return(ret); }
private List <Aria2Status> GetTorrentsMethod(Aria2Settings settings, string method, params object[] args) { var allArgs = new List <object> { GetToken(settings) }; if (args.Any()) { allArgs.AddRange(args); } var response = ExecuteRequest(settings, method, allArgs.ToArray()); var element = response.XPathSelectElement("./methodResponse/params/param/value/array/data"); var torrents = element?.Elements() .Select(x => new Aria2Status(x)) .ToList() ?? new List <Aria2Status>(); return(torrents); }
private XDocument ExecuteRequest(Aria2Settings settings, string methodName, params object[] args) { var requestBuilder = new XmlRpcRequestBuilder(settings.UseSsl, settings.Host, settings.Port, settings.RpcPath) { LogResponseContent = true, }; var request = requestBuilder.Call(methodName, args).Build(); var response = _httpClient.Execute(request); var doc = XDocument.Parse(response.Content); var faultElement = doc.XPathSelectElement("./methodResponse/fault"); if (faultElement != null) { var fault = new Aria2Fault(faultElement); throw new DownloadClientException($"Aria2 returned error code {fault.FaultCode}: {fault.FaultString}"); } return(doc); }
private string GetURL(Aria2Settings settings) { return($"http{(settings.UseSsl ? "s" : "")}://{settings.Host}:{settings.Port}{settings.RpcPath}"); }
private string GetToken(Aria2Settings settings) { return($"token:{settings?.SecretToken}"); }