Ejemplo n.º 1
0
 /// <summary>
 /// Executes the GetCurrentConnectionIDs action.
 /// </summary>
 /// <param name="parent">Parent Device object to get the Status from.</param>
 /// <returns>Out value for the ConnectionIDs action parameter.</returns>
 public int GetCurrentConnectionIDs(SonyDevice parent)
 {
     if (parent.ConnectionManager.controlURL != null)
         {
             string XMLHead = "<?xml version=\"1.0\"?>" + Environment.NewLine + "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + Environment.NewLine + "<SOAP-ENV:Body>" + Environment.NewLine;
             string XMLFoot = "</SOAP-ENV:Body>" + Environment.NewLine + "</SOAP-ENV:Envelope>" + Environment.NewLine;
             string XML = XMLHead;
             XML += "<m:GetCurrentConnectionIDs xmlns:m=\"urn:schemas-upnp-org:service:ConnectionManager:1\">" + Environment.NewLine;
             XML += "</m:GetCurrentConnectionIDs>" + XMLFoot + Environment.NewLine;
             Socket SocWeb = HelperDLNA.MakeSocket(parent.Device_IP_Address, parent.Device_Port);
             int reqi = parent.RenderingControl.controlURL.IndexOf(":") + 3;
             string req = parent.RenderingControl.controlURL.Substring(reqi);
             reqi = parent.RenderingControl.controlURL.IndexOf(":") + 1;
             req = req.Substring(reqi);
             reqi = req.IndexOf("/") + 1;
             req = req.Substring(reqi);
             string Request = HelperDLNA.MakeRequest("POST", req, XML.Length, "urn:schemas-upnp-org:service:ConnectionManager:1#GetCurrentConnectionIDs", parent.Device_IP_Address, parent.Device_Port) + XML;
             SocWeb.Send(UTF8Encoding.UTF8.GetBytes(Request), SocketFlags.None);
             string GG = HelperDLNA.ReadSocket(SocWeb, true, ref this.ReturnCode);
             GG = Extentions.ChopOffBefore(GG, "<?xml");
             GG = "<?xml" + GG;
             XmlDocument xDoc = new XmlDocument();
             xDoc.LoadXml(GG);
             XmlNode xNode = xDoc.DocumentElement.ChildNodes[0];
             int ret = 0;
             foreach (XmlNode node in xNode.ChildNodes)
             {
                 if (node.InnerText != "")
                 {
                     ret = Convert.ToInt32(node.InnerText);
                 }
             }
             parent.ConnectionManager.sv_LastChange = "GetCurrentConnectionIDs: " + ret.ToString();
             parent.ConnectionManager.sv_ConnectionID = ret;
             return ret;
         }
         return 0;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Executes the SetNextAVTransportURI action.
 /// </summary>
 /// <param name="parent">The Parent Device object to execute this action on.</param>
 /// <param name="instanceID">In value for the InstanceID action parameter.</param>
 /// <param name="nextURI">In value for the NextURI action parameter.</param>
 /// <param name="nextURIMetaData">In value for the NextURIMetaData action parameter.</param>
 public string SetNextAVTransportURI(SonyDevice parent, String nextURI, String nextURIMetaData, UInt32 instanceID = 0)
 {
     if (parent.AVTransport.controlURL != null)
         {
             string XMLHead = "<?xml version=\"1.0\"?>" + Environment.NewLine + "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + Environment.NewLine + "<SOAP-ENV:Body>" + Environment.NewLine;
             string XMLFoot = "</SOAP-ENV:Body>" + Environment.NewLine + "</SOAP-ENV:Envelope>" + Environment.NewLine;
             string XML = XMLHead;
             XML += "<u:SetNextAVTransportURI xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\">" + Environment.NewLine;
             XML += "<InstanceID>" + instanceID + "</InstanceID>" + Environment.NewLine;
             XML += "<NextURI>" + nextURI.Replace(" ", "%20") + "</NextURI>" + Environment.NewLine;
             XML += "<NextURIMetaData>" + nextURIMetaData + "</NextURIMetaData>" + Environment.NewLine;
             XML += "</u:SetNextAVTransportURI>" + Environment.NewLine;
             XML += XMLFoot + Environment.NewLine;
             Socket SocWeb = HelperDLNA.MakeSocket(parent.Device_IP_Address, parent.Device_Port);
             int reqi = parent.AVTransport.controlURL.IndexOf(":") + 3;
             string req = parent.AVTransport.controlURL.Substring(reqi);
             reqi = parent.AVTransport.controlURL.IndexOf(":") + 1;
             req = req.Substring(reqi);
             reqi = req.IndexOf("/") + 1;
             req = req.Substring(reqi);
             string Request = HelperDLNA.MakeRequest("POST", req, XML.Length, "urn:schemas-upnp-org:service:AVTransport:1#SetNextAVTransportURI", parent.Device_IP_Address, parent.Device_Port) + XML;
             SocWeb.Send(UTF8Encoding.UTF8.GetBytes(Request), SocketFlags.None);
             parent.AVTransport.sv_LastChange = "SetNextAVTransportURI";
             parent.AVTransport.sv_NextAVTransportURI = nextURI;
             parent.AVTransport.sv_A_ARG_TYPE_InstanceID = (int)instanceID;
             return HelperDLNA.ReadSocket(SocWeb, true, ref this.ReturnCode);
         }
         return null;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Executes the Stop action.
 /// </summary>
 /// <param name="parent">The Device object to execute the request on</param>
 public string Stop(SonyDevice parent)
 {
     if (parent.AVTransport.controlURL != null)
         {
             string XMLHead = "<?xml version=\"1.0\"?>" + Environment.NewLine + "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + Environment.NewLine + "<SOAP-ENV:Body>" + Environment.NewLine;
             string XMLFoot = "</SOAP-ENV:Body>" + Environment.NewLine + "</SOAP-ENV:Envelope>" + Environment.NewLine;
             string XML = XMLHead;
             XML += "<u:Stop xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>" + InstanceID + "</InstanceID><Speed>1</Speed></u:Stop>" + Environment.NewLine;
             XML += XMLFoot + Environment.NewLine;
             Socket SocWeb = HelperDLNA.MakeSocket(parent.Device_IP_Address, parent.Device_Port);
             int reqi = parent.AVTransport.controlURL.IndexOf(":") + 3;
             string req = parent.AVTransport.controlURL.Substring(reqi);
             reqi = parent.AVTransport.controlURL.IndexOf(":") + 1;
             req = req.Substring(reqi);
             reqi = req.IndexOf("/") + 1;
             req = req.Substring(reqi);
             string Request = HelperDLNA.MakeRequest("POST", req, XML.Length, "urn:schemas-upnp-org:service:AVTransport:1#PStop", parent.Device_IP_Address, parent.Device_Port) + XML;
             SocWeb.Send(UTF8Encoding.UTF8.GetBytes(Request), SocketFlags.None);
             parent.AVTransport.sv_LastChange = "Stop";
             parent.AVTransport.sv_A_ARG_TYPE_InstanceID = (int)InstanceID;
             parent.AVTransport.sv_TransportPlaySpeed = 0;
             return HelperDLNA.ReadSocket(SocWeb, true, ref this.ReturnCode);
         }
         return null;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Method used to retrieve Gen3 Devices Mac Address
 /// </summary>
 /// <returns></returns>
 public string getDeviceMac(SonyDevice mDev)
 {
     String macaddress = "";
     _Log.writetolog("Retrieving the Mac Address from: " + mDev.Name + " at IP: " + mDev.Device_IP_Address, true);
     var httpWebRequest = (HttpWebRequest)WebRequest.Create(@"http://" + mDev.Device_IP_Address + @"/sony/system");
     httpWebRequest.ContentType = "text/json";
     httpWebRequest.Method = "POST";
     SonyCommandList dataSet = new SonyCommandList();
     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.writetolog("Devices Mac Address: " + macaddress, true);
     return macaddress;
 }
Ejemplo n.º 5
0
            /// <summary>
            /// Executes the GetPositionInfo action.
            /// </summary>
            /// <param name="parent">The Parent Device object to execute this action on.</param>
            /// <remarks>Populates the following State Variables: Curent Track, Track Duration, Track Meta Data, Track URI, Relative Time, Absolute Time, Relative Counter and Absolute Counter.</remarks>
            public string GetPosition(SonyDevice parent)
            {
                //Returns the current position for the track that is playing on the DLNA server
                    if (parent.AVTransport.controlURL != null)
                    {
                        string XMLHead = "<?xml version=\"1.0\"?>" + Environment.NewLine + "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + Environment.NewLine + "<SOAP-ENV:Body>" + Environment.NewLine;
                        string XMLFoot = "</SOAP-ENV:Body>" + Environment.NewLine + "</SOAP-ENV:Envelope>" + Environment.NewLine;
                        string XML = XMLHead + "<m:GetPositionInfo xmlns:m=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"ui4\">" + InstanceID + "</InstanceID></m:GetPositionInfo>" + XMLFoot + Environment.NewLine;
                        Socket SocWeb = HelperDLNA.MakeSocket(parent.Device_IP_Address, parent.Device_Port);
                        int reqi = parent.AVTransport.controlURL.IndexOf(":") + 3;
                        string req = parent.AVTransport.controlURL.Substring(reqi);
                        reqi = parent.AVTransport.controlURL.IndexOf(":") + 1;
                        req = req.Substring(reqi);
                        reqi = req.IndexOf("/") + 1;
                        req = req.Substring(reqi);
                        string Request = HelperDLNA.MakeRequest("POST", req, XML.Length, "urn:schemas-upnp-org:service:AVTransport:1#GetPositionInfo", parent.Device_IP_Address, parent.Device_Port) + XML;
                        SocWeb.Send(UTF8Encoding.UTF8.GetBytes(Request), SocketFlags.None);
                        string GG = HelperDLNA.ReadSocket(SocWeb, true, ref this.ReturnCode);
                        GG = Extentions.ChopOffBefore(GG, "<?xml");
                        GG = "<?xml" + GG;
                        XmlDocument xDoc = new XmlDocument();
                        xDoc.LoadXml(GG);
                        XmlNode xNode = xDoc.DocumentElement.ChildNodes[0];
                        foreach (XmlNode node in xNode.ChildNodes)
                        {
                            foreach (XmlNode snode in node.ChildNodes)
                            {
                                if (snode.Name == "Track") { parent.AVTransport.sv_CurrentTrack = Convert.ToInt32(snode.InnerText); }
                                if (snode.Name == "TrackDuration") { parent.AVTransport.sv_CurrentTrackDuration = snode.InnerText; }
                                if (snode.Name == "TrackMetaData") { parent.AVTransport.sv_CurrentTrackMetaData = snode.InnerText; }
                                if (snode.Name == "TrackURI") { parent.AVTransport.sv_CurrentTrackURI = snode.InnerText; }
                                if (snode.Name == "RelTime") { parent.AVTransport.sv_RelativeTimePosition = snode.InnerText; }
                                if (snode.Name == "AbsTimne") { parent.AVTransport.sv_AbsoluteTimePosition = snode.InnerText; }
                                if (snode.Name == "RelCount") { parent.AVTransport.sv_RelativeCounterPosition = snode.InnerText; }
                                if (snode.Name == "AbsCount") { parent.AVTransport.sv_AbsoluteCounterPosition = snode.InnerText; }
                            }
                        }
                        parent.AVTransport.sv_LastChange = "GetPosition";

                    }
                    return null;
            }
Ejemplo n.º 6
0
 /// <summary>
 /// Executes the ListPresets action.
 /// </summary>
 /// <param name="parent">Parent Device object to get the Information from.</param>
 /// <returns>Out value for the CurrentPresetNameList action parameter.</returns>
 public String ListPresets(SonyDevice parent)
 {
     if (parent.RenderingControl.controlURL != null)
         {
             string XMLHead = "<?xml version=\"1.0\"?>" + Environment.NewLine + "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + Environment.NewLine + "<SOAP-ENV:Body>" + Environment.NewLine;
             string XMLFoot = "</SOAP-ENV:Body>" + Environment.NewLine + "</SOAP-ENV:Envelope>" + Environment.NewLine;
             string XML = XMLHead;
             XML += "<m:ListPresets xmlns:m=\"urn:schemas-upnp-org:service:RenderingControl:1\">" + Environment.NewLine;
             XML += "<InstanceID xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"ui4\">" + InstanceID + "</InstanceID>" + Environment.NewLine;
             XML += "</m:ListPresets>" + XMLFoot + Environment.NewLine;
             Socket SocWeb = HelperDLNA.MakeSocket(parent.Device_IP_Address, parent.Device_Port);
             int reqi = parent.RenderingControl.controlURL.IndexOf(":") + 3;
             string req = parent.RenderingControl.controlURL.Substring(reqi);
             reqi = parent.RenderingControl.controlURL.IndexOf(":") + 1;
             req = req.Substring(reqi);
             reqi = req.IndexOf("/") + 1;
             req = req.Substring(reqi);
             string Request = HelperDLNA.MakeRequest("POST", req, XML.Length, "urn:schemas-upnp-org:service:RenderingControl:1#ListPresets", parent.Device_IP_Address, parent.Device_Port) + XML;
             SocWeb.Send(UTF8Encoding.UTF8.GetBytes(Request), SocketFlags.None);
             string GG = HelperDLNA.ReadSocket(SocWeb, true, ref this.ReturnCode);
             GG = Extentions.ChopOffBefore(GG, "<?xml");
             GG = "<?xml" + GG;
             XmlDocument xDoc = new XmlDocument();
             xDoc.LoadXml(GG);
             XmlNode xNode = xDoc.DocumentElement.ChildNodes[0];
             string ret = "";
             foreach (XmlNode node in xNode.ChildNodes)
             {
                 ret += node.InnerText;
             }
             parent.RenderingControl.sv_LastChange = "ListPresets: " + ret;
             parent.RenderingControl.sv_PresetNameList = ret;
             return ret;
         }
         return null;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Executes the SetVolume action.
 /// </summary>
 /// <param name="parent">Parent Device object to Set Volume on.</param>
 /// <param name="desiredVolume">In value for the DesiredVolume action parameter. With range of 0 to 100. Increment of 1.</param>
 public void SetVolume(SonyDevice parent, int desiredVolume)
 {
     if (parent.RenderingControl.controlURL != null)
         {
             string XMLHead = "<?xml version=\"1.0\"?>" + Environment.NewLine + "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + Environment.NewLine + "<SOAP-ENV:Body>" + Environment.NewLine;
             string XMLFoot = "</SOAP-ENV:Body>" + Environment.NewLine + "</SOAP-ENV:Envelope>" + Environment.NewLine;
             string XML = XMLHead;
             XML += "<m:SetVolume xmlns:m=\"urn:schemas-upnp-org:service:RenderingControl:1\">" + Environment.NewLine;
             XML += "<InstanceID xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"ui4\">" + InstanceID + "</InstanceID>" + Environment.NewLine;
             XML += "<Channel xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"string\">" + Channel + "</Channel>" + Environment.NewLine;
             XML += "<DesiredVolume xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"ui2\">" + desiredVolume.ToString() + "</DesiredVolume>" + Environment.NewLine;
             XML += "</m:SetVolume>" + XMLFoot + Environment.NewLine;
             Socket SocWeb = HelperDLNA.MakeSocket(parent.Device_IP_Address, parent.Device_Port);
             int reqi = parent.RenderingControl.controlURL.IndexOf(":") + 3;
             string req = parent.RenderingControl.controlURL.Substring(reqi);
             reqi = parent.RenderingControl.controlURL.IndexOf(":") + 1;
             req = req.Substring(reqi);
             reqi = req.IndexOf("/") + 1;
             req = req.Substring(reqi);
             string Request = HelperDLNA.MakeRequest("POST", req, XML.Length, "urn:schemas-upnp-org:service:RenderingControl:1#SetVolume", parent.Device_IP_Address, parent.Device_Port) + XML;
             SocWeb.Send(UTF8Encoding.UTF8.GetBytes(Request), SocketFlags.None);
             string GG = HelperDLNA.ReadSocket(SocWeb, true, ref this.ReturnCode);
             parent.RenderingControl.sv_LastChange = "SetVolume: " + desiredVolume;
             parent.RenderingControl.sv_Volume = desiredVolume;
             parent.RenderingControl.sv_Channel = "Master";
         }
 }
Ejemplo n.º 8
0
 public List<string> locateDevices()
 {
     SonyDevice fdev = new SonyDevice();
     //if (service == null) { service = "IRCC:1"; }
     _Log.writetolog("UPnP is Discovering devices....", true);
     List<string> foundDevices = new List<string>();
     SonyAPILib.SSDP.Start();
     Thread.Sleep(15000);
     SonyAPILib.SSDP.Stop();
     foreach (string u in SSDP.Servers)
     {
         foundDevices.Add(u);
     }
     _Log.writetolog("Devices Discovered: " + foundDevices.Count.ToString(), true);
     return foundDevices;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Saves a device to a file
 /// </summary>
 /// <param name="path">Full path including File Name: c://temp/device.xml</param>
 /// <param name="dev">The Device Object to save.</param>
 public void DeviceSave(string path, SonyDevice dev)
 {
     XmlSerializer serializer = new XmlSerializer(typeof(SonyDevice));
     FileStream fs = new FileStream(path, FileMode.Create);
     TextWriter writer = new StreamWriter(fs, new UTF8Encoding());
     serializer.Serialize(writer, dev);
     writer.Close();
     string newPath1 = path.Substring(0, path.Length - 4);
     string newPath2 = newPath1 + "_IRCC.xml";
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Executes the XSendIRCC action.
 /// </summary>
 /// <param name="parent">The Parent Device to use.</param>
 /// <param name="irccCode">In value for the IRCCCode action parameter.</param>
 public string XSendIRCC(SonyDevice parent, String irccCode)
 {
     if (parent.IRCC.controlURL != null & parent.Registered == true)
         {
             _Log.writetolog("IRCC Recieved XSendIRCC Command: " + irccCode, false);
             string response = "";
             StringBuilder body = new StringBuilder("<?xml version=\"1.0\"?>");
             body.Append("<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">");
             body.Append("<s:Body>");
             body.Append("<u:X_SendIRCC xmlns:u=\"urn:schemas-sony-com:service:IRCC:1\">");
             body.Append("<IRCCCode>" + irccCode + "</IRCCCode>");
             body.Append("</u:X_SendIRCC>");
             body.Append("</s:Body>");
             body.Append("</s:Envelope>");
             _Log.writetolog("Sending IRCC Command: " + irccCode, true);
             string Url = parent.IRCC.controlURL;
             string Parameters = body.ToString();
             _Log.writetolog("Creating HttpWebRequest to URL: " + Url, true);
             HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Url);
             _Log.writetolog("Sending the following parameter: " + Parameters.ToString(), true);
             byte[] bytes = System.Text.Encoding.UTF8.GetBytes(Parameters);
             req.KeepAlive = true;
             req.Method = "POST";
             req.ContentType = "text/xml; charset=utf-8";
             req.ContentLength = bytes.Length;
             _Log.writetolog("Setting Header Information: " + req.Host.ToString(), false);
             if (parent.Device_Port != 80)
             {
                 req.Host = parent.Device_IP_Address + ":" + parent.Device_Port;
             }
             else
             {
                 req.Host = parent.Device_IP_Address;
             }
             _Log.writetolog("Header Host: " + req.Host.ToString(), false);
             req.UserAgent = "Dalvik/1.6.0 (Linux; u; Android 4.0.3; EVO Build/IML74K)";
             _Log.writetolog("Setting Header User Agent: " + req.UserAgent, false);
             if (parent.Actionlist.RegisterMode == 3)
             {
                 _Log.writetolog("Processing Auth Cookie", false);
                 req.CookieContainer = new CookieContainer();
                 List<SonyCookie> bal = JsonConvert.DeserializeObject<List<SonyCookie>>(parent.Cookie);
                 req.CookieContainer.Add(new Uri(@"http://" + parent.Device_IP_Address + bal[0].Path), new Cookie(bal[0].Name, bal[0].Value));
                 _Log.writetolog("Cookie Container Count: " + req.CookieContainer.Count.ToString(), false);
                 _Log.writetolog("Setting Header Cookie: auth=" + bal[0].Value, false);
             }
             else
             {
                 _Log.writetolog("Setting Header X-CERS-DEVICE-ID: TVSideView-" + parent.Server_Macaddress, false);
                 req.Headers.Add("X-CERS-DEVICE-ID", "TVSideView:" + parent.Server_Macaddress);
             }
             req.Headers.Add("SOAPAction", "\"urn:schemas-sony-com:service:IRCC:1#X_SendIRCC\"");
             if (parent.Actionlist.RegisterMode != 3)
             {
                 req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
                 req.Headers.Add("Accept-Encoding", "gzip, deflate");
             }
             else
             {
                 req.Headers.Add("Accept-Encoding", "gzip");
             }
             _Log.writetolog("Sending WebRequest", false);
             try
             {
                 System.IO.Stream os = req.GetRequestStream();
                 // Post data and close connection
                 os.Write(bytes, 0, bytes.Length);
                 _Log.writetolog("Sending WebRequest Complete", false);
                 // build response object if any
                 _Log.writetolog("Creating Web Request Response", false);
                 System.Net.HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
                 Stream respData = resp.GetResponseStream();
                 StreamReader sr = new StreamReader(respData);
                 response = sr.ReadToEnd();
                 _Log.writetolog("Response returned: " + response, false);
                 os.Close();
                 sr.Close();
                 respData.Close();
                 if (response != "")
                 {
                     _Log.writetolog("Command WAS sent Successfully", true);
                     Thread.Sleep(1000);
                 }
                 else
                 {
                     _Log.writetolog("Command was NOT sent successfully", true);
                 }
                 parent.IRCC.sv_LastChange = response;
             }
             catch
             {
                 _Log.writetolog("Error communicating with device", true);
             }
             return response;
         }
         if (parent.IRCC.controlURL == null)
         {
             _Log.writetolog("ERROR: controlURL for IRCC Service is NULL", true);
         }
         else
         {
             _Log.writetolog("ERROR: Device Registration is FALSE", true);
         }
         _Log.writetolog("Or, this device is not compatiable with this Service!", false);
         return "Error";
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Executes the XGetStatus action.
 /// </summary>
 /// <param name="parent">Parent Device object to get the Status from.</param>
 public string XGetStatus(SonyDevice parent)
 {
     string retstatus = "";
         if (parent.Actionlist.RegisterMode != 3)
         {
             if (parent.Actionlist.getStatus != null)
             {
                 try
                 {
                     _Log.writetolog("Checking Status of Device " + parent.Name, false);
                     string cstatus;
                     int x;
                     //cstatus = HttpGet(parent.Actionlist.getStatus);
                     String Url = parent.Actionlist.getStatus;
                     _Log.writetolog("Creating HttpWebRequest to URL: " + Url, true);
                     HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Url);
                     req.KeepAlive = true;
                     // Set our default header Info
                     _Log.writetolog("Setting Header Information: " + req.Host.ToString(), false);
                     req.Host = parent.Device_IP_Address + ":" + parent.Device_Port;
                     req.UserAgent = "Dalvik/1.6.0 (Linux; u; Android 4.0.3; EVO Build/IML74K)";
                     req.Headers.Add("X-CERS-DEVICE-INFO", "Android4.03/TVSideViewForAndroid2.7.1/EVO");
                     req.Headers.Add("X-CERS-DEVICE-ID", "TVSideView:" + parent.Server_Macaddress);
                     req.Headers.Add("Accept-Encoding", "gzip");
                     try
                     {
                         _Log.writetolog("Creating Web Request Response", false);
                         System.Net.WebResponse resp = req.GetResponse();
                         _Log.writetolog("Executing StreamReader", false);
                         System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
                         cstatus = sr.ReadToEnd().Trim();
                         _Log.writetolog("Response returned: " + cstatus, false);
                         sr.Close();
                         resp.Close();
                         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.writetolog("Device returned a Status of: " + retstatus, true);
                     }
                     catch (Exception e)
                     {
                         _Log.writetolog("There was an error during the Web Request or Response! " + e.ToString(), true);
                     }
                 }
                 catch (Exception ex)
                 {
                     _Log.writetolog("Checking Device Status for " + parent.Name + " Failed!", true);
                     _Log.writetolog(ex.ToString(), true);
                     retstatus = "";
                 }
             }
             else
             {
                 _Log.writetolog("ERROR: getStatusUrl is NULL", true);
                 _Log.writetolog("This device is not compatiable with this Service!", false);
                 return "Error";
             }
         }
         else
         {
             try
             {
                 _Log.writetolog("Checking Status of Device " + parent.Name, false);
                 var httpWebRequest = (HttpWebRequest)WebRequest.Create(@"http://" + parent.Device_IP_Address + @"/sony/system");
                 httpWebRequest.ContentType = "application/json";
                 httpWebRequest.Method = "POST";
                 SonyCommandList dataSet = new SonyCommandList();
                 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.writetolog("Device returned a Status of: " + retstatus, true);
             }
             catch (Exception ex)
             {
                 _Log.writetolog("Check Status Failed: " + ex, true);
             }
         }
         parent.IRCC.sv_LastChange = retstatus;
         parent.IRCC.sv_CurrentStatus = retstatus;
         return retstatus;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Executes the GetProtocolInfo action.
 /// </summary>
 /// <param name="parent">Parent Device object to get the Status from.</param>
 /// <remarks>Populates the following State Variables: Sink and Source</remarks>
 public void GetProtocolInfo(SonyDevice parent)
 {
     if (parent.ConnectionManager.controlURL != null)
        {
            string XMLHead = "<?xml version=\"1.0\"?>" + Environment.NewLine + "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + Environment.NewLine + "<SOAP-ENV:Body>" + Environment.NewLine;
            string XMLFoot = "</SOAP-ENV:Body>" + Environment.NewLine + "</SOAP-ENV:Envelope>" + Environment.NewLine;
            string XML = XMLHead;
            XML += "<m:GetProtocolInfo xmlns:m=\"urn:schemas-upnp-org:service:ConnectionManager:1\">" + Environment.NewLine;
            XML += "</m:GetProtocolInfo>" + XMLFoot + Environment.NewLine;
            Socket SocWeb = HelperDLNA.MakeSocket(parent.Device_IP_Address, parent.Device_Port);
            int reqi = parent.ConnectionManager.controlURL.IndexOf(":") + 3;
            string req = parent.ConnectionManager.controlURL.Substring(reqi);
            reqi = parent.ConnectionManager.controlURL.IndexOf(":") + 1;
            req = req.Substring(reqi);
            reqi = req.IndexOf("/") + 1;
            req = req.Substring(reqi);
            string Request = HelperDLNA.MakeRequest("POST", req, XML.Length, "urn:schemas-upnp-org:service:ConnectionManager:1#GetProtocolInfo", parent.Device_IP_Address, parent.Device_Port) + XML;
            SocWeb.Send(UTF8Encoding.UTF8.GetBytes(Request), SocketFlags.None);
            string GG = HelperDLNA.ReadSocket(SocWeb, true, ref this.ReturnCode);
            GG = Extentions.ChopOffBefore(GG, "<?xml");
            GG = "<?xml" + GG;
            XmlDocument xDoc = new XmlDocument();
            xDoc.LoadXml(GG);
            XmlNode xNode = xDoc.DocumentElement.ChildNodes[0];
            foreach (XmlNode node in xNode.ChildNodes)
            {
                foreach (XmlNode snode in node.ChildNodes)
                {
                    if (snode.Name == "Source") { parent.ConnectionManager.sv_ProticolSource = snode.InnerText; }
                    if (snode.Name == "Sink") { parent.ConnectionManager.sv_ProticolSink = snode.InnerText; }
                }
            }
            parent.ConnectionManager.sv_LastChange = "GetProtocolInfo";
        }
 }