private string GetPostUri(Enigma2WebInterfacesMethods method) { string result = string.Empty; switch(method) { case Enigma2WebInterfacesMethods.GetDeviceInfo: result = this.Connection.ConnectionSettings.URIString + "/web/deviceinfo"; break; case Enigma2WebInterfacesMethods.GetServiceList: result = this.Connection.ConnectionSettings.URIString + "/web/getservices"; break; case Enigma2WebInterfacesMethods.GetLocationList: result = this.Connection.ConnectionSettings.URIString + "/web/getlocations"; break; case Enigma2WebInterfacesMethods.GetCurrentLocation: result = this.Connection.ConnectionSettings.URIString + "/web/getcurrlocation"; break; case Enigma2WebInterfacesMethods.GetTimerList: result = this.Connection.ConnectionSettings.URIString + "/web/timerlist"; break; default: result = string.Empty; break; } return result; }
public T Execute(Enigma2WebInterfacesMethods method, IDictionary<string, string> parameters) { T result = default(T); string p = "?"; try { // Check parameters if (parameters != null && parameters.Count > 0) { foreach (var d in parameters) { p += d.Key + "=" + d.Value; } } string uri = this.GetPostUri(method) + p; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.KeepAlive = false; request.Method = "POST"; //request.Timeout = this.Connection.ConnectionSettings.Timeout; using (WebResponse response = request.GetResponse()) { using (Stream responseStream = response.GetResponseStream()) { using (StreamReader responseReader = new StreamReader(responseStream, Encoding.UTF8)) { //string resultString = responseReader.ReadToEnd(); // Deserialize XML XmlSerializer xSerializer = new System.Xml.Serialization.XmlSerializer(typeof(T)); result = (T)xSerializer.Deserialize(responseReader); } } } } catch (Exception ex) { } return result; }
public T Execute(Enigma2WebInterfacesMethods method) { T result = default(T); try { var uri = this.GetPostUri(method); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.KeepAlive = false; request.Method = "POST"; //request.Timeout = this.Connection.ConnectionSettings.Timeout; using (WebResponse response = request.GetResponse()) { using (Stream responseStream = response.GetResponseStream()) { using (StreamReader responseReader = new StreamReader(responseStream, Encoding.UTF8)) { //string resultString = responseReader.ReadToEnd(); // Deserialize XML XmlSerializer xSerializer = new System.Xml.Serialization.XmlSerializer(typeof(T)); result = (T)xSerializer.Deserialize(responseReader); } } } } catch (Exception ex) { //string exceptionMessage = String.Format(@"Error while calling \\n\\n JSON RPC method {0} \\n\\n with parameters \\n\\n {1}", jsonRequest.Method, jsonRequest.Params); //throw new JsonRpcCommunicationException(exceptionMessage, ex); } return result; }