Ejemplo n.º 1
0
        /// <summary>
        /// 修改下载任务在队列中的位置,并返回调整后的位置。
        /// 例如:pos=-1,origin=PositionOrigin.Current时,向前移动一位
        /// pos=-1,origin=PositionOrigin.End,调整为队列中的倒数第二位
        /// </summary>
        /// <param name="gid"></param>
        /// <param name="pos"></param>
        /// <param name="origin"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static int ChangePosition(string gid, int pos, PositionOrigin origin, object id = null)
        {
            string how = "";

            switch (origin)
            {
            case PositionOrigin.Begin:
                how = "POS_SET";
                break;

            case PositionOrigin.Current:
                how = "POS_CUR";
                break;

            case PositionOrigin.End:
                how = "POS_END";
                break;

            default:
                break;
            }
            var result = JsonRpcHelper.RemoteCall(RPC_URL, "aria2.changePosition", id, gid, pos, how);

            return(Convert.ToInt32(result));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 获取指定GID对应任务的状态,
 /// </summary>
 /// <param name="gid"></param>
 /// <param name="id"></param>
 /// <param name="keys">
 /// 所需要的字段,
 /// 可选参数,若不指定,则返回值将包含所有信息,指定所需要的字段,能避免不必要的数据传输
 /// 例如 指定 ["gid", "status"],则返回Aria2TaskInfo实例仅Gid和Status属性可用,其余属性均为初始值。
 /// </param>
 /// <returns></returns>
 public static Aria2TaskInfo TellStatus(string gid, object id = null, params string[] keys)
 {
     try
     {
         var result = (JObject)JsonRpcHelper.RemoteCall(RPC_URL, "aria2.tellStatus", id, gid, keys);
         return(result.ToObject <Aria2TaskInfo>());
     }
     catch (Exception)
     {
         // TODO: 处理异常
         return(new Aria2TaskInfo()
         {
             Gid = gid, Status = Models.TaskStatus.Removed
         });
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 强制关闭Aria2
 /// </summary>
 /// <param name="id"></param>
 public static void ForceShutdown(object id = null)
 {
     JsonRpcHelper.RemoteCall(RPC_URL, "aria2.forceShutdown", id);
 }
Ejemplo n.º 4
0
 public static void GetSessionInfo(object id = null)
 {
     JsonRpcHelper.RemoteCall(RPC_URL, "aria2.getSessionInfo", id);
 }
Ejemplo n.º 5
0
 public static void GetVersion(string gid, object id = null)
 {
     var result = (JObject)JsonRpcHelper.RemoteCall(RPC_URL, "aria2.getVersion", id);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 从内存中移除,给定Gid对应的已完成/出错/已移除的下载任务
        /// This method returns OK for success.
        /// </summary>
        public static bool RemoveDownloadResult(string gid, object id = null)
        {
            var result = (string)JsonRpcHelper.RemoteCall(RPC_URL, "aria2.removeDownloadResult", id, gid);

            return(result == RESULT_OK);
        }
Ejemplo n.º 7
0
        private static Aria2TaskInfo[] _TellMethodBase(string method, int offset, int num, object id = null, params string[] keys)
        {
            var result = (JArray)JsonRpcHelper.RemoteCall(RPC_URL, method, id, offset, num, keys);

            return(result.ToObject <Aria2TaskInfo[]>());
        }
Ejemplo n.º 8
0
 /// <summary>
 /// 强制暂停给定GID对应的下载任务
 /// </summary>
 /// <param name="gid"></param>
 /// <param name="id"></param>
 /// <returns></returns>
 public static void ForcePause(string gid, object id = null)
 {
     var result = JsonRpcHelper.RemoteCall(RPC_URL, "aria2.forcePause", id, gid);
 }
Ejemplo n.º 9
0
        /// <summary>
        /// This method returns currently connected HTTP(S)/FTP/SFTP servers of the download denoted by gid (string).
        /// The response is an array of structs and contains the following keys.
        /// </summary>
        public static JArray GetServers(string gid, object id = null)
        {
            var result = (JArray)JsonRpcHelper.RemoteCall(RPC_URL, "aria2.getServers", id);

            return(result);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// This method returns a list peers of the download denoted by gid (string).
        /// This method is for BitTorrent only.
        /// The response is an array of structs and contains the following keys.
        /// </summary>
        public static PeerToken[] GetPeers(string gid, object id = null)
        {
            var result = (JArray)JsonRpcHelper.RemoteCall(RPC_URL, "aria2.getPeers", id);

            return(result.ToObject <PeerToken[]>());
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 相当于对所有下载任务调用Unpause方法
        /// This method is equal to calling aria2.unpause() for every active/waiting download. This methods
        /// </summary>
        /// <param name="id"></param>
        public static bool UnpauseAll(object id = null)
        {
            var result = JsonRpcHelper.RemoteCall(RPC_URL, "aria2.unpauseAll", id);

            return((string)result == RESULT_OK);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 将给定GID对应的下载任务,从paused 状态变更为waiting状态,使下载重新启动
        /// </summary>
        /// <param name="gid"></param>
        /// <param name="id"></param>
        public static bool Unpause(string gid, object id = null)
        {
            var result = JsonRpcHelper.RemoteCall(RPC_URL, "aria2.unpause", id, gid);

            return((string)result == gid);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// 强制暂停所有下载任务
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public static void ForcePauseAll(object id = null)
 {
     var result = JsonRpcHelper.RemoteCall(RPC_URL, "aria2.forcePauseAll", id);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// 将当前的Session保存到文件中
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public static bool SaveSession(object id = null)
 {
     return((string)JsonRpcHelper.RemoteCall(RPC_URL, "aria2.saveSession", id) == RESULT_OK);
 }
Ejemplo n.º 15
0
        /// <summary>
        /// 获取所有正在运行的下载项目
        /// </summary>
        /// <param name="keys">参考TellStatus方法</param>
        /// <returns></returns>
        public static Aria2TaskInfo[] TellActive(object id = null, params string[] keys)
        {
            var result = (JArray)JsonRpcHelper.RemoteCall(RPC_URL, "aria2.tellActive", id, keys);

            return(result.ToObject <Aria2TaskInfo[]>());
        }
Ejemplo n.º 16
0
        // TODO: system.multicall

        #region "ListMethods"

        public static string[] _ListMethods(string method, object id = null)
        {
            var result = (JArray)JsonRpcHelper.RemoteCall(RPC_URL, method, id);

            return(result.ToObject <string[]>());
        }
Ejemplo n.º 17
0
 private object RawRemoteCall(JsonRpcToken token)
 {
     return(JsonRpcHelper.RemoteCall(this.m_rpcUrl, token));
 }