private static RPCRequestModel GetInputRequestModel(Input enumCode) { var reqData = new RPCRequestModel(); reqData.Id = 1; reqData.Method = Helper.GetEnumMethodName(enumCode); return(reqData); }
private static RPCRequestModel GetSystemRequestModel(System system) { var reqData = new RPCRequestModel(); reqData.Id = 1; reqData.Method = Helper.GetEnumMethodName(system); return(reqData); }
private static RPCRequestModel GetVolumeMethodRequestModel(Application appMethod, VolumeMethod volumeMethod) { var reqData = new RPCRequestModel(); reqData.Id = 1; reqData.Method = Helper.GetEnumMethodName(appMethod); reqData.Params = appMethod == Application.SetVolume ? Volume.GetVolumeParamsObject(volumeMethod) : Volume.GetVoulueParamsForMute(); return(reqData); }
private byte[] GetRequstByteData(RPCRequestModel reqData) { var jsonStr = JsonConvert.SerializeObject(reqData , Formatting.Indented , new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver() }); return(Encoding.UTF8.GetBytes(jsonStr)); }
public async Task <bool> SendRequstAsync(RPCRequestModel reqData) { var req = HttpWebRequest.Create(GetJsonRpcUrl(reqData.Method)) as HttpWebRequest; req.Method = _option.Type; req.ContentType = _option.ContentType; var byteData = GetRequstByteData(reqData); req.ContentLength = byteData.Length; req.GetRequestStream().Write(byteData, 0, byteData.Length); var response = await req.GetResponseAsync() as HttpWebResponse; if (response.StatusCode == HttpStatusCode.OK) { var reader = new StreamReader(response.GetResponseStream()); var r = reader.ReadToEnd(); return(true); } return(false); }