Пример #1
0
        // Rename to Get
        public async Task <T> CommandAsync <T>(RemoteCommands command)
        {
            if (_connectedRemoteSystem == null)
            {
                Debug.WriteLine("You are using CommandAsync() but you are not connected to a remote system");
                return(default(T));
            }

            //Debug.WriteLine("Sending " + command + " to " + _connectedRemoteSystem.EndPoint.Address + ":" + _connectedRemoteSystem.EndPoint.Port);
            //string response = await _socketService.SendReceiveMessageAsync(_connectedRemoteSystem.EndPoint, JsonConvert.SerializeObject(new RemoteParameter() { Command = command }));

            var parameter = JsonConvert.SerializeObject(new RemoteParameter()
            {
                Command = command
            });

            string response = await _bluetoothService.GetAsync(parameter);

            if (response == null)
            {
                return(default(T));
            }

            if (typeof(T) == response.GetType())
            {
                return((T)(object)response);
            }

            return(JsonConvert.DeserializeObject <T>(response));
        }
Пример #2
0
        /// <summary>
        /// Executes the specified param.
        /// </summary>
        /// <param name="param">The param.</param>
        /// <param name="result">The result.</param>
        /// <returns></returns>
        public OpResult Execute(string param)
        {
            OpResult opResult = new OpResult();
            try
            {
                XmlDocument doc = new XmlDocument();

                doc.Load(System.Environment.GetEnvironmentVariable("windir") + "\\ehome\\vmcController.xml");

                XmlNodeList commands = doc.DocumentElement.SelectNodes("macros/macro[@id='" + param + "']/action");

                if (commands.Count == 0)
                {
                    opResult.StatusCode = OpStatusCode.Exception;
                    opResult.StatusText = "Macro not found";
                } else
                {
                    RemoteCommands rc = new RemoteCommands();
                    OpResult innerOp;
                    opResult.StatusCode = OpStatusCode.Ok;
                    foreach (XmlNode command in commands)
                    {
                        innerOp = rc.Execute(command.Attributes.GetNamedItem("command").Value,command.InnerText);
                        opResult.StatusText += innerOp.StatusCode.ToString() + ": " + innerOp.StatusText + "<br>";
                    }
                }
            }
            catch (Exception ex)
            {
                opResult.StatusCode = OpStatusCode.Exception;
                opResult.StatusText = ex.Message;
            }
            return opResult;
        }
Пример #3
0
        /// <summary>
        /// Triggered when a node recieves data.
        /// </summary>
        /// <param name="data">The data recieved.</param>
        public void OnDataRecieve(Node node, byte[] data)
        {
            string[] arguments = Encoding.ASCII.GetString(data).Split('\0');
            string   command   = arguments[0].ToLower();

            node.SendData(Encoding.ASCII.GetBytes(RemoteCommands.Handle(command, arguments)));
            node.Socket.Dispose(); // We don't need this connection anymore.
        }
Пример #4
0
        public void Command(RemoteCommands command)
        {
            if (_connectedRemoteSystem == null)
            {
                Debug.WriteLine("You are using CommandAsync() but you are not connected to a remote system");
                return;
            }

            //_socketService.SendMessage(_connectedRemoteSystem.EndPoint, JsonConvert.SerializeObject(new RemoteParameter() { Command = command }));
        }
Пример #5
0
        public GenericRemote(XmlNode settings)
        {
            _remoteName = settings.Attributes["name"].Value;
            XmlNamespaceManager nsMgr = new XmlNamespaceManager(settings.OwnerDocument.NameTable);

            nsMgr.AddNamespace("def", "http://smarthomecontrol.voronin.co.uk");
            CommandLifeTime = int.Parse(settings.Attributes["commandLifeTime"].InnerText);

            foreach (XmlNode node in settings.SelectSingleNode("def:Commands", nsMgr).ChildNodes)
            {
                GenericRemoteCommand com = new GenericRemoteCommand(node, this);
                RemoteCommands.Add(com);
            }
        }
Пример #6
0
        /// <summary>
        /// Executes the specified param.
        /// </summary>
        /// <param name="param">The param.</param>
        /// <param name="result">The result.</param>
        /// <returns></returns>
        public OpResult Execute(string param)
        {
            OpResult opResult = new OpResult();

            try
            {
                XmlDocument doc = new XmlDocument();

                doc.Load(System.Environment.GetEnvironmentVariable("windir") + "\\ehome\\vmcController.xml");

                XmlNodeList commands = doc.DocumentElement.SelectNodes("macros/macro[@id='" + param + "']/action");

                if (commands.Count == 0)
                {
                    opResult.StatusCode = OpStatusCode.Exception;
                    opResult.StatusText = "Macro not found";
                }
                else
                {
                    RemoteCommands rc = new RemoteCommands();
                    OpResult       innerOp;
                    opResult.StatusCode = OpStatusCode.Ok;
                    foreach (XmlNode command in commands)
                    {
                        innerOp              = rc.Execute(command.Attributes.GetNamedItem("command").Value, command.InnerText);
                        opResult.StatusText += innerOp.StatusCode.ToString() + ": " + innerOp.StatusText + "<br>";
                    }
                }
            }
            catch (Exception ex)
            {
                opResult.StatusCode = OpStatusCode.Exception;
                opResult.StatusText = ex.Message;
            }
            return(opResult);
        }
Пример #7
0
 /// <summary>
 /// Constructs a new remote manager.
 /// </summary>
 /// <param name="ip">The IP to listen from.</param>
 /// <param name="port">The port to listen from.</param>
 /// <param name="allowExternal">Whether to allow connections
 /// from locations other than just localhost.</param>
 public RemoteManager(string ip, int port)
 {
     this.Listener = new ConnectionListener(ip, port, this);
     RemoteCommands.LoadCommands();
 }