public override string Execute(ESmartCommands command) { string result = string.Empty; switch (command) { case ESmartCommands.On: result = "TV turned on!"; break; case ESmartCommands.Off: result = "TV turned off!"; break; case ESmartCommands.ChannelUp: result = "Channel went up!"; break; case ESmartCommands.ChannelDown: result = "Channel went down!"; break; default: result = defaultResult; break; } return(result); }
public SmartObjectExecutionResult Execute(string ipAddress, int port, ESmartCommands command) { SmartObjectExecutionResult result = new SmartObjectExecutionResult(); try { TcpClient client = new TcpClient(ipAddress, port); byte[] data = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(((int)command).ToString())); NetworkStream stream = client.GetStream(); stream.Write(data, 0, data.Length); data = new Byte[256]; string responseData = string.Empty; int bytes = stream.Read(data, 0, data.Length); responseData = Encoding.ASCII.GetString(data, 0, bytes); stream.Close(); client.Close(); result = new SmartObjectExecutionResult(responseData); } catch (Exception e) { AddNotification("Error", e.Message); } return(result); }
public override string Execute(ESmartCommands command) { string result = string.Empty; switch (command) { case ESmartCommands.On: result = "Water Heater turned on!"; break; case ESmartCommands.Off: result = "Water Heater turned off!"; break; case ESmartCommands.TemperatureUp: result = "Temperature went up!"; break; case ESmartCommands.TemperatureDown: result = "Temperature went down!"; break; default: result = defaultResult; break; } return(result); }
public void Listen(IPAddress address, int port, SmartThing smartThing) { try { TcpListener server = new TcpListener(address, port); server.Start(); byte[] bytes = new Byte[256]; string data = null; Console.Clear(); while (true) { Console.WriteLine("Waiting for an action..."); TcpClient client = server.AcceptTcpClient(); Console.WriteLine("Finally! An Action!"); data = null; NetworkStream stream = client.GetStream(); int i; while ((i = stream.Read(bytes, 0, bytes.Length)) != 0) { data = Encoding.ASCII.GetString(bytes, 0, i); ESmartCommands command = JsonConvert.DeserializeObject <ESmartCommands>(data); string response = smartThing.Execute(command); byte[] msg = Encoding.ASCII.GetBytes(response); stream.Write(msg, 0, msg.Length); } client.Close(); } } catch { Console.WriteLine("something went wrong..."); } }
public override string Execute(ESmartCommands command) { string result = string.Empty; switch (command) { case ESmartCommands.On: result = "Light turned on!"; break; case ESmartCommands.Off: result = "Light turned off!"; break; default: result = defaultResult; break; } return(result); }
public override string Execute(ESmartCommands command) { string result = string.Empty; switch (command) { case ESmartCommands.Lock: result = "Locked!"; break; case ESmartCommands.Unlock: result = "Unlocked!"; break; default: result = defaultResult; break; } return(result); }
public abstract string Execute(ESmartCommands command);