Exemple #1
0
        public async Task<GWClientResult> ExecuteAsync(Dictionary<string, string> parameters)
        {
            GWClientResult ret = new GWClientResult();

            List<CommsInterface> netInterfaces  = await CommsInterface.GetAllInterfacesAsync();
            
            if (netInterfaces != null)
            {
                
                XElement root = new XElement("NetInterfaces");
                ret.Data.Add(root);
                foreach (CommsInterface netInterface in netInterfaces)
                {
                    XElement item = new XElement("NetInterface");
                    item.Add(new XAttribute("Id", netInterface.NativeInterfaceId));
                    item.Add(new XElement("Name", netInterface.Name));
                    item.Add(new XElement("Ip", netInterface.IpAddress ?? string.Empty));
                    item.Add(new XElement("Gateway", netInterface.GatewayAddress ?? string.Empty));
                    item.Add(new XElement("Broadcast", netInterface.BroadcastAddress ?? string.Empty));
                    item.Add(new XElement("Status", (int)netInterface.ConnectionStatus));
                    item.Add(new XElement("StatusText", netInterface.ConnectionStatus.ToString()));
                    item.Add(new XElement("Usable", (netInterface.IsUsable ? "1" : "0")));
                    item.Add(new XElement("Loopback", (netInterface.IsLoopback ? "1" : "0")));
                    root.Add(item);
                }
                ret.Success = true;
            }
            else
            {
                ret.Message = "Unable to get network interface list !";
            }

            return ret;
        }
Exemple #2
0
        public async Task<GWClientResult> ExecuteAsync(Dictionary<string, string> parameters)
        {
            string host = string.Empty;
            int port = MiLightCommands.DefaultPort;
            string type = string.Empty;
            int grp = 0;
            string cmd = string.Empty;
            string param = string.Empty;
            GWClientResult ret = new GWClientResult();

            if (ParseParameters(parameters, out host, out port, out type, out grp, out cmd, out param))
            {

                if (cmd == C_RQCMD_SCENE)
                {
                    // scene command
                    switch (type)
                    {
                        case C_RQTYPE_WHITE: WhiteScene(host, port, grp, cmd, param); break;
                        case C_RQTYPE_RGBW: RGBWScene(host, port, grp, cmd, param); break;
                    }
                    ret.Success = true;

                }
                else
                {

                    // simple command
                    List<byte[]> miCmd = null;
                    switch (type)
                    {
                        case C_RQTYPE_WHITE: miCmd = WhiteBytes(grp, cmd, param); break;
                        case C_RQTYPE_RGBW: miCmd = RGBWBytes(grp, cmd, param); break;
                    }


                    if (miCmd != null && miCmd.Count > 0)
                    {
                        CancelSceneIfNeed(host, type, grp);
                        await MiLightCommands.SendDataAsync(host, port, miCmd, 100);

                        // add return data 
                        ret.Data.Add(new XElement("Host", host));
                        ret.Data.Add(new XElement("Port", port));
                        XElement xCommands = new XElement("Commands");
                        ret.Data.Add(xCommands);
                        foreach (var command in miCmd)
                        {
                            XElement xCommand = new XElement("Command");
                            foreach (var el in command)
                            {
                                xCommand.Add(new XElement("Value", el));
                            }

                            xCommands.Add(xCommand);
                        }
                        ret.Success = true;
                    }
                }
            }
            else
            {
                ret.Message = "Parsing parameters error !";
            }
            
            return ret;
        }