Ejemplo n.º 1
0
 private static void TryGetHelp(string input, string[] data)
 {
     if (data.Length == 1)
     {
         OutputWriter.WriteMessageOnNewLine($"{new string('_', 124)}");
         OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -122}|", "make directory - mkdir: path "));
         OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -122}|", "traverse directory - ls: depth "));
         OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -122}|", "comparing files - cmp: path1 path2"));
         OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -122}|", "change directory - cdRel: relative path or .."));
         OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -122}|", "change directory - cdAbs: absolute path"));
         OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -122}|", "read students data base - readDb: path"));
         OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -122}|", "display data entities - display: students/courses ascending/descending"));
         OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -122}|", "filter {courseName} excelent/average/poor  take 2/5/all - filterExcelent (the output is written on the console)"));
         OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -122}|", "order increasing students - order {courseName} ascending/descending take 20/10/all (the output is written on the console)"));
         OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -122}|", "download file - download: path of file (saved in current directory)"));
         OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -122}|", "download file asinchronously - downloadAsynch: path of file (save in the current directory)"));
         OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -122}|", "get help – help"));
         OutputWriter.WriteMessageOnNewLine($"{new string('_', 124)}");
         OutputWriter.WriteEmptyLine();
     }
     else
     {
         OutputWriter.DisplayExeptions(ExceptionMessages.InvalidCommandMessage(input));
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Use Breadth First Search Algorithm to display all the directories and subdirectories in a given path
        /// https://upload.wikimedia.org/wikipedia/commons/5/5d/Breadth-First-Search-Algorithm.gif
        /// </summary>
        /// <param name="endDepth"></param>
        public void TraverseDirectory(int endDepth)
        {
            var path = SessionData.CurrentPath;

            OutputWriter.WriteEmptyLine();

            var subFolders = new Queue <string>();

            //Getting the initial folder's path into the queue
            subFolders.Enqueue(path);

            //Get the initial depth level to measure correctly the depth later
            var pathSeparator     = SessionData.PathSeparator;
            var initialDepthLevel = path.Split(pathSeparator).Length;

            //Traverse the subfolders
            while (subFolders.Count > 0)
            {
                var folderPath = subFolders.Dequeue();

                //Measure the level of depth where the folder is so it can be displayed correctly on the output
                var currentDepth = folderPath.Split(pathSeparator).Length - initialDepthLevel;

                //This means that we needn't traverse any further
                if (endDepth - currentDepth < 0)
                {
                    break;
                }

                OutputWriter.WriteMessageOnNewLine($"{new string('-', currentDepth)}{folderPath}");

                try
                {
                    //Print the files in the folder
                    var files = Directory.GetFiles(folderPath);
                    foreach (var file in files)
                    {
                        var lastSlash = file.LastIndexOf(pathSeparator);

                        //Getting only the file name
                        var fileName = file.Substring(lastSlash);

                        //Full path will be replaced with dashes, to point out files are located there
                        OutputWriter.WriteMessageOnNewLine($"{new string('-', lastSlash)}{fileName}");
                    }

                    //Enqueue the subfolders
                    var subFoldersToEnqueue = Directory.GetDirectories(folderPath);
                    foreach (var folder in subFoldersToEnqueue)
                    {
                        subFolders.Enqueue(folder);
                    }
                }
                catch (UnauthorizedAccessException) { OutputWriter.DisplayException(ExceptionMessages.AccessDeniedException); }
            }
        }
Ejemplo n.º 3
0
        public void TraverseDirectory(int depth)
        {
            OutputWriter.WriteEmptyLine();
            var            currentPath       = SessionData.CurrentPath;
            int            initialIdentation = currentPath.Split('\\').Length;
            Queue <string> subFolders        = new Queue <string>();

            subFolders.Enqueue(currentPath);

            while (subFolders.Count != 0)
            {
                currentPath = subFolders.Dequeue();
                int identation = currentPath.Split('\\').Length - initialIdentation;
                if (depth - identation < 0)
                {
                    break;
                }

                try
                {
                    OutputWriter.WriteMessageOnNewLine(string.Format("{0}{1}", new string('-', identation),
                                                                     currentPath));
                    foreach (var directoryPath in Directory.GetDirectories(currentPath + "\\"))
                    {
                        subFolders.Enqueue(directoryPath);
                        var indexOfLastSlash = directoryPath.LastIndexOf("\\");
                        if (indexOfLastSlash < 0)
                        {
                            indexOfLastSlash = 0;
                        }
                        var directoryName = directoryPath.Substring(indexOfLastSlash);
                        OutputWriter.WriteMessageOnNewLine(new string('-', indexOfLastSlash + identation) + directoryName);
                    }

                    foreach (var file in Directory.GetFiles(currentPath + "\\"))
                    {
                        var indexOfLastSlash = file.LastIndexOf("\\");
                        if (indexOfLastSlash < 0)
                        {
                            indexOfLastSlash = 0;
                        }
                        var fileName = file.Substring(indexOfLastSlash);
                        OutputWriter.WriteMessageOnNewLine(new string('-', indexOfLastSlash + identation) + fileName);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    OutputWriter.DisplayException(ExceptionMessages.UnauthorizedAccessExceptionMessage);

                    Console.ReadKey();
                }
            }
        }
Ejemplo n.º 4
0
        public void StartReadingCommands()
        {
            OutputWriter.WriteMessage($"{SessionData.CurrentPath}> ");
            var input = Console.ReadLine();

            while (input != null && input.ToLower() != EndCommand)
            {
                var inputCommand = input.Trim().ToLower();
                interpreter.InterpretCommand(inputCommand);

                OutputWriter.WriteEmptyLine();
                OutputWriter.WriteMessage($"{SessionData.CurrentPath}> ");
                input = Console.ReadLine();
            }
        }
 public static void PrintHelp()
 {
     OutputWriter.WriteMessageOnNewLine($"{new string('_', 100)}");
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "make directory - mkdir: path "));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "traverse directory - ls: depth "));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "comparing files - cmp: path1 path2"));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "change directory - cdRl:relative path"));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "change directory - cdAbs:absolute path"));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "read students data base - readDb: path"));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "filter {courseName} excelent/average/poor  take 2/5/all students - filterExcelent (the output is written on the console)"));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "order increasing students - order {courseName} ascending/descending take 20/10/all (the output is written on the console)"));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "download file - download: path of file (saved in current directory)"));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "get help – help"));
     OutputWriter.WriteMessageOnNewLine($"{new string('_', 100)}");
     OutputWriter.WriteEmptyLine();
 }
Ejemplo n.º 6
0
        public void TraverseDirectory(int depth)
        {
            OutputWriter.WriteEmptyLine();
            var initialIdentation = SessionData.CurrentPath.Split('\\').Length;
            var subFolders        = new Queue <string>();

            subFolders.Enqueue(SessionData.CurrentPath);

            while (true)
            {
                if (subFolders.Count == 0)
                {
                    break;
                }

                var currentPath = subFolders.Dequeue();
                var identation  = currentPath.Split('\\').Length - initialIdentation;

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

                OutputWriter.WriteMessageOnNewLine($"{new string('-', identation)}{currentPath}");

                try
                {
                    foreach (var file in Directory.GetFiles(currentPath))
                    {
                        var indexOfLastSlash = file.LastIndexOf("\\");
                        var filename         = file.Substring(indexOfLastSlash);
                        OutputWriter.WriteMessageOnNewLine(new string('-', indexOfLastSlash) + filename);
                    }

                    var subDirectories = Directory.GetDirectories(currentPath);

                    foreach (var subDir in subDirectories)
                    {
                        subFolders.Enqueue(subDir);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    OutputWriter.DisplayException(ExceptionMessage.UnauthorizedAccessException);
                }
            }
        }
Ejemplo n.º 7
0
        public void TraverseDirectory(int depth)
        {
            OutputWriter.WriteEmptyLine();
            int initialIdentation = SessionData.currentPath.Split('\\').Length;
            Queue<string> subfolders = new Queue<string>();
            subfolders.Enqueue(SessionData.currentPath);

            while (subfolders.Count != 0)
            {
                string currentFolder = subfolders.Dequeue();
                int identation = currentFolder.Split('\\').Length - initialIdentation;
                //check depth
                if (depth - identation < 0)
                {
                    break;
                }
                //display current folder
                OutputWriter.WriteMessageOnNewLine(string.Format("{0}{1}",
                    new string('-', identation), currentFolder));

                //display files in current folder
                try
                {
                    foreach (var file in Directory.GetFiles(currentFolder))
                    {
                        int indexOfLastSlash = file.LastIndexOf("\\");
                        string fileName = file.Substring(indexOfLastSlash);
                        OutputWriter.WriteMessageOnNewLine(
                            new string('-', indexOfLastSlash) + fileName);
                    }

                    //adding subfolders
                    foreach (string directoryPath in Directory.GetDirectories(currentFolder))
                    {
                        subfolders.Enqueue(directoryPath);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    OutputWriter.DisplayException(
                        ExceptionMessages.UnauthorizedAccessExceptionMessage);
                }
            }
        }
Ejemplo n.º 8
0
        public void TraverseDirectory(int depth)
        {
            OutputWriter.WriteEmptyLine();
            int            initialIndentation = SessionData.currentPath.Split('\\').Length;
            Queue <string> subFolders         = new Queue <string>();

            subFolders.Enqueue(SessionData.currentPath);

            while (subFolders.Count > 0)
            {
                string currentPath = subFolders.Dequeue();

                int indentation = currentPath.Split('\\').Length - initialIndentation;

                if (depth - indentation < 0)
                {
                    break;
                }
                OutputWriter.WriteMessageOnNewLine($"{new string('-', indentation)}{currentPath}");

                try
                {
                    string[] files = Directory.GetFiles(currentPath);

                    foreach (string file in files)
                    {
                        int    indexOfLastSlash = file.LastIndexOf(@"\");
                        string fileName         = file.Substring(indexOfLastSlash);
                        OutputWriter.WriteMessageOnNewLine($"{new string('-', indexOfLastSlash)}{fileName}");
                    }

                    string[] directories = Directory.GetDirectories(currentPath);

                    foreach (string directory in directories)
                    {
                        subFolders.Enqueue(directory);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    OutputWriter.DisplayException(ExceptionMessages.UnauthorizedAccessExceptionMessage);
                }
            }
        }
        public void TraverseDirectory(int depth)
        {
            OutputWriter.WriteEmptyLine();

            Queue <string> subfolders = new Queue <string>();

            subfolders.Enqueue(GetCurrentDirectoryPath());

            for (int identation = 0; identation <= depth; identation++)
            {
                Queue <string> nextSubfolders = new Queue <string>();

                while (subfolders.Count > 0)
                {
                    string currentDir = subfolders.Dequeue();

                    OutputWriter.WriteMessageOnNewLine($"{new string('-', identation)}{currentDir}");

                    string[] subdirs         = new string[0];
                    string[] currentDirFiles = new string[0];

                    try
                    {
                        subdirs         = Directory.GetDirectories(currentDir);
                        currentDirFiles = Directory.GetFiles(currentDir);
                    }
                    catch (UnauthorizedAccessException)
                    {
                        OutputWriter.DisplayException(ExceptionMessages.UnauthorizesExceptionMessage);
                    }

                    PrintPaths(identation, subdirs);
                    PrintPaths(identation, currentDirFiles);

                    subdirs.ToList().ForEach(nextSubfolders.Enqueue);
                }

                subfolders = nextSubfolders;
            }
        }
Ejemplo n.º 10
0
        public void TraverseDirectory(int depth)
        {
            OutputWriter.WriteEmptyLine();
            var initIndentation = SessionData.CurrentPath.Split('\\').Length;
            var subFolders      = new Queue <string>();

            subFolders.Enqueue(SessionData.CurrentPath);

            while (subFolders.Count != 0)
            {
                var currentPath = subFolders.Dequeue();

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

                    foreach (var dirPath in Directory.GetDirectories(currentPath))
                    {
                        subFolders.Enqueue(dirPath);
                    }
                }
                catch (Exception)
                {
                    OutputWriter.DisplayException(ExceptionMessages.UnauthorizedAccessExceptionMessage);
                }

                var indentation = currentPath.Split('\\').Length - initIndentation;
                if (depth - indentation < 0)
                {
                    break;
                }

                OutputWriter.WriteMessageOnNewLine($"{indentation} - {currentPath}");
            }
        }
Ejemplo n.º 11
0
        public void TraverseDirectory(int depth)
        {
            OutputWriter.WriteEmptyLine();
            int            initialIdentation = SessionData.currentPath.Split('\\').Length;
            Queue <string> subFolders        = new Queue <string>();

            subFolders.Enqueue(SessionData.currentPath);

            while (subFolders.Count != 0)
            {
                string currentPath = subFolders.Dequeue();
                int    identation  = currentPath.Split('\\').Length - initialIdentation;

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

                try
                {
                    foreach (var directoryPath in Directory.GetDirectories(currentPath))
                    {
                        subFolders.Enqueue(directoryPath);
                    }

                    OutputWriter.WriteMessageOnNewLine($"{new string('-', identation)}{currentPath}");

                    foreach (var file in Directory.GetFiles(SessionData.currentPath))
                    {
                        int    indexOfLastSlash = file.LastIndexOf("\\", StringComparison.Ordinal);
                        string fileName         = file.Substring(indexOfLastSlash);
                        OutputWriter.WriteMessageOnNewLine(new string('-', indexOfLastSlash) + fileName);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    OutputWriter.WriteMessageOnNewLine(ExceptionMessages.UnauthorizedExceptionMessage);
                }
            }
        }
Ejemplo n.º 12
0
        public void TraverseDirectory(int depth)
        {
            OutputWriter.WriteEmptyLine();
            int            initialIdentation = SessionData.currentPath.Split('\\').Length;
            Queue <string> subFolders        = new Queue <string>();

            subFolders.Enqueue(SessionData.currentPath);
            while (subFolders.Count != 0)
            {
                string currentPath = subFolders.Dequeue();
                int    identation  = currentPath.Split('\\').Length - initialIdentation;

                if (depth - identation < 0)
                {
                    break;
                }
                //C# Advanced----->>>>
                //Gives error with the indexes if you use the commented way of printing!!1
                //OutputWriter.WriteMessageOnNewLine(string.Format($"{new string('-', identation)}{currentPath}"));
                OutputWriter.WriteMessageOnNewLine(string.Format("{0}{1}", new string('-', identation), currentPath));
                try
                {
                    foreach (string file in Directory.GetFiles(currentPath))
                    {
                        int    indexOfLastSlash = file.LastIndexOf("\\");
                        string fileName         = file.Substring(indexOfLastSlash);
                        OutputWriter.WriteMessageOnNewLine(new string('-', indexOfLastSlash) + fileName);
                    }
                    string[] subDirectories = Directory.GetDirectories(currentPath);
                    foreach (string subDirectory in subDirectories)
                    {
                        subFolders.Enqueue(subDirectory);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    OutputWriter.WriteMessageOnNewLine(ExceptionMessages.UnauthorizedAccessExceptionMessage);
                }
            }
        }
Ejemplo n.º 13
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);
                }
            }
        }