private static async Task <Aria2TaskInfo[]> _TellMethodBaseAsync(string method, int offset, int num, object id = null, params string[] keys) { var obj = JsonRpcHelper.RemoteCallAsync(RPC_URL, method, id, offset, num, keys); var result = (JArray)(await obj); return(result.ToObject <Aria2TaskInfo[]>()); }
/// <summary> /// 异步获取所有正在运行的下载项目 /// </summary> /// <param name="keys">参考TellStatus方法</param> /// <returns></returns> public static async Task <Aria2TaskInfo[]> TellActiveAsync(object id = null, params string[] keys) { var obj = JsonRpcHelper.RemoteCallAsync(RPC_URL, "aria2.tellActive", id, keys); var result = (JArray)(await obj); return(result.ToObject <Aria2TaskInfo[]>()); }
internal async void SendSimInitializeRequest() { var serverUri = _communication.SimulatorServerUri; if (serverUri == null) { return; } var param0 = new GeneralSimInitializeRequestParams { SupportedFormats = _supportedScoreFileFormats }; var @params = new object[] { param0 }; var rpcResult = await SendRequestAsync(serverUri, CommonProtocolMethodNames.General_SimInitialize, @params, null); if (!rpcResult.StatusCode.IsSuccessful()) { // TODO: Handle HTTP protocol errors. return; } Debug.Assert(rpcResult.ResponseObject != null, "result.ResponseObject != null"); if (!JsonRpcHelper.IsResponseValid(rpcResult.ResponseObject)) { // TODO: Handle malformed RPC object. Debug.Print("RPC response is invalid."); return; } if (JsonRpcHelper.IsResponseSuccessful(rpcResult.ResponseObject)) { var response = JsonRpcHelper.TranslateAsResponse(rpcResult.ResponseObject); Debug.Assert(response.Result != null, "response.Result != null"); var result = response.GetResult <GeneralSimInitializeResponseResult>(); Debug.Assert(result != null, nameof(result) + " != null"); var selectedFormat = result.SelectedFormat; if (selectedFormat == null) { // No common format } else { // Select it as the common format } } else { var error = JsonRpcHelper.TranslateAsResponse(rpcResult.ResponseObject); } }
protected override void OnGeneralSimInitialize(object sender, JsonRpcMethodEventArgs e) { LogToScreen("Received request: general/simInitialize"); if (JsonRpcHelper.IsRequestValid(e.ParsedRequestObject, out string errorMessage)) { var requestObject = JsonRpcHelper.TranslateAsRequest(e.ParsedRequestObject); var param0 = requestObject.Params[0]; Debug.Assert(param0 != null, nameof(param0) + " != null"); var param0Object = param0.ToObject <GeneralSimInitializeRequestParams>(); var selectedFormat = SelectFormat(param0Object.SupportedFormats); var responseResult = new GeneralSimInitializeResponseResult { SelectedFormat = selectedFormat }; e.Context.RpcOk(responseResult); } else { Debug.Print(errorMessage); e.Context.RpcError(JsonRpcErrorCodes.InvalidRequest, errorMessage); } }
public static async Task <string[]> _ListMethodsAsync(string method, object id = null) { var obj = JsonRpcHelper.RemoteCallAsync(RPC_URL, method, id); var result = (JArray)(await obj); return(result.ToObject <string[]>()); }
protected override void OnGeneralSimLaunched(object sender, JsonRpcMethodEventArgs e) { if (JsonRpcHelper.IsRequestValid(e.ParsedRequestObject, out string errorMessage)) { var requestObject = JsonRpcHelper.TranslateAsRequest(e.ParsedRequestObject); var param0 = requestObject.Params[0]; Debug.Assert(param0 != null, nameof(param0) + " != null"); var param0Object = param0.ToObject <GeneralSimLaunchedNotificationParams>(); var simulatorServerUri = new Uri(param0Object.SimulatorServerUri); _communication.SimulatorLifeCycleStage = LifeCycleStage.Launched; _communication.SimulatorServerUri = simulatorServerUri; e.Context.RpcOk(); _communication.Client.SendSimInitializeRequest(); } else { Debug.Print(errorMessage); e.Context.RpcError(JsonRpcErrorCodes.InvalidRequest, errorMessage); } }
/// <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)); }
protected override void OnPreviewPause(object sender, JsonRpcMethodEventArgs e) { LogToScreen("Received request: preview/pause"); if (JsonRpcHelper.IsRequestValid(e.ParsedRequestObject, out string errorMessage)) { var syncTimer = _communication.Game.FindSingleElement <SyncTimer>(); if (syncTimer == null) { e.Context.RpcError(JsonRpcErrorCodes.InternalError, "Cannot find the " + nameof(SyncTimer) + " component.", statusCode: HttpStatusCode.InternalServerError); return; } syncTimer.Pause(); e.Context.RpcOk(); _communication.Client.SendPausedNotification(); } else { Debug.Print(errorMessage); e.Context.RpcError(JsonRpcErrorCodes.InvalidRequest, errorMessage); } }
protected override void OnPreviewStopped(object sender, JsonRpcMethodEventArgs e) { if (JsonRpcHelper.IsRequestValid(e.ParsedRequestObject, out string errorMessage)) { e.Context.RpcOk(); } else { Debug.Print(errorMessage); e.Context.RpcError(JsonRpcErrorCodes.InvalidRequest, errorMessage); } }
protected override void OnEditReloaded(object sender, JsonRpcMethodEventArgs e) { if (JsonRpcHelper.IsRequestValid(e.ParsedRequestObject, out string errorMessage)) { _communication.SimulatorLifeCycleStage = LifeCycleStage.Reloaded; e.Context.RpcOk(); } else { Debug.Print(errorMessage); e.Context.RpcError(JsonRpcErrorCodes.InvalidRequest, errorMessage); } }
protected override void OnPreviewGetPlaybackState(object sender, JsonRpcMethodEventArgs e) { LogToScreen("Received request: preview/getPlaybackState"); if (JsonRpcHelper.IsRequestValid(e.ParsedRequestObject, out string errorMessage)) { e.Context.RpcOk(); } else { Debug.Print(errorMessage); e.Context.RpcError(JsonRpcErrorCodes.InvalidRequest, errorMessage); } }
/// <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 }); } }
internal async void SendReloadRequest([NotNull] EditReloadRequestParams param0) { var serverUri = _communication.SimulatorServerUri; if (serverUri == null) { return; } var @params = new object[] { param0 }; var result = await SendRequestAsync(serverUri, CommonProtocolMethodNames.Edit_Reload, @params, null); if (!result.StatusCode.IsSuccessful()) { // TODO: Handle HTTP protocol errors. return; } Debug.Assert(result.ResponseObject != null, "result.ResponseObject != null"); if (!JsonRpcHelper.IsResponseValid(result.ResponseObject)) { // TODO: Handle malformed RPC object. Debug.Print("RPC response is invalid."); return; } if (JsonRpcHelper.IsResponseSuccessful(result.ResponseObject)) { var response = JsonRpcHelper.TranslateAsResponse(result.ResponseObject); } else { var error = JsonRpcHelper.TranslateAsResponse(result.ResponseObject); } }
/// <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); }
protected override void OnEditReload(object sender, JsonRpcMethodEventArgs e) { LogToScreen("Received request: edit/reload"); if (!JsonRpcHelper.IsRequestValid(e.ParsedRequestObject, out string errorMessage)) { Debug.Print(errorMessage); e.Context.RpcError(JsonRpcErrorCodes.InvalidRequest, errorMessage); return; } var beatmapLoader = _communication.Game.FindSingleElement <BeatmapLoader>(); if (beatmapLoader == null) { e.Context.RpcError(JsonRpcErrorCodes.InternalError, "Cannot find the " + nameof(BeatmapLoader) + " component.", statusCode: HttpStatusCode.InternalServerError); return; } var requestObject = JsonRpcHelper.TranslateAsRequest(e.ParsedRequestObject); var param0 = requestObject.Params[0]; Debug.Assert(param0 != null, nameof(param0) + " != null"); var param0Object = param0.ToObject <EditReloadRequestParams>(); if (!string.IsNullOrEmpty(param0Object.BeatmapFile)) { if (File.Exists(param0Object.BeatmapFile)) { var backgroundMusic = _communication.Game.FindSingleElement <BackgroundMusic>(); if (!string.IsNullOrEmpty(param0Object.BackgroundMusicFile)) { if (backgroundMusic == null) { e.Context.RpcError(JsonRpcErrorCodes.InternalError, "Cannot find the " + nameof(BackgroundMusic) + " component.", statusCode: HttpStatusCode.InternalServerError); return; } backgroundMusic.LoadMusic(param0Object.BackgroundMusicFile); } else { backgroundMusic?.LoadMusic(null); } beatmapLoader.Load(param0Object.BeatmapFile); } else { LogToScreen($"Not found: {param0Object.BeatmapFile}"); } } e.Context.RpcOk(); // DO NOT await _communication.Client.SendReloadedNotification(); }
/// <summary> /// 强制暂停所有下载任务 /// </summary> /// <param name="id"></param> /// <returns></returns> public static void ForcePauseAll(object id = null) { var result = JsonRpcHelper.RemoteCall(RPC_URL, "aria2.forcePauseAll", id); }
/// <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); }
/// <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); }
/// <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); }
/// <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[]>()); }
// 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[]>()); }
/// <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[]>()); }
/// <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); }
/// <summary> /// 强制关闭Aria2 /// </summary> /// <param name="id"></param> public static void ForceShutdown(object id = null) { JsonRpcHelper.RemoteCall(RPC_URL, "aria2.forceShutdown", id); }
public static void GetSessionInfo(object id = null) { JsonRpcHelper.RemoteCall(RPC_URL, "aria2.getSessionInfo", id); }
/// <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); }
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[]>()); }
public static void GetVersion(string gid, object id = null) { var result = (JObject)JsonRpcHelper.RemoteCall(RPC_URL, "aria2.getVersion", id); }
private object RawRemoteCall(JsonRpcToken token) { return(JsonRpcHelper.RemoteCall(this.m_rpcUrl, token)); }