public void ExceptionIsLogged()
 {
     exLogged = false;
     SemanticProcessor sp = new SemanticProcessor();
     sp.Register<LoggerMembrane, LoggerReceptor>();
     sp.Register<LoggerMembrane, ExceptionReceptor>();
     sp.Register<TestMembrane, TestReceptor>();
     sp.ProcessInstance<TestMembrane, TypeThrowsException>(true);
     Assert.That(exLogged, "Expected Exception call to be logged.");
 }
 public void ProcessCallIsLogged()
 {
     stLogged = false;
     SemanticProcessor sp = new SemanticProcessor();
     sp.Register<LoggerMembrane, LoggerReceptor>();
     sp.Register<LoggerMembrane, ExceptionReceptor>();
     sp.Register<TestMembrane, TestReceptor>();
     sp.ProcessInstance<TestMembrane, TestSemanticType>(true);
     Assert.That(stLogged, "Expected Process call to be logged.");
 }
        public void DistributedComputation()
        {
            SemanticProcessor spOut = new SemanticProcessor();
            SemanticProcessor spIn = new SemanticProcessor();

            received = "";
            OutboundDistributedComputingReceptor dcrOut = new OutboundDistributedComputingReceptor(4002);
            InboundDistributedComputingReceptor dcrIn = new InboundDistributedComputingReceptor(4002, spIn);

            // Create an "emitter" in which a semantic type emitted on the TestMembrane permeates
            // into the inner DistributedProcessMembrane for our test type.
            spOut.AddChild<TestMembrane, DistributedProcessMembrane>();
            spOut.OutboundPermeableTo<TestMembrane, TestDistributedSemanticType>();
            spOut.InboundPermeableTo<DistributedProcessMembrane, TestDistributedSemanticType>();

            // The stateful DCR out lives in the distributed process membrane.
            spOut.Register<DistributedProcessMembrane>(dcrOut);

            // Create a "receiver" in which a semantic type is received on the inner DistributedProcessMembrane
            // and the test type permeates out to a "handler" receptor.
            spIn.AddChild<TestMembrane, DistributedProcessMembrane>();
            spIn.OutboundPermeableTo<DistributedProcessMembrane, TestDistributedSemanticType>();
            spIn.InboundPermeableTo<TestMembrane, TestDistributedSemanticType>();

            // The stateful DCR in lives in the distributed process membrane.
            spIn.Register<DistributedProcessMembrane>(dcrIn);
            // The responding receptor lives in the TestMembrane
            spIn.Register<TestMembrane, TestReceptor>();

            // Put a semantic type instance on the outbound side.
            spOut.ProcessInstance<TestMembrane, TestDistributedSemanticType>((t) =>
                {
                    t.Message = "Hello World";
                });

            // Wait a bit for threads to do their thing and Http posts to do their things.
            // System.Diagnostics.Debug.WriteLine("Waiting...");
            // !*!*!*!* Sometimes this wait must be longer -- the unit test engine can really slow things down.
            // !*!*!*!* This is particularly true when running the test in the debugger!
            // !*!*!*!* If this delay isn't long enough for the server's message to be processed, you will get
            // !*!*!*!* errors related to accessing objects on an unloaded AppDomain.
            // !*!*!*!* In real life this woudn't happen -- this is an artifact of unit testing a complex
            // !*!*!*!* multi-threaded process.
            //Thread.Sleep(500);

            // Because we know it works, we could actually do this, which is particularly useful when we're
            // debugging and single stepping through code -- we do not want the test in this AppDomain
            // to exit prematurely!
            while (String.IsNullOrEmpty(received))
            {
                Thread.Sleep(0);
            }

            Assert.That(received == "Hello World", "Expected to receive 'Hello World'");
        }
        public void DistributedComputation()
        {
            SemanticProcessor spOut = new SemanticProcessor();
            SemanticProcessor spIn  = new SemanticProcessor();

            received = "";
            OutboundDistributedComputingReceptor dcrOut = new OutboundDistributedComputingReceptor(4002);
            InboundDistributedComputingReceptor  dcrIn  = new InboundDistributedComputingReceptor(4002, spIn);

            // Create an "emitter" in which a semantic type emitted on the TestMembrane permeates
            // into the inner DistributedProcessMembrane for our test type.
            spOut.AddChild <TestMembrane, DistributedProcessMembrane>();
            spOut.OutboundPermeableTo <TestMembrane, TestDistributedSemanticType>();
            spOut.InboundPermeableTo <DistributedProcessMembrane, TestDistributedSemanticType>();

            // The stateful DCR out lives in the distributed process membrane.
            spOut.Register <DistributedProcessMembrane>(dcrOut);

            // Create a "receiver" in which a semantic type is received on the inner DistributedProcessMembrane
            // and the test type permeates out to a "handler" receptor.
            spIn.AddChild <TestMembrane, DistributedProcessMembrane>();
            spIn.OutboundPermeableTo <DistributedProcessMembrane, TestDistributedSemanticType>();
            spIn.InboundPermeableTo <TestMembrane, TestDistributedSemanticType>();

            // The stateful DCR in lives in the distributed process membrane.
            spIn.Register <DistributedProcessMembrane>(dcrIn);
            // The responding receptor lives in the TestMembrane
            spIn.Register <TestMembrane, TestReceptor>();

            // Put a semantic type instance on the outbound side.
            spOut.ProcessInstance <TestMembrane, TestDistributedSemanticType>((t) =>
            {
                t.Message = "Hello World";
            });

            // Wait a bit for threads to do their thing and Http posts to do their things.
            // System.Diagnostics.Debug.WriteLine("Waiting...");
            // !*!*!*!* Sometimes this wait must be longer -- the unit test engine can really slow things down.
            // !*!*!*!* This is particularly true when running the test in the debugger!
            // !*!*!*!* If this delay isn't long enough for the server's message to be processed, you will get
            // !*!*!*!* errors related to accessing objects on an unloaded AppDomain.
            // !*!*!*!* In real life this woudn't happen -- this is an artifact of unit testing a complex
            // !*!*!*!* multi-threaded process.
            //Thread.Sleep(500);

            // Because we know it works, we could actually do this, which is particularly useful when we're
            // debugging and single stepping through code -- we do not want the test in this AppDomain
            // to exit prematurely!
            while (String.IsNullOrEmpty(received))
            {
                Thread.Sleep(0);
            }

            Assert.That(received == "Hello World", "Expected to receive 'Hello World'");
        }
        public void ExceptionIsLogged()
        {
            exLogged = false;
            SemanticProcessor sp = new SemanticProcessor();

            sp.Register <LoggerMembrane, LoggerReceptor>();
            sp.Register <LoggerMembrane, ExceptionReceptor>();
            sp.Register <TestMembrane, TestReceptor>();
            sp.ProcessInstance <TestMembrane, TypeThrowsException>(true);
            Assert.That(exLogged, "Expected Exception call to be logged.");
        }
        public void ProcessCallIsLogged()
        {
            stLogged = false;
            SemanticProcessor sp = new SemanticProcessor();

            sp.Register <LoggerMembrane, LoggerReceptor>();
            sp.Register <LoggerMembrane, ExceptionReceptor>();
            sp.Register <TestMembrane, TestReceptor>();
            sp.ProcessInstance <TestMembrane, TestSemanticType>(true);
            Assert.That(stLogged, "Expected Process call to be logged.");
        }
示例#7
0
        public void MultipleProcessCalls()
        {
            callSuccess  = false;
            callSuccess2 = false;
            SemanticProcessor sp = new SemanticProcessor();

            sp.Register <TestMembrane>(new TestReceptor());
            sp.Register <TestMembrane>(new TestReceptor2());
            sp.ProcessInstance <TestMembrane, TestSemanticType>(true);
            Assert.That(callSuccess, "Expected TestReceptor.Process to be called.");
            Assert.That(callSuccess2, "Expected TestReceptor2.Process to be called.");
        }
示例#8
0
        public void ComplexTypePropertyProcessing()
        {
            simpleTypeProcessed  = false;
            complexTypeProcessed = false;
            SemanticProcessor sp = new SemanticProcessor();

            sp.Register <TestMembrane, ComplexReceptor>();
            sp.Register <TestMembrane, SimpleReceptor>();
            sp.ProcessInstance <TestMembrane, ComplexType>(true);
            Assert.That(complexTypeProcessed, "Expected ComplexReceptor.Process to be called.");
            Assert.That(simpleTypeProcessed, "Expected SimpleReceptor.Process to be called.");
        }
示例#9
0
        static void Main(string[] args)
        {
            ServiceManager sm = new ServiceManager();

            SemanticProcessor semproc = new SemanticProcessor();

            semproc.Initialize(sm);
            sm.RegisterSingleton <ISemanticProcessor>(semproc);

            var wsClient = new WebSocketClientService();

            wsClient.Initialize(sm);
            sm.RegisterSingleton <IWebSocketClientService>(wsClient);

            semproc.Register <SocketMembrane, ServerSocketReceiver>();

            // wsClient.Start("ws://127.0.0.1", 1000, "/wstest");
            wsClient.Start("ws://24.105.201.179", 31415, "/wstest");
            // wsClient.Start("ws://emsserver.club", 443, "/wstest");


            // wsClient.Start("wss://24.105.201.179", 443, "/wstest");
            // wsClient.Start("wss://emsserver.club", 443, "/wstest");

            // Console.WriteLine("WS client connected to 127.0.0.1:1000");
            wsClient.Send("Hello World!");
            Console.ReadLine();
        }
示例#10
0
        public void InstantiateReceptor(string typeName)
        {
            var       agent    = Assembly.GetExecutingAssembly().GetTypes().SingleOrDefault(at => at.IsClass && at.IsPublic && at.Name == typeName);
            IReceptor receptor = (IReceptor)Activator.CreateInstance(agent);

            sp.Register <HopeMembrane>(receptor);
        }
示例#11
0
        public void InstantiateReceptor(string name)
        {
            Type      t    = assy.GetTypes().Single(at => at.Name == name);
            IReceptor inst = (IReceptor)Activator.CreateInstance(t);

            // sp.Register(membrane, inst);
            sp.Register <App.HopeMembrane>(inst);
        }
示例#12
0
        public void ReceptorDoesNotReceiveSemanticTypeOnAnotherMembrane()
        {
            callSuccess = false;
            SemanticProcessor sp = new SemanticProcessor();

            sp.Register <TestMembrane>(new TestReceptor());
            sp.ProcessInstance <TestMembrane2, TestSemanticType>(true);
            Assert.That(!callSuccess, "Expected TestReceptor.Process to NOT be called.");
        }
        public void InitializerCalledForSemanticTypeConstruction()
        {
            bool initializerCalled = false;
            SemanticProcessor sp   = new SemanticProcessor();

            sp.Register <TestMembrane, TestReceptor>();
            sp.ProcessInstance <TestMembrane, TestSemanticType>((t) => initializerCalled = true, true);
            Assert.That(initializerCalled, "Expected semantic type initializer to be called.");
        }
示例#14
0
        public void BaseClassProcessCalled()
        {
            callSuccess = false;
            SemanticProcessor sp = new SemanticProcessor();

            sp.Register <TestMembrane>(new DerivedTestReceptor());
            sp.ProcessInstance <TestMembrane, TestSemanticType>(true);
            Assert.That(callSuccess, "Expected TestReceptor.Process to be called.");
        }
示例#15
0
        public void ReceptorOfInterfaceTypCalled()
        {
            callSuccess = false;
            SemanticProcessor sp = new SemanticProcessor();

            sp.Register <TestMembrane>(new InterfaceTestReceptor());
            sp.ProcessInstance <TestMembrane, InterfaceTestSemanticType>(true);
            Assert.That(callSuccess, "Expected TestReceptor.Process to be called.");
        }
示例#16
0
        public void ReceptorReceivesSemanticTypeOnItsMembrane()
        {
            callSuccess = false;
            SemanticProcessor sp = new SemanticProcessor();

            sp.Register <TestMembrane>(new TestReceptor());
            sp.ProcessInstance <TestMembrane, TestSemanticType>(true);
            Assert.That(callSuccess, "Expected TestReceptor.Process to be called.");
        }
示例#17
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.
        }
        public void RemoveType()
        {
            callSuccess = false;
            SemanticProcessor sp = new SemanticProcessor();

            sp.Register <TestMembrane, TestReceptor>();
            sp.RemoveTypeNotify <TestMembrane, TestReceptor, TestSemanticType>();
            sp.ProcessInstance <TestMembrane, TestSemanticType>(true);
            Assert.That(!callSuccess, "Expected TestReceptor.Process to NOT be called.");
        }
示例#19
0
 public void NotPermeableOut()
 {
     callSuccess = false;
     SemanticProcessor sp = new SemanticProcessor();
     // sp.OutboundPermeableTo<InnerMembrane, TestSemanticType>();
     sp.InboundPermeableTo<OuterMembrane, TestSemanticType>();
     sp.AddChild<OuterMembrane, InnerMembrane>();
     sp.Register<OuterMembrane, TestReceptor>();
     sp.ProcessInstance<InnerMembrane, TestSemanticType>(true);
     Assert.That(!callSuccess, "Expected receptor in outer membrane to NOT receive the ST placed in the inner membrane.");
 }
        public void ReceptorTypeCreateDestroy()
        {
            constructorCalled = false;
            disposeCalled     = false;
            SemanticProcessor sp = new SemanticProcessor();

            sp.Register <TestMembrane, TestReceptor>();
            sp.ProcessInstance <TestMembrane, TestSemanticType>(true);
            Assert.That(constructorCalled, "Expected constructor to be called.");
            Assert.That(disposeCalled, "Expected Dispose to be called.");
        }
示例#21
0
        public void ReceptorInstanceCreateDestroy()
        {
            SemanticProcessor sp = new SemanticProcessor();

            sp.Register <TestMembrane>(new TestReceptor());
            constructorCalled = false;
            disposeCalled     = false;
            sp.ProcessInstance <TestMembrane, TestSemanticType>(true);
            Assert.That(!constructorCalled, "Expected constructor NOT to be called.");
            Assert.That(!disposeCalled, "Expected Dispose NOT to be called.");
        }
示例#22
0
		static void Main()
		{
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			Form1 form = new Form1();
			SemProc = new SemanticProcessor();
			SemProc.Register<LoggerMembrane, LoggingReceptor>();
			// DistReceptor = new DistributedComputingReceptor();
			// InitializeSemantics(form);

			Application.Run(form);
		}
        public void NotPermeableOut()
        {
            callSuccess = false;
            SemanticProcessor sp = new SemanticProcessor();

            // sp.OutboundPermeableTo<InnerMembrane, TestSemanticType>();
            sp.InboundPermeableTo <OuterMembrane, TestSemanticType>();
            sp.AddChild <OuterMembrane, InnerMembrane>();
            sp.Register <OuterMembrane, TestReceptor>();
            sp.ProcessInstance <InnerMembrane, TestSemanticType>(true);
            Assert.That(!callSuccess, "Expected receptor in outer membrane to NOT receive the ST placed in the inner membrane.");
        }
        public void TypePermeatesIn()
        {
            callSuccess = false;
            SemanticProcessor sp = new SemanticProcessor();

            sp.OutboundPermeableTo <OuterMembrane, TestSemanticType>();
            sp.InboundPermeableTo <InnerMembrane, TestSemanticType>();
            sp.AddChild <OuterMembrane, InnerMembrane>();
            sp.Register <InnerMembrane, TestReceptor>();
            sp.ProcessInstance <OuterMembrane, TestSemanticType>(true);
            Assert.That(callSuccess, "Expected receptor in inner membrane to process the ST placed in the outer membrane.");
        }
示例#25
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Form1 form = new Form1();

            SemProc = new SemanticProcessor();
            SemProc.Register <LoggerMembrane, LoggingReceptor>();
            // DistReceptor = new DistributedComputingReceptor();
            // InitializeSemantics(form);

            Application.Run(form);
        }
        public void ReceptorInitialization()
        {
            receptorInitializerCalled = false;
            SemanticProcessor sp = new SemanticProcessor();

            sp.Register <TestMembrane, TestReceptor>((ir) =>
            {
                // Unfortunately, a cast is required, because ir is type declared as IReceptor
                // and I don't think it's possible to fix that because of the late callback.
                TestReceptor r            = (TestReceptor)ir;
                r.AFlag                   = true;
                receptorInitializerCalled = true;
            });
            sp.ProcessInstance <TestMembrane, TestSemanticType>(true);
            Assert.That(receptorInitializerCalled, "Expected TestReceptor initializer to be called to be called.");
        }
示例#27
0
        static void Main(string[] args)
        {
            ServiceManager sm = new ServiceManager();

            SemanticProcessor semproc = new SemanticProcessor();

            semproc.Initialize(sm);
            sm.RegisterSingleton <ISemanticProcessor>(semproc);

            wsServer = new WebSocketServerService();
            wsServer.Initialize(sm);
            sm.RegisterSingleton <IWebSocketServerService>(wsServer);

            semproc.Register <SocketMembrane, ServerSocketReceiver>();
            wsServer.Start("127.0.0.1", 1000, "/wstest");

            Console.WriteLine("WS listening on 127.0.0.1:1000");
            Console.ReadLine();
            wsServer.Stop();
        }
示例#28
0
 public void TypePermeatesAcross()
 {
     callSuccess = false;
     SemanticProcessor sp = new SemanticProcessor();
     sp.OutboundPermeableTo<InnerMembrane, TestSemanticType>();
     sp.InboundPermeableTo<OuterMembrane, TestSemanticType>();
     sp.OutboundPermeableTo<OuterMembrane, TestSemanticType>();
     sp.InboundPermeableTo<InnerMembrane2, TestSemanticType>();
     sp.AddChild<OuterMembrane, InnerMembrane>();
     sp.AddChild<OuterMembrane, InnerMembrane2>();
     sp.Register<InnerMembrane2, TestReceptor>();
     sp.ProcessInstance<InnerMembrane, TestSemanticType>(true);
     Assert.That(callSuccess, "Expected receptor in inner membrane to process the ST placed in the adjacent inner membrane.");
 }