Esempio n. 1
0
 static void RunParameterCommand(FileSystem file, string x)
 {
     // check the start of the string names to find out what parameter dependent command they are referencing and run the applicable command using the parameters as input.
     // it then prints out the return value of the command of either True or False
     if (x.Substring(0, x.IndexOf(' ')) == "mkdir")
     {
         System.Console.WriteLine(file.AddDirectory(x.Substring(x.IndexOf(' ') + 1)));
     }
     else if (x.Substring(0, x.IndexOf(' ')) == "rmdir")
     {
         System.Console.WriteLine(file.RemoveDirectory(x.Substring(x.IndexOf(' ') + 1)));
     }
     else if (x.Substring(0, x.IndexOf(' ')) == "mkfile")
     {
         System.Console.WriteLine(file.AddFile(x.Substring(x.IndexOf(' ') + 1)));
     }
     else if (x.Substring(0, x.IndexOf(' ')) == "rmfile")
     {
         System.Console.WriteLine(file.RemoveFile(x.Substring(x.IndexOf(' ') + 1)));
     }
     else // if none of the above cases are executed, remind the user that they can use help to learn the commands
     {
         System.Console.WriteLine("For help, type \"help\"");
     }
 }
Esempio n. 2
0
    public static void Main(string[] args)
    {
        FileSystem t = new FileSystem();

        //char command;

        // interface
        Console.WriteLine("\nHere are your options:\n1. Add Directory\n2. Remove Directory\n3. Add File\n4. Remove File\n5. Find Number of Files in Filesystem\n6. Print File System\n7. Exit");
        char choice = Convert.ToChar(Console.ReadLine());

        Console.Clear();
        while (choice != '7')
        {
            switch (choice)
            {
            case '1':
                Console.WriteLine("At what address do you want to add a directory?");
                t.AddDirectory(Console.ReadLine());
                break;

            case '2':
                Console.WriteLine("What is the address of the directory you want to delete?");
                t.RemoveDirectory(Console.ReadLine());
                break;

            case '3':
                Console.WriteLine("At what address would you like to add a file?");
                t.AddFile(Console.ReadLine());
                break;

            case '4':
                Console.WriteLine("What is the address of the file you want to delete?");
                t.RemoveFile(Console.ReadLine());
                break;

            case '5':
                Console.WriteLine("Number of files in the entire filesystem:{0}", t.NumberFiles());
                break;

            case '6':
                string address;
                address = t.PrintFileSystem();
                Console.WriteLine(address);
                break;

            case '7':
                return;

            default:
                Console.WriteLine("Not a valid option");
                break;
            }
            Console.WriteLine("\nHere are your options:\n1. Add Directory\n2. Remove Directory\n3. Add File\n4. Remove File\n5. Find Number of Files in Filesystem\n6. Print File System\n7. Exit");
            choice = Convert.ToChar(Console.ReadLine());
            Console.Clear();
        }
        Console.WriteLine("See you next time");
        Console.ReadLine();
    }
Esempio n. 3
0
        private void GivenRootFolder(params string[] subfolders)
        {
            FileSystem.AddDirectory(_rootFolder);

            foreach (var folder in subfolders)
            {
                FileSystem.AddDirectory(folder);
            }
        }
        static void Main()                                                                                                                    // main method to call all of the methods mentioned above
        {
            Console.WriteLine("***********************************************************************************************************"); //Design
            Console.WriteLine("******************************* COIS 2020 - Data Structures and Algorithms ********************************"); //Design
            Console.WriteLine("************************************* Assignment - 3 File Systems  ****************************************"); //Design
            Console.WriteLine("***********************************************************************************************************"); //Design
            Console.Write("Enter Root Directory==>   ");                                                                                      // Prompt to ask for the root directory
            FileSystem System = new FileSystem(Console.ReadLine());                                                                           //read the root directory and initiate a file system

            while (true)
            {
                // Prompt to ask for operations to perform
                Console.WriteLine("Contol Panel: \n Select 1 to Add a file \n Select 2 to Remove a file \n Select 3 to Add a directory \n Select 4 to Remove Directory \n Select 5 to Count the number of files \n Select 6 to Print the complete File System \n Select 7 to Exit");
                int operation = Int32.Parse(Console.ReadLine()); // creating an integer variable to read the above operations and Parse them per the switch-case-break operation
                switch (operation)                               // parsing the given selection of operation and parse them to identify which operation to perform as per switch-case-break
                {
                case 0:                                          // if selected 0, then break the program and loop the contol panel
                    break;

                case 1:
                    Console.Write("Address to add file ==>  "); // prompt to ask where to add the file
                    System.AddFile(Console.ReadLine());         // Calling the AddFile method to read the prompt
                    break;                                      //Loop again

                case 2:
                    Console.Write("Address to remove the file ==> "); //prompt to ask where to remove the file from
                    System.RemoveFile(Console.ReadLine());            // Calling the RomoveFile method to read the prompt
                    break;                                            // Loop Again

                case 3:
                    Console.Write("Address to Add the directory ==> "); //prompt to ask where to add the directory
                    System.AddDirectory(Console.ReadLine());            // Calling the AddDirectory method to read the prompt
                    break;

                case 4:
                    Console.Write("Address to remove the directory ==> "); //prompt to ask where to remove the directory from
                    System.RemoveDirectory(Console.ReadLine());            //Calling the RemoveDirectory method to read the prompt
                    break;                                                 // Loop Again

                case 5:
                    System.NumberFiles(System.root);     //Calling the NumberFiles method when option 5 is selected to count the number of files inserted in the file system
                    break;

                case 6:
                    System.PrintFileSystem(System.root);     //Calling the PrintFileSystem method when option 6 is selected to print the entire file system
                    break;

                case 7:
                    return;      // break the program when option 7 is selected
                }
            }
        }
        public void ThenCanFilterOutNonExistingTestResultFiles()
        {
            FileSystem.AddDirectory(@"c:\");
            var args = new[] { @"-link-results-file=c:\DoesNotExist.xml;" };

            var  configuration             = new Configuration();
            var  commandLineArgumentParser = new CommandLineArgumentParser(FileSystem);
            bool shouldContinue            = commandLineArgumentParser.Parse(args, configuration, TextWriter.Null);

            Check.That(shouldContinue).IsTrue();
            Check.That(configuration.HasTestResults).IsFalse();
            Check.That(configuration.TestResultsFiles).IsEmpty();
        }
        public void should_remove_unpack_from_folder_name(string prefix)
        {
            var folderName = "Alien Ant Farm - Truant (2003)";

            FileSystem.AddDirectory(string.Format(@"C:\drop\{0}{1}", prefix, folderName).AsOsAgnostic());

            Subject.ProcessRootFolder(DiskProvider.GetDirectoryInfo(_droneFactory));

            Mocker.GetMock <IParsingService>()
            .Verify(v => v.GetAuthor(folderName), Times.Once());

            Mocker.GetMock <IParsingService>()
            .Verify(v => v.GetAuthor(It.Is <string>(s => s.StartsWith(prefix))), Times.Never());
        }
        public void ThenSavesCssFilesToCorrectLocation()
        {
            FileSystem.AddDirectory(@"c:\output\");
            var htmlResourceWriter = new HtmlResourceWriter(FileSystem);

            htmlResourceWriter.WriteTo(@"c:\output\");

            var filesOnFileSystem = FileSystem.AllFiles.AsEnumerable <string>().ToArray();

            Check.That(filesOnFileSystem).Contains(@"c:\output\css\master.css");
            Check.That(filesOnFileSystem).Contains(@"c:\output\css\reset.css");
            Check.That(filesOnFileSystem).Contains(@"c:\output\css\global.css");
            Check.That(filesOnFileSystem).Contains(@"c:\output\css\global.css");
            Check.That(filesOnFileSystem).Contains(@"c:\output\css\structure.css");
            Check.That(filesOnFileSystem).Contains(@"c:\output\css\print.css");
            Check.That(filesOnFileSystem).Contains(@"c:\output\css\font-awesome.css");
        }
Esempio n. 8
0
        static void Main()
        {
            //Creates the file system
            FileSystem fs = new FileSystem();
            int        choice;

            try
            {
                do
                {
                    //Prints the file system so the user can see it
                    Console.WriteLine("Here is what the file system looks like so far");
                    fs.PrintFileSystem();

                    //asks the user what they want to do
                    Console.WriteLine("\nPress 1 to add a directory \nPress 2 to add a file \nPress 3 to remove a directory \nPress 4 to remove a file \nPress 5 to return the number of files in the system \nPress 6 to print the file system \nPress 7 to quit");
                    choice = Convert.ToInt32(Console.ReadLine());

                    if (choice == 1)
                    {
                        //Asks the user which directory they wish to add to and then goes through the process of trying to add
                        Console.WriteLine("Which directory would you like to add a directory to?");
                        fs.AddDirectory(Console.ReadLine());
                    }
                    else if (choice == 2)
                    {
                        //Asks the user which directory they wish to add a file to and then goes through the process of trying to add a file
                        Console.WriteLine("Which directory would you like to add a file to?");
                        fs.AddFile(Console.ReadLine());
                    }
                    else if (choice == 3)
                    {
                        //Asks the user which directory they wish to remove and then goes through the process of trying to remove it
                        Console.WriteLine("What is the directory that holds the directory you would like removed called?");
                        fs.RemoveDirectory(Console.ReadLine());
                    }
                    else if (choice == 4)
                    {
                        //Asks the user which directory they wish to remove a file from and then goes through the process of trying to remove it
                        Console.WriteLine("What is the directory of the file that you would like to remove?");
                        string remFile = Console.ReadLine();
                        fs.RemoveFile(remFile);
                    }
                    else if (choice == 5)
                    {
                        //Prints the number of files
                        int count = fs.NumberFiles();
                        Console.WriteLine("The file system has: " + count + " files");
                    }
                    else if (choice == 6)
                    {
                        //prints the file system, should probably have a friendly message next to it... nah
                        fs.PrintFileSystem();
                    }
                    else if (choice < 1 || choice > 7)
                    {
                        //if the user didn't hit the right option, then give them error
                        Console.WriteLine("\nPlease enter a valid option\n");
                    }

                    //if the user wants to quit, they hit 7 and BAM! gone
                } while (choice != 7);
            }
            catch
            {
                //if anything happens that we didn't see happening, we got ourselves covered.
                throw new ArgumentException("An error occured");
            }
        }
    public static void Main()
    {
        // Operation codes
        const string CODE_ADD_FILE         = "AF";
        const string CODE_REMOVE_FILE      = "DF";
        const string CODE_ADD_DIRECTORY    = "AD";
        const string CODE_REMOVE_DIRECTORY = "DD";
        const string CODE_NUMBER_FILES     = "NF";
        const string CODE_PRINT            = "PR";
        const string CODE_QUIT             = "Q";
        // Stores the file system
        FileSystem fileSystem = new FileSystem();
        // Stores user input
        string userInput = "";

        // Greet the user
        Console.WriteLine("Hello and welcome to the file system manipulator (FSM)!");
        Console.WriteLine("This program allows you to add/remove files/directories in a file system,");
        Console.WriteLine("which is implemented using a leftmost-child, right-sibling data structure.\n");

        // Explain controls
        Console.WriteLine("The possible operations are:");
        Console.WriteLine("Use '{0}' to add a new file", CODE_ADD_FILE);
        Console.WriteLine("Use '{0}' to remove a file", CODE_REMOVE_FILE);
        Console.WriteLine("Use '{0}' to add a new directory", CODE_ADD_DIRECTORY);
        Console.WriteLine("Use '{0}' to remove a directory", CODE_REMOVE_DIRECTORY);
        Console.WriteLine("Use '{0}' to output a number of files", CODE_NUMBER_FILES);
        Console.WriteLine("Use '{0}' to print the directories in a pre-order fashion along with their files", CODE_PRINT);
        Console.WriteLine("Use '{0}' to quit the program\n", CODE_QUIT);

        //Ask for an input
        Console.WriteLine("What do you want to do?");
        userInput = Console.ReadLine().ToUpper();

        // Ask for an input while the code of operation is not CODE_QUIT
        while (userInput != CODE_QUIT)
        {
            // Use desired operation
            switch (userInput)
            {
            case CODE_ADD_FILE:
                Console.WriteLine("Please, input the address:");
                // Say whether the operation was successful or not
                if (fileSystem.AddFile(Console.ReadLine()))
                {
                    Console.WriteLine("Successfully added new file.\n");
                }
                else
                {
                    Console.WriteLine("Path not found or file exists.\n");
                }
                break;

            case CODE_REMOVE_FILE:
                Console.WriteLine("Please, input the address:");
                // Say whether the operation was successful or not
                if (fileSystem.RemoveFile(Console.ReadLine()))
                {
                    Console.WriteLine("Successfully removed the file.\n");
                }
                else
                {
                    Console.WriteLine("Path not found or file does not exist.\n");
                }
                break;

            case CODE_ADD_DIRECTORY:
                Console.WriteLine("Please, input the address:");
                // Say whether the operation was successful or not
                if (fileSystem.AddDirectory(Console.ReadLine()))
                {
                    Console.WriteLine("Successfully added a directory. \n");
                }
                else
                {
                    Console.WriteLine("Path not found or directory exists.\n");
                }
                break;

            case CODE_REMOVE_DIRECTORY:
                Console.WriteLine("Please, input the address:");
                // Say whether the operation was successful or not
                if (fileSystem.RemoveDirectory(Console.ReadLine()))
                {
                    Console.WriteLine("Successfully removed the directory.\n");
                }
                else
                {
                    Console.WriteLine("Path not found or directory does not exist.\n");
                }
                break;

            case CODE_NUMBER_FILES:
                Console.WriteLine("Currently, the file system contains {0} file(s).\n", fileSystem.NumberFiles());
                break;

            case CODE_PRINT:
                Console.WriteLine("Currently, the file system contains:");
                fileSystem.PrintFileSystem();
                break;

            default:
                System.Console.WriteLine("Invalid command, please try again.\n");
                break;
            }
            // Ask for a next input
            Console.WriteLine("What do you want to do?");
            userInput = Console.ReadLine().ToUpper();
        }

        // Goodbye, see you soon!
        Console.ReadLine();
    }
Esempio n. 10
0
        // used to create a random selection of sample folders and files for the user to interact with
        static void init(FileSystem file)
        {
            file.AddDirectory("/home/seth/");
            file.AddDirectory("/home/seth/downloads/");
            file.AddDirectory("/home/seth/documents/");
            file.AddDirectory("/home/seth/pictures/");
            file.AddDirectory("/home/seth/videos/");

            file.AddDirectory("/home/seth/documents/school/");
            file.AddFile("/home/seth/documents/school/sup.txt");
            file.AddFile("/home/seth/documents/school/sup1.txt");
            file.AddFile("/home/seth/documents/school/sup2.txt");
            file.AddFile("/home/seth/documents/school/sup3.txt");

            file.AddDirectory("/home/seth/documents/school/COIS2020/");
            file.AddFile("/home/seth/documents/school/COIS2020/this.txt");
            file.AddFile("/home/seth/documents/school/COIS2020/is.txt");
            file.AddFile("/home/seth/documents/school/COIS2020/the.txt");
            file.AddFile("/home/seth/documents/school/COIS2020/best.txt");
            file.AddFile("/home/seth/documents/school/COIS2020/class.txt");
            file.AddFile("/home/seth/documents/school/COIS2020/ever.txt");


            file.AddDirectory("/home/seth/documents/school/COIS2830/");

            file.AddDirectory("/home/seth/documents/school/COIS1010/");
            file.AddFile("/home/seth/documents/school/COIS1010/sup.txt");
            file.AddFile("/home/seth/documents/school/COIS1010/sup1.txt");
            file.AddFile("/home/seth/documents/school/COIS1010/sup2.txt");
            file.AddFile("/home/seth/documents/school/COIS1010/sup3.txt");

            file.AddDirectory("/home/seth/documents/games/");
            file.AddDirectory("/home/seth/documents/games/terraria/");
            file.AddDirectory("/home/seth/documents/games/csgo/");
            file.AddDirectory("/home/seth/documents/games/insurgency/");
            file.AddDirectory("/home/seth/documents/games/borderlands/");
            file.AddDirectory("/home/seth/documents/games/minecraft/");
            file.AddDirectory("/home/seth/documents/games/frogger/");
        }
 private void GivenExistingFolder(string path)
 {
     FileSystem.AddDirectory(path);
 }
Esempio n. 12
0
    public static void Option(FileSystem fileSystem, string input)
    {
        string address;
        bool   result;

        switch (input)
        {
        case "1":                                                                                                       // Add directory
            Console.Write("\n\nPlease enter a directory to be added: ");
            address = Console.ReadLine();

            if (!address.EndsWith("/") && !address.EndsWith(" "))                                                       // Validate string input
            {
                result = fileSystem.AddDirectory(address);
                if (result)
                {
                    Console.WriteLine("Directory Added");
                }
                else
                {
                    Console.WriteLine("Directory Already Exists or the Path is Undefined");
                }
            }
            else
            {
                Console.WriteLine("Invalid directory passed");
            }
            break;

        case "2":                                                                                                       // Delete directory
            Console.Write("\n\nPlease enter a directory to be removed: ");
            address = Console.ReadLine();

            result = fileSystem.RemoveDirectory(address);
            if (result)
            {
                Console.WriteLine("Directory Removed");
            }
            else
            {
                Console.WriteLine("Path is Undefined");
            }
            break;

        case "3":                                                                                                       // Add file
            Console.Write("\n\nPlease enter a file to be added: ");
            address = Console.ReadLine();

            if (address.Length != 0 && !address.EndsWith("/") && !address.EndsWith(" "))                                // Validate string input
            {
                result = fileSystem.AddFile(address);

                if (result)
                {
                    Console.WriteLine("File Added");
                }
                else
                {
                    Console.WriteLine("File Already Exists in Directory or the Path is Undefined");
                }
            }
            else
            {
                Console.WriteLine("Invalid directory passed");
            }
            break;

        case "4":                                                                                                       // Delete file
            Console.Write("\n\nPlease enter a file to be removed: ");
            address = Console.ReadLine();

            result = fileSystem.RemoveFile(address);
            if (result)
            {
                Console.WriteLine("File Removed");
            }
            else
            {
                Console.WriteLine("Path is Undefined");
            }
            break;

        default:                                                                                                        // Invalid user input
            Console.WriteLine("Error invalid selection");
            break;
        }
    }