예제 #1
0
        /// <summary>
        /// If command Get contains paramater of Indirect type, then it means we have to
        /// get selection list from receiver.
        /// </summary>
        /// <param name="mdg">MethodDescription</param>
        /// <param name="funcType">FunctionType</param>
        /// <returns>Xelement selection list</returns>
        private XElement GetSelectList(XElement cmdX, MethodDescription mdg, FunctionType funcType)
        {
            XElement result = null;

            if (mdg.Parameters.Count() > 0)
            {
                if (mdg.Parameters.Where(x => x.GetType() == typeof(Indirect)).Count() > 0)
                {
                    string id   = mdg.Parameters.Where(x => x.GetType() == typeof(Indirect)).FirstOrDefault().ID;
                    string path = YNCDefineFuncSelector.SelectCmdFunctionPath(funcType, id);
                    result = (new Communication(this._hostNameOrAddress)).SendYNCCommand(MethodType.GET, path);//.Descendants().Where(x => x.Name.ToString().StartsWith("Item_")).ToList();
                }
                else
                {
                    result = cmdX.Descendants("Get").Descendants().Where(x => x.Name.ToString().StartsWith("Param_")).FirstOrDefault();
                }
            }
            return(result);
        }
예제 #2
0
        public static string SelectCmdFunctionPath(FunctionType funcType, string id)
        {
            string path = null;

            if ((int)funcType <= (int)FunctionType.SysDMCControl)
            {
                path = YNCDefineFuncSelector.SystemFunction(id);
            }
            else if ((int)FunctionType.SubunitInput <= (int)funcType && (int)funcType <= (int)FunctionType.SubunitHDMIStandbyThrough)
            {
                path = YNCDefineFuncSelector.MainZoneFunction(id);
            }
            else if ((int)FunctionType.TunerStatus <= (int)funcType && (int)funcType <= (int)FunctionType.TunerPlayInfoStatusStereo)
            {
                path = YNCDefineFuncSelector.TunerFunction(id);
            }
            else if ((int)FunctionType.AirPlayStatus <= (int)funcType && (int)funcType <= (int)FunctionType.AirPlayPlayInfoInputLogoURL)
            {
                path = YNCDefineFuncSelector.AirPlayFunction(id);
            }
            else if ((int)FunctionType.iPodInit <= (int)funcType && (int)funcType <= (int)FunctionType.iPodListBrowseInfoMaxLine)
            {
                path = YNCDefineFuncSelector.IPodFunction(id);
            }
            else if ((int)FunctionType.USBStatus <= (int)funcType && (int)funcType <= (int)FunctionType.USBListBrowseInfoMaxLine)
            {
                path = YNCDefineFuncSelector.USBFunction(id);
            }
            else if ((int)FunctionType.NETRadioStatus <= (int)funcType && (int)funcType <= (int)FunctionType.NETRadioListBrowseInfoMaxLine)
            {
                path = YNCDefineFuncSelector.NETRadioFunction(id);
            }
            else if ((int)FunctionType.DLNAStatus <= (int)funcType)
            {
                path = YNCDefineFuncSelector.DLNAFunction(id);
            }

            return(path);
        }
예제 #3
0
        /// <summary>
        /// Method sends request to receiver to change status of a function.
        /// </summary>
        /// <param name="funcType">FunctionType enum value</param>
        /// <param name="value">Value to be sent to receiver</param>
        /// <returns>bool</returns>
        public bool SetStatusOf(FunctionType funcType, object value)
        {
            object            funcValue = value;
            string            funcPath  = "";
            bool              result    = false;
            XElement          cmdX      = GetCommandXMLDescription(funcType);
            MethodDescription mdp       = new MethodDescription(cmdX, MethodType.PUT);

            if (VerifyInputParameter(mdp, (string)value))
            {
                if (mdp.PutType == 1) //if <Put_1>
                {
                    //<Put_1> nodes value usually represents value that should be sent.
                    //Usually there can be many <Put_1> nodes for particular command,
                    //but they all have the same ID. So let's take funcPath <Cmd_List> node by ID.
                    if (mdp.Commands.Count() > 0)
                    {
                        Command cmd = mdp.Commands[0];
                        funcPath = YNCDefineFuncSelector.SelectCmdFunctionPath(funcType, cmd.ID);
                    }
                }
                else if (mdp.PutType == 2) //if <Put_2>
                {
                    if (mdp.Commands.Count() > 0)
                    {
                        Command cmd = mdp.Commands[0];

                        if (cmd.Values.Count() > 1)
                        {
                            funcPath = YNCDefineFuncSelector.SelectCmdFunctionPath(funcType, cmd.ID);
                            List <XElement> elements = new List <XElement>();

                            foreach (string s in cmd.Values)
                            {
                                string     tag       = s.EqualSplit(0);
                                string     param_n   = s.EqualSplit(1);
                                XElement   element   = new XElement(tag);
                                IParameter parameter = mdp.FindParameter(param_n);
                                element.Value = (parameter.GetType() == typeof(Range) ? (string)value : parameter.Value);
                                elements.Add(element);
                            }
                            //funcValue is an object type, we set List<XElement> list to it
                            funcValue = elements;
                        }
                        else
                        {
                            //if <Cmd> node value contains only Param_1: <Cmd ID="P3">Param_1</Cmd>
                            //then refer command in <Cmd_List> node by ID
                            if (cmd.Values[0].Equals(Atomics.Param))
                            {
                                funcPath = YNCDefineFuncSelector.SelectCmdFunctionPath(funcType, cmd.ID);
                            }
                            else
                            {
                            }
                        }
                    }
                }

                try
                {
                    XElement resp = (new Communication(this._hostNameOrAddress)).SendYNCCommand(MethodType.PUT, funcPath, funcValue);
                    if (resp.Attribute("RC")?.Value == "0")
                    {
                        result = true;
                    }
                }
                catch {}
            }
            else
            {
                throw new Exception("Parameter is not valid. Acceptable parameters: " + _acceptableParameters);
            }

            return(result);
        }
예제 #4
0
        private XElement GetReceiverList(FunctionType funcType, string id)
        {
            string path = YNCDefineFuncSelector.SelectCmdFunctionPath(funcType, id);

            return((new Communication(this._hostNameOrAddress)).SendYNCCommand(MethodType.GET, path));
        }
예제 #5
0
        /// <summary>
        /// Method sends XML request to receiver about function status. Returned XML response is parsed and its parameter and value
        /// returned as list of OutputParameter objects.
        /// </summary>
        /// <param name="funcType">FunctionType enum value</param>
        /// <returns>List of OutputParameter objects</returns>
        public List <Output> GetStatusOf(FunctionType funcType)
        {
            List <Output> output = new List <Output>();

            //Find XML menu node that contains definitions for function
            XElement cmdX = GetCommandXMLDescription(funcType);

            //Find and parse GET definitions for the function
            MethodDescription mdg = new MethodDescription(cmdX, MethodType.GET);

            //<Get> node may contain only one <Cmd> node which describes function and what parameters it returns.
            //<Get> node also may contain description of returning values in <Param_1>, <Param_2>, <Param_n> nodes.
            //Usually <Get> functions do not have parameters to pass with request. They use "GetParam" keyword as
            //a value for XML request.
            if (mdg.Commands.Count() > 0)
            {
                Command cmd = mdg.Commands[0];

                //<Cmd> node has ID atribute (like ID="G1") which value (G1) referes to request (Get) command in
                //<Cmd_List><Define ID="G1"> node. So we'll take function path from <Cmd_List> by ID.
                //Value of Cmd node just describes from what nodes in response we should get requested value.
                string path = YNCDefineFuncSelector.SelectCmdFunctionPath(funcType, cmd.ID);

                //path contains comma delimited string like this "Main_Zone,Basic_Status". For valid request we should
                //build XML request out of that path - <Main_Zone><Basic_Status>GetParam</Basic_Status></Main_Zone>
                //and send it over to receiver.
                this.UnitResponse = (new Communication(this._hostNameOrAddress)).SendYNCCommand(MethodType.GET, path);


                //Command of <Get> node may look like this: <Cmd Type="Number" ID="P2">Val=Param_1:Exp=Param_2:Unit=Param_3</Cmd>
                //It contains descriptions of three nodes <Val>, <Exp>, <Unit> :"Val=Param_1", "Exp=Param_2", "Unit=Param_3".
                //"Param_" values just refer description of returning data and can be found in <Param_1>, <Param_2>, <Param_3> nodes
                //next to <Cmd> node.
                // <Get>
                //    <Cmd Type="Number" ID="G1">Volume,Lvl,Val=Param_1:Volume,Lvl,Exp=Param_2:Volume,Lvl,Unit=Param_3</Cmd>
                //    <Param_1>
                //        <Range>-805,165,5</Range>
                //    </Param_1>
                //    <Param_2>
                //        <Direct>1</Direct>
                //    </Param_2>
                //    <Param_3>
                //        <Direct>dB</Direct>
                //    </Param_3>
                //</Get>
                foreach (string scmd in cmd.Values)
                {
                    XElement outPar = this.UnitResponse;
                    string[] nodes  = scmd.Split(new string[] { "=", "," }, StringSplitOptions.RemoveEmptyEntries);

                    foreach (string n in nodes)
                    {
                        if (!n.StartsWith("Param", StringComparison.CurrentCultureIgnoreCase))
                        {
                            outPar = outPar.Descendants(n).ToList()[0];
                        }
                    }

                    if (outPar != null)
                    {
                        output.Add(new Output()
                        {
                            ParameterName = outPar.Name.ToString(), Value = outPar.Value
                        });
                    }
                }

                this.SelectionList = GetSelectList(cmdX, mdg, funcType);
            }


            return(output);
        }