Libraries

Volta includes HTML and XML libraries, as well a sample Virtual Earth library to show how existing JavaScript controls can be used with Volta. This section documents using those included controls.

HTML

The Volta HTML library provides programmatic access to the Dynamic HTML Object Model hosted by the browser. We use this library to access the DOM elements so we could query their contents (such as the text typed in an input field), respond to events (such as fire off a method when a button is clicked), or update them (such as a status message).

To use the Volta HTML library in a C# project for example, add a reference to the VoltaHtml library installed by the Volta installer:

image020

Next use the classes provided through the Microsoft.LiveLabs.Volta.Html namespace:

image021

Then obtain references to DOM elements from the Document class, via the GetById methods (generic and non-generic) or the [] operator (indexed access):

greetingElement = Document.GetById<Div>("Greeting");

button1         = (Button)Document["Button1"];

Finally, interact with these objects through properties, methods and events, most of which are defined by the HtmlElement superclass. Some subclasses, such as Table, and TableRow extend this class with type–specific functionality, adding methods such as InsertTable or InsertCell. For the complete documentation of the MSHTML API refer to the online resources.

XML

The Volta XML library implements a subset of the classes provided by the .NET MSXML2 3.0. We use this library to work with XML, such as load and save documents, create and access document nodes, as well as implement the XmlHttpRequest Call Ajax design pattern..

To use the Volta XML library in a C# project for example, add a reference to the VoltaXml library installed by the Volta installer:

image022

Next use the classes provided through the Microsoft.LiveLabs.Volta.Xml namespace:

image023

Finally, create an instance of XmlHttpRequest to call the sever:

var xhr = new Microsoft.LiveLabs.Volta.Xml.XMLHttpRequest();

xhr.Open("GET", uri);

xhr.Send();

if (xhr.Status != 200)

{

    // error!

}

else

{

    // process server's response

}

For more details about using XmlHttpRequest see the Invoking Services section in this guidance. Note that Volta allows us to use XmlHttpRequest, a class typically available only in the browser, even after relocating the code to the server through tier-splitting.

Virtual Earth

The Volta Virtual Earth library is a gateway to the existing Virtual Earth Map control. Natively, the Virtual Earth Map control can only be accessed from JavaScript. The Volta library wraps the map control, allowing us to access it from .NET languages and managed code, with all the benefits of static type checking, IntelliSense, autocompletion, integrated debugging, and so on.

To use the Volta Virtual Earth library in a C# project for example, add a reference to the VoltaVirtualEarth library installed by the Volta installer:

image011

Next, access the classes provided by the library through the Microsoft.LiveLabs.Volta.VirtualEarth namespace:

image012

Finally, instantiate the Map class, which is the entry point for interacting with the control. Warning: The name of the Virtual Earth Map class collides with the Map class from the Volta.Html namespace. Therefore, we must fully qualify the references to these classes, as below:

map = new Microsoft.LiveLabs.Volta.VirtualEarth.Map(div.Id);

Alternatively we could create an alias for the namespace via the using directive.

Complete documentation for the Virtual Earth control is available online. The Volta library replaces the JavaScript VE prefix naming convention with a .NET namespace. So VEMap from the control’s documentation becomes VE.Map in the Volta library. Likewise, VEShapeType from the control’s documentation becomes the VE.ShapeType enumeration. And so on for the other types.