Esempio n. 1
0
        public FileNode parent; // odniesienie do węzła nadrzędnego

        #endregion Fields

        #region Constructors

        public FileNode()
        {
            this.name = "";
            this.isDirectory = false;
            this.fileLocation = null;
            this.children = null;
            this.parent = null;
        }
Esempio n. 2
0
 public FileNode(string name)
 {
     this.name = name;
     this.isDirectory = true;
     this.fileLocation = null;
     this.children = new List<FileNode>();
     this.parent = null;
 }
Esempio n. 3
0
 public FileNode(string name, FileNetworkAddress address)
 {
     this.name = name;
     this.isDirectory = false;
     this.fileLocation = new ArrayList();
     this.fileLocation.Add(address);
     this.children = null;
     this.parent = null;
 }
Esempio n. 4
0
 public FileTree()
 {
     root = new FileNode("/");
 }
Esempio n. 5
0
        public string mkdir(string path, string name)
        {
            FileNode newDirectory = new FileNode(name);
            FileNode directory;
            bool exist = false;

            directory = locateDirectory(path);
            if (directory == null)
                return "Path doesn't exist. Can't create directory!";

            foreach (FileNode fn in directory.children)
                if (fn.name == name && fn.isDirectory == true)
                    exist = true;

            if (exist == true)
                return "Directory exist. Can't create!";
            else
            {
                newDirectory.parent = directory;
                directory.children.Add(newDirectory);
                return "Directory created.";
            }
        }
Esempio n. 6
0
 private void delete()
 {
     root = new FileNode("/");
 }
Esempio n. 7
0
        public void findDirectory(FileNode directory, string workingDirectory, string name, ArrayList result)
        {
            foreach (FileNode fn in directory.children)
            {
                Console.WriteLine("AAA {0}, {1}, {2},", fn.name, name, fn.isDirectory);
                if (fn.name == name && fn.isDirectory == true)
                {
                    result.Add(workingDirectory + "/" + name);
                    Console.WriteLine("ffff");
                }

                if (fn.isDirectory == true)
                    findDirectory(fn, workingDirectory + "/" + fn.name, name, result);
            }
        }
Esempio n. 8
0
        public void findFile(FileNode directory, string workingDirectory, string name, ArrayList result)
        {
            foreach (FileNode fn in directory.children)
            {
                if (fn.name == name && fn.isDirectory == false)
                    result.Add(workingDirectory + "/" + name);

                if (fn.isDirectory == true)
                    findFile(fn, workingDirectory + "/" + fn.name, name, result);
            }
        }
Esempio n. 9
0
        public string create(string path, string name, string locationIP, string locationPort, string id)
        {
            FileNode directory;
            bool exist = false;

            directory = locateDirectory(path);
            if (directory == null)
                return "Path doesn't exist. Can't create file!";

            foreach (FileNode fn in directory.children)
                if (fn.name == name && fn.isDirectory == false)
                    exist = true;

            if (exist == true)
                return "File exist. Can't create!";
            else
            {
                FileNetworkAddress address = new FileNetworkAddress(id, locationIP, locationPort);
                FileNode newFile = new FileNode(name, address);
                newFile.parent = directory;
                directory.children.Add(newFile);

                return "File successfully created.";
            }
        }
Esempio n. 10
0
        public string cpdir(string sourcePath, string destinationPath)
        {
            FileNode file, newFile;
            FileNode destinationDiretory;
            bool exist = false;

            file = locateDirectory(sourcePath);
            if (file == null)
                return "Directory doesn't exist. Can't copy!";

            destinationDiretory = locateDirectory(destinationPath);
            if (destinationDiretory == null)
                return "Destination directory doesn't exist. Can't copy!";

            if (file.children.Count > 0)
                return "Source directory doesn't empty. Can't copy!";

            foreach (FileNode fn in destinationDiretory.children)
                if (fn.name == file.name && fn.isDirectory == true)
                    exist = true;

            if (exist == true)
                return "In destination directory exist directory with the same name. Can't copy!";

            newFile = new FileNode(file.name);
            newFile.parent = destinationDiretory;
            destinationDiretory.children.Add(newFile);

            return "Directory successfully copied.";
        }
Esempio n. 11
0
        public string cp(string sourcePath, string destinationPath, FileNetworkAddress address)
        {
            FileNode file, newFile;
            FileNode destinationDiretory;
            bool exist = false;

            file = locateFile(sourcePath);
            if (file == null)
                return "File doesn't exist. Can't copy!";

            destinationDiretory = locateDirectory(destinationPath);
            if (destinationDiretory == null)
                return "Destination directory doesn't exist. Can't copy!";

            foreach (FileNode fn in destinationDiretory.children)
                if (fn.name == file.name && fn.isDirectory == false)
                    exist = true;

            if (exist == true)
                return "In destination directory exist file with the same name. Can't copy!";

            newFile = new FileNode(file.name, address);
            newFile.parent = destinationDiretory;
            destinationDiretory.children.Add(newFile);

            return "File successfully copied.";
        }
Esempio n. 12
0
 private void delete()
 {
     root = new FileNode("/");
 }
Esempio n. 13
0
 public FileTree()
 {
     root = new FileNode("/");
 }