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); }
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 ShellProfile MoshBackwardCompatibilityFixProfile(ShellProfile profile) { var fixedProfile = MoshBackwardCompatibility.FixProfile(profile); if (ReferenceEquals(fixedProfile, profile)) { // Nothing changed return(fixedProfile); } if (fixedProfile is SshProfile sshProfile) { DeleteSshProfile(profile.Id); SaveSshProfile(sshProfile); } else { DeleteShellProfile(profile.Id); SaveShellProfile(fixedProfile); } return(fixedProfile); }