/// <summary>
        /// 获取普通下载服务器链接信息
        /// </summary>
        /// <param name="gid">任务标识符</param>
        /// <returns>成功返回服务器链接列表,失败返回空</returns>
        public static List <Aria2cLink> GetServers(string gid)
        {
            XmlRpcStruct[]    xmlstruct = aria2c.GetFiles(Aria2cRpcSecret, gid);
            List <Aria2cLink> servers   = Aria2cTools.ConvertToAria2cServers(xmlstruct);

            return(servers);
        }
        /// <summary>
        /// 获取下载任务的文件信息
        /// </summary>
        /// <param name="gid">任务标识符</param>
        /// <returns>成功返回文件信息列表,失败返回空</returns>
        public static List <Aria2cFile> GetFiles(string gid)
        {
            XmlRpcStruct[]    xmlstruct = aria2c.GetFiles(Aria2cRpcSecret, gid);
            List <Aria2cFile> files     = Aria2cTools.ConvertToAria2cFiles(xmlstruct);

            return(files);
        }
        /// <summary>
        /// 获取下载任务的链接地址
        /// </summary>
        /// <param name="gid">任务标识符</param>
        /// <returns>成功返回下载地址列表,失败返回空</returns>
        public static List <Aria2cUri> GetUris(string gid)
        {
            XmlRpcStruct[]   xmlstruct = aria2c.GetUris(Aria2cRpcSecret, gid);
            List <Aria2cUri> uris      = Aria2cTools.ConvertToAria2cUris(xmlstruct);

            return(uris);
        }
        private static void StartProcess(string path, string args = "")
        {
            try
            {
                var    aria2Dir   = Aria2cTools.GetDirectoryName(path);
                var    aria2cName = Aria2cTools.GetFileNameWithoutExtension(path);
                string config     = aria2cName + ".conf";

                if (string.IsNullOrWhiteSpace(args))
                {
                    if (File.Exists(Path.Combine(aria2Dir, config)))
                    {
                        args = " --conf-path=" + config;
                    }
                    else
                    {
                        args = " --enable-rpc --rpc-listen-all=true --rpc-allow-origin-all --rpc-listen-port=6800 -c -D";
                    }
                }

                var psi = new ProcessStartInfo(path, args);
                psi.WorkingDirectory       = aria2Dir;
                psi.WindowStyle            = ProcessWindowStyle.Hidden;
                psi.CreateNoWindow         = true;
                psi.UseShellExecute        = false;
                psi.RedirectStandardOutput = false;
                psi.RedirectStandardError  = false;
                aria2cProcess = Process.Start(psi);
            }
            catch (Exception ex)
            {
                throw ex;
                // Logger.Debug(ex);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 将rpc信息转换到服务器信息中
        /// </summary>
        /// <param name="rpcStruct"></param>
        public Aria2cLink(XmlRpcStruct rpcStruct)
        {
            List <string> keyList   = rpcStruct.Keys as List <string>;
            List <object> valueList = rpcStruct.Values as List <object>;

            for (int i = 0; i < rpcStruct.Count; i++)
            {
                string key   = keyList[i];
                object value = valueList[i];

                if (key == "index")
                {
                    this.Index = Convert.ToInt64(value as string);
                }
                else if (key == "servers")
                {
                    this.Servers = Aria2cTools.ConvertToAria2cServerLink(value as XmlRpcStruct[]);
                }
                else
                {
                    throw new Exception("无法将属性转换到Aria2cServer中");
                }
            }
        }
 /// <summary>
 /// 获取会话ID
 /// </summary>
 /// <returns>成功返回会话ID,失败返回空字符串</returns>
 public static string GetSessionInfo()
 {
     XmlRpcStruct rpcStruct = aria2c.GetSessionInfo();
     string sessionId = Aria2cTools.GetRpcStructValue(rpcStruct, "sessionId") as string;
     return sessionId;
 }
 /// <summary>
 /// 获取版本信息
 /// </summary>
 /// <returns>成功返回版本号,失败返回空字符串</returns>
 public static string GetVersion()
 {
     XmlRpcStruct rpcStruct = aria2c.GetVersion();
     string version = Aria2cTools.GetRpcStructValue(rpcStruct, "version") as string;
     return version;
 }
 /// <summary>
 /// 改变任务在列表中的位置
 /// </summary>
 /// <param name="gid">任务标识符param>
 /// <param name="pos">位置</param>
 /// <param name="how">更改方式, "POS_SET":列表首位, "POS_CUR":移动到pos指定位置,  "POS_END":列表末尾</param>
 /// <returns>成功返回true, 失败返回fale</returns>
 public static bool ChangePosition(string gid, int pos, PosType how)
 {
     string desc = Aria2cTools.GetEnumDescription(how);
     int resultt = aria2c.ChangePosition(gid, pos, desc);
     return true;
 }
 /// <summary>
 /// 停止的的任务信息
 /// </summary>
 /// <param name="tasks">返回的任务信息列表</param>
 /// <param name="keys">查找的属性关键字</param>
 /// <returns>成功返回停止的的任务信息列表,失败返回空</returns>
 public static List<Aria2cTask> TellStopped(int offset, int num, params string[] keys)
 {
     XmlRpcStruct[] xmlstruct = aria2c.TellStopped(offset, num, keys);
     List<Aria2cTask> tasks = Aria2cTools.ConvertToAria2cTasks(xmlstruct);
     return tasks;
 }
 /// <summary>
 /// 所有正在下载的任务信息
 /// </summary>
 /// <param name="tasks">返回的任务信息列表</param>
 /// <param name="keys">查找的属性关键字</param>
 /// <returns>成功返回正在下载的任务信息列表,失败返回空</returns>
 public static List<Aria2cTask> TellActive(params string[] keys)
 {
     XmlRpcStruct[] xmlstruct = aria2c.TellActive(keys);
     List<Aria2cTask> tasks = Aria2cTools.ConvertToAria2cTasks(xmlstruct);
     return tasks;
 }
 /// <summary>
 /// 获取BT下载种子链接信息
 /// </summary>
 /// <param name="gid">任务标识符</param>
 /// <returns>成功返回种子链接信息列表,失败返回空</returns>
 public static List<Aria2cPeers> GetPeers(string gid)
 {
     XmlRpcStruct[] xmlstruct = aria2c.GetFiles(gid);
     List<Aria2cPeers> peers = Aria2cTools.ConvertToAria2cPeers(xmlstruct);
     return peers;
 }
Exemplo n.º 12
0
        /// <summary>
        /// 将RPC信息转换为下载任务
        /// </summary>
        /// <param name="rpcStruct">RPC信息</param>
        public Aria2cTask(XmlRpcStruct rpcStruct)
        {
            List <string> keyList   = rpcStruct.Keys as List <string>;
            List <object> valueList = rpcStruct.Values as List <object>;

            for (int i = 0; i < rpcStruct.Count; i++)
            {
                string key   = keyList[i];
                object value = valueList[i];

                if (key == "gid")
                {
                    this.Gid = value as string;
                }
                else if (key == "status")
                {
                    this.Status = ConvertToAria2cTaskStatus(value as string);
                }
                else if (key == "totalLength")
                {
                    this.TotalLength = Convert.ToInt64(value as string);
                }
                else if (key == "completedLength")
                {
                    this.CompletedLength = Convert.ToInt64(value as string);
                }
                else if (key == "uploadLength")
                {
                    this.UploadLength = Convert.ToInt64(value as string);
                }
                else if (key == "bitfield")
                {
                    this.Bitfield = value as string;
                }
                else if (key == "downloadSpeed")
                {
                    this.DownloadSpeed = Convert.ToInt64(value as string);
                }
                else if (key == "uploadSpeed")
                {
                    this.UploadSpeed = Convert.ToInt64(value as string);
                }
                else if (key == "infoHash")
                {
                    this.InfoHash = value as string;
                }
                else if (key == "numSeeders")
                {
                    this.NumSeeders = Convert.ToInt64(value as string);
                }
                else if (key == "numPieces")
                {
                    this.NumPieces = Convert.ToInt64(value as string);
                }
                else if (key == "seeder")
                {
                    this.Seeder = (value as string) == "true" ? true : false;
                }
                else if (key == "pieceLength")
                {
                    this.PieceLength = Convert.ToInt64(value as string);
                }
                else if (key == "connections")
                {
                    this.Connections = Convert.ToInt64(value as string);
                }
                else if (key == "errorCode")
                {
                    this.ErrorCode = Convert.ToInt64(value as string);
                }
                else if (key == "errorMessage")
                {
                    this.ErrorMessage = value as string;
                }
                else if (key == "followedBy")
                {
                    this.FollowedBy = value;
                }
                else if (key == "following")
                {
                    this.Following = value;
                }
                else if (key == "belongsTo")
                {
                    this.BelongsTo = value as string;
                }
                else if (key == "dir")
                {
                    this.Dir = value as string;
                }
                else if (key == "files")
                {
                    this.Files = Aria2cTools.ConvertToAria2cFiles(value as XmlRpcStruct[]);
                }
                else if (key == "bittorrent")
                {
                    this.Bittorrent = new Aria2cBittorrent(value as XmlRpcStruct);
                }
                else if (key == "verifiedLength")
                {
                    this.VerifiedLength = Convert.ToInt64(value as string);
                }
                else if (key == "verifyIntegrityPending")
                {
                    this.VerifyIntegrityPending = (value as string) == "true" ? true : false;
                }
                else
                {
                    throw new Exception("Aria2cTask不包含该属性");
                }
            }
        }