/// <summary> /// 下载种子链接文件 /// </summary> /// <param name="torrent">种子文件</param> /// <param name="fileName">输出文件名</param> /// <param name="dir">下载目录</param> /// <param name="taskOptions">下载任务选项</param> /// <returns>成功返回任务标识符,失败返回空</returns> public string AddTorrent(string torrent, string fileName = "", string dir = "", List <Dictionary <string, string> > taskOptions = null) { try { string autoSaveFileID = ""; string gid = Aria2cWarpper.AddTorrent(ref autoSaveFileID, torrent, fileName, dir, taskOptions); if (!string.IsNullOrWhiteSpace(gid)) { Aria2cTask task = Aria2cWarpper.TellStatus(gid); OnStart?.Invoke(this, new Aria2cTaskEvent(task)); AddDownTask(task); if (autoSaveFileID != "") { gidAndTorrentOrMeta4Map.Add(gid, autoSaveFileID + ".torrent"); } } return(gid); } catch (Exception ex) { Console.WriteLine(ex); return(string.Empty); } }
/// <summary> /// 下载磁链接文件 /// </summary> /// <param name="metalink">磁链接文件</param> /// <param name="fileName">输出文件名</param> /// <param name="dir">下载目录</param> /// <param name="taskOptions">下载任务选项</param> /// <returns>成功返回任务标识符数组,失败返回空数组</returns> public string[] AddMetalink(string metalink, string fileName = "", string dir = "", List <Dictionary <string, string> > taskOptions = null) { try { string autoSaveFileID = ""; string[] gids = Aria2cWarpper.AddMetalink(ref autoSaveFileID, metalink, fileName, dir, taskOptions); foreach (var gid in gids) { if (!string.IsNullOrWhiteSpace(gid)) { Aria2cTask task = Aria2cWarpper.TellStatus(gid); OnStart?.Invoke(this, new Aria2cTaskEvent(task)); AddDownTask(task); if (autoSaveFileID != "") { gidAndTorrentOrMeta4Map.Add(gid, autoSaveFileID + ".meta4"); } } } return(gids); } catch (Exception ex) { Console.WriteLine(ex); return(new string[] { "" }); } }
/// <summary> /// 下载任务设置 /// </summary> /// <param name="gid">任务标识符</param> /// <param name="options">设置参数</param> /// <returns>成功返回true, 失败返回fale</returns> public bool ChangeOption(string gid, Aria2cOption option) { try { return(Aria2cWarpper.ChangeOption(gid, option)); } catch (Exception ex) { Console.WriteLine(ex); return(false); } }
/// <summary> /// 获取下载任务设置 /// </summary> /// <param name="gid">任务标识符</param> /// <param name="option">设置信息</param> /// <returns>成功返回任务设置, 失败返回空</returns> public Aria2cOption GetOption(string gid) { try { return(Aria2cWarpper.GetOption(gid)); } catch (Exception ex) { Console.WriteLine(ex); return(null); } }
/// <summary> /// 更改下载任务的链接信息 /// </summary> /// <param name="gid">任务标识符</param> /// <param name="fileIndex">一个下载任务可能包含多个下载文件,指定文件索引, 从1开始</param> /// <param name="delUris">要删除的现在链接</param> /// <param name="addUris">要添加的下载链接</param> /// <param name="position">链接插入的位置</param> /// <returns>成功返回true, 失败返回fale</returns> public bool ChangeUri(string gid, int fileIndex, string[] delUris, string[] addUris) { try { return(Aria2cWarpper.ChangeUri(gid, fileIndex, delUris, addUris)); } catch (Exception ex) { Console.WriteLine(ex); return(false); } }
/// <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 bool ChangePosition(string gid, int pos, PosType how) { try { return(Aria2cWarpper.ChangePosition(gid, pos, how)); } catch (Exception ex) { Console.WriteLine(ex); return(false); } }
/// <summary> /// 停止的的任务信息 /// </summary> /// <param name="tasks">返回的任务信息列表</param> /// <param name="keys">查找的属性关键字</param> /// <returns>成功返回停止的的任务信息列表,失败返回空</returns> public List <Aria2cTask> TellStopped(int offset, int num, params string[] keys) { try { return(Aria2cWarpper.TellStopped(offset, num, keys)); } catch (Exception ex) { Console.WriteLine(ex); return(null); } }
/// <summary> /// 所有正在下载的任务信息 /// </summary> /// <param name="tasks">返回的任务信息列表</param> /// <param name="keys">查找的属性关键字</param> /// <returns>成功返回正在下载的任务信息列表,失败返回空</returns> public List <Aria2cTask> TellActive(params string[] keys) { try { return(Aria2cWarpper.TellActive(keys)); } catch (Exception ex) { Console.WriteLine(ex); return(null); } }
/// <summary> /// 设置全局下载设置 /// </summary> /// <param name="option">设置信息</param> /// <returns>成功返回true, 失败返回fale</returns> public bool ChangeGlobalOption(Aria2cOption option) { try { return(Aria2cWarpper.ChangeGlobalOption(option)); } catch (Exception ex) { Console.WriteLine(ex); return(false); } }
/// <summary> /// 获取全局下载状态 /// </summary> /// <param name="globalStat">设置信息</param> /// <returns>成功返回全局下载状态, 失败返回空</returns> public Aria2cGlobalStat GetGlobalStat() { try { return(Aria2cWarpper.GetGlobalStat()); } catch (Exception ex) { Console.WriteLine(ex); return(null); } }
/// <summary> /// 获取下载任务的文件信息 /// </summary> /// <param name="gid">任务标识符</param> /// <returns>成功返回文件信息列表,失败返回空</returns> public List <Aria2cFile> GetFiles(string gid) { try { return(Aria2cWarpper.GetFiles(gid)); } catch (Exception ex) { Console.WriteLine(ex); return(null); } }
/// <summary> /// 保存会话 /// </summary> public bool SaveSession() { try { return(Aria2cWarpper.SaveSession()); } catch (Exception ex) { Console.WriteLine(ex); return(false); } }
/// <summary> /// 获取下载状态 /// </summary> /// <param name="gid">任务标识符</param> /// <param name="task">获取的任务信息</param> /// <param name="keys">属性过滤字段</param> /// <returns>成功返回任务信息,失败返回空</returns> public Aria2cTask TellStatus(string gid, params string[] keys) { try { return(Aria2cWarpper.TellStatus(gid, keys)); } catch (Exception ex) { Console.WriteLine(ex); return(null); } }
/// <summary> /// 强制关机 /// </summary> public bool ForceShutdown() { try { return(Aria2cWarpper.ForceShutdown()); } catch (Exception ex) { Console.WriteLine(ex); return(false); } }
/// <summary> /// 获取会话ID /// </summary> /// <returns>成功返回会话ID,失败返回空字符串</returns> public string GetSessionInfo() { try { return(Aria2cWarpper.GetSessionInfo()); } catch (Exception ex) { Console.WriteLine(ex); return(string.Empty); } }
/// <summary> /// 移除指定任务信息, 清空内存 /// </summary> /// <param name="gid">任务标识符</param> /// <returns>成功返回true, 失败返回fale</returns> public bool RemoveDownloadResult(string gid) { try { return(Aria2cWarpper.RemoveDownloadResult(gid)); } catch (Exception ex) { Console.WriteLine(ex); return(false); } }
/// <summary> /// 清空内存 /// </summary> /// <returns>成功返回true, 失败返回fale</returns> public bool PurgeDownloadResult() { try { return(Aria2cWarpper.PurgeDownloadResult()); } catch (Exception ex) { Console.WriteLine(ex); return(false); } }
/// <summary> /// 取消暂停所有任务 /// </summary> /// <param name="gid">任务标识符</param> /// <returns>成功返回true, 失败返回fale</returns> public bool UnPauseAll() { try { bool result = Aria2cWarpper.UnPauseAll(); if (result) { OnUnPauseAll?.Invoke(this, new EventArgs()); } return(result); } catch (Exception ex) { Console.WriteLine(ex); return(false); } }
/// <summary> /// 取消暂停任务 /// </summary> /// <param name="gid">任务标识符</param> /// <returns>成功返回true, 失败返回fale</returns> public bool UnPause(string gid) { try { bool result = Aria2cWarpper.UnPause(gid); if (result) { Aria2cTask task = Aria2cWarpper.TellStatus(gid); OnUnPause?.Invoke(this, new Aria2cTaskEvent(task)); } return(result); } catch (Exception ex) { Console.WriteLine(ex); return(false); } }
/// <summary> /// 强制暂停任务 /// </summary> /// <param name="gid">任务标识符</param> /// <returns>成功返回true, 失败返回fale</returns> public bool ForcePause(string gid) { try { bool pause = Aria2cWarpper.ForcePause(gid); if (pause) { Aria2cTask task = Aria2cWarpper.TellStatus(gid); OnPaused?.Invoke(this, new Aria2cTaskEvent(task)); } return(pause); } catch (Exception ex) { Console.WriteLine(ex); return(false); } }
/// <summary> /// 添加下载任务 /// </summary> /// <param name="uri">下载地址</param> /// <param name="fileName">输出文件名</param> /// <param name="dir">下载文件夹</param> /// <param name="taskOptions">下载任务选项</param> /// <returns>成功返回任务标识符,失败返回空</returns> public string AddUri(string uri, string fileName = "", string dir = "", List <Dictionary <string, string> > taskOptions = null) { try { string gid = Aria2cWarpper.AddUri(uri, fileName, dir, taskOptions); if (!string.IsNullOrWhiteSpace(gid)) { Aria2cTask task = Aria2cWarpper.TellStatus(gid); OnStart?.Invoke(this, new Aria2cTaskEvent(task)); AddDownTask(task); } return(gid); } catch (Exception ex) { Console.WriteLine(ex); return(string.Empty); } }
/// <summary> /// 强制删除任务 /// </summary> /// <param name="gid">任务标识符</param> /// <returns>成功返回true, 失败返回fale</returns> public bool ForceRemove(string gid) { try { bool result = Aria2cWarpper.ForceRemove(gid); if (result) { OnRemoved?.Invoke(this, new Aria2cEvent(gid)); RemoveDownTask(gid); } return(result); } catch (Exception ex) { Console.WriteLine(ex); return(false); } }
/// <summary> /// 下载磁链接文件 /// </summary> /// <param name="metalink">磁链接文件</param> /// <param name="dir">下载目录</param> /// <returns>成功返回任务标识符,失败返回空</returns> public string AddMetalink(string metalink, string fileName = "", string dir = "") { try { string gid = Aria2cWarpper.AddMetalink(metalink, fileName, dir); if (!string.IsNullOrWhiteSpace(gid)) { Aria2cTask task = Aria2cWarpper.TellStatus(gid); OnStart?.Invoke(this, new Aria2cTaskEvent(task)); AddDownTask(task); } return(gid); } catch (Exception ex) { Console.WriteLine(ex); return(string.Empty); } }