Click or drag to resize
Page 5: Iterate over the Local Database

Next, we'd like to write out all elements of the local database. This can be achieved with the following method ...

C#
private static void WriteChildren(INode node, int depth)
{
    var indent = new string(' ', 2 * depth);

    foreach (var child in node.Children)
    {
        var childNode = child as INode;

        if (childNode != null)
        {
            Console.WriteLine("{0}Node {1}", indent, child.Identifier);
            WriteChildren(childNode, depth + 1);
        }
        else
        {
            var childParameter = child as IParameter;

            if (childParameter != null)
            {
                Console.WriteLine("{0}Parameter {1}: {2}", indent, child.Identifier, childParameter.Value);
            }
        }
    }
}

... which we call from Main() as follows ...

C#
AsyncPump.Run(
    async () =>
    {
        using (var client = await ConnectAsync("localhost", 9000))
        using (var consumer = await Consumer<MyRoot>.CreateAsync(client))
        {
            WriteChildren(consumer.Root, 0);
        }
    });

... which produces the following output:

Node Sapphire
  Node identity
    Parameter product: sapphire
    Parameter company: (c) L-S-B Broadcast Technologies GmbH
  Node Sources
    Node FPGM 1
      Parameter Audio Type: 2
      Node Fader
        Parameter Number: 1
        Parameter dB Value: -255.999999999998
        Parameter Position: 0
      Node DSP
        Node Input
          Parameter Gain: 0
          Parameter Phase: True
          Parameter LR Mode: 0
        Node Delay
          Parameter Time (ms): 0
    Node FPGM 2
      Parameter Audio Type: 2
      Node Fader
        Parameter Number: 2
        Parameter dB Value: 9
        Parameter Position: 255
      Node DSP
        Node Input
          Parameter Gain: 0
          Parameter Phase: False
          Parameter LR Mode: 0
        Node Delay
          Parameter Time (ms): 0

Proceed to Page 6: React to Changes.