Using the Domain Model

Now that you have a language model, we'll demonstrate how you might use it after a user has used the graphical designer to build a navigation model.

As you've seen previously, a set of .NET classes are constructed to reflect the language model. These classes are created in memory as an object graph as the user constructs the graphical designer.

The object model that is created is strongly typed to the language you defined in the language designer, making it extremely straightforward to use. Consider the following example, which iterates around all of the pages defined in the Navigation model depicted in Figure 6-15 and outputs each page's Name and a list of all the pages to which it links:

      IList MELPages = this.Store.ElementDirectory.GetElements                       (DomainModel.Page.MetaClassGuid);      foreach (DomainModel.Page MELPage in MELPages)      {         Debug.WriteLine( "Page: " + MELPage.Name );         if (MELPage.ChildPages.Count > 0)         {            Debug.WriteLine("Links to: ");            foreach (DomainModel.Page MELChildPage in MELPage.ChildPages)            {               Debug.WriteLine(MELChildPage.Name);            }            Debug.WriteLine("\n");         }         else         {            Debug.WriteLine("Links to nothing");         }      } 

Here's the output:

      Page: Logon      Links to:      Logon Failed      My Accounts      View Statement      Move Money      Page: Logon Failed      Links to:      Logon      Page: My Accounts      Links to:      Signoff      Page: View Statement      Links to:      Signoff      Page: Transfer Money      Links to:      Signoff      Page: Signoff      Links to nothing 

The code sample uses the in-built ElementDirectory to find all of the Page elements in our domain model and then iterates through them. Note that the ChildPages collection is the left-hand role of the Transition relationship that we defined in the language model, which gives you access to a collection of references to other pages within the model.

The object model is extremely easy to navigate and is typically used by any extensions you build into your designer. Examples of such extensions include code generation or custom save and load routines for your designer; a custom save routine would persist the contents of a model to a proprietary file format and the corresponding custom load routine would then convert from that file format back into the language model to be viewed using the graphical designer.

Professional Visual Studio 2005 Team System
Professional Visual Studio 2005 Team System (Programmer to Programmer)
ISBN: 0764584367
EAN: 2147483647
Year: N/A
Pages: 220 © 2008-2017.
If you may any questions please contact us: