Ejemplo n.º 1
0
 private static void TryParseParametersForOrderAndTake(string takeCommand, string takeQuantity,
                                                       string courseName, string filter)
 {
     if (takeCommand == "take")
     {
         if (takeQuantity == "all")
         {
             StudentsRepository.OrderAndTake(courseName, filter);
         }
         else
         {
             int  studentsToTake;
             bool hasParsed = int.TryParse(takeQuantity, out studentsToTake);
             if (hasParsed)
             {
                 StudentsRepository.OrderAndTake(courseName, filter, studentsToTake);
             }
             else
             {
                 OutputWriter.DisplayMessage(ExceptionMessages.InvalidTakeQuantityParameter);
             }
         }
     }
     else
     {
         OutputWriter.DisplayMessage(ExceptionMessages.InvalidTakeQuantityParameter);
     }
 }
Ejemplo n.º 2
0
        public static void ChangeCurrentDirectoryAbsolute(string absolutePath)
        {
            if (!Directory.Exists(absolutePath))
            {
                OutputWriter.DisplayMessage(ExceptionMessages.InvalidPath);
                return;
            }

            SessionData.currentPath = absolutePath;
        }
Ejemplo n.º 3
0
        public static void CreateDirectoryInCurrentFolder(string name)
        {
            string path = SessionData.currentPath + "\\" + name;

            try
            {
                Directory.CreateDirectory(path);
            }
            catch (ArgumentException)
            {
                OutputWriter.DisplayMessage(ExceptionMessages.ForbiddenSymbolsContainedInName);
            }
        }
        public void InterpredCommand(string input)
        {
            string[] data        = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            string   commandName = data[0].ToLower();

            try
            {
                Command command = this.ParseCommand(input, commandName, data);
                command.Execute();
            }
            catch (Exception ex)
            {
                OutputWriter.DisplayMessage(ex.Message);
            }
        }
Ejemplo n.º 5
0
        public static void TraverseFolder(int depth)
        {
            OutputWriter.WriteEmptyLine();
            int            initialIdentity = SessionData.currentPath.Split('\\').Length;
            Queue <string> subFolders      = new Queue <string>();

            subFolders.Enqueue(SessionData.currentPath);

            while (subFolders.Count > 0)
            {
                string currentPath = subFolders.Dequeue();
                int    identention = currentPath.Split('\\').Length - initialIdentity;
                OutputWriter.WriteMessageOnNewLine($"{new string('-', identention)}{currentPath}");

                if (depth - identention < 0)
                {
                    break;
                }

                try
                {
                    foreach (string file in Directory.GetFiles(currentPath))
                    {
                        int    indexOfSlash = file.LastIndexOf("\\");
                        string fileName     = file.Substring(indexOfSlash);
                        OutputWriter.WriteMessageOnNewLine($"{new string('-', indexOfSlash)}{fileName}");
                    }

                    foreach (string directoryPath in Directory.GetDirectories(currentPath))
                    {
                        subFolders.Enqueue(directoryPath);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    OutputWriter.DisplayMessage(ExceptionMessages.UnauthorizedAccessExceptionMessage);
                }
            }
        }
Ejemplo n.º 6
0
 public static void ChangeCurrentDirectoryRelative(string relativePath)
 {
     if (relativePath == "..")
     {
         try
         {
             string currentPath      = SessionData.currentPath;
             int    indexOfLastSlash = currentPath.LastIndexOf("\\");
             string newPath          = currentPath.Substring(0, indexOfLastSlash);
             SessionData.currentPath = newPath;
         }
         catch (ArgumentOutOfRangeException)
         {
             OutputWriter.DisplayMessage(ExceptionMessages.UnableToGoHigherInPartitionHierarchy);
         }
     }
     else
     {
         string currentPath = SessionData.currentPath;
         currentPath += $"\\{relativePath}";
         ChangeCurrentDirectoryAbsolute(currentPath);
     }
 }
Ejemplo n.º 7
0
 private static void TryTraverseFolders(string input, string[] data)
 {
     if (data.Length == 1)
     {
         IOManager.TraverseFolder(0);
     }
     else if (data.Length == 2)
     {
         int  depth;
         bool hasParsed = int.TryParse(data[1], out depth);
         if (hasParsed)
         {
             IOManager.TraverseFolder(depth);
         }
         else
         {
             OutputWriter.DisplayMessage(ExceptionMessages.UnableToParseNumber);
         }
     }
     else
     {
         DisplayInvalidCommandMessage(input);
     }
 }
Ejemplo n.º 8
0
 private static void DisplayInvalidCommandMessage(string input)
 {
     OutputWriter.DisplayMessage($"The command '{input}' is invalid!");
 }