예제 #1
0
        private static RPCRequestModel GetInputRequestModel(Input enumCode)
        {
            var reqData = new RPCRequestModel();

            reqData.Id     = 1;
            reqData.Method = Helper.GetEnumMethodName(enumCode);
            return(reqData);
        }
예제 #2
0
        private static RPCRequestModel GetSystemRequestModel(System system)
        {
            var reqData = new RPCRequestModel();

            reqData.Id     = 1;
            reqData.Method = Helper.GetEnumMethodName(system);
            return(reqData);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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));
        }
예제 #5
0
        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);
        }