private string CreateTask(TaskDescriptor description) { DeviceHolder holder = GetHolder(description.DeviceId); if (holder == null) { Console.WriteLine("Creating task for non-existing device {0}", description.DeviceId); return(""); } AutomationTask task = new AutomationTask(holder.Device); if (task.Id == "") { Console.WriteLine("Couldn't create task for {0}", description.DeviceId); return(""); } task.DeviceSensor = description.Condition.SensorType; task.TaskCondition = description.Condition.ComparisonType; task.Value = description.Condition.Target; task.ActionType = description.Action.Type; task.ActionParameter = description.Action.Parameter; Console.WriteLine("New task for {0}", holder.Device.Id); holder.Device.Tasks.Add(task); return(task.Id); }
private void Ping(string deviceId) { DeviceHolder holder = GetHolder(deviceId); if (holder == null) { Console.WriteLine("Ping from non-existing device {0}", deviceId); return; } }
private List <AutomationTask> GetTasks(string deviceId) { DeviceHolder holder = GetHolder(deviceId); if (holder == null) { return(null); } return(holder.Device.Tasks); }
private void Disconnect(string deviceId) { DeviceHolder holder = GetHolder(deviceId); if (holder == null) { Console.WriteLine("Disconnecting non-existing device {0}", deviceId); return; } Console.WriteLine(">>> Disonnect {0}", deviceId); holder.Present = false; }
private void Connect(string deviceId) { DeviceHolder holder = GetHolder(deviceId); if (holder != null) { Console.WriteLine("Reconnecting device {0}", deviceId); holder.Present = true; } else { Console.WriteLine("<<< Connect {0}", deviceId); holders.Add(new DeviceHolder(deviceId)); } }
private void CompleteTask(string taskId) { DeviceHolder holder = GetTaskHolder(taskId); if (holder == null) { Console.WriteLine("Completing task for non-existing device"); return; } if (!holder.Present) { Console.WriteLine("Completing task for non-present device"); } AutomationTask thisTask = null; foreach (var task in holder.Device.Tasks) { if (task.Id != taskId) { continue; } thisTask = task; break; } if (thisTask == null) { Console.WriteLine("Task wasn't found the second time!?"); return; } Console.WriteLine("Task {0} for {1} completed!", taskId, holder.Device.Id); if ((thisTask.ActionType & Action.Indication) == Action.Indication) { /* Do Nothing... */ } if ((thisTask.ActionType & Action.Activation) == Action.Activation) { TaskCompletedMessage data = new TaskCompletedMessage { TaskId = taskId, TaskAction = "activation", Parameter = (string)thisTask.ActionParameter, }; Broadcast(MessageHeaders.TaskCompleted, data); } if ((thisTask.ActionType & Action.Facebook) == Action.Facebook) { Console.WriteLine("Celebrating on facebook (:"); } if ((thisTask.ActionType & Action.Notification) == Action.Notification) { Console.WriteLine("Sending notification to origin device"); } DeleteTask(taskId); }