Beispiel #1
0
 public void SearchbyFileNoExist()
 {
     Directory dossier = new Directory("dossier", null);
     dossier.mkdir("hui");
     dossier.chmod(7);
     Assert.AreEqual(dossier.search("cuicui").Count, 0);
 }
Beispiel #2
0
        public void SearchbyFile()
        {
            Directory dossier = new Directory("dossier", null);
            File fileCurrent = dossier;
            fileCurrent.chmod(7);

            fileCurrent.mkdir("hui");
            fileCurrent = fileCurrent.cd("hui");
            fileCurrent.chmod(7);
            fileCurrent.mkdir("hui");
            fileCurrent = fileCurrent.cd("hui");
            fileCurrent.chmod(7);
            fileCurrent.mkdir("hui");
            fileCurrent = fileCurrent.cd("hui");
            fileCurrent.chmod(1);

            Assert.AreEqual(dossier.search("hui").Count, 3);
        }
 public void TestSearchFileExist()
 {
     Directory dossier = new Directory("dossier", null);
     dossier.chmod("7");
     dossier.createNewFile("file");
     Assert.AreEqual(dossier.search("Fichier").Count, 0);
 }
        public void TestSearchFile()
        {
            Directory dossier = new Directory("dossier", null);
            File file = dossier;
            file.chmod("7");
            file.mkdir("Directory");
            file = file.cd("Directory");
            file.chmod("7");
            file.mkdir("Directory");
            file = file.cd("Directory");
            file.chmod("7");
            file.createNewFile("Directory");

            Assert.AreEqual(dossier.search("Directory").Count, 3);
        }
 public void search()
 {
     repCourant.cd("lol");
     lol = (Directory)repCourant;
     lol.createNewFile("truc");
     lol.getParent();
     lol.getParent();
     Assert.AreEqual(lol.search("truc").Count, 1);
 }
Beispiel #6
0
 public static void getInstruction(string instruction, File Current, List<string> options)
 {
     File old = Current;
     var dir = new Directory();
     if(Current.getDir())
          dir = (Directory)Current;
     switch (instruction)
     {
         case "ls":
             List<File>ls =new List<File>();
             ls = Current.ls();
             if (ls.Count == 0 && Current.getFile())
                 Console.WriteLine("Vous etes dans un fichier");
             else
             if (ls.Count > 0)
             {
                 ls.ForEach(delegate(File f){
                     if (f.canExecute())
                         Console.Write("e");
                     Console.Write('-');
                     if (f.canRead())
                         Console.Write("r");
                     Console.Write("-");
                     if (f.canWrite())
                         Console.Write("w");
                     Console.Write("-");
                     Console.Write("   (" + f.GetType().ToString().Replace("FileSystem.", " ").Substring(0,4) + " )   " + f.path + "\n");
                 });
             }
             break;
         case "cd":
             location = Current.cd(options[1]);
             if (location.path == null)
                 location = old;
             break;
         case "type":
             String type = Current.GetType().ToString();
             string[] t = type.Split('.');
             Console.WriteLine(t[1]);
             break;
         case "mkdir":
             bool created = false;
             if (Current.getDir())
                 created = dir.mkdir(options[1]);
             else
                 Console.WriteLine("Impossible de créer quelque chose dans un fichier");
             break;
         case "parent":
             location = Current.getParent();
             break;
         case "root":
             File root = new File();
             root =Current.getRoot();
             location = (Directory)root;
             break;
         case "create":
             bool c = false;
             if(Current.getDir())
                 c= dir.create(options[1]);
             if (!c)
                 Console.WriteLine("    Une erreur c'est produite");
             break;
         case "rename":
             bool r = false;
             if(Current.getDir())
               r = dir.rename(options[1],options[2]);
             if (r)
                 Console.WriteLine("    " + options[1] + " a été renommé en : " + options[2]);
             else
                 Console.WriteLine("    Impossible de renommer ce fichier.");
             break;
         case "path":
             string path = dir.getPath();
             Console.WriteLine("   " + path);
             break;
         case "name":
             Current.getName();
             break;
         case "file":
             break;
         case "directory":
             if (Current.getDir())
                 Console.WriteLine("C'est un dossier");
             else
                 Console.WriteLine("Ce n'est pas un dossier");
             break;
         case "search":
             var  list = new List<File>();
             if (Current.getDir())
             dir.search(options[1],list);
             list.ForEach(delegate(File f)
             {
                 Console.WriteLine("   found : " + f.GetType().ToString().Replace("FileSystem.", " ").Substring(0,4) + "  "+f.path);
             });
             break;
         case "delete":
             bool deleted = false;
             if(Current.getDir())
                 deleted = dir.delete(options[1]);
             if (deleted)
                 Console.WriteLine("Le dossier " + options[1] + " a été érradiqué");
             else
                 Console.WriteLine("Le dossier n'a pas été trouvé :(");
             break;
         case "chmod":
             if(dir.isRoot==true)
             {
                 Console.WriteLine("Impossible de faire un chmod sur la racine");
                 break;
             }
             int number;
             if (int.TryParse(options[1].ToString(), out number))
                 Current.chmod(int.Parse(options[1]));
             else
                 Console.WriteLine("    You shall not parse !");
             break;
         default:
             Console.WriteLine("Commande inconnue");
             break;
     }
 }