public string ListDevices(DeviceState state) { var sb = new StringBuilder(); foreach (var device in state.DeviceManager.AllDevices()) { sb.Append(Environment.NewLine).Append(device.Category).Append(" ").Append(device.Id); } if (sb.Length > 0) { sb.Insert(0, "Type ID"); return(sb.ToString()); } return("No devices are connected."); }
public string Parse(string command, ref DeviceState state) { var strings = command.Split(" "); switch (strings[0].ToLower()) { case "help": return(HelpText()); case "list": return(ListDevices(state)); case "select": return(SelectDevice(strings[1], ref state)); } return("Command not recognised, type 'help' to see all commands."); }
private string SelectDevice(string id, ref DeviceState state) { var device = state.DeviceManager.GetDevice(id); if (device != null) { state.SelectedDevice = device; switch (device) { case ICamera cam: state.Parser = new CameraCommandParser(); break; } return($"Selected {device.Id}."); } return($"Device {id} not found."); }
public override string Parse(string command, ref DeviceState state) { var cam = state.SelectedDevice as ICamera; if (cam == null) { throw new ArgumentException("Selected Device is null or not a camera."); } var err = base.Parse(command, ref state); double val = 0; var strings = command.Split(" "); try { // If base has handled the command, all of these should fall through. // If it hasn't, then we will get the "Not Recognised" message switch (strings[0].ToLower()) { case "pan": if (TryParse(strings[1], out val, out err)) { return(Pan(cam, val)); } break; case "pitch": if (TryParse(strings[1], out val, out err)) { return(Pitch(cam, val)); } break; case "tilt": if (TryParse(strings[1], out val, out err)) { return(Tilt(cam, val)); } break; case "zoom": if (TryParse(strings[1], out val, out err)) { return(Zoom(cam, val)); } break; case "lookat": if (TryParse(strings.Skip(1).ToArray(), out var values, out err)) { return(LookAt(cam, values)); } break; } } catch (NotSupportedException e) { err = "Operation is not supported on this camera."; } return(err); }