Click or drag to resize
Page 7: Send Local Changes to the Provider

As you might expect, modifying a value is as easy as setting the IParameterValue property. However, as we've already seen on Page 6: React to Changes, getting to specific elements is rather cumbersome:

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

            // Navigate to the parameters we're interested in.
            var sapphire = (INode)root.Children.First(c => c.Identifier == "Sapphire");
            var sources = (INode)sapphire.Children.First(c => c.Identifier == "Sources");
            var fpgm1 = (INode)sources.Children.First(c => c.Identifier == "FPGM 1");
            var fader = (INode)fpgm1.Children.First(c => c.Identifier == "Fader");
            var level = (IParameter)fader.Children.First(c => c.Identifier == "dB Value");
            var position = (IParameter)fader.Children.First(c => c.Identifier == "Position");

            // Set parameters to the desired values.
            level.Value = -67.0;
            position.Value = 128L;

            // We send the changes back to the provider with the call below. Here, this is necessary so that
            // the changes are sent before Dispose is called on the consumer. In a real-world application
            // however, SendAsync often does not need to be called explicitly because it is automatically
            // called every 100ms as long as there are pending changes. See AutoSendInterval for more
            // information.
            await consumer.SendAsync();
        }
    });

Proceed to Page 8: Handle Communication Errors.