Esempio n. 1
0
        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());
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public bool RemoveCompletedTorrent(Aria2Settings settings, string gid)
        {
            var response = ExecuteRequest(settings, "aria2.removeDownloadResult", GetToken(settings), gid);

            var result = response.GetStringResponse();

            return(result == "OK");
        }
Esempio n. 4
0
        public bool RemoveTorrent(Aria2Settings settings, string gid)
        {
            var response = ExecuteRequest(settings, "aria2.forceRemove", GetToken(settings), gid);

            var gidres = response.GetStringResponse();

            return(gid == gidres);
        }
Esempio n. 5
0
        public string AddTorrent(Aria2Settings settings, byte[] torrent)
        {
            var response = ExecuteRequest(settings, "aria2.addTorrent", GetToken(settings), torrent);

            var gid = response.GetStringResponse();

            return(gid);
        }
Esempio n. 6
0
        private IAria2 BuildClient(Aria2Settings settings)
        {
            var client = XmlRpcProxyGen.Create <IAria2>();

            client.Url = GetURL(settings);

            return(client);
        }
Esempio n. 7
0
        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));
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        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");
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
        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);
        }
Esempio n. 17
0
        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);
        }
Esempio n. 18
0
        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);
        }
Esempio n. 19
0
        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);
        }
Esempio n. 20
0
        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);
        }
Esempio n. 21
0
 private string GetURL(Aria2Settings settings)
 {
     return($"http{(settings.UseSsl ? "s" : "")}://{settings.Host}:{settings.Port}{settings.RpcPath}");
 }
Esempio n. 22
0
 private string GetToken(Aria2Settings settings)
 {
     return($"token:{settings?.SecretToken}");
 }