public void Delete(ExecutedCommand executedCommand) { _history?.RemoveAll(c => string.Equals(c.Value, executedCommand.Value, StringComparison.OrdinalIgnoreCase)); _historyContainer.Delete(GetHash(executedCommand.Value)); Messenger.Default.Send(new CommandHistoryChangedMessage()); }
public void ExecuteCommand(ExecutedCommand command, bool partOfMultiCommand) { if (command.Command is BaseCommand) { var commandToRun = (BaseCommand)command.Command; command.Handled = commandToRun.Execute(command, partOfMultiCommand); } }
public void MarkUsed(ShellProfile profile) { var history = GetRawHistory(); var existing = history.FirstOrDefault(c => string.Equals(c.Value, profile.Name, StringComparison.OrdinalIgnoreCase)); if (existing == null) { existing = new ExecutedCommand { Value = profile.Name, IsProfile = GetAllProfiles().Any(p => string.Equals(p.Name, profile.Name, StringComparison.OrdinalIgnoreCase)) }; if (!existing.IsProfile) { existing.ShellProfile = profile; } var overflow = history.Count - MaxHistory + 1; if (overflow > 0) { // We already have max number of commands in history, so we need to delete some // Let's first try with cleanup CleanupHistory(); overflow = history.Count - MaxHistory + 1; if (overflow > 0) { // We will remove the oldest commands var toRemove = history.OrderBy(c => c.LastExecution).ThenBy(c => c.ExecutionCount) .Take(overflow).ToList(); foreach (var command in toRemove) { history.Remove(command); Delete(command); } } } history.Add(existing); } existing.LastExecution = DateTime.UtcNow; existing.ExecutionCount++; Save(existing); }
private void CommandTextBox_OnQuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args) { _lastChosenCommand = null; if (args.ChosenSuggestion is CommandItemViewModel commandItem) { var executedCommand = ViewModel.Commands.FirstOrDefault(c => c.ExecutedCommand.Value.Equals(commandItem.ExecutedCommand.Value, StringComparison.OrdinalIgnoreCase))?.ExecutedCommand; if (executedCommand != null) { ViewModel.SetProfile(executedCommand.ShellProfile.Clone()); } } }
public override bool Execute(ExecutedCommand command, bool partOfMultiCommand) { if (command.Arguments.Count == 0) { ConsoleWindow3.SendConsoleResponse($"Modloader v{Loader.MOD_LOADER_VERSION} by juanmuscaria", ConsoleMessageType.SpecialInfo); ConsoleWindow3.SendConsoleResponse("Use modloader mods to list all installed mods", ConsoleMessageType.SpecialInfo); } else { if (command.Arguments[0].ToLower().Equals("mods")) { ConsoleWindow3.SendConsoleResponse($"Modloader v{Loader.MOD_LOADER_VERSION} by juanmuscaria", ConsoleMessageType.SpecialInfo); if (Loader.LoadedMods.Count > 0) { foreach (var mod in Loader.LoadedMods) { var info = ModInfo.OfMod(mod); ConsoleWindow3.SendConsoleResponse("--------------------", ConsoleMessageType.SpecialInfo); ConsoleWindow3.SendConsoleResponse($"Mod name: {info.name}", ConsoleMessageType.SpecialInfo); ConsoleWindow3.SendConsoleResponse($"Mod description: {info.description}", ConsoleMessageType.SpecialInfo); ConsoleWindow3.SendConsoleResponse($"Mod version: {info.version}", ConsoleMessageType.SpecialInfo); } ConsoleWindow3.SendConsoleResponse("--------------------", ConsoleMessageType.SpecialInfo); } else { ConsoleWindow3.SendConsoleResponse("You have no mod installed :(", ConsoleMessageType.Error); } } else { ConsoleWindow3.SendConsoleResponse($"Modloader v{Loader.MOD_LOADER_VERSION} by juanmuscaria", ConsoleMessageType.SpecialInfo); ConsoleWindow3.SendConsoleResponse("Unknown subcommand " + command.Arguments[0].ToLower(), ConsoleMessageType.Error); } } return(true); }
public List <ExecutedCommand> GetAll() { var commands = GetAllPrivate(); for (var i = 0; i < commands.Count; i++) { var command = commands[i]; if (command.ShellProfile == null) { continue; } var newProfile = MoshBackwardCompatibility.FixProfile(command.ShellProfile); if (ReferenceEquals(command.ShellProfile, newProfile)) { continue; } if (!command.IsProfile) { newProfile.Name = $"{newProfile.Location} {newProfile.Arguments}".Trim(); } var newCommand = new ExecutedCommand { Value = newProfile.Name, IsProfile = command.IsProfile, LastExecution = command.LastExecution, ExecutionCount = command.ExecutionCount, ShellProfile = newProfile }; commands.Insert(i, newCommand); commands.RemoveAt(i + 1); Delete(command); Save(newCommand); } return(commands); }
private void FixMoshBackwardCompatibility(List <ExecutedCommand> commands) { for (var i = 0; i < commands.Count; i++) { var command = commands[i]; if (command.ShellProfile == null) { continue; } var newProfile = MoshBackwardCompatibility.FixProfile(command.ShellProfile); if (ReferenceEquals(command.ShellProfile, newProfile)) { continue; } if (!command.ProfileId.HasValue) { newProfile.Name = $"{newProfile.Location} {newProfile.Arguments}".Trim(); } var newCommand = new ExecutedCommand { Value = newProfile.Name, ProfileId = command.ProfileId, LastExecution = command.LastExecution, ExecutionCount = command.ExecutionCount, ShellProfile = newProfile }; commands.Insert(i, newCommand); commands.RemoveAt(i + 1); Delete(command); Save(newCommand); } }
public bool TryGetCommand(string value, out ExecutedCommand executedCommand) { var found = TryGetCommandPrivate(value, out executedCommand); if (!found || executedCommand?.ShellProfile == null) { return(found); } var newProfile = MoshBackwardCompatibility.FixProfile(executedCommand.ShellProfile); if (ReferenceEquals(executedCommand.ShellProfile, newProfile)) { return(true); } if (!executedCommand.IsProfile) { newProfile.Name = $"{newProfile.Location} {newProfile.Arguments}".Trim(); } var newCommand = new ExecutedCommand { Value = newProfile.Name, IsProfile = executedCommand.IsProfile, LastExecution = executedCommand.LastExecution, ExecutionCount = executedCommand.ExecutionCount, ShellProfile = newProfile }; Delete(executedCommand); Save(newCommand); executedCommand = newCommand; return(true); }
private bool TryGetCommandPrivate(string value, out ExecutedCommand executedCommand) { var key = GetHash(value); executedCommand = null; if (!_historyContainer.TryGetValue(key, out var cmd)) { return(false); } if (cmd is string cmdStr) { try { executedCommand = JsonConvert.DeserializeObject <ExecutedCommand>(cmdStr); return(true); } catch { // ignored } } else if (cmd is ExecutedCommand execCmd) { executedCommand = execCmd; return(true); } // Not a valid command, so delete it: _historyContainer.Delete(key); return(false); }
public static async Task <ExecutionStatus> InvokeNamedParams(BaseContext context, ExecutedCommand executedCommand) { var parameters = await MapParameters(executedCommand.ParameterInfo, context.Request).ConfigureAwait(false); return(await Invoke(executedCommand : executedCommand, context : context, parameters : parameters).ConfigureAwait(false)); }
public virtual async Task <ExecutionStatus> ActionExecuting(ExecutedCommand executedCommand) { return(await InvokeNamedParams(Context, executedCommand).ConfigureAwait(false)); }
private void CommandTextBox_OnSuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args) { _lastChosenCommand = (args.SelectedItem as CommandItemViewModel)?.ExecutedCommand; }
//private RelayCommand m_TryUrlCommand; //public ICommand TryUrlCommand //{ // get { return m_TryUrlCommand ?? (m_TryUrlCommand = new RelayCommand(x => TryUrl())); } //} public ExecutedCommandDataElement(ExecutedCommand command) { Command = command; }
//This method is called when your command is executed //Return true if the command was handled. //Returning false will continue the search for any other command matching the same name as yours public override bool Execute(ExecutedCommand command, bool partOfMultiCommand) { ConsoleWindow3.SendConsoleResponse("An example command from ExampleMod1", ConsoleMessageType.SpecialInfo); return(true); }
public async Task RequestProcessing() { //Listener.AcceptSocketAsync using (TcpClient client = await TcpListener.AcceptTcpClientAsync().ConfigureAwait(false)) { Logger.LogInformation($"New connection from: {client.Client.RemoteEndPoint}"); // Get a stream object for reading and writing using (NetworkStream netStream = client.GetStream()) { // Stream Checks ================================================================= if (!netStream.CanRead) { Logger.LogCritical("Can Not Read Stream".ToErrorString(this)); netStream.Close(); client.Close(); return; } if (!netStream.CanWrite) { Logger.LogCritical("Can Not Write To The Stream".ToErrorString(this)); netStream.Close(); client.Close(); return; } // Stream Checks ================================================================= ExecutedCommand executedCommand = null; Request request = null; Exception exception = null; try { #if DEBUG request = await Request.BuildRequest(netStream, Settings.RequestSettings, ServiceProvider.GetRequiredService <ILogger <Request> >()).ConfigureAwait(false); //request.LogPacket(); #else request = await Request.BuildRequest(netStream, Settings.RequestSettings).ConfigureAwait(false); #endif } catch (MalformedRequestException MalformedRequestException) { exception = MalformedRequestException; } if (request is not null && RequestedEndpoint(request) is ExecutedCommand executedCommand1) { executedCommand = executedCommand1; } var response = new Response(Settings.ResponseSettings); var middleware = ContextBuilder.CreateContext(executedCommand?.ClassExecuted, Middleware, netStream, request, response, ServiceProvider); object bodyContent; bool isReturnTypeVoid = false; if (exception is not null) { bodyContent = await middleware.BadRequest(exception).ConfigureAwait(false); } else if (executedCommand is null) { bodyContent = await middleware.NotFound(request).ConfigureAwait(false); } else { try { var temp = await middleware.ActionExecuting(executedCommand).ConfigureAwait(false); isReturnTypeVoid = temp.IsReturnTypeVoid; bodyContent = temp.ReturnValue; } catch (IOException) { throw; } catch (Exception ex) { bodyContent = await middleware.InternalServerError(ex).ConfigureAwait(false); } } await middleware.Context.WriteBodyAsync(isReturnTypeVoid, bodyContent).ConfigureAwait(false); } } }
/// <summary> /// This method is executed when your command is called by the user /// </summary> /// <param name="command">The context of the current executed command</param> /// <param name="partOfMultiCommand">true if the command is part of a multi command execution</param> /// <returns> /// true if the command was handled. returning false will continue the search for any other command matching the /// same name /// </returns> public abstract bool Execute(ExecutedCommand command, bool partOfMultiCommand);
private void Save(ExecutedCommand executedCommand) { _historyContainer.WriteValueAsJson(GetHash(executedCommand.Value), executedCommand); Messenger.Default.Send(new CommandHistoryChangedMessage()); }
public void Delete(ExecutedCommand executedCommand) => _historyContainer.Delete(GetHash(executedCommand.Value));
public void Save(ExecutedCommand executedCommand) => _historyContainer.WriteValueAsJson(GetHash(executedCommand.Value), executedCommand);
public void MarkUsed(ShellProfile profile) { var history = GetRawHistory(); var existing = history.FirstOrDefault(c => c.ProfileId?.Equals(profile.Id) ?? string.Equals(profile.Name, c.Value, StringComparison.OrdinalIgnoreCase)); if (existing == null) { if (string.IsNullOrEmpty(profile.Name)) { profile.Name = $"{profile.Location} {profile.Arguments}".Trim(); } existing = new ExecutedCommand { Value = profile.Name }; if (_settingsService.GetAllProfiles().Any(p => p.Id.Equals(profile.Id))) { existing.ProfileId = profile.Id; } else { existing.ShellProfile = profile; } var overflow = history.Count - MaxHistory + 1; if (overflow > 0) { // We already have max number of commands in history, so we need to delete some // Let's first try with cleanup CleanupHistory(); overflow = history.Count - MaxHistory + 1; if (overflow > 0) { // We will remove the oldest commands var toRemove = history.OrderBy(c => c.LastExecution).ThenBy(c => c.ExecutionCount) .Take(overflow).ToList(); foreach (var command in toRemove) { history.Remove(command); Delete(command); } } } history.Add(existing); } existing.LastExecution = DateTime.UtcNow; existing.ExecutionCount++; Save(existing); }
public void Execute(object parameter) { ExecutedCommand?.Invoke(); }
protected override BaseLeafTreeElement CreateLeaf(TreeElementViewModel parent, ExecutedCommand item, IEnumerable<CriteriaEnum> criteres) { return new ExecutedCommandLeaf(parent, criteres, SearchCriteria, LogCategoryEnum.ExecutedCommand, item); }
public override void ExecuteCommand(ExecutedCommand command, bool partOfMultiCommand) { var commandName = command.Command.CommandName; if (commandName != CommandValue) { return; } command.Handled = true; if (command.Arguments.Count == 0 || command.Arguments.Count != 2 && command.Arguments[0].ToLower() == "all" || command.Arguments.Count != 1 && command.Arguments[0].ToLower() != "all") { SendConsoleResponseMessage("invalid command. Ex: remotedoor 1 d23", ConsoleMessageType.Warning); } else { var instance = DungeonManager.Instance; Door door1 = null; var lower = command.Arguments.Last().ToLower(); foreach (var door2 in instance.doors) { if (door2.LabelSimple.ToLower() == lower) { door1 = door2; break; } } if (door1 != null && door1.corridor.containsRoom(drone.CurrentRoom)) { var bounds = door1.corridor.GetComponent <Collider>().bounds; bounds.Expand(new Vector3(0.3f, 0.3f, 0.3f)); if (bounds.Intersects(drone.GetComponent <Collider>().bounds)) { if (door1.powered) { SendConsoleResponseMessage("door already powered: " + lower, ConsoleMessageType.Info); } else { if (Quantity <= 0 || !UpgradeUsed()) { SendConsoleResponseMessage("charges depleted, unable to power door", ConsoleMessageType.Warning); return; } Quantity--; SendConsoleResponseMessage("powered door: " + lower, ConsoleMessageType.Benefit); door1.power(true); DroneManager.Instance.currentDronePanel.UpgradesChanged = true; } } else { drone.NavigateToAndExecuteCommand(door1.corridor.gameObject, command, CollisionType.BoundsIntesect); } } else { SendConsoleResponseMessage("specified door not found: " + lower, ConsoleMessageType.Warning); } } }