示例#1
0
文件: FileTree.cs 项目: stachupl/MNFS
        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;
        }
示例#2
0
文件: FileTree.cs 项目: stachupl/MNFS
 public FileNode(string name)
 {
     this.name = name;
     this.isDirectory = true;
     this.fileLocation = null;
     this.children = new List<FileNode>();
     this.parent = null;
 }
示例#3
0
文件: FileTree.cs 项目: stachupl/MNFS
 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;
 }
示例#4
0
文件: FileTree.cs 项目: stachupl/MNFS
 public FileTree()
 {
     root = new FileNode("/");
 }
示例#5
0
文件: FileTree.cs 项目: stachupl/MNFS
        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.";
            }
        }
示例#6
0
文件: FileTree.cs 项目: stachupl/MNFS
 private void delete()
 {
     root = new FileNode("/");
 }
示例#7
0
文件: FileTree.cs 项目: stachupl/MNFS
        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);
            }
        }
示例#8
0
文件: FileTree.cs 项目: stachupl/MNFS
        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);
            }
        }
示例#9
0
文件: FileTree.cs 项目: stachupl/MNFS
        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.";
            }
        }
示例#10
0
文件: FileTree.cs 项目: stachupl/MNFS
        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.";
        }
示例#11
0
文件: FileTree.cs 项目: stachupl/MNFS
        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.";
        }
示例#12
0
文件: FileTree.cs 项目: stachupl/MNFS
 private void delete()
 {
     root = new FileNode("/");
 }
示例#13
0
文件: FileTree.cs 项目: stachupl/MNFS
 public FileTree()
 {
     root = new FileNode("/");
 }