internal virtual void list(Filesystem.DirectoryPrx dir, bool recursive, int depth) { StringBuilder b = new StringBuilder(); for (int i = 0; i < depth; ++i) { b.Append('\t'); } string indent = b.ToString(); NodeDesc[] contents = dir.list(); for (int i = 0; i < contents.Length; ++i) { DirectoryPrx d = contents[i].type == NodeType.DirType ? DirectoryPrxHelper.uncheckedCast(contents[i].proxy) : null; Console.Write(indent + contents[i].name + (d != null ? " (directory)" : " (file)")); if (d != null && recursive) { Console.WriteLine(":"); list(d, true, ++depth); } else { Console.WriteLine(); } } }
// Recursively print the contents of directory "dir" in tree fashion. // For files, show the contents of each file. The "depth" // parameter is the current nesting level (for indentation). static void listRecursive(DirectoryPrx dir, int depth) { var indent = new string('\t', ++depth); NodePrx[] contents = dir.list(); foreach (var node in contents) { var subdir = DirectoryPrxHelper.checkedCast(node); var file = FilePrxHelper.uncheckedCast(node); Console.WriteLine(indent + node.name() + (subdir != null ? " (directory):" : " (file):")); if (subdir != null) { listRecursive(subdir, depth); } else { var text = file.read(); for (int j = 0; j < text.Length; ++j) { Console.WriteLine(indent + "\t" + text[j]); } } } }
internal virtual void cat(string name) { DirectoryPrx dir = (DirectoryPrx)_dirs[0]; NodeDesc d; try { d = dir.find(name); } catch (NoSuchName) { Console.WriteLine("`" + name + "': no such file"); return; } if (d.type == NodeType.DirType) { Console.WriteLine("`" + name + "': not a file"); return; } FilePrx f = FilePrxHelper.uncheckedCast(d.proxy); string[] l = f.read(); for (int i = 0; i < l.Length; ++i) { Console.WriteLine(l[i]); } }
internal virtual void write(IList args) { DirectoryPrx dir = (DirectoryPrx)_dirs[0]; string name = (string)args[0]; args.RemoveAt(0); NodeDesc d; try { d = dir.find(name); } catch (NoSuchName) { Console.WriteLine("`" + name + "': no such file"); return; } if (d.type == NodeType.DirType) { Console.WriteLine("`" + name + "': not a file"); return; } FilePrx f = FilePrxHelper.uncheckedCast(d.proxy); string[] l = new string[args.Count]; args.CopyTo(l, 0); try { f.write(l); } catch (GenericError ex) { Console.WriteLine("`" + name + "': cannot write to file: " + ex.reason); } }
// Recursively print the contents of directory "dir" in tree fashion. // For files, show the contents of each file. The "depth" // parameter is the current nesting level (for indentation). static void listRecursive(DirectoryPrx dir, int depth) { string indent = new string('\t', ++depth); NodePrx[] contents = dir.list(); foreach(NodePrx node in contents) { DirectoryPrx subdir = DirectoryPrxHelper.checkedCast(node); FilePrx file = FilePrxHelper.uncheckedCast(node); Console.WriteLine(indent + node.name() + (subdir != null ? " (directory):" : " (file):")); if(subdir != null) { listRecursive(subdir, depth); } else { string[] text = file.read(); for(int j = 0; j < text.Length; ++j) { Console.WriteLine(indent + "\t" + text[j]); } } } }
public override int run(String[] args) { // // Terminate cleanly on receipt of a signal. // shutdownOnInterrupt(); // // Create a proxy for the root directory // Ice.ObjectPrx @base = communicator().stringToProxy("RootDir:default -h localhost -p 10000"); // // Down-cast the proxy to a Directory proxy. // DirectoryPrx rootDir = DirectoryPrxHelper.checkedCast(@base); if (rootDir == null) { throw new Error("Invalid proxy"); } Parser p = new Parser(rootDir); return(p.parse()); }
public static int Main(string[] args) { int status = 0; Ice.Communicator ic = null; try { Ice.InitializationData data = new Ice.InitializationData(); // // Create a communicator // ic = Ice.Util.initialize(ref args, data); // // Create a proxy for the root directory // Ice.ObjectPrx obj = ic.stringToProxy("RootDir:default -h localhost -p 10000"); // // Down-cast the proxy to a Directory proxy // DirectoryPrx rootDir = DirectoryPrxHelper.checkedCast(obj); if (rootDir == null) { throw new ApplicationException("Invalid proxy"); } // // Recursively list the contents of the root directory // Console.WriteLine("Contents of root directory:"); listRecursive(rootDir, 0); } catch (Exception e) { Console.Error.WriteLine(e); status = 1; } if (ic != null) { try { ic.destroy(); } catch (Exception e) { Console.Error.WriteLine(e); status = 1; } } return(status); }
internal virtual void destroy(IList names) { DirectoryPrx dir = (DirectoryPrx)_dirs[0]; foreach (string name in names) { if (name.Equals("*")) { NodeDesc[] nodes = dir.list(); for (int j = 0; j < nodes.Length; ++j) { try { nodes[j].proxy.destroy(); } catch (PermissionDenied ex) { Console.WriteLine("cannot remove `" + nodes[j].name + "': " + ex.reason); } } return; } else { NodeDesc d; try { d = dir.find(name); } catch (NoSuchName) { Console.WriteLine("`" + name + "': no such file or directory"); return; } try { d.proxy.destroy(); } catch (PermissionDenied ex) { Console.WriteLine("cannot remove `" + name + "': " + ex.reason); } } } }
internal virtual void createFile(IList names) { DirectoryPrx dir = (DirectoryPrx)_dirs[0]; foreach (string name in names) { if (name.Equals("..")) { Console.WriteLine("Cannot create a file named `..'"); continue; } try { dir.createFile(name); } catch (NameInUse) { Console.WriteLine("`" + name + "' exists already"); } } }
internal virtual void cd(string name) { if (name.Equals("/")) { while (_dirs.Count > 1) { _dirs.RemoveAt(0); } return; } if (name.Equals("..")) { if (_dirs.Count > 1) { _dirs.RemoveAt(0); } return; } DirectoryPrx dir = (DirectoryPrx)_dirs[0]; NodeDesc d; try { d = dir.find(name); } catch (NoSuchName) { Console.WriteLine("`" + name + "': no such directory"); return; } if (d.type == NodeType.FileType) { Console.WriteLine("`" + name + "': not a directory"); return; } _dirs.Insert(0, DirectoryPrxHelper.uncheckedCast(d.proxy)); }
internal Parser(DirectoryPrx root) { _dirs = new ArrayList(); _dirs.Insert(0, root); }
public static int Main(string[] args) { int status = 0; Ice.Communicator ic = null; try { Ice.InitializationData data = new Ice.InitializationData(); #if COMPACT // // When using Ice for .NET Compact Framework, we need to specify // the assembly so that Ice can locate classes and exceptions. // data.properties = Ice.Util.createProperties(); data.properties.setProperty("Ice.FactoryAssemblies", "client,version=1.0.0.0"); #endif // // Create a communicator // ic = Ice.Util.initialize(ref args, data); // // Create a proxy for the root directory // Ice.ObjectPrx obj = ic.stringToProxy("RootDir:default -h localhost -p 10000"); // // Down-cast the proxy to a Directory proxy // DirectoryPrx rootDir = DirectoryPrxHelper.checkedCast(obj); if (rootDir == null) { throw new ApplicationException("Invalid proxy"); } // // Recursively list the contents of the root directory // Console.WriteLine("Contents of root directory:"); listRecursive(rootDir, 0); } catch (Exception e) { Console.Error.WriteLine(e); status = 1; } if (ic != null) { try { ic.destroy(); } catch (Exception e) { Console.Error.WriteLine(e); status = 1; } } return(status); }