Go home pageWeb site mapUnified development processOOADdevelopmentJobs.Netroot@webudp.com

C# persistent layer

Product Rational Rose
Notation UML, C#
Tutorials Customers, ASPX

C# persistent layer classes:
  //Fields attribute base class
  [AttributeUsage(AttributeTargets.Field , Inherited = true, AllowMultiple = false)]
public class MemberAttributeBase : System.Attribute
     public Type  Class;
     public Type  Collection;
     public string Member;
     public string Filter;
     public string Order;
     public string Key;
     public int     Max;
   public Type Element
   public string ClassName
   public virtual bool IsRelation
   public virtual bool IsScalar
   public virtual bool IsIdentity
   public virtual bool IsTransient
   public MemberAttributeBase(Type Class)
  //Fields relation attibute class
  [AttributeUsage(AttributeTargets.Field , Inherited = true, AllowMultiple = false)]
public class Relation : MemberAttributeBase
   public override bool IsRelation
  //Fields indentity class
  [AttributeUsage(AttributeTargets.Field , Inherited = true, AllowMultiple = false)]
public class Identity : MemberAttributeBase
   public static bool ValueIsEmpty(object value)
   public static bool IsPrimitive(object value)
   public static bool IsEmpty(object obj)
   public static FieldInfo Get(Type type)
   public static FieldInfo Get(object obj)
   public static void Set(object obj,object value)
   public static void Search(ISyntax syntax,object obj)
   public override bool IsIdentity
  //Fields scalar attibute class
  [AttributeUsage(AttributeTargets.Field , Inherited = true, AllowMultiple = false)]
public class Scalar : MemberAttributeBase
   public override bool IsScalar
  //Fields transient attibute class
  [AttributeUsage(AttributeTargets.Field , Inherited = true, AllowMultiple = false)]
public class Transient : MemberAttributeBase
   public override bool IsTransient
  //Persistent objects base interface
public interface IObject
     bool OnCreate();
     void OnCreateComplete();
     bool OnUpdate();
     bool OnRemove();
     void OnValidate(IErrorWriter Error);
  //Persistent objects base interface
public class ObjectBase : IObject
   protected object this[string Name]
   public ObjectBase()
   public virtual bool OnCreate()
   public virtual void OnCreateComplete()
   public virtual bool OnUpdate()
   public virtual bool OnRemove()
   public virtual void OnValidate(IErrorWriter Error)
   public static object Copy(object Instance)
  //Collection of persistent object class
public class Collection : System.Collections.ArrayList
   public Collection(Type Class)
   public static implicit operator object[](Collection List)
  //Error writer interface
public interface IErrorWriter
     void Write(string Message);
     void Write(object value,string Message);
     void Write(int value,int Min,int Max,string Message);
     void Write(double value,double Min,double Max,string Message);
     void Write(string value,string Message);
     void Write(DateTime value,DateTime Min,DateTime Max,string Message);
     void WriteUri(string value,string Message);
     void WriteMail(string value,string Message);
   bool Empty
  //Package interface
public interface IPackage
     void Pack (object value);
     object UnPack (Type Class);
  //Binary package class
public class BinaryPackage : IPackage
   public string ToBase64
   public byte[] ToBytes
   void IPackage.Pack (object value)
   object IPackage.UnPack (Type Class)
  //IFilter interface
public interface IFilter
     void And();
     void Or();
     void Not();
     void Xor();
     void Search(string Name,string Operator,object value);
     void Search(string Name,object value);
     void Search(object Instance);
     void Like(string Name,string value);
     void Between(string Name,object Start,object End);
     void In(string Name,params object[] Params);
     void Filter(string Filter,params object[] Params);
     void Exists(Type Class,string Filter,params object[] Params);
     void Exists(object Syntax);
     void IN(string Name,Type Class,string Member,string Filter,params object[] Params);
     void IN(string Name,object Syntax);
     void Order(string Name,bool Asc);
     void Order(string Name);
  //Syntax interface
public interface ISyntax : IFilter
   int Max
   Type Class
     void Select(Type Class,params string[] Members);
     void Update(object Instance,params string[] Members);
     void Insert(object Instance,bool All);
     void Delete(Type Class);
     void Call(Type Class,object Method,params object[] Params);
     void Inner(string Entity,string Filter);
     void Left(string Entity,string Filter);
     void Right(string Entity,string Filter);
     void Group(string Name);
     void Filter(IFilter Filter);
  //Syntax base class
public class Syntax : ISyntax
   protected virtual void Clear()
   protected virtual void WriteElement(Element Element)
   protected virtual void WriteMax(int Max)
   protected virtual void WriteMember(string Member)
   protected virtual void WriteClass(Type Class,string Alias,Element Lock)
   protected virtual void WriteEntity(string Entity,string Alias,Element Lock)
   protected virtual void WriteSyntax(ISyntax Syntax)
   protected virtual void WriteSyntax(object Data)
   protected virtual object ToObject()
   protected virtual void WriteOperator(string Operator)
   protected virtual void WriteEqual(object value)
   protected virtual void Write(object value)
   protected virtual void Write(string value)
   protected virtual void Write(object Start,object End)
   protected virtual void Write(object[] List)
   protected virtual void WriteDelimiter()
   protected virtual void WriteBegin()
   protected virtual void WriteEnd()
   protected virtual void WriteExpression(string Expression,params object[] Params)
   protected virtual void WriteMethod(string Name,params object[] Params)
   int ISyntax.Max
   Type ISyntax.Class
   void IFilter.And()
   void IFilter.Or()
   void IFilter.Not()
   void IFilter.Xor()
   void IFilter.Search(string Name,string Operator,object value)
   void IFilter.Search(string Name,object value)
   void IFilter.Search(object Instance)
   void IFilter.Like(string Name,string value)
   void IFilter.Between(string Name,object Start,object End)
   void IFilter.In(string Name,params object[] Params)
   void IFilter.Filter(string Filter,params object[] Params)
   void IFilter.Exists(Type Class,string Filter,params object[] Params)
   void IFilter.Exists(object Syntax)
   void IFilter.IN(string Name,Type Class,string Member,string Filter,params object[] Params)
   void IFilter.IN(string Name,object Syntax)
   void IFilter.Order(string Name,bool Asc)
   void IFilter.Order(string Name)
   void ISyntax.Select(Type Class,params string[] Members)
   void ISyntax.Update(object Instance,params string[] Members)
   void ISyntax.Insert(object Instance,bool All)
   void ISyntax.Delete(Type Class)
   void ISyntax.Call(Type Class, object Method,params object[] Params)
   void ISyntax.Inner(string Entity,string Filter)
   void ISyntax.Left(string Entity,string Filter)
   void ISyntax.Right(string Entity,string Filter)
   void ISyntax.Group(string Name)
   void ISyntax.Filter(IFilter Filter)
  //The persistent objects repository
public class Repository
   public static void Open(string Class,string Connection,int Pool,string LogDir)
   public static EventLog Event(string Name,Type Class)
   public static ISyntax Syntax()
   public static ISyntax Syntax(Type Class,int Max)
   public static ISyntax Syntax(Type Class)
   public static IFilter Filter(Type Class,int Max)
   public static IFilter Filter(Type Class)
   public static IFilter Filter()
   public static object Covert(object value,Type Class)
   public static object Reload(object Instance)
   public static object[] All(Type Class)
   public static object Lookup(object Instance)
   public static object Lookup(Type Class,object ID)
   public static object Lookup(IFilter Filter)
   public static object Lookup(Type Class, string Filter,string Order,params object[] Params)
   public static object Lookup(IList List,IFilter Filter)
   public static object Lookup(Type ListType,IFilter Filter)
   public static object Lookup(IDictionary Dictionary,string Key,IFilter Filter)
   public static object Lookup(Type DictionaryType,string Key,IFilter Filter)
   public static object Lookup(object Instance,string Member)
   public static bool Exists(IFilter Filter)
   public static bool Exists(Type Class,string Filter,params object[] Params)
   public static object Call(Type Class,object Method,params object[] Params)
   public static void Store(object Instance)
   public static void Update(object Instance)
   public static void Update(object Instance,string Members,string Filter,params object[] Params)
   public static void Update(object Instance,string Members,IFilter Filter)
   public static void Remove(object Instance)
   public static void Remove(Type Class,string Filter,params object[] Params)
   public static void Remove(Type Class,IFilter Filter)
  //The events logger class
public class EventLog
   public void WriteBegin(string Event,Type Class)
   public void WriteLine(params object[] Tokens)
   public void WriteException(Exception Error)
   public void WriteEnd()
   public override string ToString()
  //Any storage providers interface base
public interface IStorage
   ISyntax Syntax
   EventLog Event
     bool Exists();
     bool Read();
     bool IsValid(int Index);
   object this[int Index,Type Type]
     void Store();
     void OnRelease();
     void Close();
  //Storage factory internal class
public class Factory : System.Collections.Stack
   public Factory(Type Class,string Connection,int Pool)
   public IStorage Create()
   public void Release(IStorage Storage)
   public void Close()
  //Xml formatter interface base
public interface IXmlFormatter
     void Serialize(System.Xml.XmlWriter writer, object obj);
     object Deserialize(System.Xml.XmlReader reader);
  //Xml formatter class
public class XmlFormatter : IXmlFormatter
   public static void SaveTo(string FileName,object obj)
   public static object LoadFrom(string FileName)
   public XmlFormatter(object XmlData)
   string override ToString()
   void virtual FromString(string value)
   void IXmlFormatter.Serialize(XmlWriter writer, object obj)
   object IXmlFormatter.Deserialize(XmlReader reader)

Customer demo:
public class Customer : ObjectBase
     public int ID;
     public string CompanyName;
     public string ContactName;
     public string ContactTitle;
     public string Address;
     public string City;
     public string Region;
     public string Country;
     public string Phone;
     public string EMail;
     public string Web;
     public string ICQ;
     public string State;
     public string Comment;
     public DateTime CreatedTime;
     public DateTime ContactTime;
     [Relation(typeof(Message[]),Max=100,Member="Customer",Order="ID desc",Filter="State!='Removing'")]
     protected object _Messages;
   public Message[] Messages
           get{return (Message[])this["_Messages"];}
   public static Customer[] Planning
           get{return (Customer[])Repository.Lookup(typeof(Customer[]),"ContactTime==null&&State==?","ID","Planning");}
   public string Name
           get{return CompanyName==null || CompanyName.Length==0?"None":CompanyName;}
   public override bool OnCreate()
           if (CompanyName==null || CompanyName.Length==0) CompanyName=Name;
           CreatedTime = DateTime.Now;
           State = "Planning";
           return base.OnCreate();
   public override bool OnRemove()
           return !Repository.Exists(typeof(Message[]),"Customer=?",this);
   public override void OnValidate(IErrorWriter Error)
           Error.Write(ContactName,"Name cannot be empty !");
           Error.Write(Country,"County cannot be empty !");
           Error.WriteMail(EMail,"Email address is invalid!");
           if (Web==null || Web.Length==0) return;
           if (Web.IndexOf(':')==-1) Web ="http://" + Web;
           Error.WriteUri(Web,"Web url is invalid !");
   public void Receive(string Subject,string Body)
           Message message = new Message(this,"IN",Subject,Body);
           message.State = "Received";
           if (String.Compare("Working",State,true)!=0)
            State = "Working";
            ContactTime = DateTime.Now;
   public void Send(string Subject,string Body)
           Message message = new Message(this,"OUT",Subject,Body);
           message.State = "Sending";
           if (State==null || State.Length==0 || String.Compare("Planning",State,true)==0)
            State = "Proposal";
public class Message :ObjectBase
     public int ID;
     public object customer;
   public Customer Customer  
            return (Message[])Repository.Lookup(typeof(Message[]),"this.Kind==?&&this.State==?",null,"OUT","Sending");
     public string CustomerName;
     public string Kind;
     public string State;
     public string Address;
     public string Subject;
     public string Body;
     public DateTime CreatedTime;
     public static Message[] Sending
            return (Message[])Repository.Lookup(typeof(Message[]),"this.Kind==?&&this.State==?",null,"OUT","Sending");
     public bool IsOUT
           get{return String.Compare("OUT",Kind,true)==0;}
   public Message()
     public Message(Customer Sender,string Kind,string Subject,string Body)
           customer = Sender;
           CreatedTime = DateTime.Now;
           State = "Sending";
           this.Address = Sender.EMail;
           this.Kind = Kind;
           this.Subject = (Subject!=null&&Subject.Length!=0)?Subject:"(No Subject)";
           this.Body = Body;
     public override bool OnUpdate()
           if (Subject==null || Subject.Length==0) Subject = "(No Subject)";
           return base.OnUpdate();
     public override bool OnRemove()
           if (String.Compare(State,"Removing",true)==0) return base.OnRemove();
           State = "Removing";
           return false;
     public override void OnValidate(IErrorWriter Error)
           Error.Write(customer,"Reference to customer cannot be empty !");
           Error.Write(Body,"Message content cannot be empty !");
           Error.Write(Address,"Email address is invalid!");

        <title>Demo report</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      <body bgcolor="#FFFFFF" text="#000000">
      <p><font size="4">Today is</font>:<%=DateTime.Now.ToString();%></p>
      <table width="75%" border="1">
        <td width="30%"><b>Name</b></td>
        <td width="24%"><b>Phone</b></td>
        <td width="29%"><b>Time of first contact</b></td>
        <td width="17%"><b>Customer state</b></td>
      <%foreach(CRM.Customer Customer in Repository.All(typeof(CRM.Customer[]))){%>
        <td width="30%"><%=Customer.ContactName;%></td>
        <td width="24%"><%=Customer.Phone;%></td>
        <td width="29%"><%=Customer.ContactTime.ToString();%></td>
        <td width="17%"><%=Customer.State;%></td>

Home Map UDP OOAD Development Jobs .Net Email