Program.cs :  » Persistence-Frameworks » ODX » Presonia » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Persistence Frameworks » ODX 
ODX » Presonia » Program.cs
using System;
using System.Collections.Generic;
using System.Data;
using NUnit.Framework;
using ODX.Core;
using ODX.LazyUnitTester;

namespace Presonia{
    public enum Sex
    {
        Undefined,
        Male,
        Female
    }

    [Table]
    [HierarchyRoot]
    [TypeDef("P")]
    public abstract class Person : Entity
    {
        public abstract string Name { get; set; }
        public abstract Sex Sex{ get; set; }

        public abstract Person Mother { get; set; }
        public abstract Person Father{ get; set; }

        [Column("MotherID")]
        protected abstract IEntityList<Person> MotherChildren { get; }

        [Column("FatherID")]
        protected abstract IEntityList<Person> FatherChildren { get; }

        [Column("PairID")]
        protected abstract Person Pair { get; set; }

        [Column("FormerPairID")]
        public abstract IEntityList<Person> FormerPairs{ get; }

        public IEntityList<Person> Children { get { return Sex == Sex.Male ? FatherChildren : MotherChildren; } }

        [LinkTable("PersonToPerson", ParentColumn = "Friend1ID", ChildColumn = "Friend2ID")]
        public abstract IEntityList<Person> Friends { get; }

        [LinkTable("PersonToPerson", ParentColumn = "Friend2ID", ChildColumn = "Friend1ID")]
        protected abstract IEntityList<Person> Friends2 { get; }


        protected override void OnChanged(DataColumnChangeEventArgs e)
        {
            if (e.Column.ColumnName == "PairID")
            {
                foreach (Person p in new List<Person>(FormerPairs))
                    if (p == Pair)
                        FormerPairs.Remove(p);

                foreach (Person p in new List<Person>(FormerPairs))
                    if (p.Pair == this)
                        p.Pair = null;

                if (Pair != null && Pair.Pair != this)
                    Pair.Pair = this;

                foreach (Person p in new List<Person>(FormerPairs))
                    if (p == Pair)
                        FormerPairs.Remove(p);

            }
            base.OnChanged(e);
        }

        protected override void OnChanging(DataColumnChangeEventArgs e)
        {
            if (e.Column.ColumnName == "PairID")
                if (Pair != null)
                    FormerPairs.Add(Pair);

            base.OnChanging(e);
        }

        public void WritePair()
        {
            string pair = Pair != null ? Pair.Name : "null";
            Console.WriteLine("{0} -> {1}", Name, pair);
        }
    }

    [TypeDef("M")]
    public abstract class Man : Person
    {
        public Man() { Sex = Sex.Male; }
        public Woman Wife
        {
            get { return (Woman) Pair; }
            set { Pair = value; }
        }
    }

    [TypeDef("M")]
    public abstract class Woman : Person
    {
        public Woman() { Sex = Sex.Female; }
        public Man Husband
        {
            get { return (Man)Pair; }
            set { Pair = value; }
        }
    }

    [TestFixture]
    public class Program
    {
        [TestBody]
        static void Main()
        {
            Session s = new Session();
            s.RegisterAssembly(typeof(Person).Assembly);
            s.Prepare();

            Man john = s.Create<Man>();
            john.Name = "John";

            Man smith = s.Create<Man>();
            smith.Name = "Smith";

            Woman kate = s.Create<Woman>();
            kate.Name = "Kate";

            WriteFormers(kate);

            kate.Husband = smith;
            WriteFormers(kate);
            WriteFormers(smith);
            WriteFormers(john);
            
            kate.Husband = john;
            WriteFormers(kate);
            WriteFormers(smith);
            WriteFormers(john);

            kate.Husband = smith;
            WriteFormers(kate);
            WriteFormers(smith);
            WriteFormers(john);

            kate.Husband = john;
            WriteFormers(kate);
            WriteFormers(smith);
            WriteFormers(john);
        }

        private static void WriteFormers(Person person)
        {
            person.WritePair();
            foreach (Person fm in person.FormerPairs)
            {
                LUT.WriteLine(fm.Name);
            }
            LUT.WriteLine("----------------------------");
        }

        [Test]
        public void Test()
        {
            LUT.Execute(Main);
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.