using System; using System.Xml ; using System.Xml.Serialization ; using System.Xml.XPath ; using System.Reflection; namespace WebApplication2.Xml { /// <summary> /// Procedure 的摘要说明。 /// </summary> public class Procedure { public Procedure() { // // TODO: 在此处添加构造函数逻辑 // } private Command[] _Commands; [XmlArray("Commands")] public Command[] Commands { get { return this._Commands;} set { this._Commands=value; } } public static object Instance(System.Web.HttpContext context) { System.Xml.XmlDocument doc=new System.Xml.XmlDocument(); doc.Load(context.Server.MapPath("Xml/Procedure.xml")); System.Xml.XmlNodeList nodeList=doc.GetElementsByTagName("Procedure"); if(nodeList.Count!=1) throw new Exception("配置参数出错了!!"); System.Xml.XmlNode section=nodeList.Item(0); XPathNavigator nav = section.CreateNavigator(); string typename = (string) nav.Evaluate("string(@type)"); Type t = Type.GetType(typename); XmlSerializer ser = new XmlSerializer(t); XmlNodeReader xnr=new XmlNodeReader(section);
object obj= ser.Deserialize(xnr); return obj; } } public class Pm { /*<Pm ParameterName="@ID" Direction="Output" SqlDbType="Int" Size="4"></Pm>*/
public Pm() { } private string _ParameterName; [XmlAttribute("ParameterName")] public string ParameterName { get { return this._ParameterName;} set { this._ParameterName=value;
} } private System.Data.ParameterDirection _Direction; [XmlAttribute("Direction")] public System.Data.ParameterDirection Direction { get { return this._Direction;} set { this._Direction=value;
} } private System.Data.SqlDbType _SqlType; [XmlAttribute("SqlDbType")] public System.Data.SqlDbType SqlDbType { get { return this._SqlType;} set { this._SqlType=value;
} } private int _KeyNo; [XmlAttribute("KeyNo")] public int KeyNo { get { return this._KeyNo;} set { this._KeyNo=value;
} } private int _Size; [XmlAttribute("Size")] public int Size { get { return this._Size;} set { this._Size=value;
} } private readonly object HandlerLock = new object(); private ConstructorInfo constructor = null; public object Instance() { if(constructor == null) { lock(HandlerLock) { if(constructor == null) { System.Type t = System.Type.GetType("WebApplication2.Pm,WebApplication2"); constructor = t.GetConstructor(new Type[0]); } } } return constructor.Invoke(null); } public System.Data.SqlClient.SqlParameter toSqlParameter() { System.Data.SqlClient.SqlParameter pa=new System.Data.SqlClient.SqlParameter(); pa.ParameterName=this.ParameterName; pa.Direction=this.Direction ; pa.Size=this.Size; pa.SqlDbType=this.SqlDbType; return pa; } } public class Command { private int _ArgsLen; [XmlAttribute("ArgsLen")] public int ArgsLen { get { return this._ArgsLen; } set { this._ArgsLen=value; } } private string _CommandText; [XmlAttribute("CommandText")] public string CommandText { get { return this._CommandText;} set { this._CommandText=value;
} } private Pm[] _Parameters; [XmlArray("Parameters")] public Pm[] Parameters { get { return this._Parameters;} set { this._Parameters=value;