-
Notifications
You must be signed in to change notification settings - Fork 217
/
Client.ts
83 lines (76 loc) · 2.27 KB
/
Client.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// **********************************************************************
//
// Copyright (c) 2003-present ZeroC, Inc. All rights reserved.
//
// **********************************************************************
import {Ice} from "ice";
import {Filesystem} from "./generated";
(async () =>
{
//
// 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).
//
async function listRecursive(dir:Filesystem.DirectoryPrx, depth:number)
{
const indent = "\t".repeat(depth + 1);
const contents = await dir.list();
for(const node of contents)
{
const subdir = await Filesystem.DirectoryPrx.checkedCast(node);
console.log(indent + (await node.name()) + (subdir ? " (directory):" : " (file):"));
if(subdir)
{
await listRecursive(subdir, depth);
}
else
{
const file = Filesystem.FilePrx.uncheckedCast(node);
const text = await file.read();
for(const line of text)
{
console.log(`${indent}\t${line}`);
}
}
}
}
let communicator:Ice.Communicator;
try
{
communicator = Ice.initialize(process.argv);
if(process.argv.length > 2)
{
throw new Error("too many arguments");
}
//
// Create a proxy for the root directory
//
const base = communicator.stringToProxy("RootDir:default -h localhost -p 10000");
//
// Down-cast the proxy to a directory proxy
//
const rootDir = await Filesystem.DirectoryPrx.checkedCast(base);
if(!rootDir)
{
throw new Error("Invalid proxy");
}
//
// Recursively list the contents of the root directory
//
console.log("Contents of root directory:");
await listRecursive(rootDir, 0);
}
catch(ex)
{
console.log(ex.toString());
process.exitCode = 1;
}
finally
{
if(communicator)
{
await communicator.destroy();
}
}
})();