/// <summary>
        /// Send a code with a specific controller
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static async Task <bool> Send(this IRCCCodes code, IRCCController controller)
        {
            if (controller == null)
            {
                throw new InvalidDataException("A controller must be defined");
            }

            return(await controller.Send(code));
        }
        /// <summary>
        /// Get the code value
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string GetCode(this IRCCCodes code)
        {
            MemberInfo memberInfo = typeof(IRCCCodes).GetMember(code.ToString())
                                    .FirstOrDefault();

            if (memberInfo != null)
            {
                IRCCCodeAttribute attribute = (IRCCCodeAttribute)
                                              memberInfo.GetCustomAttributes(typeof(IRCCCodeAttribute), false)
                                              .FirstOrDefault();
                return(attribute.Code);
            }

            return(null);
        }
예제 #3
0
        /// <summary>
        /// Send an IRCC control code to the device
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public async Task <bool> Send(IRCCCodes code)
        {
            string         parameters = string.Format(_soapEnvelopeTemplate, code.GetCode());
            HttpWebRequest req        = (HttpWebRequest)WebRequest.Create(Url);

            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;

            req.Headers.Add("SOAPAction", "\"urn:schemas-sony-com:service:IRCC:1#X_SendIRCC\"");
            req.Headers.Add("X-Auth-PSK", PinCode);

            try
            {
                bool isOK;
                using (Stream os = req.GetRequestStream())
                {
                    // Post data and close connection
                    os.Write(bytes, 0, bytes.Length);
                    using (HttpWebResponse resp = (await req.GetResponseAsync()) as HttpWebResponse)
                    {
                        isOK = resp.StatusCode == HttpStatusCode.OK;

                        //using (Stream respData = resp.GetResponseStream())
                        //{
                        //    using (StreamReader sr = new StreamReader(respData))
                        //    {
                        //        string response = sr.ReadToEnd();
                        //    }
                        //}
                    }
                }

                return(isOK);
            }
            catch (Exception ex) {  }

            return(false);
        }