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]); } } } }