Example #1
0
        //public static T Cast<T>(object o)
        //{
        //	return (T)o;
        //}

        static void Main(string[] args)
        {
            SemanticProcessor sp = new SemanticProcessor();

            // AnotherType gets notified when instances of OneType are added to the pool.
            sp.Register <SurfaceMembrane, AReceptor>();                         // auto register
            sp.Register <SurfaceMembrane, BReceptor>();
            sp.Register <SurfaceMembrane, CReceptor>();

            // Explicit register
            //sp.TypeNotify<AReceptor, OneType>();
            //sp.TypeNotify<AReceptor, SecondType>();

            OneType           t1 = new OneType();
            SecondType        t2 = new SecondType();
            SecondDerivedType t3 = new SecondDerivedType();

            // object foo = Cast<SecondType>(t3);

            sp.ProcessInstance(sp.Surface, t1);
            sp.ProcessInstance(sp.Surface, t2);
            sp.ProcessInstance(sp.Surface, t3);

            Thread.Sleep(1000);                         // Wait for threaded processes to complete.

            Console.WriteLine("\r\nChained processing...");
            sp.RemoveTypeNotify <SurfaceMembrane, AReceptor, IOneType>();
            sp.RemoveTypeNotify <SurfaceMembrane, AReceptor, SecondType>();
            sp.RemoveTypeNotify <SurfaceMembrane, BReceptor, OneType>();
            sp.RemoveTypeNotify <SurfaceMembrane, CReceptor, SecondDerivedType>();

            // Chaining...
            // auto register:
            sp.Register <SurfaceMembrane, Chain1>();
            sp.Register <SurfaceMembrane, Chain2>();

            // Explicit register:
            //sp.TypeNotify<Chain1, OneType>();
            //sp.TypeNotify<Chain2, SecondType>();

            sp.ProcessInstance(sp.Surface, new OneType());

            Thread.Sleep(1000);                         // Wait for threaded processes to complete.
        }
Example #2
0
 public void Process(ISemanticProcessor pool, IMembrane membrane, OneType obj)
 {
     Console.WriteLine("B: Processing OneType on thread ID " + Thread.CurrentThread.ManagedThreadId);
 }