/// <summary> /// Method used to retrieve Gen3 Devices Mac Address /// </summary> /// <returns></returns> private string findDevMac() { String macaddress = ""; Log.Debug("Auto3D: Retrieving the Mac Address from: " + Name + " at IP: " + DeviceIPAddress); var httpWebRequest = (HttpWebRequest)WebRequest.Create(@"http://" + DeviceIPAddress + @"/sony/system"); httpWebRequest.ContentType = "text/json"; httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = "{\"id\":19,\"method\":\"getSystemSupportedFunction\",\"version\":\"1.0\",\"params\":[]}\""; streamWriter.Write(json); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var responseText = streamReader.ReadToEnd(); dataSet = JsonConvert.DeserializeObject <SonyCommandList>(responseText); } string first = dataSet.result[0].ToString(); List <SonyOption> bal = JsonConvert.DeserializeObject <List <SonyOption> >(first); macaddress = bal.Find(x => x.option.ToLower() == "WOL".ToLower()).value.ToString(); Log.Debug("Auto3D: Device Mac Address: " + macaddress); return(macaddress); }
/// <summary> /// Method used to retrieve Gen3 Devices Mac Address /// </summary> /// <returns></returns> private string findDevMac() { String macaddress = ""; Log.Debug("Auto3D: Retrieving the Mac Address from: " + Name + " at IP: " + DeviceIPAddress); var httpWebRequest = (HttpWebRequest)WebRequest.Create(@"http://" + DeviceIPAddress + @"/sony/system"); httpWebRequest.ContentType = "text/json"; httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = "{\"id\":19,\"method\":\"getSystemSupportedFunction\",\"version\":\"1.0\",\"params\":[]}\""; streamWriter.Write(json); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var responseText = streamReader.ReadToEnd(); dataSet = JsonConvert.DeserializeObject<SonyCommandList>(responseText); } string first = dataSet.result[0].ToString(); List<SonyOption> bal = JsonConvert.DeserializeObject<List<SonyOption>>(first); macaddress = bal.Find(x => x.option.ToLower() == "WOL".ToLower()).value.ToString(); Log.Debug("Auto3D: Device Mac Address: " + macaddress); return macaddress; }
/// <summary> /// This method will retrieve Gen1 and Gen2 XML IRCC Command List or Gen3 JSON Command List. /// </summary> /// <returns>Returns a string containing the contents of the returned XML Command List for your Use</returns> /// <remarks>This method will also populate the SonyDevice.Commands object list with the retrieved command list</remarks> public string get_remote_command_list() { string cmdList = ""; if (Generation <= 2) { Log.Debug(Name + " is Retrieving Generation:" + Generation + " Remote Command List"); cmdList = HttpGet(getActionlist("getRemoteCommandList", actionListURL)); if (cmdList != "") { Log.Debug("Retrieve Command List was Successful"); DataSet CommandList = new DataSet(); System.IO.StringReader xmlSR = new System.IO.StringReader(cmdList); CommandList.ReadXml(xmlSR, XmlReadMode.Auto); DataTable IRCCcmd = new DataTable(); var items = CommandList.Tables[0].AsEnumerable().Select(r => new SonyCommands { name = r.Field<string>("name"), value = r.Field<string>("value") }); var itemlist = items.ToList(); Commands = itemlist; Log.Debug(Name + " Commands have been Populated"); } else { Log.Error("Retrieve Command List was NOT successful"); } } else { Log.Debug(Name + " is Retrieving Generation:" + Generation + " Remote Command List"); var httpWebRequest = (HttpWebRequest)WebRequest.Create(@"http://" + DeviceIPAddress + @"/sony/system"); httpWebRequest.ContentType = "text/json"; httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = "{\"id\":20,\"method\":\"getRemoteControllerInfo\",\"version\":\"1.0\",\"params\":[]}"; streamWriter.Write(json); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var responseText = streamReader.ReadToEnd(); cmdList = responseText; if (cmdList != "") { Log.Debug("Response Returned: " + cmdList); Log.Debug("Retrieve Command List was successful"); } else { Log.Error("Retrieve Command List was NOT successful"); } dataSet = JsonConvert.DeserializeObject<SonyCommandList>(responseText); } string first = dataSet.result[1].ToString(); List<SonyCommands> bal = JsonConvert.DeserializeObject<List<SonyCommands>>(first); Commands = bal; Log.Debug(Name + " Commands have been Populated: " + Commands.Count().ToString()); } return cmdList; }
/// <summary> /// This method Gets the current Status of the device /// </summary> /// <returns>Returns the device response as a string</returns> public string checkStatus() { string retstatus = ""; if (Generation != 3) { try { Log.Debug("Auto3D: Checking Status of Device " + Name); string cstatus; int x; cstatus = HttpGet(getActionlist("getStatus", actionListURL)); cstatus = cstatus.Replace("/n", ""); x = cstatus.IndexOf("name="); cstatus = cstatus.Substring(x + 6); x = cstatus.IndexOf("\""); string sname = cstatus.Substring(0, x); cstatus = cstatus.Substring(x); x = cstatus.IndexOf("value="); cstatus = cstatus.Substring(x + 7); x = cstatus.IndexOf("\""); string sval = cstatus.Substring(0, x); retstatus = sname + ":" + sval; Log.Debug("Auto3D: Device returned a Status of: " + retstatus); } catch (Exception ex) { Log.Error("Auto3D: Checking Device Status for " + Name + " failed!"); Log.Error("Auto3D: " + ex.Message); retstatus = ""; } } else { try { Log.Debug("Auto3D: Checking Status of Device " + Name); var httpWebRequest = (HttpWebRequest)WebRequest.Create(@"http://" + DeviceIPAddress + @"/sony/system"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = "{\"id\":19,\"method\":\"getPowerStatus\",\"version\":\"1.0\",\"params\":[]}\""; streamWriter.Write(json); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var responseText = streamReader.ReadToEnd(); dataSet = JsonConvert.DeserializeObject<SonyCommandList>(responseText); } string first = dataSet.result[0].ToString(); first = first.Replace("{", ""); first = first.Replace("\"", ""); retstatus = first; Log.Debug("Auto3D: Device returned a Status of: " + retstatus); } catch (Exception ex) { Log.Error("Auto3D: Checking Device Status for " + Name + " failed!"); Log.Error("Auto3D: " + ex.Message); retstatus = ""; } } return retstatus; }
/// <summary> /// This method Gets the current Status of the device /// </summary> /// <returns>Returns the device response as a string</returns> public string checkStatus() { string retstatus = ""; if (Generation != 3) { try { Log.Debug("Auto3D: Checking Status of Device " + Name); string cstatus; int x; cstatus = HttpGet(getActionlist("getStatus", actionListURL)); cstatus = cstatus.Replace("/n", ""); x = cstatus.IndexOf("name="); cstatus = cstatus.Substring(x + 6); x = cstatus.IndexOf("\""); string sname = cstatus.Substring(0, x); cstatus = cstatus.Substring(x); x = cstatus.IndexOf("value="); cstatus = cstatus.Substring(x + 7); x = cstatus.IndexOf("\""); string sval = cstatus.Substring(0, x); retstatus = sname + ":" + sval; Log.Debug("Auto3D: Device returned a Status of: " + retstatus); } catch (Exception ex) { Log.Error("Auto3D: Checking Device Status for " + Name + " failed!"); Log.Error("Auto3D: " + ex.Message); retstatus = ""; } } else { try { Log.Debug("Auto3D: Checking Status of Device " + Name); var httpWebRequest = (HttpWebRequest)WebRequest.Create(@"http://" + DeviceIPAddress + @"/sony/system"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = "{\"id\":19,\"method\":\"getPowerStatus\",\"version\":\"1.0\",\"params\":[]}\""; streamWriter.Write(json); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var responseText = streamReader.ReadToEnd(); dataSet = JsonConvert.DeserializeObject <SonyCommandList>(responseText); } string first = dataSet.result[0].ToString(); first = first.Replace("{", ""); first = first.Replace("\"", ""); retstatus = first; Log.Debug("Auto3D: Device returned a Status of: " + retstatus); } catch (Exception ex) { Log.Error("Auto3D: Checking Device Status for " + Name + " failed!"); Log.Error("Auto3D: " + ex.Message); retstatus = ""; } } return(retstatus); }
/// <summary> /// This method will retrieve Gen1 and Gen2 XML IRCC Command List or Gen3 JSON Command List. /// </summary> /// <returns>Returns a string containing the contents of the returned XML Command List for your Use</returns> /// <remarks>This method will also populate the SonyDevice.Commands object list with the retrieved command list</remarks> public string get_remote_command_list() { string cmdList = ""; if (Generation <= 2) { Log.Debug(Name + " is Retrieving Generation:" + Generation + " Remote Command List"); cmdList = HttpGet(getActionlist("getRemoteCommandList", actionListURL)); if (cmdList != "") { Log.Debug("Retrieve Command List was Successful"); DataSet CommandList = new DataSet(); System.IO.StringReader xmlSR = new System.IO.StringReader(cmdList); CommandList.ReadXml(xmlSR, XmlReadMode.Auto); DataTable IRCCcmd = new DataTable(); var items = CommandList.Tables[0].AsEnumerable().Select(r => new SonyCommands { name = r.Field <string>("name"), value = r.Field <string>("value") }); var itemlist = items.ToList(); Commands = itemlist; Log.Debug(Name + " Commands have been Populated"); } else { Log.Error("Retrieve Command List was NOT successful"); } } else { Log.Debug(Name + " is Retrieving Generation:" + Generation + " Remote Command List"); var httpWebRequest = (HttpWebRequest)WebRequest.Create(@"http://" + DeviceIPAddress + @"/sony/system"); httpWebRequest.ContentType = "text/json"; httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = "{\"id\":20,\"method\":\"getRemoteControllerInfo\",\"version\":\"1.0\",\"params\":[]}"; streamWriter.Write(json); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var responseText = streamReader.ReadToEnd(); cmdList = responseText; if (cmdList != "") { Log.Debug("Response Returned: " + cmdList); Log.Debug("Retrieve Command List was successful"); } else { Log.Error("Retrieve Command List was NOT successful"); } dataSet = JsonConvert.DeserializeObject <SonyCommandList>(responseText); } string first = dataSet.result[1].ToString(); List <SonyCommands> bal = JsonConvert.DeserializeObject <List <SonyCommands> >(first); Commands = bal; Log.Debug(Name + " Commands have been Populated: " + Commands.Count().ToString()); } return(cmdList); }