예제 #1
0
        public static HttpWebRequest CreateGetCommandHttpWebRequest(string ipAddress, string contentType, string soapAction,
                                                                    Soap.WemoGetCommands cmd, string requestMethod)
        {
            var req = CreateHttpWebRequest(ipAddress, contentType, soapAction, cmd.ToString(), requestMethod);

            return(req);
        }
예제 #2
0
        public async Task <T> GetWemoResponseObjectAsync <T>(Soap.WemoGetCommands cmd, string ipAddress)
        {
            if (cmd == Soap.WemoGetCommands.GetPower || cmd == Soap.WemoGetCommands.GetInsightParams)
            {
                var plug = new WemoInsightPlug {
                    WebRequest = this.WebRequest
                };

                var response = await plug.GetResponseAsync(cmd, ipAddress);

                var objResponse = plug.GetResponseObject <T>(response);
                return((T)objResponse);
            }
            else
            {
                var plug = new WemoPlug {
                    WebRequest = this.WebRequest
                };

                var response = await plug.GetResponseAsync(cmd, ipAddress);

                var objResponse = plug.GetResponseObject <T>(response);
                return((T)objResponse);
            }
        }
예제 #3
0
        /// <summary>
        /// Call the command to construct a soap Http Request - returning a translated response object
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="ipAddress"></param>
        /// <returns></returns>
        public async Task <WemoResponse> GetWemoPlugResponseAsync(Soap.WemoGetCommands cmd, string ipAddress)
        {
            var plug = new WemoPlug {
                WebRequest = this.WebRequest
            };
            var response = await plug.GetResponseAsync(cmd, ipAddress);

            return(response);
        }
예제 #4
0
        /// <summary>
        /// Call the command to construct a soap Http Request - returning a translated response object
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="ipAddress"></param>
        /// <returns></returns>
        internal async Task <WemoResponse> GetWemoPlugResponseAsync(Soap.WemoGetCommands cmd, string ipAddress)
        {
            var plug = new WemoPlug(PortNumber)
            {
                Request = _request
            };
            var response = await plug.GetResponseAsync(cmd, ipAddress);

            return(response);
        }
예제 #5
0
        private HttpWebRequest CreateBinaryStateHttpWebRequest(Soap.WemoGetCommands cmd, string ipAddress)
        {
            HttpWebRequest request = BinarySetRequest;

            if (request == null)
            {
                request = CreateHttpWebRequest(cmd, ipAddress);
            }
            return(request);
        }
예제 #6
0
        internal async Task <string> GetWemoResponseValueAsync(Soap.WemoGetCommands cmd, string ipAddress)
        {
            var plug = new WemoPlug {
                GetResponseWebRequest = GetResponseWebRequest
            };

            var response = await plug.GetResponseAsync(cmd, ipAddress);

            var value = plug.GetResponseValue(response);

            return(value);
        }
예제 #7
0
        private HttpWebRequest CreateHttpWebRequest(Soap.WemoGetCommands cmd, string ipAddress)
        {
            var fullIpAddress = $"{ipAddress}:{Port}{Event}";

            HttpWebRequest request = Request;

            if (request == null)
            {
                request = HttpRequest.CreateHttpWebRequest(fullIpAddress, ContentType, SoapAction, cmd.ToString(), "POST");
            }
            return(request);
        }
예제 #8
0
        public async Task <WemoResponse> GetResponseAsync(Soap.WemoGetCommands cmd, string ipAddress)
        {
            WemoResponse response;

            // Construct the HttpWebRequest
            var request = CreateHttpWebRequest(cmd, ipAddress);

            // Construct the Soap Request
            var reqContentSoap = Soap.GenerateGetRequest(cmd);

            response = await ExecuteGetResponseAsync(request, reqContentSoap);

            return(response);
        }
예제 #9
0
        public async Task <WemoResponse> GetResponseAsync(Soap.WemoGetCommands cmd, string ipAddress)
        {
            WemoResponse response;

            // Construct the HttpWebRequest - if not null we will use the supplied HttpWebRequest object - which is probably a Mock
            var request = WebRequest
                          ?? HttpRequest.CreateGetCommandHttpWebRequest($"{ipAddress}:{Port}{Event}", ContentType, SoapAction, cmd, RequestMethod);

            // Construct the Soap Request
            var reqContentSoap = Soap.GenerateGetRequest(cmd, "urn:Belkin:service:insight:1");

            response = await ExecuteGetResponseAsync(request, reqContentSoap);

            return(response);
        }
예제 #10
0
        private static Soap.WemoGetCommands GenerateWemoCommand(System.Type obj)
        {
            Soap.WemoGetCommands cmd = Soap.WemoGetCommands.Null;

            if (obj == typeof(GetBinaryStateResponse))
            {
                cmd = Soap.WemoGetCommands.GetBinaryState;
            }

            if (obj == typeof(GetFriendlyNameResponse))
            {
                cmd = Soap.WemoGetCommands.GetFriendlyName;
            }

            if (obj == typeof(GetHomeInfoResponse))
            {
                cmd = Soap.WemoGetCommands.GetHomeInfo;
            }

            return(cmd);
        }
예제 #11
0
        /// <summary>
        /// Acquire the existing state of the target Wemo plug.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="cmd"></param>
        /// <param name="ipAddress"></param>
        /// <returns></returns>
        internal async Task <T> GetWemoResponseObjectAsync <T>(string ipAddress)
        {
            var typeofObject = typeof(T);

            // Determine which command to use, per object type
            Soap.WemoGetCommands cmd = GenerateWemoCommand(typeofObject);

            if (cmd == Soap.WemoGetCommands.Null)
            {
                throw new System.Exception($"Object not supported: {typeofObject.ToString()}");
            }

            var plug = new WemoPlug(PortNumber)
            {
                Request = _request
            };

            var response = await plug.GetResponseAsync(cmd, ipAddress);

            var objResponse = plug.GetResponseObject <T>(response);

            return((T)objResponse);
        }
예제 #12
0
        /// <summary>
        /// Acquire the existing state of the target Wemo plug.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="cmd"></param>
        /// <param name="ipAddress"></param>
        /// <returns></returns>
        internal async Task <T> GetWemoResponseObjectAsync <T>(string ipAddress)
        {
            Soap.WemoGetCommands cmd = Soap.WemoGetCommands.Null;

            var obj = typeof(T);

            // Determine which command to use, per object
            if (obj == typeof(GetBinaryStateResponse))
            {
                cmd = Soap.WemoGetCommands.GetBinaryState;
            }

            if (obj == typeof(GetFriendlyNameResponse))
            {
                cmd = Soap.WemoGetCommands.GetFriendlyName;
            }

            if (obj == typeof(GetHomeInfoResponse))
            {
                cmd = Soap.WemoGetCommands.GetHomeInfo;
            }

            if (cmd == Soap.WemoGetCommands.Null)
            {
                throw new System.Exception($"Object not supported: {obj.ToString()}");
            }

            var plug = new WemoPlug {
                GetResponseWebRequest = GetResponseWebRequest
            };

            var response = await plug.GetResponseAsync(cmd, ipAddress);

            var objResponse = plug.GetResponseObject <T>(response);

            return((T)objResponse);
        }