예제 #1
0
        public void Run()
        {
            AddToLogger("Application run.");

            _table.ClearContent();
            _table.AddRange(GetSubDirectories(_config.Path));
            _table.AddRange(GetFiles(_config.Path));
            _table.SetPage(_config.Page);
            _appUi.Update();

            CommandParser comparser    = new CommandParser(_config);
            ParsedParams  parsedParams = new ParsedParams();

            while (true)
            {
                try
                {
                    parsedParams = comparser.Parse(Console.ReadLine());
                    _appUi.PrintInfo("");

                    switch (parsedParams.Command)
                    {
                    case Commands.CreateFile:
                        var fs = File.Create(parsedParams.InitPath);
                        fs.Close();
                        break;

                    case Commands.CreateDirectory:
                        Directory.CreateDirectory(parsedParams.InitPath);
                        break;

                    case Commands.RemoveFileOrDirectory:
                        RemoveFileOrDirectory(parsedParams.InitPath);
                        break;

                    case Commands.Cd:
                        GoToPath(AddSlash(parsedParams.DestPath), parsedParams.Page);
                        break;

                    case Commands.CopyFile:
                        File.Copy(parsedParams.InitPath, parsedParams.DestPath, true);
                        break;

                    case Commands.CopyDirectory:
                        CopyDirectory(parsedParams.InitPath, parsedParams.DestPath);
                        break;
                    }
                }
                catch (DirNotFoundException e)
                {
                    _appUi.PrintInfo(e.Message);
                    AddToLogger(e.Message);
                }
                catch (InvalidCmdParameterException e)
                {
                    _appUi.PrintInfo(e.Message);
                    AddToLogger(e.Message);
                }
                catch (WrongCmdException e)
                {
                    _appUi.PrintInfo(e.Message);
                    AddToLogger(e.Message);
                }
                catch (IOException e)
                {
                    _appUi.PrintInfo("Ошибка создания файла.");
                    AddToLogger(e.Message);
                }
                catch (Exception e)
                {
                    _appUi.PrintInfo("Неизвестная ошибка.");
                    AddToLogger(e.Message);
                }

                GoToPath(AddSlash(parsedParams.DestPath), parsedParams.Page);
                _appUi.Update();
                _appUi.FocusOnCommandLine();
                AddToLogger($"Path: {_table.Path} ");
                _config = SaveConfig(_config);
            }
        }
예제 #2
0
        public bool Parse(string stringInput, out ICommand parsedCmd)
        {
            parsedCmd = null;


            if (!CommandParser.ParseWithStrArgs(stringInput, names, out string[] cmd) || cmd.Length <= 1 || cmd.Length > 3)