public MainViewModel(ConnectionViewModel connectionViewModel, TerminalCommand terminalCommand, ControlPanelCommand controlPanelCommand, PidTuningCommand pidTuningCommand, SettingsCommand settingsCommand) { this.ConnectionsViewModel = connectionViewModel; this.TerminalCommand = terminalCommand; this.ControlPanelCommand = controlPanelCommand; this.PidTuningCommand = pidTuningCommand; this.SettingsCommand = settingsCommand; }
void Commands_OnRemove(TerminalCommand obj) { var item = CommandItems.FirstOrDefault(o => o.Model.Equals(obj)); if (item != null) { CommandItems.Remove(item); Destroy(item.gameObject); } }
public void AddHistoricalCommandWithEmptyOutputTest() { var terminalState = new TerminalState(); var terminalCommand = new TerminalCommand { TerminalCommandInput = "testInput", TerminalCommandOutput = string.Empty }; var isHistoryLimitSet = terminalState.TrySetCommandHistoryLimit(10); var isAddHistoricalCommandSuccess = terminalState.TryAddHistoricalCommand(terminalCommand); Assert.IsTrue(isHistoryLimitSet); Assert.IsFalse(isAddHistoricalCommandSuccess); }
public bool TryAddHistoricalCommand(TerminalCommand historicalCommand) { if (historicalCommand == null || string.IsNullOrEmpty(historicalCommand.TerminalCommandInput) || string.IsNullOrEmpty(historicalCommand.TerminalCommandOutput) || _previousTerminalCommands.Count == GetCommandHistoryLimit()) { return(false); } _previousTerminalCommands.Add(historicalCommand); return(true); }
/// <summary> /// Initialize the view model. /// </summary> public AdcpUtilitiesViewModel() : base("ADCP Utilities") { // Set Event Aggregator _events = IoC.Get <IEventAggregator>(); // Compass Cal command CompassCalCommand = ReactiveCommand.Create(); CompassCalCommand.Subscribe(_ => CompassCal()); // Compass Utility command CompassUtilityCommand = ReactiveCommand.Create(); CompassUtilityCommand.Subscribe(_ => _events.PublishOnUIThread(new ViewNavEvent(ViewNavEvent.ViewId.CompassUtilityView))); // Terminal command TerminalCommand = ReactiveCommand.Create(); TerminalCommand.Subscribe(_ => _events.PublishOnUIThread(new ViewNavEvent(ViewNavEvent.ViewId.TerminalView))); // Download command DownloadCommand = ReactiveCommand.Create(); DownloadCommand.Subscribe(_ => _events.PublishOnUIThread(new ViewNavEvent(ViewNavEvent.ViewId.DownloadDataView))); // Upload Firmware command UploadCommand = ReactiveCommand.Create(); UploadCommand.Subscribe(_ => _events.PublishOnUIThread(new ViewNavEvent(ViewNavEvent.ViewId.UpdateFirmwareView))); // Screen data command ScreenCommand = ReactiveCommand.Create(); ScreenCommand.Subscribe(_ => _events.PublishOnUIThread(new ViewNavEvent(ViewNavEvent.ViewId.ScreenDataView))); VmOptionsCommand = ReactiveCommand.Create(); VmOptionsCommand.Subscribe(_ => _events.PublishOnUIThread(new ViewNavEvent(ViewNavEvent.ViewId.VesselMountOptionsView))); // Predicition Model command PredicitionModelCommand = ReactiveCommand.Create(); PredicitionModelCommand.Subscribe(_ => _events.PublishOnUIThread(new ViewNavEvent(ViewNavEvent.ViewId.AdcpPredictionModelView))); // RTI Compass Calibration Model command RtiCompassCalCommand = ReactiveCommand.Create(); RtiCompassCalCommand.Subscribe(_ => _events.PublishOnUIThread(new ViewNavEvent(ViewNavEvent.ViewId.RtiCompassCalView))); // Diagnostics View command DiagnosticsCommand = ReactiveCommand.Create(); DiagnosticsCommand.Subscribe(_ => _events.PublishOnUIThread(new ViewNavEvent(ViewNavEvent.ViewId.DiagnosticView))); // Data Output View command DataOutputCommand = ReactiveCommand.Create(); DataOutputCommand.Subscribe(_ => _events.PublishOnUIThread(new ViewNavEvent(ViewNavEvent.ViewId.DataOutputView))); }
public void HistoricalCommandIsVisibleByDefaultTest() { var terminalState = new TerminalState(); var terminalCommand = new TerminalCommand { TerminalCommandInput = "testInput", TerminalCommandOutput = "testOutput" }; var isHistoryLimitSet = terminalState.TrySetCommandHistoryLimit(10); var isAddSuccess = terminalState.TryAddHistoricalCommand(terminalCommand); var previousCommands = terminalState.GetPreviousTerminalCommands(); var previousCommand = previousCommands.FirstOrDefault(); Assert.IsTrue(isHistoryLimitSet); Assert.IsTrue(isAddSuccess); Assert.IsTrue(previousCommand.IsVisibleInTerminal); }
public void AddHistoricalCommandTest() { var terminalState = new TerminalState(); var terminalCommand = new TerminalCommand { TerminalCommandInput = "testInput", TerminalCommandOutput = "testOutput" }; var isHistoryLimitSet = terminalState.TrySetCommandHistoryLimit(10); var isAddHistoricalCommandSuccess = terminalState.TryAddHistoricalCommand(terminalCommand); var previousCommands = terminalState.GetPreviousTerminalCommands(); Assert.IsTrue(isHistoryLimitSet); Assert.IsTrue(isAddHistoricalCommandSuccess); Assert.IsNotNull(previousCommands); Assert.IsNotEmpty(previousCommands); Assert.IsTrue(previousCommands.Contains(terminalCommand)); }
public static void RegisterCommand() { TerminalCommandMethodInfo MInfo = new TerminalCommandMethodInfo("thanking.connect", "connect a server", typeof(Connect).GetMethod("DoConnection", ReflectionVariables.PublicStatic)); TerminalCommandParameterInfo[] Properties = { new TerminalCommandParameterInfo("IP", "IP of server to connect to", typeof(String), "127.0.0.1"), new TerminalCommandParameterInfo("Port", "Port of server to connect to", typeof(ushort), "27045"), new TerminalCommandParameterInfo("Password", "Password of server to connect to", typeof(String), "") }; TerminalCommand ConnectCommand = new TerminalCommand(MInfo, Properties); Terminal.registerCommand(ConnectCommand); }
public void DoNotRemoveHistoricalCommandWhenUnderLimitTest() { var terminalState = new TerminalState(); var terminalCommand = new TerminalCommand { TerminalCommandInput = "testInput", TerminalCommandOutput = "testOutput" }; var isHistoryLimitSet = terminalState.TrySetCommandHistoryLimit(5); var isAddSuccess = terminalState.TryAddHistoricalCommand(terminalCommand); var isRemoveSuccess = terminalState.TryRemoveOldestHistoricalCommand(); var previousCommands = terminalState.GetPreviousTerminalCommands(); Assert.IsTrue(isHistoryLimitSet); Assert.IsTrue(isAddSuccess); Assert.IsFalse(isRemoveSuccess); Assert.IsTrue(previousCommands.Contains(terminalCommand)); Assert.IsNotEmpty(previousCommands); }
void Commands_OnAdd(TerminalCommand obj) { //inst var instance = (GameObject)Instantiate(CommandPrototype.gameObject); var script = instance.GetComponent <TerminalViewCommand>(); script.Label.text = obj.Label; script.Handler = obj.Method; script.Model = obj; //parent instance.transform.SetParent(CommandLayout.transform); instance.SetActive(true); CommandItems.Add(script); Invoke("ResetCommandScroll", .01f); }
void Commands_OnAdd(TerminalCommand obj) { //inst var instance = Instantiate(CommandPrototype.gameObject); var script = instance.GetComponent <TerminalCommandView>(); script.Label.text = obj.Label; script.Handler = obj.Method; script.Model = obj; //parent instance.transform.SetParent(CommandLayout); //wtf instance.transform.localScale = new Vector3(1, 1, 1); instance.SetActive(true); CommandItems.Add(script); }
public bool Add(TerminalCommand command) { if (command == null) { return(false); } if (string.IsNullOrEmpty(command.TerminalId)) { return(false); } if (!commands.ContainsKey(command.TerminalId)) { var result = commands.TryAdd(command.TerminalId, command); return(result); } return(false); }
public void AddHistoricalCommandWhenAtLimitTest() { var terminalState = new TerminalState(); var underLimitTerminalCommand = new TerminalCommand { TerminalCommandInput = "underLimitInput", TerminalCommandOutput = "underLimitOutput" }; var overLimitTerminalCommand = new TerminalCommand { TerminalCommandInput = "overLimitInput", TerminalCommandOutput = "overLimitOutput" }; var isHistoryLimitSet = terminalState.TrySetCommandHistoryLimit(1); var isUnderLimitAddHistoricalCommandSuccess = terminalState.TryAddHistoricalCommand(underLimitTerminalCommand); var isOverLimitAddHistoricalCommandSuccess = terminalState.TryAddHistoricalCommand(overLimitTerminalCommand); var previousCommands = terminalState.GetPreviousTerminalCommands(); Assert.IsTrue(isHistoryLimitSet); Assert.IsTrue(isUnderLimitAddHistoricalCommandSuccess); Assert.IsFalse(isOverLimitAddHistoricalCommandSuccess); Assert.IsTrue(previousCommands.Contains(underLimitTerminalCommand)); Assert.IsFalse(previousCommands.Contains(overLimitTerminalCommand)); }
void Commands_OnAdd(TerminalCommand obj) { //inst var instance = Instantiate(CommandPrototype.gameObject); var script = instance.GetComponent<TerminalCommandView>(); script.Label.text = obj.Label; script.Handler = obj.Method; script.Model = obj; //parent instance.transform.SetParent(CommandLayout); //wtf instance.transform.localScale = new Vector3(1, 1, 1); instance.SetActive(true); CommandItems.Add(script); }
public static void PopulateTerminalCommands() { Commands = new List <TerminalCommand>(); foreach (var type in ReflectMan.Types) { if (type.GetInterfaces().Contains(typeof(IShiftOSWindow))) { var winopenattrib = type.GetCustomAttributes(false).FirstOrDefault(x => x is WinOpenAttribute) as WinOpenAttribute; if (winopenattrib != null) { var winc = new WinOpenCommand(); winc.CommandType = type; var rupg = type.GetCustomAttributes().FirstOrDefault(x => x is RequiresUpgradeAttribute) as RequiresUpgradeAttribute; if (rupg != null) { winc.Dependencies = rupg.Upgrade; } winc.CommandInfo = new Engine.Command(winopenattrib.ID, "", "Opens the \"" + winopenattrib.ID + " program."); winc.RequiredArguments = new List <string>(); winc.RequiresElevation = false; winc.ShiftOSWindow = type; var ambiguity = Commands.FirstOrDefault(x => x.CommandInfo.name == winc.CommandInfo.name); if (ambiguity != null) { throw new Exception("Ambiguity error. The program " + winc.CommandInfo.name + " collides with another program or terminal command with the same name. Please either change the already-existing program/command, or change this one's WinOpenAttribute value to compensate."); } Commands.Add(winc); } } foreach (var mth in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) { var cmd = mth.GetCustomAttributes(false).FirstOrDefault(x => x is Command); if (cmd != null) { var tc = new TerminalCommand(); tc.RequiresElevation = !(type.GetCustomAttributes(false).FirstOrDefault(x => x is KernelModeAttribute) == null); tc.CommandInfo = cmd as Command; tc.RequiresElevation = tc.RequiresElevation || !(mth.GetCustomAttributes(false).FirstOrDefault(x => x is KernelModeAttribute) == null); tc.RequiredArguments = new List <string>(); foreach (var arg in mth.GetCustomAttributes(false).Where(x => x is RequiresArgument)) { var rarg = arg as RequiresArgument; tc.RequiredArguments.Add(rarg.argument); } var rupg = mth.GetCustomAttributes(false).FirstOrDefault(x => x is RequiresUpgradeAttribute) as RequiresUpgradeAttribute; if (rupg != null) { tc.Dependencies = rupg.Upgrade; } else { tc.Dependencies = ""; } tc.CommandType = type; tc.CommandHandler = mth; var ambiguity = Commands.FirstOrDefault(x => x.CommandInfo.name == tc.CommandInfo.name); if (ambiguity != null) { throw new Exception("Command ambiguity error. You can't have two commands with the same name: " + $"{tc} == {ambiguity}"); } if (!Commands.Contains(tc)) { Commands.Add(tc); } } } } Console.WriteLine("[termdb] " + Commands.Count + " commands found."); }
// Game Loop - Executed Once Per Frame public void Update() { // First, figure out if the user has done anything to modify the input var isUpArrowPressed = Input.GetKeyDown(KeyCode.UpArrow); var isDownArrowPressed = Input.GetKeyDown(KeyCode.DownArrow); var userInputString = Input.inputString; var userInteraction = _userInterfaceController.GetUserInteraction(userInputString, isUpArrowPressed, isDownArrowPressed, _terminalState); // Next, if the user submitted input as part of their interactions, attempt to validate and execute what they submitted if (userInteraction.IsInputSubmitted) { // Need to get the current directory before we execute the command since it could change the current directory var currentDirectory = _fileSystemState.GetCurrentDirectory(); var userInteractionResponse = new StringBuilder(); // Since the user submitted input, we now need to parse that input Debug.Log($"User input submitted: `{userInteraction.SubmittedInput}`"); var isParseInputSuccess = _userInputParser.TryParseUserInput(userInteraction.SubmittedInput, out var parsedUserSubmittedInput); if (!isParseInputSuccess) { Debug.Log($"Failed to parse user input: `{userInteraction.SubmittedInput}`"); } // Extract the arguments into a parameterized array var args = parsedUserSubmittedInput.Arguments?.ToArray(); // Check to see that the we can retrieve the command the user wants to execute from the parsed input var isCommandRetrievedSuccess = _commandController.TryGetCommand(_commandState, parsedUserSubmittedInput.CommandName, out var command); if (!isCommandRetrievedSuccess) { userInteractionResponse.AppendLine($"Command `{parsedUserSubmittedInput.CommandName}` not found."); userInteractionResponse.AppendLine($"Run `{_helpCommandName}` for a list of available commands"); } // Execute the command if we successfully retrieved it // Note - Each command is in charge of its own validation and if / how it executes after succeeding or failing validation else { var commandResponse = command.ExecuteCommand(args); userInteractionResponse.AppendLine(commandResponse); } // Mark that the user's output will change based on this latest terminal command userInteraction.IsOutputModified = true; var terminalCommand = new TerminalCommand { TerminalCommandNumber = _terminalState.GetTerminalCommandSubmissionNumber(), TerminalCommandPath = _directoryController.GetDirectoryPath(currentDirectory), TerminalCommandInput = userInteraction.SubmittedInput, TerminalCommandOutput = userInteractionResponse.ToString(), // If the command was a valid `clear` command, we do not want to show output for it, otherwise we do want output visible IsVisibleInTerminal = command == null || command.GetType() != typeof(ClearCommand) || !command.TryValidateArguments(out _, args) }; _terminalState.IncrementTerminalCommandSubmissionNumber(); // Add the input to the list of historical inputs if it is a valid input (not empty, null, or over the character limit) if (_terminalState.TryValidateInput(userInteraction.SubmittedInput, out var validSubmittedInput)) { var isAddHistoricalInputSuccess = _terminalState.TryAddHistoricalCommand(terminalCommand); if (!isAddHistoricalInputSuccess && _terminalState.TryRemoveOldestHistoricalCommand()) { isAddHistoricalInputSuccess = _terminalState.TryAddHistoricalCommand(terminalCommand); } Debug.Assert(isAddHistoricalInputSuccess, $"Failed to add valid historical input: {validSubmittedInput} with output: {userInteractionResponse}"); } } // Next, if the user has modified input, make sure that is reflected back in the UI if (userInteraction.IsInputModified) { // Grab the current directory after the command has executed, because the command could have changed the current directory var currentDirectory = _fileSystemState.GetCurrentDirectory(); var currentDirectoryPath = _directoryController.GetDirectoryPath(currentDirectory); _userInterfaceController.SetUserInterfaceTextWithInputPrompt(InputTextObject, userInteraction.ModifiedInput, currentDirectoryPath); } // Finally, if the user's input requires a corresponding change in output, reflect that in the UI if (userInteraction.IsOutputModified) { // If a command was submitted, it has already been added to the previous commands with relevant output // We can construct full output to the user with the list of previous commands var previousTerminalCommands = _terminalState.GetPreviousTerminalCommands(); userInteraction.ModifiedOutput = _userInterfaceController.BuildUserInterfaceText(previousTerminalCommands); _userInterfaceController.SetUserInterfaceText(OutputTextObject, userInteraction.ModifiedOutput); } }
void Commands_OnAdd(TerminalCommand obj) { //inst var instance = (GameObject)Instantiate(CommandPrototype.gameObject); var script = instance.GetComponent<TerminalViewCommand>(); script.Label.text = obj.Label; script.Handler = obj.Method; script.Model = obj; //parent instance.transform.SetParent(CommandLayout.transform); instance.SetActive(true); CommandItems.Add(script); Invoke("ResetCommandScroll", .01f); }