Gestalt Consuming External AssembliesMar 31, 2010 In Development By Hans Hugli
Gestalt, the union of the Dynamic Language Runtime and Silverlight, enables writing Rich Internet Applications directly in HTML with Ruby/Python + XAML. Gestalt can call out to external assemblies that exist as loose files or are contained in zip files, which are treated as mini file systems by the DLR. We’ve had some inquires about this feature from our readers, so I thought it was worth calling out.
What does this mean for you?
What does being able to call out to external assemblies enable? It gives Gestalt the ability to consume third party written controls and libraries contained in assemblies in an easy and elegant way. XAML fragments can now include the namespaces of controls that are defined in those external assemblies. Additionally, code defined in libraries can be called directly from Ruby or Python, which gives Gestalt access to code that executes with the high performance of static code.
I recommend you take a look at Jimmy Schementi’s session (27 minutes in), in which he talks about this in some detail.
Examining the Sample
I want to take a 10,000 ft. look at Ashish’s sample from the perspective of calling out to external DLL’s. Bingmaps.zip contains Microsoft.Maps.MapControl.dll and Microsoft.Maps.MapControl.Common.dll. By adding a reference to the bingmaps.zip file, as in the following, the DLR becomes aware of the files that are contained within that ZIP file:
Please also note that the “defer” attribute on the XAML file is set to true to prevent the DLR from loading up the XAML immediately. We’ll see why this is necessary in a minute.
We now add a reference to the MapControl in the XAML file by adding a namespace, exactly as you would normally do in XAML.
<UserControl x:Name="silverlight_map" ... xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl"> <m:Map x:Name="map"> <m:Map.Projection> <PlaneProjection RotationX="-0" RotationY="0" RotationZ="0"/> </m:Map.Projection> </m:Map> </UserControl>
To add a reference to DLL’s in Ruby,we add the following “require” statements to the Ruby file. Notice that the path includes the name of the ZIP file:
require "bingmaps/Microsoft.Maps.MapControl" require "bingmaps/Microsoft.Maps.MapControl.Common" ... include Microsoft::Scripting::Silverlight DynamicApplication.current.load_root_visual_from_string File.read("SilverlightMap.xaml") ...
The XAML is loaded when the “load_root_visual_from_string” method is executed. We wanted to defer the loading of the XAML so that the namespace contained in the XAML would be recognized. If the DLR had loaded the XAML immediately,we would have gotten an error, since at that point the DLR was not aware of the MapControl dependencies. Adding the “require” statements allowed Silverlight to successfully load the XAML file and resolve the namespace references. The source and binaries for Ashish’s sample are located here.
With its ability to call out to external DLL’s, Gestalt opens up a wide spectrum of capabilities that were difficult, if not impossible, to achieve before.
The only downside of this feature is that utilizing external DLL’s goes against the primary intent of Gestalt — to make all the source viewable to the end user. It’s good to know, however, that there’s an option available for doing so… when it’s your only option.
I’ve been wanting to add smooth streaming support to the Video Widget. The source code for Silverlight smooth streaming support is not available, but there is a DLL that ships with Blend that provides this capability. Being able to call out to an external DLL is exactly what’s needed to be able to add this support!