473,473 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

a more OO approach.

The class below uses the switch clause in the GetXSLT method. I want it to code it with a more OO approach does anyone have any suggestions, or change to make.

cheers

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
using System.Diagnostics;

namespace MetaData
{
/// <summary>
/// MessageController Class
/// This class is used to parse the ORE XML Messages, and identify which set of XSLT transforms to use to
/// process the XML to fill the ORE Message with meta data. Depending on the ORE XML Message an instance
/// of the DAOFacade class is instantiated and the retrieve method is called to access the DB Meta Repository
/// In order to start the process of reading debug strings you should do the following:
/// 1) Set the string XMLMessage property to the ORE XML Message.
/// 2) execute the MessageParser instance method, which instances GetXSLT method;
/// 3) register at least one event handler for the DebugData event;
/// 4) Depending on the Action value, Transform mehtod is executed and/or GetMetaData/ UpdateMetaData methods.
/// </summary>
public class MessageController
{
#region Constructor

public MessageController()
{
mstrXSLTDir = ConfigurationSettings.AppSettings["XSLTDir"];
mstrMetaConn = ConfigurationSettings.AppSettings["MetaConnString"];
}
#endregion

#region Variable Declarations
public static Hashtable xmlEntityCache = new Hashtable();
public static Hashtable xsltCache = new Hashtable();

private string mstrXmlMessage;
private string mstrDACMessage;
private string mstrEntityName;
private string mstrXSLTDir;
private string mstrMetaConn;
private string mstrAction;

#endregion

#region Message Controller Properties
public string xmlAction
{
get
{
return mstrAction;
}
set
{
mstrAction = value;
}
}
public string xmlEntityName
{
get
{
return mstrEntityName;
}
set
{
mstrEntityName = value;
}
}
public string xmlInMessage
{
get
{
return mstrXmlMessage;
}
set
{
mstrXmlMessage = value ;
}
}

public string DACOutMessage
{
get
{
return mstrDACMessage;
}
set
{
mstrDACMessage = value ;
}
}
#endregion

#region Message Parser Method
/// <summary>
/// Message Parser Method retrieves the values of the Entity and Action attributes
/// and uses property mstrXMLMessage to find the Action and Entity value.
/// </summary>
/// <returns>XML message response as string</returns>
public string MessageParser()
{
XmlDataDocument xmlDoc = new XmlDataDocument();

xmlDoc.LoadXml(mstrXmlMessage);

XPathNavigator Nav = xmlDoc.CreateNavigator();

System.Xml.XPath.XPathNodeIterator ActionIterator = Nav.Select("//message/@action");
System.Xml.XPath.XPathNodeIterator EntityIterator = Nav.Select("//message/Entity/@Name");

ActionIterator.MoveNext();
EntityIterator.MoveNext();

mstrAction = ActionIterator.Current.Value.ToString();
//TODO: if Action is Retrieve then check cache for schemas, iterate through entities.

mstrEntityName = EntityIterator.Current.Value.ToString();

return GetXSLT();
}
#endregion

#region Private Methods and Constructors

/// <summary>
/// Parses XML strings to Hashtable
/// </summary>
/// <param name="entityName"></param>
/// <returns>Values of elements in Hashtable</returns>
private bool ParseToHashtable(string entityName)
{
if(xmlEntityCache.ContainsKey(entityName))
{
//return cached schema
return false;
}
else
{
return true;
}
}
/// <summary>
/// Entity Processor performs the main XSLT's and queries database to return schemas as
/// output to DAC or ORE
/// </summary>
/// <returns>XML String for DAC (Schema, DataSet)</returns>
/// <paramref name="No Parameters"/>
public string GetXSLT()
{
string result;
switch (mstrAction)
{
case "CreateEntity":

result = MessageController.Transform(mstrXSLTDir + "\\" + "createEntity_dac.xslt", mstrXmlMessage);

return result;

case "Create":

//result = MessageController.Transform(mstrXSLTDir + "\\" + "DataSetFromDAC.xslt", GetMetaDataSet().GetXml().ToString());
result = MessageController.Transform(mstrXSLTDir + "\\" + "metamessage.xslt", GetMetaDataSet().GetXml().ToString());
return result;

case "Retrieve":

//result = MessageController.Transform(mstrXSLTDir + "\\" + "DataSetFromDAC.xslt",GetMetaDataSet().GetXml().To String());
result = MessageController.Transform(mstrXSLTDir + "\\" + "metamessage.xslt", GetMetaDataSet().GetXml().ToString());

MessageCache.SaveToFileCache(result, mstrEntityName);

return result;

case "Update":

//result = MessageController.Transform(mstrXSLTDir + "\\" + "DataSetFromDAC.xslt",GetMetaDataSet().GetXml().To String());
result = MessageController.Transform(mstrXSLTDir + "\\" + "metamessage.xslt",GetMetaDataSet().GetXml().ToStr ing());

MessageCache.SaveToFileCache(result, mstrEntityName);

return result;

case "RetrieveSchema":

if (ParseToHashtable(mstrEntityName) == false)
{
return xmlEntityCache[mstrEntityName].ToString();
}
else
{
//DataSet dacresult meta query to get entity
//DataSet dacresult1 = new DataSet();
//dacresult1.ReadXml(mstrXSLTDir + "\\" + "oregetschemadac.xml");

result = MessageController.Transform(mstrXSLTDir + "\\" + "OreGetSchema.xslt", GetMetaDataSet().GetXml().ToString());

xmlEntityCache.Add(mstrEntityName, result);
return result;
}
}
return "error";
}

/// <summary>
/// Returns the xml node as a string of all the connection details.
/// </summary>
/// <param name="MetaConnString"></param>
/// <param name="DLLFileName"></param>
private void GetConnection(out string MetaConnString, out string DLLFileName)
{
XmlDocument doc = new XmlDocument();
doc.Load(mstrXSLTDir + "\\" + "Provider_Types1.xml");

DLLFileName = doc.SelectSingleNode("NewDataSet/DataSource[IsMaster = -1]/FileName").InnerXml;
MetaConnString = doc.SelectSingleNode("NewDataSet/DataSource[IsMaster = -1]/ConnectionString").InnerXml;

}

private DataSet GetMetaDataSet()
{
try
{
//Transform entity dataset
string tmpEntityMetaData = MessageController.Transform(mstrXSLTDir + "\\" + "EntityDataSetnew.xslt", mstrXmlMessage);

string tmpEntityMetaDataMessage = MessageController.Transform(mstrXSLTDir + "\\" + "EntityDataSetMeta.xslt", mstrXmlMessage);

//Get entity dataset from DAC giving tmpEntityMetaData
DAOFacade daoentity = new DAOFacade();
DataSet EntityData = new DataSet();

EntityData = daoentity.RetrieveData(tmpEntityMetaData, tmpEntityMetaDataMessage);

//EntityData.ReadXml(mstrXSLTDir + "\\" + "EntityDataSet.xml");

//Transform entity dataset
string tmpAttributeMetaData = MessageController.Transform(mstrXSLTDir + "\\" + "AttributeDataSetnew.xslt", EntityData.GetXml().ToString());

string tmpAttributeMetaDataMessage = MessageController.Transform(mstrXSLTDir + "\\" + "AttributeDataSetMeta.xslt", EntityData.GetXml().ToString());

//Get Attribute dataset from DAC
DataSet AttribData = new DataSet();
DAOFacade daoattribute = new DAOFacade();
AttribData = daoattribute.RetrieveData(tmpAttributeMetaData, tmpAttributeMetaDataMessage);

//AttribData.ReadXml(mstrXSLTDir + "\\" + "AttributeDataSet.xml");

//Merge Datasets (Entity and Attribute)
EntityData.Merge(AttribData);

EntityData.Dispose();
AttribData.Dispose();
return EntityData;

}
catch(Exception ex)
{
throw(ex);
}
}
/// <summary>
/// Inserts entries into MetaData Store.
/// </summary>
/// <param name="oreMessage"></param>
/// <returns></returns>
public DataSet UpdateMetaData(string oreMessage)
{

try
{
//Transform entity dataset

// Transform ORE orignal message to create Meta DataSet to update MetaStore DB.
string tmpEntityMetaData = MessageController.Transform(mstrXSLTDir + "\\" + "CreateEntity.xslt", oreMessage);

//Create new instance of a dataset that will hold the returned Entity/Attribute datatables.
DataSet EntityData = new DataSet();
//EntityData.ReadXmlSchema("C:\\DACXML\\EntityAttrib ute.xsd");

//read the transformed xml in a StringReader
StringReader sr = new StringReader(tmpEntityMetaData);

//sr.Read((tmpEntityMetaData.ToCharArray()),0,tmpEnt ityMetaData.ToCharArray().Length);
EntityData.ReadXmlSchema("C:\\DACXML\\EntityAttrib ute.xsd");
//Fill the dataset with the stream contents.
EntityData.ReadXml(sr);

sr.Close();

//Create a new instance of the DAC facade

//Method call to update MetaStore.
string MetaConn;
string MetaDLLFile;
GetConnection(out MetaConn, out MetaDLLFile);

DAOFacade DAOIns = new DAOFacade();
DAOIns.UpdateDataSet(MetaDLLFile, MetaConn, EntityData);

EntityData.Dispose();

return EntityData;
}
catch(Exception ex)
{
EventLog.WriteEntry("UpdateMetaData", ex.Message);

throw(ex);
}
}

#endregion

#region XSLT Transform Method
/// <summary>
/// Main XSLT Transform Method static method.
/// </summary>
/// <param name="xsltName">Name of xslt file to use in the transform</param>
/// <param name="xmlMessage">xmlMessage to transfom</param>
/// <returns>XML transform string</returns>
public static string Transform(string xsltName, string xmlMessage)
{
try
{
//get the xml doc.
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlMessage);

XslTransform xslDoc = new XslTransform();
xslDoc.Load(xsltName);

XsltArgumentList args=new XsltArgumentList();

MemoryStream ms = new MemoryStream();

xslDoc.Transform(xmlDoc,args,ms,new XmlUrlResolver());

ms.Flush();
ms.Position =0;
StreamReader sr = new StreamReader(ms);
string result = sr.ReadToEnd();
sr.Close();
ms.Close();

return result;
}
catch(Exception ex)
{
throw(ex);
}
finally
{
//ms.Close();
}
}

#endregion

}
}

************************************************** ********************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
Nov 15 '05 #1
2 1373
Hello Chris,
From what I see from your code, all the code paths do the same thing
with different xslt files, so you could just get the xslt from the same
XML file that yr reading to determine the action and eliminate the
swtich. From an oo standpoint you could use a (abstract)factory pattern,
but in this case it may not be required.
Hope that helps

ch**********@voyage.co.uk wrote:
The class below uses the switch clause in the GetXSLT method. I want it to code it with a more OO approach does anyone have any suggestions, or change to make.

cheers

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
using System.Diagnostics;

namespace MetaData
{
/// <summary>
/// MessageController Class
/// This class is used to parse the ORE XML Messages, and identify which set of XSLT transforms to use to
/// process the XML to fill the ORE Message with meta data. Depending on the ORE XML Message an instance
/// of the DAOFacade class is instantiated and the retrieve method is called to access the DB Meta Repository
/// In order to start the process of reading debug strings you should do the following:
/// 1) Set the string XMLMessage property to the ORE XML Message.
/// 2) execute the MessageParser instance method, which instances GetXSLT method;
/// 3) register at least one event handler for the DebugData event;
/// 4) Depending on the Action value, Transform mehtod is executed and/or GetMetaData/ UpdateMetaData methods.
/// </summary>
public class MessageController
{
#region Constructor

public MessageController()
{
mstrXSLTDir = ConfigurationSettings.AppSettings["XSLTDir"];
mstrMetaConn = ConfigurationSettings.AppSettings["MetaConnString"];
}
#endregion

#region Variable Declarations
public static Hashtable xmlEntityCache = new Hashtable();
public static Hashtable xsltCache = new Hashtable();

private string mstrXmlMessage;
private string mstrDACMessage;
private string mstrEntityName;
private string mstrXSLTDir;
private string mstrMetaConn;
private string mstrAction;

#endregion

#region Message Controller Properties
public string xmlAction
{
get
{
return mstrAction;
}
set
{
mstrAction = value;
}
}
public string xmlEntityName
{
get
{
return mstrEntityName;
}
set
{
mstrEntityName = value;
}
}
public string xmlInMessage
{
get
{
return mstrXmlMessage;
}
set
{
mstrXmlMessage = value ;
}
}

public string DACOutMessage
{
get
{
return mstrDACMessage;
}
set
{
mstrDACMessage = value ;
}
}
#endregion

#region Message Parser Method
/// <summary>
/// Message Parser Method retrieves the values of the Entity and Action attributes
/// and uses property mstrXMLMessage to find the Action and Entity value.
/// </summary>
/// <returns>XML message response as string</returns>
public string MessageParser()
{
XmlDataDocument xmlDoc = new XmlDataDocument();

xmlDoc.LoadXml(mstrXmlMessage);

XPathNavigator Nav = xmlDoc.CreateNavigator();

System.Xml.XPath.XPathNodeIterator ActionIterator = Nav.Select("//message/@action");
System.Xml.XPath.XPathNodeIterator EntityIterator = Nav.Select("//message/Entity/@Name");

ActionIterator.MoveNext();
EntityIterator.MoveNext();

mstrAction = ActionIterator.Current.Value.ToString();
//TODO: if Action is Retrieve then check cache for schemas, iterate through entities.

mstrEntityName = EntityIterator.Current.Value.ToString();

return GetXSLT();
}
#endregion

#region Private Methods and Constructors

/// <summary>
/// Parses XML strings to Hashtable
/// </summary>
/// <param name="entityName"></param>
/// <returns>Values of elements in Hashtable</returns>
private bool ParseToHashtable(string entityName)
{
if(xmlEntityCache.ContainsKey(entityName))
{
//return cached schema
return false;
}
else
{
return true;
}
}
/// <summary>
/// Entity Processor performs the main XSLT's and queries database to return schemas as
/// output to DAC or ORE
/// </summary>
/// <returns>XML String for DAC (Schema, DataSet)</returns>
/// <paramref name="No Parameters"/>
public string GetXSLT()
{
string result;
switch (mstrAction)
{
case "CreateEntity":

result = MessageController.Transform(mstrXSLTDir + "\\" + "createEntity_dac.xslt", mstrXmlMessage);

return result;

case "Create":

//result = MessageController.Transform(mstrXSLTDir + "\\" + "DataSetFromDAC.xslt", GetMetaDataSet().GetXml().ToString());
result = MessageController.Transform(mstrXSLTDir + "\\" + "metamessage.xslt", GetMetaDataSet().GetXml().ToString());
return result;

case "Retrieve":

//result = MessageController.Transform(mstrXSLTDir + "\\" + "DataSetFromDAC.xslt",GetMetaDataSet().GetXml().To String());
result = MessageController.Transform(mstrXSLTDir + "\\" + "metamessage.xslt", GetMetaDataSet().GetXml().ToString());

MessageCache.SaveToFileCache(result, mstrEntityName);

return result;

case "Update":

//result = MessageController.Transform(mstrXSLTDir + "\\" + "DataSetFromDAC.xslt",GetMetaDataSet().GetXml().To String());
result = MessageController.Transform(mstrXSLTDir + "\\" + "metamessage.xslt",GetMetaDataSet().GetXml().ToStr ing());

MessageCache.SaveToFileCache(result, mstrEntityName);

return result;

case "RetrieveSchema":

if (ParseToHashtable(mstrEntityName) == false)
{
return xmlEntityCache[mstrEntityName].ToString();
}
else
{
//DataSet dacresult meta query to get entity
//DataSet dacresult1 = new DataSet();
//dacresult1.ReadXml(mstrXSLTDir + "\\" + "oregetschemadac.xml");

result = MessageController.Transform(mstrXSLTDir + "\\" + "OreGetSchema.xslt", GetMetaDataSet().GetXml().ToString());

xmlEntityCache.Add(mstrEntityName, result);
return result;
}
}
return "error";
}

/// <summary>
/// Returns the xml node as a string of all the connection details.
/// </summary>
/// <param name="MetaConnString"></param>
/// <param name="DLLFileName"></param>
private void GetConnection(out string MetaConnString, out string DLLFileName)
{
XmlDocument doc = new XmlDocument();
doc.Load(mstrXSLTDir + "\\" + "Provider_Types1.xml");

DLLFileName = doc.SelectSingleNode("NewDataSet/DataSource[IsMaster = -1]/FileName").InnerXml;
MetaConnString = doc.SelectSingleNode("NewDataSet/DataSource[IsMaster = -1]/ConnectionString").InnerXml;

}

private DataSet GetMetaDataSet()
{
try
{
//Transform entity dataset
string tmpEntityMetaData = MessageController.Transform(mstrXSLTDir + "\\" + "EntityDataSetnew.xslt", mstrXmlMessage);

string tmpEntityMetaDataMessage = MessageController.Transform(mstrXSLTDir + "\\" + "EntityDataSetMeta.xslt", mstrXmlMessage);

//Get entity dataset from DAC giving tmpEntityMetaData
DAOFacade daoentity = new DAOFacade();
DataSet EntityData = new DataSet();

EntityData = daoentity.RetrieveData(tmpEntityMetaData, tmpEntityMetaDataMessage);

//EntityData.ReadXml(mstrXSLTDir + "\\" + "EntityDataSet.xml");

//Transform entity dataset
string tmpAttributeMetaData = MessageController.Transform(mstrXSLTDir + "\\" + "AttributeDataSetnew.xslt", EntityData.GetXml().ToString());

string tmpAttributeMetaDataMessage = MessageController.Transform(mstrXSLTDir + "\\" + "AttributeDataSetMeta.xslt", EntityData.GetXml().ToString());

//Get Attribute dataset from DAC
DataSet AttribData = new DataSet();
DAOFacade daoattribute = new DAOFacade();
AttribData = daoattribute.RetrieveData(tmpAttributeMetaData, tmpAttributeMetaDataMessage);

//AttribData.ReadXml(mstrXSLTDir + "\\" + "AttributeDataSet.xml");

//Merge Datasets (Entity and Attribute)
EntityData.Merge(AttribData);

EntityData.Dispose();
AttribData.Dispose();
return EntityData;

}
catch(Exception ex)
{
throw(ex);
}
}
/// <summary>
/// Inserts entries into MetaData Store.
/// </summary>
/// <param name="oreMessage"></param>
/// <returns></returns>
public DataSet UpdateMetaData(string oreMessage)
{

try
{
//Transform entity dataset

// Transform ORE orignal message to create Meta DataSet to update MetaStore DB.
string tmpEntityMetaData = MessageController.Transform(mstrXSLTDir + "\\" + "CreateEntity.xslt", oreMessage);

//Create new instance of a dataset that will hold the returned Entity/Attribute datatables.
DataSet EntityData = new DataSet();
//EntityData.ReadXmlSchema("C:\\DACXML\\EntityAttrib ute.xsd");

//read the transformed xml in a StringReader
StringReader sr = new StringReader(tmpEntityMetaData);

//sr.Read((tmpEntityMetaData.ToCharArray()),0,tmpEnt ityMetaData.ToCharArray().Length);
EntityData.ReadXmlSchema("C:\\DACXML\\EntityAttrib ute.xsd");
//Fill the dataset with the stream contents.
EntityData.ReadXml(sr);

sr.Close();

//Create a new instance of the DAC facade

//Method call to update MetaStore.
string MetaConn;
string MetaDLLFile;
GetConnection(out MetaConn, out MetaDLLFile);

DAOFacade DAOIns = new DAOFacade();
DAOIns.UpdateDataSet(MetaDLLFile, MetaConn, EntityData);

EntityData.Dispose();

return EntityData;
}
catch(Exception ex)
{
EventLog.WriteEntry("UpdateMetaData", ex.Message);

throw(ex);
}
}

#endregion

#region XSLT Transform Method
/// <summary>
/// Main XSLT Transform Method static method.
/// </summary>
/// <param name="xsltName">Name of xslt file to use in the transform</param>
/// <param name="xmlMessage">xmlMessage to transfom</param>
/// <returns>XML transform string</returns>
public static string Transform(string xsltName, string xmlMessage)
{
try
{
//get the xml doc.
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlMessage);

XslTransform xslDoc = new XslTransform();
xslDoc.Load(xsltName);

XsltArgumentList args=new XsltArgumentList();

MemoryStream ms = new MemoryStream();

xslDoc.Transform(xmlDoc,args,ms,new XmlUrlResolver());

ms.Flush();
ms.Position =0;
StreamReader sr = new StreamReader(ms);
string result = sr.ReadToEnd();
sr.Close();
ms.Close();

return result;
}
catch(Exception ex)
{
throw(ex);
}
finally
{
//ms.Close();
}
}

#endregion

}
}

************************************************** ********************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...


--
Regards,
Dilip Krishnan
MCAD, MCSD.net
dilipdotnet at apdiya dot com
Nov 15 '05 #2
Sure,
First, create an interface of type MessageAction. Give it a method of
GetXSLT(param1,param2...)
Derive a series of classes from MessageAction, each one implementing one of
the different sections in your GetXSLT() routine below.
Create a factory method in MessageController that returns an object of type
"MessageAction" when provided with a string describing the action.
In the MessageAction classes, have them look to a config file to get the
name of the XSLT to use for each message action. Do this in the
constructor. This gives you more flexibility to create a new MessageAction.

MessageAction ma = this.CreateMessageAction(mstrAction);
return ma.GetXSLT(GetMetaDataSet().GetXml().ToString());

--- Nick
P.S. I'm not sure what CreateEntity does, but it doesn't fit the pattern of
the rest. Is there something structurally different with this one?
You may have a design defect if you need to do something structurally
different in a class like this.

"chrisybhoy" <ch**********@voyage.co.uk> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
The class below uses the switch clause in the GetXSLT method. I want it to code it with a more OO approach does anyone have any suggestions, or
change to make.
cheers

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
using System.Diagnostics;

namespace MetaData
{
/// <summary>
/// MessageController Class
/// This class is used to parse the ORE XML Messages, and identify which set of XSLT transforms to use to /// process the XML to fill the ORE Message with meta data. Depending on the ORE XML Message an instance /// of the DAOFacade class is instantiated and the retrieve method is called to access the DB Meta Repository /// In order to start the process of reading debug strings you should do the following: /// 1) Set the string XMLMessage property to the ORE XML Message.
/// 2) execute the MessageParser instance method, which instances GetXSLT method; /// 3) register at least one event handler for the DebugData event;
/// 4) Depending on the Action value, Transform mehtod is executed and/or GetMetaData/ UpdateMetaData methods. /// </summary>
public class MessageController
{
#region Constructor

public MessageController()
{
mstrXSLTDir = ConfigurationSettings.AppSettings["XSLTDir"];
mstrMetaConn = ConfigurationSettings.AppSettings["MetaConnString"];
}
#endregion

#region Variable Declarations
public static Hashtable xmlEntityCache = new Hashtable();
public static Hashtable xsltCache = new Hashtable();

private string mstrXmlMessage;
private string mstrDACMessage;
private string mstrEntityName;
private string mstrXSLTDir;
private string mstrMetaConn;
private string mstrAction;

#endregion

#region Message Controller Properties
public string xmlAction
{
get
{
return mstrAction;
}
set
{
mstrAction = value;
}
}
public string xmlEntityName
{
get
{
return mstrEntityName;
}
set
{
mstrEntityName = value;
}
}
public string xmlInMessage
{
get
{
return mstrXmlMessage;
}
set
{
mstrXmlMessage = value ;
}
}

public string DACOutMessage
{
get
{
return mstrDACMessage;
}
set
{
mstrDACMessage = value ;
}
}
#endregion

#region Message Parser Method
/// <summary>
/// Message Parser Method retrieves the values of the Entity and Action attributes /// and uses property mstrXMLMessage to find the Action and Entity value.
/// </summary>
/// <returns>XML message response as string</returns>
public string MessageParser()
{
XmlDataDocument xmlDoc = new XmlDataDocument();

xmlDoc.LoadXml(mstrXmlMessage);

XPathNavigator Nav = xmlDoc.CreateNavigator();

System.Xml.XPath.XPathNodeIterator ActionIterator = Nav.Select("//message/@action"); System.Xml.XPath.XPathNodeIterator EntityIterator = Nav.Select("//message/Entity/@Name");
ActionIterator.MoveNext();
EntityIterator.MoveNext();

mstrAction = ActionIterator.Current.Value.ToString();
//TODO: if Action is Retrieve then check cache for schemas, iterate through entities.
mstrEntityName = EntityIterator.Current.Value.ToString();

return GetXSLT();
}
#endregion

#region Private Methods and Constructors

/// <summary>
/// Parses XML strings to Hashtable
/// </summary>
/// <param name="entityName"></param>
/// <returns>Values of elements in Hashtable</returns>
private bool ParseToHashtable(string entityName)
{
if(xmlEntityCache.ContainsKey(entityName))
{
//return cached schema
return false;
}
else
{
return true;
}
}
/// <summary>
/// Entity Processor performs the main XSLT's and queries database to return schemas as /// output to DAC or ORE
/// </summary>
/// <returns>XML String for DAC (Schema, DataSet)</returns>
/// <paramref name="No Parameters"/>
public string GetXSLT()
{
string result;
switch (mstrAction)
{
case "CreateEntity":

result = MessageController.Transform(mstrXSLTDir + "\\" + "createEntity_dac.xslt", mstrXmlMessage);
return result;

case "Create":

//result = MessageController.Transform(mstrXSLTDir + "\\" + "DataSetFromDAC.xslt", GetMetaDataSet().GetXml().ToString()); result = MessageController.Transform(mstrXSLTDir + "\\" + "metamessage.xslt", GetMetaDataSet().GetXml().ToString()); return result;

case "Retrieve":

//result = MessageController.Transform(mstrXSLTDir + "\\" + "DataSetFromDAC.xslt",GetMetaDataSet().GetXml().To String()); result = MessageController.Transform(mstrXSLTDir + "\\" + "metamessage.xslt", GetMetaDataSet().GetXml().ToString());
MessageCache.SaveToFileCache(result, mstrEntityName);

return result;

case "Update":

//result = MessageController.Transform(mstrXSLTDir + "\\" + "DataSetFromDAC.xslt",GetMetaDataSet().GetXml().To String()); result = MessageController.Transform(mstrXSLTDir + "\\" + "metamessage.xslt",GetMetaDataSet().GetXml().ToStr ing());
MessageCache.SaveToFileCache(result, mstrEntityName);

return result;

case "RetrieveSchema":

if (ParseToHashtable(mstrEntityName) == false)
{
return xmlEntityCache[mstrEntityName].ToString();
}
else
{
//DataSet dacresult meta query to get entity
//DataSet dacresult1 = new DataSet();
//dacresult1.ReadXml(mstrXSLTDir + "\\" + "oregetschemadac.xml");

result = MessageController.Transform(mstrXSLTDir + "\\" + "OreGetSchema.xslt", GetMetaDataSet().GetXml().ToString());
xmlEntityCache.Add(mstrEntityName, result);
return result;
}
}
return "error";
}

/// <summary>
/// Returns the xml node as a string of all the connection details.
/// </summary>
/// <param name="MetaConnString"></param>
/// <param name="DLLFileName"></param>
private void GetConnection(out string MetaConnString, out string DLLFileName) {
XmlDocument doc = new XmlDocument();
doc.Load(mstrXSLTDir + "\\" + "Provider_Types1.xml");

DLLFileName = doc.SelectSingleNode("NewDataSet/DataSource[IsMaster = -1]/FileName").InnerXml; MetaConnString = doc.SelectSingleNode("NewDataSet/DataSource[IsMaster = -1]/ConnectionString").InnerXml;
}

private DataSet GetMetaDataSet()
{
try
{
//Transform entity dataset
string tmpEntityMetaData = MessageController.Transform(mstrXSLTDir + "\\" + "EntityDataSetnew.xslt", mstrXmlMessage);
string tmpEntityMetaDataMessage = MessageController.Transform(mstrXSLTDir + "\\" + "EntityDataSetMeta.xslt", mstrXmlMessage);
//Get entity dataset from DAC giving tmpEntityMetaData
DAOFacade daoentity = new DAOFacade();
DataSet EntityData = new DataSet();

EntityData = daoentity.RetrieveData(tmpEntityMetaData, tmpEntityMetaDataMessage);
//EntityData.ReadXml(mstrXSLTDir + "\\" + "EntityDataSet.xml");

//Transform entity dataset
string tmpAttributeMetaData = MessageController.Transform(mstrXSLTDir + "\\" + "AttributeDataSetnew.xslt", EntityData.GetXml().ToString());
string tmpAttributeMetaDataMessage = MessageController.Transform(mstrXSLTDir + "\\" +
"AttributeDataSetMeta.xslt", EntityData.GetXml().ToString());
//Get Attribute dataset from DAC
DataSet AttribData = new DataSet();
DAOFacade daoattribute = new DAOFacade();
AttribData = daoattribute.RetrieveData(tmpAttributeMetaData, tmpAttributeMetaDataMessage);
//AttribData.ReadXml(mstrXSLTDir + "\\" + "AttributeDataSet.xml");

//Merge Datasets (Entity and Attribute)
EntityData.Merge(AttribData);

EntityData.Dispose();
AttribData.Dispose();
return EntityData;

}
catch(Exception ex)
{
throw(ex);
}
}
/// <summary>
/// Inserts entries into MetaData Store.
/// </summary>
/// <param name="oreMessage"></param>
/// <returns></returns>
public DataSet UpdateMetaData(string oreMessage)
{

try
{
//Transform entity dataset

// Transform ORE orignal message to create Meta DataSet to update MetaStore DB. string tmpEntityMetaData = MessageController.Transform(mstrXSLTDir + "\\" + "CreateEntity.xslt", oreMessage);
//Create new instance of a dataset that will hold the returned Entity/Attribute datatables. DataSet EntityData = new DataSet();
//EntityData.ReadXmlSchema("C:\\DACXML\\EntityAttrib ute.xsd");

//read the transformed xml in a StringReader
StringReader sr = new StringReader(tmpEntityMetaData);

//sr.Read((tmpEntityMetaData.ToCharArray()),0,tmpEnt ityMetaData.ToCharArray(
).Length); EntityData.ReadXmlSchema("C:\\DACXML\\EntityAttrib ute.xsd");
//Fill the dataset with the stream contents.
EntityData.ReadXml(sr);

sr.Close();

//Create a new instance of the DAC facade

//Method call to update MetaStore.
string MetaConn;
string MetaDLLFile;
GetConnection(out MetaConn, out MetaDLLFile);

DAOFacade DAOIns = new DAOFacade();
DAOIns.UpdateDataSet(MetaDLLFile, MetaConn, EntityData);

EntityData.Dispose();

return EntityData;
}
catch(Exception ex)
{
EventLog.WriteEntry("UpdateMetaData", ex.Message);

throw(ex);
}
}

#endregion

#region XSLT Transform Method
/// <summary>
/// Main XSLT Transform Method static method.
/// </summary>
/// <param name="xsltName">Name of xslt file to use in the transform</param> /// <param name="xmlMessage">xmlMessage to transfom</param>
/// <returns>XML transform string</returns>
public static string Transform(string xsltName, string xmlMessage)
{
try
{
//get the xml doc.
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlMessage);

XslTransform xslDoc = new XslTransform();
xslDoc.Load(xsltName);

XsltArgumentList args=new XsltArgumentList();

MemoryStream ms = new MemoryStream();

xslDoc.Transform(xmlDoc,args,ms,new XmlUrlResolver());

ms.Flush();
ms.Position =0;
StreamReader sr = new StreamReader(ms);
string result = sr.ReadToEnd();
sr.Close();
ms.Close();

return result;
}
catch(Exception ex)
{
throw(ex);
}
finally
{
//ms.Close();
}
}

#endregion

}
}

************************************************** ********************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP &

ASP.NET resources...
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Chinook | last post by:
OO approach to decision sequence? --------------------------------- In a recent thread (Cause for using objects?), Chris Smith replied with (in part): > If your table of photo data has...
2
by: R0bert Neville | last post by:
I have been working a rounded content box approach. The layout rendered beautifully in Firefox, yet IE threw a wrench into my layout. The approach has to be re-thought and aligned for compatibility...
2
by: Rene | last post by:
Hi, In my VB6 application I'm using a class/object that is using full-async ADO. I can start multiple queries, the class stores the ADODB.Recordset object in an array and waits for the...
16
by: Robert Zurer | last post by:
Can anyone suggest the best book or part of a book on this subject. I'm looking for an in-depth treatment with examples in C# TIA Robert Zurer robert@zurer.com
1
by: Craig Kenisston | last post by:
Hi, I'm developing my first asp.net application. It will be a small e-commerce site, with product catalogos, shoping cart, etc. I started to develop using a single page, the default.aspx, and...
8
by: Harvey Triana | last post by:
Hello. By example, I have string with a "Hello There". I use Right("Hello There", 3) function in VB.NET to just get "ere" out of the string but there doesn't seem to be one in C#. I have two...
1
by: =?Utf-8?B?Tkg=?= | last post by:
Hi, I have been building asp.net 2.0 apps now for a few years. In general I use MS Ajax and the MS Data Enterprise Application Block to manage the connecting and getting data from the database....
5
by: jehugaleahsa | last post by:
Hello: I am trying to find what is the very best approach to business objects in Windows Forms. Windows Forms presents an awesome opportunity to use DataTables and I would like to continue doing...
20
by: mike3 | last post by:
Hi. (Xposted to both comp.lang.c++ and comp.programming since I've got questions related to both C++ language and general programming) I've got the following C++ code. The first routine runs in...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.