Пример #1
0
        /// <summary>
        /// Interprets a command string, executes if an appropriate command is found
        /// and returns all output via the outputter interface.
        /// </summary>
        /// <param name="command">string which is entered, containing the command and the parameters.</param>
        /// <param name="outputter">Implementation of the outputter interface to which the output text is sent.</param>
        public void ExecuteCommand(string command, IOutputter outputter)
        {
            string        cmdName    = ParseCommandName(command);
            List <string> parameters = ParseCommandParameters(command);

            try
            {
                foreach (DosCommand cmd in commands)
                {
                    if (cmd.CompareCommandName(cmdName))
                    {
                        cmd.SetParameters(parameters);
                        if (cmd.CheckParameters(outputter))
                        {
                            cmd.Execute(outputter);
                        }
                        return;
                    }
                }

                outputter.PrintLine("\'" + cmdName + "\' is not recognized as an internal or external command,");
                outputter.PrintLine("operable program or batch file.");
            }
            catch (Exception e)
            {
                outputter.PrintLine(e.Message);
            }
        }
Пример #2
0
        public override void Execute(IOutputter outputter)
        {
            if (GetParameterCount() > 0)
            {
                if (GetParameterCount() == 1 && GetParameterAt(0).Equals("/w", StringComparison.InvariantCultureIgnoreCase))
                {
                    outputter.PrintLine("Microsoft Windows XP [Versi 5.1.2600]");
                    outputter.PrintLine("Igustiawan");
                    outputter.PrintLine("*****@*****.**");
                    //return true;
                }
                else
                {
                    outputter.PrintLine(VER_IS_INVALID);
                    //return false;
                }
            }
            else
            {
                outputter.PrintLine("Microsoft Windows XP [Versi 5.1.2600]");
                //return true;
            }

            //return false;
        }
Пример #3
0
        public override void Execute(IOutputter outputter)
        {
            List <FileSystemItem> content = dirToPrint.Content;

            outputter.PrintLine("Directory of " + dirToPrint.Path);
            outputter.NewLine();

            foreach (FileSystemItem item in content)
            {
                if (item.IsDirectory())
                {
                    outputter.Print("<DIR>");
                }
                else
                {
                    outputter.Print("" + item.GetSize());
                }

                outputter.Print("\t" + item.Name);
                outputter.NewLine();
            }

            outputter.PrintLine("\t" + dirToPrint.GetNumberOfFiles() + " File(s)");
            outputter.PrintLine("\t" + dirToPrint.GetNumberOfDirectories() + " Dir(s)");
        }
Пример #4
0
        /// <summary>
        /// Processes input from the console and invokes the invoker until 'exit' is typed.
        /// </summary>
        public void ProcessInput()
        {
            string line = string.Empty;

            outputter.PrintLine("Zühlke Agile Course [Version 19.1.2010]");
            outputter.PrintLine("(C) Copyright 2006-2010 Rainer Grau and Daniel Tobler.");

            while (line.Trim().Equals("exit", StringComparison.OrdinalIgnoreCase) == false)
            {
                int readChar = 0;
                var input    = new StringBuilder();

                outputter.NewLine();
                outputter.Print(drive.Prompt);
                try
                {
                    while (readChar != '\n')
                    {
                        readChar = System.Console.Read();
                        input.Append((char)readChar);
                    }

                    line = input.ToString();
                }
                catch (IOException)
                {
                    // do nothing by intention
                }

                invoker.ExecuteCommand(line, outputter);
            }

            outputter.PrintLine("\nGoodbye!");
            drive.Save();
        }
Пример #5
0
        public override void Execute(IOutputter outputter)
        {
            string fileName = GetParameters()[0];

            var dirToPrint = Drive.CurrentDirectory;
            var file       = dirToPrint.Content.OfType <Filesystem.File>().Single(f => f.Name == fileName);
            var content    = file.FileContent;

            outputter.PrintLine($"-- Content of {file.Name} --");
            outputter.PrintLine(content);
        }
Пример #6
0
 public override void Execute(IOutputter outputter)
 {
     if (GetParameterCount() > 0)
     {
         outputter.PrintLine(TIME_IS_INVALID);
     }
     else
     {
         outputter.PrintLine("TIME " + System.DateTime.Now.ToString("HH:mm:ss"));
     }
     // return true;
 }
Пример #7
0
 public override void Execute(IOutputter outputter)
 {
     if (GetParameters().Count == 0 || (GetParameters().Count == 1 && GetParameters()[0] == "C:"))
     {
         outputter.PrintLine($"Volume in drive C is {base.Drive.Label}");
         outputter.PrintLine($"Volume Serial Number is 1E16-3FE3");
     }
     else
     {
         outputter.PrintLine("The system cannot find the drive specified.");
     }
 }
Пример #8
0
        public override void Execute(IOutputter outputter)
        {
            if (GetParameterCount() > 0)
            {
                string fileName    = GetParameterAt(0);
                string fileContent = GetContent(fileName, Drive.CurrentDirectory);
                string timeStamp   = GetTimeStamp(fileName, Drive.CurrentDirectory);

                if (GetParameterCount() == 3 && GetParameterAt(2).Equals("/y", StringComparison.InvariantCultureIgnoreCase))
                {
                    File DelFile = new File(fileName, null, null);
                    this.destinationDirectory.Del(DelFile);

                    File CopyFile = new File(fileName, fileContent, timeStamp);
                    this.destinationDirectory.Add(CopyFile, true);

                    outputter.Print("Copy File " + fileName + " is Succeed Replace");
                    outputter.NewLine();
                }
                else
                {
                    File CopyFile = new File(fileName, fileContent, timeStamp);
                    this.destinationDirectory.Add(CopyFile, false);

                    outputter.Print("Copy File " + fileName + " is Succeed");
                    outputter.NewLine();
                }
            }
            else
            {
                outputter.PrintLine(VER_IS_INVALID);
            }
        }
Пример #9
0
        protected override bool CheckParameterValues(IOutputter outputter)
        {
            if (GetParameters().Count > 0)
            {
                string         dirPath = GetParameters()[0];
                FileSystemItem fs      = Drive.GetItemFromPath(dirPath);
                if (fs == null)
                {
                    outputter.PrintLine("File Not Found");
                    return(false);
                }

                if (fs.IsDirectory() == false)
                {
                    dirToPrint = fs.Parent;
                }
                else
                {
                    dirToPrint = (Directory)fs;
                }
            }
            else
            {
                dirToPrint = Drive.CurrentDirectory;
            }

            return(true);
        }
Пример #10
0
        private static Directory ExtractAndCheckIfValidDirectory(string destinationDirectoryName, IDrive drive, IOutputter outputter)
        {
            FileSystemItem tempDestinationDirectory = drive.GetItemFromPath(destinationDirectoryName);

            if (tempDestinationDirectory == null)
            {
                outputter.PrintLine(SYSTEM_CANNOT_FIND_THE_PATH_SPECIFIED);
                return(null);
            }
            if (!tempDestinationDirectory.IsDirectory())
            {
                outputter.PrintLine(DESTINATION_IS_FILE);
                return(null);
            }
            return((Directory)tempDestinationDirectory);
        }
Пример #11
0
        public static Directory ExtractAndCheckIfValidDirectory(string destinationDirectoryName, IDrive drive, IOutputter outputter)
        {
            FileSystemItem tempDestinationDirectory = drive.GetItemFromPath(destinationDirectoryName);

            if (tempDestinationDirectory == null)
            {
                outputter.PrintLine(NO_IS_FILE + destinationDirectoryName);
                return(null);
            }
            if (!tempDestinationDirectory.IsDirectory())
            {
                outputter.PrintLine(DESTINATION_IS_FILE);
                return(null);
            }
            return((Directory)tempDestinationDirectory);
        }
Пример #12
0
 /// <summary>
 /// Checks the passed parameters. This consists of two steps which are overrideable by concrete commands.
 /// 1.) Check the number of parameters.
 /// 2.) Check the values of all passed parameters
 /// Template Method Pattern: Template Method.
 /// </summary>
 /// <param name="outputter">The outputter must be used to printout any error description.</param>
 /// <returns>
 /// - true  if number and values of the parameters are correct. Execute() may use the parameters afterwards unchecked.
 /// - false if the number is below or above excepted range or if any value is incorrect. An explaining error message must be given
 ///         by the concrete command.
 /// </returns>
 public bool CheckParameters(IOutputter outputter)
 {
     if (!CheckNumberOfParameters(parameters.Count))
     {
         outputter.PrintLine(INCORRECT_SYNTAX);
         return(false);
     }
     if (!CheckParameterValues(outputter))
     {
         if (!outputter.HasCharactersPrinted())
         {
             outputter.PrintLine(DEFAULT_ERROR_MESSAGE_WRONG_PARAMETER);
         }
         return(false);
     }
     return(true);
 }
Пример #13
0
        public override void Execute(IOutputter outputter)
        {
            if (GetParameters().Count == 1)
            {
                var newLbl = GetParameters()[0];
                if (GetParameters().Count == 2)
                {
                    newLbl = GetParameters()[1];
                }
                base.Drive.Label = newLbl;

                outputter.PrintLine($"Set new volume label {base.Drive.Label}");
            }
            else
            {
                outputter.PrintLine("invalid usage, label [newLblName]");
            }
        }
Пример #14
0
        private static void ChangeCurrentDirectory(Directory destinationDirectory, IDrive drive, IOutputter outputter)
        {
            bool success = drive.ChangeCurrentDirectory(destinationDirectory);

            if (!success)
            {
                outputter.PrintLine(SYSTEM_CANNOT_FIND_THE_PATH_SPECIFIED);
            }
        }
Пример #15
0
 private static bool ParameterContainsBacklashes(string parameter, IOutputter outputter)
 {
     // Do not allow "mkdir c:\temp\dir1" to keep the command simple
     if (parameter.Contains("\\") || parameter.Contains("/"))
     {
         outputter.PrintLine(PARAMETER_CONTAINS_BACKLASH);
         return(true);
     }
     return(false);
 }
Пример #16
0
        public override void Execute(IOutputter outputter)
        {
            bool retVal = false;

            // cd without parameters
            if (newDirectoryName == null)
            {
                outputter.PrintLine(Drive.CurrentDirectory.Path);
                return;
            }

            // cd with parameters: Check if passed directory is valid before change to this directory
            FileSystemItem newDir = Drive.GetItemFromPath(newDirectoryName);

            if (newDir == null)
            {
                outputter.PrintLine(SYSTEM_CANNOT_FIND_THE_PATH_SPECIFIED);
                return;
            }

            if (newDir.IsDirectory() == false)
            {
                outputter.PrintLine(SYSTEM_CANNOT_FIND_THE_PATH_SPECIFIED);
                return;
            }

            if (Drive.GetItemFromPath(newDir.Path) != newDir)
            {
                outputter.PrintLine("Path not in drive " + Drive.DriveName);
                return;
            }

            if (newDir.IsDirectory())
            {
                retVal = Drive.ChangeCurrentDirectory((Directory)newDir);
            }

            if (retVal == false)
            {
                outputter.PrintLine(SYSTEM_CANNOT_FIND_THE_PATH_SPECIFIED);
            }
        }
Пример #17
0
        private Directory CheckAndPreparePathParameter(string pathName, IOutputter outputter)
        {
            FileSystemItem fsi = Drive.GetItemFromPath(pathName);

            if (fsi == null)
            {
                outputter.PrintLine(SYSTEM_CANNOT_FIND_THE_PATH_SPECIFIED);
                return(null);
            }
            if (!fsi.IsDirectory())
            {
                return(fsi.Parent);
            }
            if (fsi.IsDirectory())
            {
                outputter.PrintLine(ACCESS_DENIED);
                return(null);
            }
            return((Directory)fsi);
        }
Пример #18
0
        protected override bool CheckParameterValues(IOutputter outputter)
        {
            foreach (string parameter in GetParameters())
            {
                // Do not allow "mkdir c:\temp\dir1" to keep the command simple
                if (parameter.Contains("\\") || parameter.Contains("/"))
                {
                    outputter.PrintLine("At least one parameter denotes a path rather than a directory name.");
                    return(false);
                }
            }

            return(true);
        }
Пример #19
0
        /// <summary>
        /// Processes input from the console and invokes the invoker until 'exit' is typed.
        /// </summary>
        public void ProcessInput()
        {
            string line = string.Empty;

            outputter.PrintLine("DOSBox, Scrum.org, Professional Scrum Developer Training");
            outputter.PrintLine("Copyright (c) Rainer Grau and Daniel Tobler. All rights reserved.");

            while (line.Trim().Equals("exit", StringComparison.OrdinalIgnoreCase) == false)
            {
                int readChar = 0;
                var input    = new StringBuilder();

                outputter.NewLine();
                outputter.Print(drive.Prompt);
                try
                {
                    while (readChar != '\n')
                    {
                        readChar = System.Console.Read();
                        input.Append((char)readChar);
                    }

                    line = input.ToString();
                }
                catch (IOException)
                {
                    // do nothing by intention
                }

                outputter.ResetStatistics();
                invoker.ExecuteCommand(line, outputter);
            }

            outputter.PrintLine("\nGoodbye!");
            drive.Save();
        }
Пример #20
0
        public override void Execute(IOutputter outputter)
        {
            if (GetParameterCount() > 0)
            {
                string fileName = GetParameterAt(0).Substring(GetParameterAt(0).LastIndexOf("\\") + 1);
                File   DelFile  = new File(fileName, null, null);
                this.destinationDirectory.Del(DelFile);

                outputter.Print("File " + fileName + " is Deleted");
                outputter.NewLine();
            }
            else
            {
                outputter.PrintLine(VER_IS_INVALID);
            }
        }
Пример #21
0
        public static Directory ExtractAndCheckIfValidDirectory(string destinationDirectoryName, IDrive drive, IOutputter outputter)
        {
            FileSystemItem tempDestinationDirectory = drive.GetItemFromPath(destinationDirectoryName);

            if (tempDestinationDirectory == null)
            {
                outputter.PrintLine(NO_IS_FILE + drive + "\\" + destinationDirectoryName);
                return(null);
            }
            //jika subdirektori tidak ingin dihapus
            //if (tempDestinationDirectory.IsDirectory())
            //{
            //outputter.PrintLine(NO_IS_FILE + drive + "\\" + destinationDirectoryName);
            //return null;
            //}
            return(tempDestinationDirectory.Parent);
        }
Пример #22
0
        public override void Execute(IOutputter outputter)
        {
            string fileName = GetParameterAt(0);

            if (!string.IsNullOrEmpty(fileName))
            {
                //add variabel timestamp buat lempar ke function file
                string fileContent = GetParameterAt(1);
                string timeStamp   = System.DateTime.Now.ToString();
                File   newFile     = new File(fileName, fileContent ?? string.Empty, timeStamp);
                this.Drive.CurrentDirectory.Add(newFile, false);
            }
            else
            {
                outputter.PrintLine("syntax of the command is incorrect");
                //return false;
            }
            //return true;
        }
Пример #23
0
        /// <summary>
        /// Checks the passed parameters. This consists of three steps which are both overrideable by concrete commands.<br/>
        /// 1.) Check the number of parameters.<br/>
        /// 2.) Check the values of all passed parameters<br/>
        /// 3.) Assign the parameters to attributes in the concrete commands.<br/>
        /// <br/>
        /// Template Method Pattern: Template Method.
        /// </summary>
        /// <param name="outputter">The outputter must be used to output any error description.</param>
        /// <returns>
        /// <li/> true  if number and values of the parameters are correct. Execute() may use the parameters afterwards unchecked.
        /// <li/> false if the number is below or above excepted range or if any value is incorrect. An explaining error message must be given
        ///           by the concrete command.
        /// </returns>
        public bool CheckParameters(IOutputter outputter)
        {
            if (parameters == null)
            {
                throw new Exception("Parameters checked before set!");
            }

            if (CheckNumberOfParameters(parameters.Count) == false)
            {
                outputter.PrintLine("The syntax of the command is incorrect.");
                return(false);
            }

            if (CheckParameterValues(outputter) == false)
            {
                return(false);
            }

            SetParameters();

            return(true);
        }
Пример #24
0
 private static void PrintCurrentDirectoryPath(string currentDirectoryName, IOutputter outputter)
 {
     outputter.PrintLine(currentDirectoryName);
 }
Пример #25
0
 private static void PrintHeader(Directory directoryToPrint, IOutputter outputter)
 {
     outputter.PrintLine("Directory of " + directoryToPrint.Path);
     outputter.NewLine();
 }
Пример #26
0
 private static void PrintFooter(Directory directoryToPrint, IOutputter outputter)
 {
     outputter.PrintLine("\t" + directoryToPrint.GetNumberOfContainedFiles() + " File(s)");
     outputter.PrintLine("\t" + directoryToPrint.GetNumberOfContainedDirectories() + " Dir(s)");
 }
Пример #27
0
 public void HasCharactersPrinted_PrintEmptyNewLine_IsFalse()
 {
     outputter.PrintLine("");
     Assert.IsFalse(outputter.HasCharactersPrinted());
     Assert.AreEqual(0, outputter.NumberOfCharactersPrinted());
 }