// 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); } }
// Slice createFile() operation. public override FilePrx createFile(string name, Current c) { lock (this) { if (_destroyed) { throw new ObjectNotExistException(); } if (name.Length == 0 || _contents.ContainsKey(name)) { throw new NameInUse(name); } var f = new FileI(name, this); var node = c.adapter.add(f, f.id()); _contents.Add(name, f); return(FilePrxHelper.uncheckedCast(node)); } }