예제 #1
0
        private void GetItemAndUpdate <T>(string name, CommandItem item, NameValueCollection customValues = null)
            where T : Enum
        {
            SdcpRequest request = new SdcpRequest("SONY", RequestType.Get)
            {
                Item = item,
            };
            SdcpResponse response = SendRequest(request);

            if (response.Result == SdcpResult.OK)
            {
                if (customValues == null)
                {
                    UpdateDataSource(name, ((T)(object)response.DataValue).GetDescription());
                }
                else
                {
                    UpdateDataSource(name, ((T)(object)response.DataValue).GetDescription(customValues));
                }
            }
            else if (response.Error == SdcpError.NotApplicableItem)
            {
                UpdateDataSource(name, "N/A");
            }
        }
예제 #2
0
        public string RouteAction(string action, object args)
        {
            if (string.IsNullOrEmpty(action))
            {
                return(string.Format(CultureInfo.InvariantCulture, Properties.Resources.FMT_SDCP_ERROR, Properties.Resources.MSG_INVALID_ACTION));
            }

            if (Enum.TryParse(action, out CommandItem item))
            {
                SdcpRequest request = new SdcpRequest("SONY", RequestType.Set)
                {
                    Item = item
                };
                request.SetData(args);

                SdcpResponse response;
                lock (this.lockObject) {
                    response = TrySendRequest(request);
                    this.client.Close();
                }

                if (response.Result == SdcpResult.OK)
                {
                    return(Properties.Resources.MSG_SDCP_OK);
                }
                else
                {
                    return(string.Format(CultureInfo.InvariantCulture, Properties.Resources.FMT_SDCP_ERROR, response.Error.ToString("G")));
                }
            }
            else
            {
                return(string.Format(CultureInfo.InvariantCulture, Properties.Resources.FMT_SDCP_ERROR, Properties.Resources.MSG_INVALID_ACTION));
            }
        }
예제 #3
0
 private SdcpResponse TrySendRequest(SdcpRequest request)
 {
     try {
         return(SendRequest(request));
     } catch {
         return(new SdcpResponse(SdcpResult.ERROR, SdcpError.NetworkErrorTimeout));
     }
 }
예제 #4
0
        private T GetItem <T>(CommandItem item)
            where T : Enum
        {
            SdcpRequest request = new SdcpRequest("SONY", RequestType.Get)
            {
                Item = item,
            };
            SdcpResponse response = SendRequest(request);

            if (response.Result == SdcpResult.OK)
            {
                return((T)(object)response.DataValue);
            }

            return(default);
예제 #5
0
        private SdcpResponse SendRequest(SdcpRequest request)
        {
            // calling thread should have already aquired the lock
            // but grab it again to be safe
            lock (this.lockObject) {
                if ((this.client == null) || this.client.Closed)
                {
                    this.client = new SdcpClient(this.Host, this.Port)
                    {
                        CommandDelay = this.CommandDelay,
                    };
                }
                if (!this.client.Connected)
                {
                    this.client.Connect();
                }

                var result = this.client.Send(request);

                return(result);
            }
        }