Page 17: Iterate over the Local Database |
It is assumed that you've followed the steps from Page 1: Prerequisites to Page 15: Nullable Parameters, and thus have a runnable project open in Visual Studio 2015.
This topic contains the following sections:
First we need to declare our expectations about the provider database with the following nested types:
// Subclassing Root means that the Children collection of this node will only contain the elements declared // with properties, in this case a single node with the identifier Sapphire, which is also accessible through // the property. private sealed class MixedSapphireRoot : Root<MixedSapphireRoot> { internal MixedSapphire Sapphire { get; private set; } } // Subclassing DynamicFieldNode means that the Children collection of this node will contain *all* elements // reported by the provider. Additionally, the node with the identifier Sources is also accessible through the // property. private sealed class MixedSapphire : DynamicFieldNode<MixedSapphire> { internal CollectionNode<MixedSource> Sources { get; private set; } } // Subclassing DynamicFieldNode means that the Children collection of this node will contain *all* elements // reported by the provider. Additionally, the nodes Fader and Dsp are also accessible through their // respective properties. The Fader and Dsp types themselves derive from FieldNode, so their Children // collections will only contain the parameters declared as properties. private sealed class MixedSource : DynamicFieldNode<MixedSource> { internal Fader Fader { get; private set; } [Element(Identifier = "DSP")] internal Dsp Dsp { get; private set; } }
We can now iterate over the local database as follows ...
AsyncPump.Run( async () => { using (var client = await ConnectAsync("localhost", 9000)) using (var consumer = await Consumer<MixedSapphireRoot>.CreateAsync(client)) { WriteChildren(consumer.Root, 0); } });
... and get 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 dB Value: -255.999999999998 Parameter Position: 0 Node DSP Node Input Parameter Phase: True Parameter LR Mode: Stereo Node FPGM 2 Parameter Audio Type: 2 Node Fader Parameter dB Value: 9 Parameter Position: 255 Node DSP Node Input Parameter Phase: False Parameter LR Mode: Stereo
Note how the Audio Type parameters and the identity node with all its children now appear although we have not declared properties for them. This is due to the fact that their parents subclass DynamicFieldNodeTMostDerived rather than FieldNodeTMostDerived.
Proceed to Page 18: Send Local Changes to the Provider.