Exemplo n.º 1
0
 public void createDirectoryFalse()
 {
     //create sur un fichier
     current = (Directory)fileSystem.cd("autreDossier");
     current.chmod("4");
     Assert.IsFalse(current.createNewFile("fichier2"));
 }
Exemplo n.º 2
0
        //même principe que mkdir
        public bool CreateNewFile(string name)
        {
            if (this.IsDirectory() == true)
            {

                if (this.Cd(name) == null) //Vérifi si se fihier n'existe pas déjà
                {

                    if (this.CanWrite() == true)
                    {
                        File newFile = new File(name, this);
                        listeFils.Add(newFile);
                        return true;
                    }
                    else
                    {
                        Console.WriteLine("Erreur, Dossier non créé, vous n'aves pas les droits.");
                        return false;
                    }
                }
                else
                {
                    Console.WriteLine("Se Fichier existe déjà");
                    return false;
                }
            }
            else
            {
                Console.WriteLine("Vous ne pouvez pas car vous êtes dans un Fichier");
                return false;
            }
        }
Exemplo n.º 3
0
        public File cd(string options)
        {
            File objective = new File();
            if (this.canRead())
            {
                bool find = false;
                if (childList.Count > 0)
                {
                    childList.ForEach(delegate(File d)
                    {
                        if (d.name == options)
                        {
                            objective = d;
                            find = true;
                        }
                    });
                }
                else
                {
                    Console.WriteLine("Empty directory");
                }
                if (!find)
                {
                    Console.WriteLine("Impossible de se déplacer dans " + options);
                }
            }

            return objective;
        }
Exemplo n.º 4
0
 public bool createNewFile(string name)
 {
     bool create = false;
     if (this.canWrite())
     {
         foreach (File fichier in this.Fichiers)
         {
             if (fichier.Nom == name)
             {
                 Console.WriteLine("Ce fichier existe déjà");
                 create = true;
             }
         }
         if (create != true)
         {
             File fichier = new File(name, (Directory)this);
         }
         return create = true;
     }
     else
     {
         Console.WriteLine("Permissions insufissantes :{");
         return create;
     }
 }
Exemplo n.º 5
0
 public bool createNewFile(string name)
 {
     if (name != null && base.canWrite() && !this.exist(name)) {
         File fichier = new File (name, this);
         content.Add (fichier);
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 6
0
 public static void getCommand(File location)
 {
     Console.ForegroundColor = ConsoleColor.DarkGreen;
     Console.Write(location.path + "/> ");
     Console.ResetColor();
     string command = Console.ReadLine();
     List<string> instruction = command.Split().ToList();
     if (instruction.Count < 2)
     {
         instruction.Add(""); ;
     }
     getInstruction(instruction[0], location, instruction);
 }
Exemplo n.º 7
0
 public bool createNewFile(string name)
 {
     bool create = false;
     if (this.canWrite())
     {
         File fichier = new File(name, (Directory)this);
         return create = true;
     }
     else
     {
         Console.WriteLine("Permissions insufissantes :{");
         return create;
     }
 }
Exemplo n.º 8
0
 public bool create(string name)
 {
     bool create = false;
      bool nexist = this.notExist(name);
     if (this.canWrite() &&  nexist)
     {
         if (name != "")
         {
             File fichier = new File((Directory)this, name);
             create = true;
         }
     }
     else if (this.canWrite() == false && nexist == true)
         Console.WriteLine("Permissions insufissantes :{");
     return create;
 }
Exemplo n.º 9
0
 public void destroy(File f)
 {
     for (int i = 0; i < f.childList.Count; i++)
     {
         var child = f.childList[i];
         if (child.childList.Count > 0)
         {
             destroy(child);
         }
         else
         {
             child.parent.childList.Remove(child);
             child = null;
         }
     }
 }
Exemplo n.º 10
0
 public bool delete(string name)
 {
     bool found = false;
     if (this.canWrite())
     {
         File toRemove = new File();
         this.childList.ForEach(delegate(File child)
         {
             if (child.name == name)
             {
                 destroy(child);
                 toRemove = child;
             }
         });
         toRemove.parent.childList.Remove(toRemove);
         toRemove = null;
         found = true;
     }
     else
         Console.WriteLine("Permissions insufisantes :p");
     return found;
 }
Exemplo n.º 11
0
 public void TestIsFile_File()
 {
     File file = new File("file", null);
     Assert.IsTrue(file.isFile());
 }
Exemplo n.º 12
0
 public void TestGetNameFile()
 {
     File file = new File("file", null);
     Assert.AreEqual("file", file.getName());
 }
Exemplo n.º 13
0
 public void TestIsDirectory_File()
 {
     File file = new File("file", null);
     Assert.IsFalse(file.isDirectory());
 }
Exemplo n.º 14
0
 public FileBasedLocalCatalogue(IFileSystem fileSystem, InstallationDirectory installLocation)
 {
     _fileSystem = fileSystem;
     _file = installLocation.GetChildFile("catalogue.json");
     RemoteCatalogues = ReadExistingDataFromFile(_file);
 }
Exemplo n.º 15
0
        static void Main(string[] args)
        {
            Bloque[] Block = new Bloque[6];
            File[] Archivo = new File[3];

            for (int i = 0; i < Block.Length; i++)
            {
                Block[i] = new Bloque();
                Block[i].Disponibilidad = true;
                Block[i].Espacio = 100;
            }

            Archivo[0] = new File();
            Archivo[0].Nombre = "wow";
            Archivo[0].Tamaño = 85;

            Archivo[1] = new File();
            Archivo[1].Nombre = "yeah";
            Archivo[1].Tamaño = 125;

            Archivo[2] = new File();
            Archivo[2].Nombre = "who";
            Archivo[2].Tamaño = 253;

            Console.WriteLine("Espacios Disponibles");
            foreach (Bloque b in Block)
            {
                Console.WriteLine(b.Espacio);
            }
            Console.WriteLine();

            Console.WriteLine("Archivos a meter");
            foreach (File a in Archivo)
            {
                Console.WriteLine("Nombre: " + a.Nombre + " Tamaño: " + a.Tamaño);
            }
            Console.WriteLine();
            for (int i = 0; i < Archivo.Length; i++)
            {
                for (int j = 0; j < Block.Length; j++)
                {
                    if (Block[j].Disponibilidad == true)
                    {
                        Block[j].Nombre = Archivo[i].Nombre;

                        if (Block[j].Espacio - Archivo[i].Tamaño >= 0)
                        {
                            Block[j].Espacio -= Archivo[i].Tamaño;
                            Block[j].Disponibilidad = false;
                            break;
                        }
                        else if (Block[j].Espacio - Archivo[i].Tamaño < 0)
                        {
                            Block[j].Espacio = 0;
                            Archivo[i].Tamaño -= 100;
                            Block[j].Disponibilidad = false;
                        }
                    }
                }
            }
            Console.WriteLine("Bloque resultantes");
            foreach (Bloque b in Block)
            {
                Console.WriteLine("Nombre de archivo almacenado: " + b.Nombre + " Espacio disponible: " + b.Espacio + " Disponibilidad: " + b.Disponibilidad);
            }
            Console.ReadKey();
        }
Exemplo n.º 16
0
        public static void commande(File Actuel)
        {
            Console.Write(Actuel.path + "> ");
            string commandes = Console.ReadLine();
            List<string> action = new List<string> (commandes.Split(' '));
               switch (action[0])
               {
                   case "path":
                       if (action.Count == 1)
                       {
                           Console.WriteLine(Actuel.getPath());
                       }
                       else
                       {
                           runOrNot(Actuel);
                       }
                   break;
                   case "search":
                   if (action.Count == 2)
                   {
                       if (Actuel.isDirectory())
                       {
                           Directory dir = (Directory)Actuel;
                           var list = new List<File>();
                           if (dir.isDirectory())
                              list = dir.search(action[1]);
                           list.ForEach(delegate(File f)
                           {
                               Console.WriteLine("   found : " + f.GetType().ToString().Replace("FileSystem.", " ").Substring(0, 4) + "  " + f.path);
                           });
                       }
                       else
                       {
                           Console.WriteLine("Vous êtes dans un fichier");
                       }
                   }
                   else
                   {
                       runOrNot(Actuel);
                   }
                    break;
                   case "create":
                   if (action.Count == 2)
                   {
                       if (Actuel.isDirectory())
                       {
                           Directory dir = (Directory)Actuel;
                           dir.createNewFile(action[1]);
                           Actuel = dir;
                       }
                       else
                       {
                           Console.WriteLine("Vous n'êtes pas dans un dossier");
                       }
                   }
                   else
                   {
                       runOrNot(Actuel);
                   }
                   break;
                   case "mkdir":
                   if (action.Count == 2)
                   {
                       if (Actuel.isDirectory())
                       {
                           bool test = false;
                           Directory dir = (Directory)Actuel;
                           foreach (File fichier in dir.Fichiers)
                           {
                               if (fichier.Nom == action[1])
                               {
                                   Console.WriteLine("Ce fichier existe déjà");
                                   test = true;
                                   break;
                               }
                           }
                           if (test == false)
                           {
                               dir.mkdir(action[1]);
                               Actuel = dir;
                           }
                       }
                       else
                       {
                           Console.WriteLine("Vous n'êtes pas dans un dossier");
                       }
                   }
                   else
                   {
                       runOrNot(Actuel);
                   }
                   break;
                   case "name":
                   if (action.Count == 1)
                   {
                       Console.WriteLine(Actuel.getName());
                   }
                   else
                   {
                       runOrNot(Actuel);
                   }
                   break;
                   case "ls":
                   if (action.Count == 1)
                   {
                       if (Actuel.isDirectory())
                       {
                           Directory dir = (Directory)Actuel;
                           if (dir.Fichiers.Count > 0)
                           {
                               Console.WriteLine();
                               foreach (File file in dir.ls())
                               {
                                   if (file.GetType().ToString() == "FileSystem.Directory")
                                   {
                                       Console.WriteLine("D " + file.Nom);
                                   }
                                   else
                                   {
                                       Console.WriteLine("F " + file.Nom);
                                   }
                               }
                               Console.WriteLine();
                           }
                       }
                       else
                       {
                           Console.WriteLine("Vous n'êtes pas dans un dossier");
                       }
                   }
                   else
                   {
                       runOrNot(Actuel);
                   }
                   break;
                   case "cd":
                       if (action.Count == 2)
                       {
                           if (Actuel.isDirectory())
                           {
                               Directory dir = (Directory)Actuel;
                               Actuel = dir.cd(action[1]);
                           }
                           else
                           {
                               Console.WriteLine("Vous êtes dans un fichier");
                           }
                       }
                       else
                       {
                           runOrNot(Actuel);
                       }
                   break;
                   case "file":
                       if (action.Count == 1)
                       {
                           if (Actuel.isFile() == true)
                           {
                               Console.WriteLine("C'est un fichier");
                           }
                           else
                           {
                               Console.WriteLine("Ce n'est pas un fichier");
                           }
                       }
                       else
                       {
                           runOrNot(Actuel);
                       }

                   break;
                   case "rename":
                   if (action.Count == 3)
                   {
                       if (Actuel.isDirectory())
                       {
                           Directory dir = (Directory)Actuel;
                           dir.renameTo(action[1], action[2]);
                           Actuel = dir;
                       }
                   }
                   else
                   {
                       runOrNot(Actuel);
                   }
                   break;
                   case "chmod":
                       if (action.Count == 2)
                       {
                           int permission;
                       if (Int32.TryParse(action[1], out permission))
                       {
                           permission = Int32.Parse(action[1]);
                           Actuel.chmod(permission);
                       }
                       else
                       {
                           Console.WriteLine("Permission impossible");
                       }
                       }
                       else
                       {
                           runOrNot(Actuel);
                       }

                   break;
                   case "directory":
                   if (action.Count == 1)
                   {
                       if (Actuel.isDirectory() == true)
                       {
                           Console.WriteLine("C'est un répertoire");
                       }
                       else
                       {
                           Console.WriteLine("Ce n'est pas un répertoire");
                       }
                   }
                   else
                   {
                       runOrNot(Actuel);
                   }
                   break;
                   case "delete":
                   if (action.Count == 2)
                   {
                       if (Actuel.isDirectory())
                       {
                           Directory dir = (Directory)Actuel;
                           dir.delete(action[1]);
                           Actuel = dir;
                       }
                   }
                   else
                   {
                       runOrNot(Actuel);
                   }

                   break;
                   case "root":
                   if (action.Count == 1)
                   {
                       Console.WriteLine(Actuel.getRoot().Nom);
                   }
                   else
                   {
                       runOrNot(Actuel);
                   }
                   break;
                   case "parent":
                   if (action.Count == 1)
                   {
                       if (Actuel.getParent() != Actuel)
                       {
                           Actuel = (Directory)Actuel.getParent();
                       }

                   }
                   else
                   {
                       runOrNot(Actuel);
                   }
                   break;
                   case "exit":
                   if (action.Count == 1)
                   {
                       System.Environment.Exit(-1);
                   }
                   else
                   {
                       runOrNot(Actuel);
                   }
                   break;
                   case "":
                   break;
                   default:
                   Console.WriteLine("Commande inexistante");
                   break;
               }
               commande(Actuel);
        }
Exemplo n.º 17
0
        protected FileBasedConfiguration(IFileSystem fileSystem, File configurationPath)
        {
            FileSystem = fileSystem;

            Entries = ReadExistingConfigurationFromFile(configurationPath);
        }
Exemplo n.º 18
0
 public void IsFile()
 {
     samFichier = repCourant.cd("samFichier");
     Assert.IsTrue(samFichier.isFile());
 }
Exemplo n.º 19
0
 public void IsNotDirectory()
 {
     samFichier = repCourant.cd("samFichier");
     Assert.IsFalse(samFichier.isDirectory());
 }
Exemplo n.º 20
0
        public void SetUp()
        {
            current = new Directory("C:", true);
            current.chmod(7);
            current.mkdir("Dossier1");
            current.mkdir("Dossier2");
            current.mkdir("Dossier3");
            current.createNewFile("CFile");
            NouvFile = current.cd("NouvFile");
            Dossier1 = (Directory)current.cd("Dossier1");
            Dossier2 = (Directory)current.cd("Dossier2");
            Dossier3 = (Directory)current.cd("Dossier3");

            CFile = current.cd("CFile");
            Dossier2 = (Directory)current.cd("Dossier2");
        }
Exemplo n.º 21
0
 public void SetUp()
 {
     racine = new Directory("root") {path = "#",isRoot = true };
     courrant = racine;
 }
 internal void Add(File file)
 {
     _files.Add(file.Name, file);
 }
Exemplo n.º 23
0
 public void CreateNewFileByFile()
 {
     File file = new File("file", null);
     Assert.IsFalse(file.createNewFile("hui"));
 }
Exemplo n.º 24
0
        Entries ReadExistingConfigurationFromFile(File configurationFile)
        {
            _configurationPath = configurationFile;

            if (!configurationFile.Exists())
            {
                _log.Debug(x => x.Write("No existing configuration file found: {0}", configurationFile.Name));

                return new Entries();
            }

            return new Entries(JsonUtil.Get<Entry[]>(configurationFile.ReadToEnd()) ?? new Entry[0]);
        }
Exemplo n.º 25
0
 public void TestMkdirdansFile()
 {
     File file = new File("file", null);
     Assert.IsFalse(file.mkdir("directory"));
 }
Exemplo n.º 26
0
 public void tMkdirNom()
 {
     courrant.chmod(7);
        Directory dir = (Directory)courrant;
        dir.mkdir("next");
        courrant = dir.cd("next");
        Assert.AreEqual("next", courrant.name);
 }
Exemplo n.º 27
0
 public void TestCreateFiledansFile()
 {
     File file = new File("file", null);
     Assert.IsFalse(file.createNewFile("file"));
 }
Exemplo n.º 28
0
        ExternalLinks ReadExistingDataFromFile(File file)
        {
            _file = file;

            if (!file.Exists())
            {
                _log.Debug(x => x.Write("No existing catalogue file found: {0}", file.Name));

                return new ExternalLinks();
            }

            return new ExternalLinks(JsonUtil.Get<Remote[]>(file.ReadToEnd()) ?? new Remote[0]);
        }
Exemplo n.º 29
0
 public static void runOrNot( File Actuel)
 {
     Console.WriteLine("Commande incomplète ou argument non valide");
     commande(Actuel);
 }
Exemplo n.º 30
0
 public File getRoot()
 {
     File root = new File();
     root = (File)this;
     while (root.isRoot == false)
     {
         root = root.parent;
     }
     return root;
 }