Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

How to load static data into a lookup cache from XML
xomega
#1 Posted : Wednesday, October 17, 2012 6:54:10 PM(UTC)
xomega



Xomega Framework allows you to easily load lookup tables into the lookup cache from an XML file with static enumerations. The following steps outline this process.
  1. Create the XML file with static enumerations. If you defined your enumerations in a Xomega model, then you can generate such XML file from the model. Otherwise you can manually create it using the format described below.
  2. Add the XML file your project as an embedded resource.
  3. In a method that runs during application startup create a new instance of XmlLookupCacheLoader class constructed from the resource stream for that file, and register it with the lookup cache using the LookupCache.AddCacheLoader method.

The following example shows how to load an XML file named enumerations.xml inside a startup method for a WPF application. We use an existing type to access the assembly where this XML file is embedded, which can provide a resource stream for it.
Code:
private void Application_Startup(object sender, StartupEventArgs e)
{
    Assembly asm = typeof(MyProject.Enumerations.Operators).Assembly;
    LookupCache.AddCacheLoader(new XmlLookupCacheLoader(asm.GetManifestResourceStream(
        asm.GetName().Name + ".enumerations.xml")));
}


The format of the XML file mimics the structure of enumerations in the Xomega model and includes such essential information as the enumerations name, a list of properties, enumeration items and the property values of each item. Following is an example that demonstrates this format.
Code:
<enums xmlns="http://www.xomega.net/omodel">
 <enum name="operators">
  <properties>
   <property name="sort order"/>
   <property name="addl props" default="0"/>
   <property name="multival"/>
   <property name="type" multi-value="true"/>
   <property name="exclude type" multi-value="true"/>
   <property name="null check" default="0"/>
  </properties>
  <item name="Is Null" value="NULL">
   <prop ref="sort order" value="00"/>
   <prop ref="null check" value="1"/>
  </item>
  <item name="Is Equal To" value="IS">
   <prop ref="sort order" value="02"/>
   <prop ref="addl props" value="1"/>
   <prop ref="multival" value="0"/>
  </item>
  <item name="Is One Of" value="ONEOF">
   <prop ref="sort order" value="04"/>
   <prop ref="addl props" value="1"/>
   <prop ref="multival" value="1"/>
  </item>
 </enum>
</enums>
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Copyright © 2009-2022 Xomega.Net. All rights reserved.