diff --git a/Lawo.EmberPlusSharpDoc/Content/Library/ModelNamespace/DynamicInterface/ReactToChanges.aml b/Lawo.EmberPlusSharpDoc/Content/Library/ModelNamespace/DynamicInterface/ReactToChanges.aml index 8352252d..e64978d2 100644 --- a/Lawo.EmberPlusSharpDoc/Content/Library/ModelNamespace/DynamicInterface/ReactToChanges.aml +++ b/Lawo.EmberPlusSharpDoc/Content/Library/ModelNamespace/DynamicInterface/ReactToChanges.aml @@ -27,6 +27,37 @@ P:Lawo.EmberPlusSharp.Model.IParameter.Value (or one of its strongly typed variants) is modified locally. + + In a generic application like e.g. a viewer it would be straightforward to subscribe to + E:System.ComponentModel.INotifyPropertyChanged.PropertyChanged. In + the code below however, for demonstration purposes we're going to subscribe to event of a specific parameter. + As mentioned earlier, the dynamic interface is not very well suited for tasks that make assumptions about the + contents of the database: + + + Specifically, the code above has the following problems: + + + + No attempt is made to handle exceptions that might result from incorrect assumptions. Such exceptions + could be thrown when an expected element is not present (e.g. the parameter is named + Pos rather than Position), the actual element has a + different type (e.g. Position is of type + T:Lawo.EmberPlusSharp.Model.INode rather than + T:Lawo.EmberPlusSharp.Model.IParameter) or + Position is really a double rather than a + long. Robust code would have to handle these exceptions which would make the + process even more tedious than it already is. + + + + + The interface offers no way of getting an element by name. The code above has to use + LINQ to search for the desired elements, which is cumbersome and inefficient. + + + + We will see later how the static interface is a much better fit for this scenario.
diff --git a/Lawo.EmberPlusSharpDoc/Content/Library/ModelNamespace/DynamicInterface/SendLocalChanges.aml b/Lawo.EmberPlusSharpDoc/Content/Library/ModelNamespace/DynamicInterface/SendLocalChanges.aml index 97606450..a629527c 100644 --- a/Lawo.EmberPlusSharpDoc/Content/Library/ModelNamespace/DynamicInterface/SendLocalChanges.aml +++ b/Lawo.EmberPlusSharpDoc/Content/Library/ModelNamespace/DynamicInterface/SendLocalChanges.aml @@ -9,42 +9,17 @@ As you might expect, modifying a value is as easy as setting the P:Lawo.EmberPlusSharp.Model.IParameter.Value - property. In a generic application like e.g. a viewer it would be straightforward to do so. In the code below - however, for demonstration purposes we're going to set two specific parameters. As mentioned earlier, the - dynamic interface is not very well suited for tasks that make assumptions about the contents of the database: + property. However, as we've already seen on , getting + to specific elements is rather cumbersome: - Specifically, the code above has the following problems: - - - - No attempt is made to handle exceptions that might result from incorrect assumptions. Such exceptions - could be thrown when an expected element is not present (e.g. the parameter is named - dBValue rather than dB Value), the actual element has a - different type (e.g. Position is of type - T:Lawo.EmberPlusSharp.Model.INode rather than - T:Lawo.EmberPlusSharp.Model.IParameter) or - dB Value is really a long rather than a - double. Robust code would have to handle these exceptions which would make the - process even more tedious than it already is. - - - - - The interface offers no way of getting an element by name. The code above has to use - LINQ to search for the desired elements, which is cumbersome and inefficient. - - - - We will see later how the static interface is a much better fit for this scenario. - As soon as a parameter is modified locally, provider changes are no longer applied to the parameter until - the + As soon as a parameter is modified locally, provider changes are no longer applied to the parameter until the P:Lawo.EmberPlusSharp.Model.Consumer`1.AutoSendInterval has elapsed or - M:Lawo.EmberPlusSharp.Model.Consumer`1.SendAsync is - called. + M:Lawo.EmberPlusSharp.Model.Consumer`1.SendAsync + is called. Proceed to . diff --git a/Lawo.EmberPlusSharpDoc/Content/Library/ModelNamespace/StaticInterface/ReactToChanges.aml b/Lawo.EmberPlusSharpDoc/Content/Library/ModelNamespace/StaticInterface/ReactToChanges.aml index af92013f..9e309bcc 100644 --- a/Lawo.EmberPlusSharpDoc/Content/Library/ModelNamespace/StaticInterface/ReactToChanges.aml +++ b/Lawo.EmberPlusSharpDoc/Content/Library/ModelNamespace/StaticInterface/ReactToChanges.aml @@ -12,7 +12,7 @@ E:System.ComponentModel.INotifyPropertyChanged.PropertyChanged. We can use this event as follows: - + We can test this by running the above program and then modfiying a value of the parameter in Tiny Ember+. diff --git a/Lawo.EmberPlusSharpTest/Model/TutorialTest.cs b/Lawo.EmberPlusSharpTest/Model/TutorialTest.cs index 42852893..c78954c1 100644 --- a/Lawo.EmberPlusSharpTest/Model/TutorialTest.cs +++ b/Lawo.EmberPlusSharpTest/Model/TutorialTest.cs @@ -48,6 +48,36 @@ public void DynamicIterateTest() #endregion } + /// Demonstrates how to react to changes with the dynamic interface. + [TestMethod] + [TestCategory("Manual")] + public void DynamicReactToChangesTest() + { + #region Dynamic React to Changes + AsyncPump.Run( + async () => + { + using (var client = await ConnectAsync("localhost", 9000)) + using (var consumer = await Consumer.CreateAsync(client)) + { + INode root = consumer.Root; + + // Navigate to the parameter we're interested in. + var sapphire = (INode)root.Children.Where(c => c.Identifier == "Sapphire").First(); + var sources = (INode)sapphire.Children.Where(c => c.Identifier == "Sources").First(); + var fpgm1 = (INode)sources.Children.Where(c => c.Identifier == "FPGM 1").First(); + var fader = (INode)fpgm1.Children.Where(c => c.Identifier == "Fader").First(); + var positionParameter = fader.Children.Where(c => c.Identifier == "Position").First(); + + var valueChanged = new TaskCompletionSource(); + positionParameter.PropertyChanged += (s, e) => valueChanged.SetResult(((IElement)s).GetPath()); + Console.WriteLine("Waiting for the parameter to change..."); + Console.WriteLine("A value of the element with the path {0} has been changed.", await valueChanged.Task); + } + }); + #endregion + } + /// Modifies parameters in the dynamic local database. [TestMethod] [TestCategory("Manual")] @@ -127,12 +157,12 @@ public void StaticIterateTest() #endregion } - /// Demonstrates how to react to changes. + /// Demonstrates how to react to changes with the static interface. [TestMethod] [TestCategory("Manual")] - public void ReactToChangesTest() + public void StaticReactToChangesTest() { - #region React to Changes + #region Static React to Changes AsyncPump.Run( async () => {