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."); } }
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; }
public string addLocation(string path, string id, string ip, string port) { FileNode file; FileNetworkAddress address = new FileNetworkAddress(id, ip, port); file = locateFile(path); if (file == null) { return("File doesn't exist. Can't add new location"); } file.fileLocation.Add(address); return("New location successfully added"); }
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."); }
static void write(string path) { FileNetworkAddress servers = new FileNetworkAddress(); try { //servers = (FileNetworkAddress) nameServer.write(path); } catch (Exception) { Console.WriteLine("Device temporarily unavailable. Try again later."); } }
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."; } }
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."; }
public string addLocation(string path, string id, string ip, string port) { FileNode file; FileNetworkAddress address = new FileNetworkAddress(id, ip, port); file = locateFile(path); if (file == null) return "File doesn't exist. Can't add new location"; file.fileLocation.Add(address); return "New location successfully added"; }