- Xomega.Fwk_samples_1.3.zip
- AdventureWorks
- AdventureWorks.Client.Objects
- AdventureWorks.Client.Silverlight.Web
- AdventureWorks.Client.Silverlight
- AdventureWorks.Client.Web
- AdventureWorks.Client.WPF
- AdventureWorks.Entities
- AdventureWorks.Model
- _types.xom
- AdventureWorks.Model.xomproj
- aw_build_version.xom
- database_log.xom
- error_log.xom
- Framework
- base_operators.xom
- base_types.xom
- global.xom
- HumanResources
- department.xom
- employee.xom
- job_candidate.xom
- shift.xom
- Person
- address.xom
- address_type.xom
- contact.xom
- contact_type.xom
- country_region.xom
- state_province.xom
- Production
- bill_of_materials.xom
- culture.xom
- document.xom
- illustration.xom
- location.xom
- product.xom
- product_category.xom
- product_cost_history.xom
- product_description.xom
- product_document.xom
- product_inventory.xom
- product_list_price_history.xom
- product_model.xom
- product_model_illustration.xom
- product_model_product_description_culture.xom
- product_photo.xom
- product_product_photo.xom
- product_review.xom
- product_subcategory.xom
- scrap_reason.xom
- transaction_history.xom
- transaction_history_archive.xom
- unit_measure.xom
- work_order.xom
- work_order_routing.xom
- Purchasing
- product_vendor.xom
- purchase_order_detail.xom
- purchase_order_header.xom
- ship_method.xom
- vendor.xom
- Sales
- contact_credit_card.xom
- country_region_currency.xom
- credit_card.xom
- currency.xom
- currency_rate.xom
- customer.xom
- customer_address.xom
- individual.xom
- sales_order_detail.xom
- sales_order_header.xom
- sales_person.xom
- sales_reason.xom
- sales_tax_rate.xom
- sales_territory.xom
- sales_territory_history.xom
- shopping_cart_item.xom
- special_offer.xom
- special_offer_product.xom
- store.xom
- store_contact.xom
- AdventureWorks.Services
- AdventureWorks.sln
- Readme.txt
- Xomega.Fwk_src_1.3.zip
- Xomega.Framework
- xomega.fwk_src_1.3.zip
|
// Copyright (c) 2010-2012 Xomega.Net. All rights reserved.
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Xml.Linq;
namespace Xomega.Framework.Lookup
{
/// <summary>
/// A specialized lookup cache loader that allows loading look up tables from XML format.
/// Generally it can be used in simple cases when the static data can be defined in XML format
/// rather than stored in a relational database structure.
/// </summary>
public class XmlLookupCacheLoader : LookupCacheLoader
{
/// <summary>
/// Triggers <see cref="ValueFormat.StartUp"/> method if called first.
/// </summary>
private static readonly ValueFormat fmt = ValueFormat.Internal;
/// <summary>
/// Instrumentation hook.
/// </summary>
static XmlLookupCacheLoader() { }
/// <summary>
/// Reference to the XML document for the static data.
/// </summary>
protected XDocument doc;
/// <summary>
/// Constructs an XML lookup cache loader from the given XML stream.
/// </summary>
/// <param name="stream">The XML stream that contains the lookup data.</param>
public XmlLookupCacheLoader(Stream stream) : this(stream, false) { }
/// <summary>
/// Constructs an XML lookup cache loader from the given XML stream.
/// </summary>
/// <param name="stream">The XML stream to load the lookup data from.</param>
/// <param name="caseSensitive">A flag indicating whether or not the lookup tables should be case-sensitive.
/// Typically this is based on whether or not the application database is case-sensitive.</param>
public XmlLookupCacheLoader(Stream stream, bool caseSensitive)
: this(stream, LookupCache.Global, caseSensitive) { }
/// <summary>
/// Constructs an XML lookup cache loader from the given XML stream.
/// </summary>
/// <param name="stream">The XML stream to load the lookup data from.</param>
/// <param name="cacheType">Initializes the type of cache that this loader applies too.</param>
/// <param name="caseSensitive">A flag indicating whether or not the lookup tables should be case-sensitive.
/// Typically this is based on whether or not the application database is case-sensitive.</param>
public XmlLookupCacheLoader(Stream stream, string cacheType, bool caseSensitive)
: base(cacheType, caseSensitive)
{
doc = XDocument.Load(XmlReader.Create(stream));
}
/// <summary>
/// Loads Xomega enumerations in Xomega XML format into the current cache from the given stream.
/// </summary>
/// <param name="tableType">The lookup table type to load.</param>
/// <param name="updateCache">The method to call to store the loaded lookup table in the cache.</param>
protected override void LoadCache(string tableType, CacheUpdater updateCache)
{
string ns = "http://www.xomega.net/omodel";
foreach (XElement enm in doc.Descendants(XName.Get("enum", ns)))
{
string type = enm.Attribute(XName.Get("name")).Value;
List<Header> data = new List<Header>();
foreach (XElement itemNode in enm.Elements(XName.Get("item", ns)))
{
XElement textNode = itemNode.Element(XName.Get("text", ns));
string text = (textNode != null) ? textNode.Value : itemNode.Attribute(XName.Get("name")).Value;
string id = itemNode.Attribute(XName.Get("value")).Value;
Header item = new Header(type, id, text);
foreach (XElement prop in itemNode.Elements(XName.Get("prop", ns)))
{
string pName = prop.Attribute(XName.Get("ref")).Value;
string pVal = prop.Attribute(XName.Get("value")).Value;
if (item[pName] == null) item[pName] = pVal;
else item.AddToAttribute(pName, pVal);
}
XElement properties = itemNode.Parent.Element(XName.Get("properties", ns));
if (properties != null)
{
foreach (XElement prop in properties.Elements(XName.Get("property", ns)))
{
XAttribute def = prop.Attribute(XName.Get("default"));
string pName = prop.Attribute(XName.Get("name")).Value;
if (def != null && item[pName] == null) item[pName] = def.Value;
}
}
data.Add(item);
}
updateCache(new LookupTable(type, data, caseSensitive));
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Xomega Team is striving to increase productivity and development quality by utilizing Model Driven Development coupled with Code Generation and the best design practices for application development.
We provide MDD tools, code generators and frameworks for Visual Studio and .Net development.
Visit us at
http://www.xomega.net