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); }
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); } }
/// <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); }
/// <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); }
private HttpWebRequest CreateBinaryStateHttpWebRequest(Soap.WemoGetCommands cmd, string ipAddress) { HttpWebRequest request = BinarySetRequest; if (request == null) { request = CreateHttpWebRequest(cmd, ipAddress); } return(request); }
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); }
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); }
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); }
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); }
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); }
/// <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); }
/// <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); }