public string Execute(ICommandAccess access, string[] arguments) { var sb = new StringBuilder(); bool hadPrev = false; foreach (string argument in arguments) { if (hadPrev) { sb.AppendLine(""); } string filename = Path.IsPathRooted(argument) ? argument : Path.Combine(access.WorkingDirectory, argument); if (File.Exists(filename)) { var file = new FileInfo(filename); sb.AppendLine(GetInfo(file)); } else if (Directory.Exists(filename)) { var dir = new DirectoryInfo(filename); sb.AppendLine(GetInfo(dir)); } hadPrev = true; } return sb.ToString(); }
public string Execute(ICommandAccess access, string[] arguments) { if (arguments.Length < 1) { return Help(); } string cmd = arguments[0]; if (!Path.IsPathRooted(cmd)) { cmd = Path.Combine(access.WorkingDirectory, cmd); } string retVal = ""; try { retVal += "Opening " + cmd; Process.Start(cmd); } catch (Exception e) { retVal = e.Message; } return retVal; }
public string Execute(ICommandAccess access, string[] arguments) { if (arguments.Length < 1) { return List(access.History); } for (int i = 0; i < arguments.Length; i++) { string arg = arguments[i]; if (arg == "search" || arg == "s") { string criteria = (i + 1 < arguments.Length ? arguments[i + 1] : null); return String.IsNullOrEmpty(criteria) ? Help() : Search(criteria, access.History); } if (arg == "list" || arg == "l") { return List(access.History); } if (arg == "help" || arg == "h") { return Help(); } } return List(access.History); }
public string Execute(ICommandAccess access, string[] arguments) { if (arguments.Length < 1) { return Help(); } foreach (var arg in arguments) { if (arg == "version") { return VersionInfo(); } if (arg == "about") { return About(); } } return Help(); }
public string Execute(ICommandAccess access, string[] arguments) { if (arguments.Length < 1) { return access.WorkingDirectory; } string folder = arguments[0]; // Special case handing for ~ (user home) if (folder == "~") { folder = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); } string dir = Path.GetFullPath(Path.Combine(access.WorkingDirectory, folder)); if (!Directory.Exists(dir)) { return String.Format("Bad path/folder: '{0}' does not exist", dir); } access.SetDirectory(dir); return dir; }
public string Execute(ICommandAccess access, string[] arguments) { return "TEST"; }
public abstract string Execute(ICommandAccess access, string[] arguments);
public override string Execute(ICommandAccess access, string[] arguments) { return ""; }
public string Execute(ICommandAccess access, string[] arguments) { string directory = access.WorkingDirectory; return directory; }
public string Execute(ICommandAccess access, string[] arguments) { access.CloseInstance(); return ""; }
private static bool FinalCall(ICommandAccess commandAccess, string command) { if (String.IsNullOrEmpty(command)) { return false; } return HandleChangeDriveCommand(command, commandAccess); }
public CommandManager(ICommandAccess commandAccess) { _commandAccess = commandAccess; _commandHandlers = new Dictionary<string, ICommand>(5); }
private static bool HandleChangeDriveCommand(string command, ICommandAccess commandAccess) { command = command.Trim(); // Test for a drive path only such as C: or D:) if (command.Length <= 3 && (command.EndsWith(":") || command.EndsWith("\\"))) { DriveInfo[] drives = DriveInfo.GetDrives(); var driveInfo = drives.Where(x => x.Name.StartsWith(command)).FirstOrDefault(); if (driveInfo != null) { commandAccess.SetDirectory(driveInfo.RootDirectory.FullName); commandAccess.AppendOutput("", true, true); return true; } } return false; }
public void SetUp() { _mocks = new MockRepository(); _outputWriter = _mocks.DynamicMock<ICommandAccess>(); _executor = _mocks.DynamicMock<ICommand>(); _commandManager = new CommandManager(_outputWriter); _executor.Expect(x => x.Identifier).Return("test"); }
public string Execute(ICommandAccess access, string[] arguments) { access.ClearOutput(); return ""; }