Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions csharp/Ice/Filesystem/Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,36 @@

// Recursively list the contents of the root directory.
Console.WriteLine("Contents of root directory:");
ListRecursive(rootDir);
await ListRecursiveAsync(rootDir);

/// <summary>Recursively print the contents of a directory in tree fashion. For files, show the contents of each file.
/// </summary>
/// <param name="dir">The directory to list./<param>
/// <param name="depth">The current nesting level (for indentation).</param>
void ListRecursive(DirectoryPrx dir, int depth = 0)
async Task ListRecursiveAsync(DirectoryPrx dir, int depth = 0)
{
var indent = new string('\t', ++depth);

NodePrx?[] contents = dir.List();
NodePrx?[] contents = await dir.ListAsync();

foreach (NodePrx? node in contents)
{
Debug.Assert(node is not null); // The node proxies returned by list() are never null.

// TODO: should be an async call
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should generate a checkedCastAsync ... anything else would be inconsistent.

Copy link
Member

@pepone pepone Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding checkedCastAsync sounds good. On a side note the Slice model for this example isn't great.

I wondering if we should add a NodeInfo struct and NodeKind enum:

enum NodeKind
{
   File,
   Directory
}

struct NodeInfo
{
    string name;
    NodeKind kind;
    Node* node;
}

sequence<NodeInfo> NodeInfoSeq;

interface Directory extends Node
{
    idempotent NodeInfoSeq list();
}

This avoids the need for separate name, checkedCast requests.

DirectoryPrx? subdir = DirectoryPrxHelper.checkedCast(node);
string kind = subdir is not null ? "directory" : "file";

Console.WriteLine($"{indent}{node.Name()} {kind}:");
Console.WriteLine($"{indent}{await node.NameAsync()} {kind}:");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a name variable here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This demo is really about the power of inheritance. And implementation reuse in C++. So I would not change the model or the checkedCast[Async].


if (subdir is not null)
{
ListRecursive(subdir, depth);
await ListRecursiveAsync(subdir, depth);
}
else
{
FilePrx file = FilePrxHelper.uncheckedCast(node);
string[] lines = file.Read();
string[] lines = await file.ReadAsync();
foreach (string line in lines)
{
Console.WriteLine($"{indent}\t{line}");
Expand Down
Loading