Beispiel #1
1
 public static void StartServer(TestContext ctx)
 {
     var serverSetup = new IpcBinaryServerProtocolSetup("OneWayTest");
     ZyanHost = new ZyanComponentHost("OneWayServer", serverSetup);
     ZyanHost.RegisterComponent<ISampleServer, SampleServer>();
     ZyanConnection = new ZyanConnection("ipc://OneWayTest/OneWayServer");
 }
Beispiel #2
1
        public override void Run()
        {
            Trace.WriteLine("Zyan.Examples.MiniChat.AzureWorkerRole entry point called", "Information");

            IPEndPoint endPoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["MiniChat"].IPEndpoint;
            TcpDuplexServerProtocolSetup protocol = new TcpDuplexServerProtocolSetup(endPoint.Port, new NicknameAuthProvider(), true);

            ActiveNicknames = new List<string>();

            ZyanComponentHost host = new ZyanComponentHost("MiniChat", protocol);
            host.RegisterComponent<IMiniChat, Zyan.Examples.MiniChat.Server.MiniChat>(ActivationType.Singleton);

            host.ClientLoggedOn += new EventHandler<LoginEventArgs>((sender, e) =>
                {
                    Trace.WriteLine(string.Format("{0}: User '{1}' with IP {2} logged on.", e.Timestamp.ToString(), e.Identity.Name, e.ClientAddress));
                    ActiveNicknames.Add(e.Identity.Name);
                });
            host.ClientLoggedOff += new EventHandler<LoginEventArgs>((sender, e) =>
                {
                    Trace.WriteLine(string.Format("{0}: User '{1}' with IP {2} logged off.", e.Timestamp.ToString(), e.Identity.Name, e.ClientAddress));
                    ActiveNicknames.Remove(e.Identity.Name);
                });

            while (true)
            {
                Thread.Sleep(10000);
                Trace.WriteLine("Working", "Information");
            }
        }
Beispiel #3
1
        static void Main(string[] args)
        {
            var host = new ZyanComponentHost("ZyanDemo", 12800);
            host.RegisterComponent<IHellow, HellowServer>();

            Console.ReadLine();
        }
Beispiel #4
0
        public static void StartServer(TestContext ctx)
        {
            ZyanComponentHost.LegacyBlockingEvents = true;

            var serverSetup = new NullServerProtocolSetup(2345);

            ZyanHost = new ZyanComponentHost("EventsServer", serverSetup);
            ZyanHost.RegisterComponent <ISampleServer, SampleServer>("Singleton", ActivationType.Singleton);
            ZyanHost.RegisterComponent <ISampleServer, SampleServer>("SingleCall", ActivationType.SingleCall);

            ZyanConnection = new ZyanConnection("null://NullChannel:2345/EventsServer");
        }
Beispiel #5
0
        private EventServer()
        {
            //TcpCustomServerProtocolSetup protocol = new TcpCustomServerProtocolSetup(8083, new NullAuthenticationProvider(), true);
            MsmqServerProtocolSetup protocol = new MsmqServerProtocolSetup(@"private$\reqchannel");

            _host = new ZyanComponentHost("EventTest", protocol);
            _host.RegisterComponent <IEventComponentSingleton, EventComponentSingleton>(ActivationType.Singleton);
            _host.RegisterComponent <IEventComponentSingleCall, EventComponentSingleCall>(ActivationType.SingleCall);
            _host.RegisterComponent <ICallbackComponentSingleton, CallbackComponentSingleton>(ActivationType.Singleton);
            _host.RegisterComponent <ICallbackComponentSingleCall, CallbackComponentSingleCall>(ActivationType.SingleCall);
            _host.RegisterComponent <IRequestResponseCallbackSingleCall, RequestResponseCallbackSingleCall>(ActivationType.SingleCall);
        }
Beispiel #6
0
        public static void StartServer(TestContext ctx)
        {
            var serverSetup = new IpcBinaryServerProtocolSetup("MefClientTest");

            ZyanHost = new ZyanComponentHost("MefClientServer", serverSetup);
            ZyanHost.RegisterComponent <IMefClientSample, MefClientSample>();
            ZyanHost.RegisterComponent <IMefClientSample, MefClientSample2>("AnotherComponent");

            ZyanConnection = new ZyanConnection("ipc://MefClientTest/MefClientServer");

            MefCatalog   = new ZyanCatalog(ZyanConnection);
            MefContainer = new CompositionContainer(MefCatalog);
        }
Beispiel #7
0
        public static void StartServer(TestContext ctx)
        {
            var serverSetup = new NullServerProtocolSetup(1234);
            ZyanHost = new ZyanComponentHost("DuckTypingServer", serverSetup);

            // registration-time check
            ZyanHost.RegisterComponent<IDuck, Platypus>("Platypus");

            // invocation-time check (object factory can't be verified during registration)
            ZyanHost.RegisterComponent<IDuck>("Chicken", () => new Chicken());

            ZyanConnection = new ZyanConnection("null://NullChannel:1234/DuckTypingServer");
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            using (var host = new ZyanComponentHost(Settings.Default.ServiceUri, Settings.Default.TcpPort))
            {
                // queryable service
                host.RegisterComponent <ISampleSource, SampleSource>();

                // buggy service (to demonstrate error handling)
                host.RegisterComponent <INamedService, BuggyService>("BuggyService");

                Console.WriteLine("Linq server started. Press ENTER to quit.");
                Console.ReadLine();
            }
        }
        public static void StartServer(TestContext ctx)
        {
            var serverSetup = new NullServerProtocolSetup(1234);

            ZyanHost = new ZyanComponentHost("DuckTypingServer", serverSetup);

            // registration-time check
            ZyanHost.RegisterComponent <IDuck, Platypus>("Platypus");

            // invocation-time check (object factory can't be verified during registration)
            ZyanHost.RegisterComponent <IDuck>("Chicken", () => new Chicken());

            ZyanConnection = new ZyanConnection("null://NullChannel:1234/DuckTypingServer");
        }
            private TcpDuplexServerHostEnvironment()
            {
                var protocol = new TcpDuplexServerProtocolSetup(8088, new CustomAuthenticationProvider(), true);

                _host = new ZyanComponentHost("CustomAuthenticationTestHost_TcpDuplex", protocol);
                _host.RegisterComponent <ISampleServer, SampleServer>("SampleServer", ActivationType.SingleCall);
            }
Beispiel #11
0
        public void CallInterceptionBug()
        {
            using (var host = new ZyanComponentHost("FirstTestServer", 18888))
            {
                host.RegisterComponent <ITestService, TestService>(ActivationType.Singleton);

                using (var connection = new ZyanConnection("tcp://127.0.0.1:18888/FirstTestServer")
                {
                    CallInterceptionEnabled = true
                })
                {
                    // add a call interceptor for the TestService.TestMethod
                    connection.CallInterceptors.Add(CallInterceptor.For <ITestService>().Action(service => service.TestMethod(), data =>
                    {
                        data.Intercepted = true;
                        data.MakeRemoteCall();
                        data.ReturnValue = nameof(TestService);
                    }));

                    var testService = connection.CreateProxy <ITestService>(null);
                    var result      = testService.TestMethod();
                    Assert.AreEqual(nameof(TestService), result);
                }
            }
        }
        public override void Run()
        {
            Trace.WriteLine("Zyan.Examples.MiniChat.AzureWorkerRole entry point called", "Information");

            IPEndPoint endPoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["MiniChat"].IPEndpoint;
            TcpDuplexServerProtocolSetup protocol = new TcpDuplexServerProtocolSetup(endPoint.Port, new NicknameAuthProvider(), true);

            ActiveNicknames = new List <string>();

            ZyanComponentHost host = new ZyanComponentHost("MiniChat", protocol);

            host.RegisterComponent <IMiniChat, Zyan.Examples.MiniChat.Server.MiniChat>(ActivationType.Singleton);

            host.ClientLoggedOn += new EventHandler <LoginEventArgs>((sender, e) =>
            {
                Trace.WriteLine(string.Format("{0}: User '{1}' with IP {2} logged on.", e.Timestamp.ToString(), e.Identity.Name, e.ClientAddress));
                ActiveNicknames.Add(e.Identity.Name);
            });
            host.ClientLoggedOff += new EventHandler <LoginEventArgs>((sender, e) =>
            {
                Trace.WriteLine(string.Format("{0}: User '{1}' with IP {2} logged off.", e.Timestamp.ToString(), e.Identity.Name, e.ClientAddress));
                ActiveNicknames.Remove(e.Identity.Name);
            });

            while (true)
            {
                Thread.Sleep(10000);
                Trace.WriteLine("Working", "Information");
            }
        }
Beispiel #13
0
        private static ZyanComponentHost CreateZyanHost(int port, string name)
        {
            ZyanSettings.LegacyBlockingEvents           = true;
            ZyanSettings.LegacyBlockingSubscriptions    = true;
            ZyanSettings.LegacyUnprotectedEventHandlers = true;

            var serverSetup = new NullServerProtocolSetup(port);
            var zyanHost    = new ZyanComponentHost(name, serverSetup);          //, DummySessionManager);

            zyanHost.RegisterComponent <ISampleServer, SampleServer <int> >("Singleton", ActivationType.Singleton);
            zyanHost.RegisterComponent <ISampleServer, SampleServer <short> >("Singleton2", ActivationType.Singleton);
            zyanHost.RegisterComponent <ISampleServer, SampleServer <long> >("Singleton3", ActivationType.Singleton);
            zyanHost.RegisterComponent <ISampleServer, SampleServer <byte> >("SingleCall", ActivationType.SingleCall);
            zyanHost.RegisterComponent <ISampleServer, SampleServer <char> >("SingletonExternal", new SampleServer <char>());
            return(zyanHost);
        }
            private TcpDuplexServerHostEnvironment()
            {
                var protocol = new TcpDuplexServerProtocolSetup(8092, new NullAuthenticationProvider(), true);

                _host = new ZyanComponentHost("TcpExConnectionLockRegressionTestHost_TcpDuplex", protocol);
                _host.RegisterComponent <ISampleServer, SampleServer>("SampleServer", ActivationType.SingleCall);
            }
Beispiel #15
0
 public static void StartServer(TestContext ctx)
 {
     var serverSetup = new IpcBinaryServerProtocolSetup("StreamsTest");
     ZyanHost = new ZyanComponentHost("SampleStreamServer", serverSetup);
     ZyanHost.RegisterComponent<IStreamService, StreamService>();
     ZyanConnection = new ZyanConnection("ipc://StreamsTest/SampleStreamServer");
 }
Beispiel #16
0
        private void TestVulnerability(string hostName, string serverUrl, IServerProtocolSetup serverSetup, IClientProtocolSetup clientSetup, object payload)
        {
            ZyanSettings.DisableUrlRandomization = true;

            using (var zyanHost = new ZyanComponentHost(hostName, serverSetup))
            {
                zyanHost.RegisterComponent <ISampleServer, SampleServer>(ActivationType.Singleton);
                var credentials = new Hashtable
                {
                    { "Login", "hacker" },
                    { "Password", "secret" },
                    { string.Empty, payload }
                };

                using (var zyanConnection = new ZyanConnection(serverUrl, clientSetup))
                {
                    var proxy = zyanConnection.CreateProxy <ISampleServer>();
                    AssertEx.Throws <SecurityException>(() => proxy.TestMethod(payload));
                }

                // should throw
                AssertEx.Throws <SecurityException>(() =>
                {
                    using (new ZyanConnection(serverUrl, clientSetup, credentials, true, true))
                    {
                    }
                });
            }
        }
            private TcpSimplexServerHostEnvironment()
            {
                var protocol = new TcpCustomServerProtocolSetup(8085, new NullAuthenticationProvider(), true);

                _host = new ZyanComponentHost("RecreateClientConnectionTestHost_TcpSimplex", protocol);
                _host.RegisterComponent <ISampleServer, SampleServer>("SampleServer", ActivationType.SingleCall);
            }
        public void RefreshRegisteredComponentsTest()
        {
            using (var host = new ZyanComponentHost("RefreshTest", new NullServerProtocolSetup(123)))
                using (var conn = new ZyanConnection("null://NullChannel:123/RefreshTest"))
                {
                    // this component is registered after connection is established
                    var componentName = Guid.NewGuid().ToString();
                    host.RegisterComponent <ISampleServer, SampleServer>(componentName);

                    try
                    {
                        // proxy cannot be created because connection doesn't know about the component
                        var proxy1 = conn.CreateProxy <ISampleServer>(componentName);
                        Assert.Fail("Component is not yet known for ZyanConnection.");
                    }
                    catch (ApplicationException)
                    {
                    }

                    // refresh the list of registered components and create a proxy
                    conn.RefreshRegisteredComponents();
                    var proxy2 = conn.CreateProxy <ISampleServer>(componentName);

                    var echoString = "Hello there";
                    var result     = proxy2.Echo(echoString);
                    Assert.AreEqual(echoString, result);
                }
        }
Beispiel #19
0
        public static void StartServer(TestContext ctx)
        {
            var serverSetup = new IpcBinaryServerProtocolSetup("OneWayTest");

            ZyanHost = new ZyanComponentHost("OneWayServer", serverSetup);
            ZyanHost.RegisterComponent <ISampleServer, SampleServer>();
            ZyanConnection = new ZyanConnection("ipc://OneWayTest/OneWayServer");
        }
Beispiel #20
0
        public static void StartServer(TestContext ctx)
        {
            var serverSetup = new IpcBinaryServerProtocolSetup("StreamsTest");

            ZyanHost = new ZyanComponentHost("SampleStreamServer", serverSetup);
            ZyanHost.RegisterComponent <IStreamService, StreamService>();
            ZyanConnection = new ZyanConnection("ipc://StreamsTest/SampleStreamServer");
        }
Beispiel #21
0
        public static void StartServer(TestContext ctx)
        {
            ZyanSettings.LegacyBlockingEvents           = true;
            ZyanSettings.LegacyBlockingSubscriptions    = true;
            ZyanSettings.LegacyUnprotectedEventHandlers = true;

            var serverSetup = new NullServerProtocolSetup(2345);

            ZyanHost = new ZyanComponentHost("EventsServer", serverSetup);
            ZyanHost.RegisterComponent <ISampleServer, SampleServer <int> >("Singleton", ActivationType.Singleton);
            ZyanHost.RegisterComponent <ISampleServer, SampleServer <short> >("Singleton2", ActivationType.Singleton);
            ZyanHost.RegisterComponent <ISampleServer, SampleServer <long> >("Singleton3", ActivationType.Singleton);
            ZyanHost.RegisterComponent <ISampleServer, SampleServer <byte> >("SingleCall", ActivationType.SingleCall);
            ZyanHost.RegisterComponent <ISampleServer, SampleServer <char> >("SingletonExternal", new SampleServer <char>());

            ZyanConnection = new ZyanConnection("null://NullChannel:2345/EventsServer");
        }
Beispiel #22
0
        public static void StartServer(TestContext ctx)
        {
            var serverSetup = new NullServerProtocolSetup(4321);

            ZyanHost = new ZyanComponentHost("GenericServer", serverSetup);
            ZyanHost.RegisterComponent <ISampleServer, SampleServer>();

            ZyanConnection = new ZyanConnection("null://NullChannel:4321/GenericServer");
        }
Beispiel #23
0
 public static void Main(string[] args)
 {
     var protocol = new TcpDuplexServerProtocolSetup(12345, new NullAuthenticationProvider(), true);
     using (var host = new ZyanComponentHost("Sample", protocol))
     {
         host.RegisterComponent<ISampleService, SampleService>();
         Console.WriteLine("Server started. Press Enter to exit.");
         Console.ReadLine();
     }
 }
Beispiel #24
0
            private TcpSimplexServerHostEnvironment()
            {
                // use custom SRP parameters
                var accounts = new SampleAccountRepository(CustomSrpParameters);
                var provider = new SrpAuthenticationProvider(accounts, CustomSrpParameters);
                var protocol = new TcpCustomServerProtocolSetup(8091, provider, true);

                _host = new ZyanComponentHost("CustomAuthenticationTestHost_TcpSimplex", protocol);
                _host.RegisterComponent <ISampleServer, SampleServer>("SampleServer", ActivationType.SingleCall);
            }
Beispiel #25
0
        public static void Main(string[] args)
        {
            var protocol = new TcpDuplexServerProtocolSetup(12345, new NullAuthenticationProvider(), true);

            using (var host = new ZyanComponentHost("Sample", protocol))
            {
                host.RegisterComponent <ISampleService, SampleService>();
                Console.WriteLine("Server started. Press Enter to exit.");
                Console.ReadLine();
            }
        }
Beispiel #26
0
        public static void StartServer(TestContext ctx)
        {
            ZyanConnection.AllowUrlRandomization = false;

            var serverSetup = new IpcBinaryServerProtocolSetup("ZyanProxyTest");
            ZyanHost = new ZyanComponentHost("ZyanProxyServer", serverSetup);
            ZyanHost.RegisterComponent<ISampleServer, SampleServer>(ActivationType.Singleton);

            var clientSetup = new IpcBinaryClientProtocolSetup();
            ZyanConnection = new ZyanConnection("ipc://ZyanProxyTest/ZyanProxyServer", clientSetup);
        }
Beispiel #27
0
        static void Main(string[] args)
        {
            var protocol = new TcpDuplexServerProtocolSetup(8081, null, true);

            using (var host = new ZyanComponentHost("WhisperChat", protocol))
            {
                host.RegisterComponent <IWhisperChatService, WhisperChatService>(ActivationType.SingleCall);

                Console.WriteLine("Server running.");
                Console.ReadLine();
            }
        }
        public static void StartServer(TestContext ctx)
        {
            ZyanComponentHost.LegacyBlockingEvents = true;

            var serverSetup = new NullServerProtocolSetup(3456);

            ZyanHost = new ZyanComponentHost("CallInterceptorServer", serverSetup);
            ZyanHost.RegisterComponent <IInterceptableComponent, InterceptableComponent>(ActivationType.Singleton);

            ZyanConnection = new ZyanConnection("null://NullChannel:3456/CallInterceptorServer");
            ZyanConnection.CallInterceptionEnabled = true;
        }
Beispiel #29
0
        static void Main(string[] args)
        {
            var protocol = new TcpDuplexServerProtocolSetup(8081,null,true);

            using (var host = new ZyanComponentHost("WhisperChat", protocol))
            {
                host.RegisterComponent<IWhisperChatService, WhisperChatService>(ActivationType.SingleCall);

                Console.WriteLine("Server running.");
                Console.ReadLine();
            }
        }
Beispiel #30
0
        public static void StartServer(TestContext ctx)
        {
            ZyanSettings.LegacyBlockingEvents        = true;
            ZyanSettings.LegacyBlockingSubscriptions = true;

            var serverSetup = new NullServerProtocolSetup(4567);

            ZyanHost = new ZyanComponentHost("EventFilterServer", serverSetup);
            ZyanHost.RegisterComponent <ISampleServer, SampleServer>();

            ZyanConnection = new ZyanConnection("null://NullChannel:4567/EventFilterServer");
        }
Beispiel #31
0
        static void Main(string[] args)
        {
            HttpCustomServerProtocolSetup protocol = new HttpCustomServerProtocolSetup(8081, new BasicWindowsAuthProvider(), true);

            using (ZyanComponentHost host = new ZyanComponentHost("EbcCalc", protocol))
            {
                host.SessionManager.SessionAgeLimit = 2;

                host.RegisterComponent<ICalculator, Calculator>();

                Console.ReadLine();
            }
        }
        public static void StartServer(TestContext ctx)
        {
            ZyanConnection.AllowUrlRandomization = false;

            var serverSetup = new IpcBinaryServerProtocolSetup("ZyanProxyTest");

            ZyanHost = new ZyanComponentHost("ZyanProxyServer", serverSetup);
            ZyanHost.RegisterComponent <ISampleServer, SampleServer>(ActivationType.Singleton);

            var clientSetup = new IpcBinaryClientProtocolSetup();

            ZyanConnection = new ZyanConnection("ipc://ZyanProxyTest/ZyanProxyServer", clientSetup);
        }
Beispiel #33
0
        static void Main(string[] args)
        {
            HttpCustomServerProtocolSetup protocol = new HttpCustomServerProtocolSetup(8081, new BasicWindowsAuthProvider(), true);

            using (ZyanComponentHost host = new ZyanComponentHost("EbcCalc", protocol))
            {
                host.SessionManager.SessionAgeLimit = 2;

                host.RegisterComponent <ICalculator, Calculator>();

                Console.ReadLine();
            }
        }
        public void CreateDisposeAndRecreateComponentHostForTcpSimplexChannel()
        {
            var protocol = new TcpCustomServerProtocolSetup(8087, new NullAuthenticationProvider(), true);

            using (var host = new ZyanComponentHost("RecreateClientConnectionTestHost_TcpSimplex", protocol))
            {
                host.RegisterComponent <ISampleServer, SampleServer>("SampleServer", ActivationType.SingleCall);
            }

            using (var host = new ZyanComponentHost("RecreateClientConnectionTestHost_TcpSimplex", protocol))
            {
                host.RegisterComponent <ISampleServer, SampleServer>("SampleServer", ActivationType.SingleCall);
            }
        }
Beispiel #35
0
        static void Main(string[] args)
        {
            using (var transport = new WcfServerTransportAdapter() { BaseAddress = "net.tcp://localhost:9091" })
            {
                var protocol = ServerProtocolSetup.WithChannel(x => transport);

                using (var host = new ZyanComponentHost("HelloWcf", protocol))
                {
                    host.RegisterComponent<IEchoService, EchoService>();
                    Console.WriteLine("Server läuft!");
                    Console.ReadLine();
                }
            }
        }
        public void CreateDisposeAndRecreateComponentHostForTcpDuplexChannel()
        {
            var protocol = new TcpDuplexServerProtocolSetup(8086, new NullAuthenticationProvider(), true);

            using (var host = new ZyanComponentHost("RecreateClientConnectionTestHost_TcpDuplex", protocol))
            {
                host.RegisterComponent<ISampleServer, SampleServer>("SampleServer", ActivationType.SingleCall);
            }

            using (var host = new ZyanComponentHost("RecreateClientConnectionTestHost_TcpDuplex", protocol))
            {
                host.RegisterComponent<ISampleServer, SampleServer>("SampleServer", ActivationType.SingleCall);
            }
        }
Beispiel #37
0
        private void RegisterComponent(int port, string name, RemoteMonitor instance)
        {
            TcpDuplexServerProtocolSetup protocol = new TcpDuplexServerProtocolSetup(port);

            _znHost = new ZyanComponentHost(name, protocol);
            //_znHost.EnableDiscovery();

            //_znHost.RegisterComponent<IMonitor, RemoteMonitor>(ActivationType.Singleton);
            _znHost.RegisterComponent <IMonitor, RemoteMonitor>(instance);

            _znHost.ClientLoggedOn  += ClientLoggedOn;
            _znHost.ClientLoggedOff += ClientLoggedOff;

            Builder.Output(string.Format(ClassName + ": registrado componente {0} en puerto {1}.", name, port), TraceEventType.Verbose);
        }
Beispiel #38
0
        static void Main(string[] args)
        {
            // create a new Zyan ComponentHost
            using (var host = new ZyanComponentHost("DynamicEbcResponses", 4567))
            {
                // register the service implementation by its interface
                host.RegisterComponent<IService>(
                                                    () => new Service(),
                                                    ActivationType.SingleCall
                                                );

                // print information and keep server process running
                Console.WriteLine("Stated Zyan Server on localhost:4567, press any key to stop.");
                Console.ReadKey();
            }
        }
Beispiel #39
0
        static void Main(string[] args)
        {
            // create a new Zyan ComponentHost
            using (var host = new ZyanComponentHost("DynamicEbcResponses", 4567))
            {
                // register the service implementation by its interface
                host.RegisterComponent <IService>(
                    () => new Service(),
                    ActivationType.SingleCall
                    );

                // print information and keep server process running
                Console.WriteLine("Stated Zyan Server on localhost:4567, press any key to stop.");
                Console.ReadKey();
            }
        }
Beispiel #40
0
        static void Main(string[] args)
        {
            using (var transport = new WcfServerTransportAdapter()
            {
                BaseAddress = "net.tcp://localhost:9091"
            })
            {
                var protocol = ServerProtocolSetup.WithChannel(x => transport);

                using (var host = new ZyanComponentHost("HelloWcf", protocol))
                {
                    host.RegisterComponent <IEchoService, EchoService>();
                    Console.WriteLine("Server läuft!");
                    Console.ReadLine();
                }
            }
        }
Beispiel #41
0
        public static void StartServer(TestContext ctx)
        {
            var serverSetup = new NullServerProtocolSetup(5432);

            ZyanHost = new ZyanComponentHost("SampleQueryableServer", serverSetup);

            ZyanHost.RegisterComponent <ISampleService, SampleService>();
            ZyanHost.RegisterComponent <IObjectSource, SampleObjectSource>(new SampleObjectSource(new[] { "Hello", "World!" }));
            ZyanHost.RegisterComponent <IObjectSource, SampleObjectSource>("Sample1", new SampleObjectSource(new[] { "this", "is", "an", "example" }));
            ZyanHost.RegisterComponent <IObjectSource, SampleObjectSource>("Sample6");
            ZyanHost.RegisterComponent <IObjectSource, SampleObjectSource>("Sample7", ActivationType.SingleCall);
            ZyanHost.RegisterComponent <IEntitySource, DataWrapper>("DbSample", DataWrapper = new DataWrapper());
            ZyanHost.RegisterComponent <ISampleMethodSource, SampleMethodSource>("Disposable", ActivationType.SingleCall);

            ZyanConnection = new ZyanConnection("null://NullChannel:5432/SampleQueryableServer");
        }
Beispiel #42
0
        public void ExternalComponentCatalog_IsNotDisposed()
        {
            var disposed = false;
            var server = new ReleasableComponent { Handler = () => disposed = true };
            Assert.IsFalse(disposed);

            var serverSetup = new IpcBinaryServerProtocolSetup("CleanupTest2");
            using (var catalog = new ComponentCatalog())
            using (var host = new ZyanComponentHost("SampleServer2", serverSetup, new InProcSessionManager(), catalog))
            {
                host.RegisterComponent<ISampleComponent, ReleasableComponent>(
                    server, s => ((ReleasableComponent)s).Release());

                Assert.IsFalse(disposed);
                server.Release();
                Assert.IsTrue(disposed);
            }
        }
Beispiel #43
0
        public void OwnedComponentCatalog_IsDisposed()
        {
            var disposed = false;
            var server   = new ReleasableComponent {
                Handler = () => disposed = true
            };

            Assert.IsFalse(disposed);

            var serverSetup = new IpcBinaryServerProtocolSetup("CleanupTest1");

            using (var host = new ZyanComponentHost("SampleServer1", serverSetup))
            {
                host.RegisterComponent <ISampleComponent, ReleasableComponent>(
                    server, s => ((ReleasableComponent)s).Release());
            }

            Assert.IsTrue(disposed);
        }
Beispiel #44
0
        static void Main(string[] args)
        {
            ActiveNicknames = new List<string>();

            TcpDuplexServerProtocolSetup protocol = new TcpDuplexServerProtocolSetup(Properties.Settings.Default.TcpPort, new NicknameAuthProvider(), true);

            using (ZyanComponentHost host = new ZyanComponentHost("MiniChat", protocol))
            {
                host.PollingEventTracingEnabled = true;
                host.ClientHeartbeatReceived += new EventHandler<ClientHeartbeatEventArgs>(host_ClientHeartbeatReceived);

                host.RegisterComponent<IMiniChat, MiniChat>(ActivationType.Singleton);

                host.ClientLoggedOn += new EventHandler<LoginEventArgs>((sender, e) =>
                {
                    Console.WriteLine(string.Format("{0}: User '{1}' with IP {2} logged on.", e.Timestamp.ToString(), e.Identity.Name, e.ClientAddress));
                    ActiveNicknames.Add(e.Identity.Name);
                });

                host.ClientLoggedOff += new EventHandler<LoginEventArgs>((sender, e) =>
                {
                    Console.WriteLine(string.Format("{0}: User '{1}' with IP {2} logged off.", e.Timestamp.ToString(), e.Identity.Name, e.ClientAddress));
                    ActiveNicknames.Remove(e.Identity.Name);
                });

                host.ClientSessionTerminated += new EventHandler<LoginEventArgs>((sender, e) =>
                {
                    Console.WriteLine(string.Format("{0}: User '{1}' with IP {2} was kicked due to inactivity.", e.Timestamp.ToString(), e.Identity.Name, e.ClientAddress));
                    ActiveNicknames.Remove(e.Identity.Name);
                });

                host.EnableDiscovery();
                Console.WriteLine("Chat server started. Press Enter to exit.");
                Console.ReadLine();
            }
        }
Beispiel #45
0
 private EventServer()
 {
     //TcpCustomServerProtocolSetup protocol = new TcpCustomServerProtocolSetup(8083, new NullAuthenticationProvider(), true);
     MsmqServerProtocolSetup protocol = new MsmqServerProtocolSetup(@"private$\reqchannel");
     _host = new ZyanComponentHost("EventTest", protocol);
     _host.RegisterComponent<IEventComponentSingleton, EventComponentSingleton>(ActivationType.Singleton);
     _host.RegisterComponent<IEventComponentSingleCall, EventComponentSingleCall>(ActivationType.SingleCall);
     _host.RegisterComponent<ICallbackComponentSingleton, CallbackComponentSingleton>(ActivationType.Singleton);
     _host.RegisterComponent<ICallbackComponentSingleCall, CallbackComponentSingleCall>(ActivationType.SingleCall);
     _host.RegisterComponent<IRequestResponseCallbackSingleCall, RequestResponseCallbackSingleCall>(ActivationType.SingleCall);
 }
Beispiel #46
0
        public void OwnedComponentCatalog_IsDisposed()
        {
            var disposed = false;
            var server = new ReleasableComponent { Handler = () => disposed = true };
            Assert.IsFalse(disposed);

            var serverSetup = new IpcBinaryServerProtocolSetup("CleanupTest1");
            using (var host = new ZyanComponentHost("SampleServer1", serverSetup))
            {
                host.RegisterComponent<ISampleComponent, ReleasableComponent>(
                    server, s => ((ReleasableComponent)s).Release());
            }

            Assert.IsTrue(disposed);
        }
        public void RefreshRegisteredComponentsTest()
        {
            using (var host = new ZyanComponentHost("RefreshTest", new NullServerProtocolSetup(123)))
            using (var conn = new ZyanConnection("null://NullChannel:123/RefreshTest"))
            {
                // this component is registered after connection is established
                var componentName = Guid.NewGuid().ToString();
                host.RegisterComponent<ISampleServer, SampleServer>(componentName);

                try
                {
                    // proxy cannot be created because connection doesn't know about the component
                    var proxy1 = conn.CreateProxy<ISampleServer>(componentName);
                    Assert.Fail("Component is not yet known for ZyanConnection.");
                }
                catch (ApplicationException)
                {
                }

                // refresh the list of registered components and create a proxy
                conn.RefreshRegisteredComponents();
                var proxy2 = conn.CreateProxy<ISampleServer>(componentName);

                var echoString = "Hello there";
                var result = proxy2.Echo(echoString);
                Assert.AreEqual(echoString, result);
            }
        }
Beispiel #48
0
        public static void StartServer(TestContext ctx)
        {
            ZyanComponentHost.LegacyBlockingEvents = true;

            var serverSetup = new NullServerProtocolSetup(2345);
            ZyanHost = new ZyanComponentHost("EventsServer", serverSetup);
            ZyanHost.RegisterComponent<ISampleServer, SampleServer>("Singleton", ActivationType.Singleton);
            ZyanHost.RegisterComponent<ISampleServer, SampleServer>("SingleCall", ActivationType.SingleCall);

            ZyanConnection = new ZyanConnection("null://NullChannel:2345/EventsServer");
        }
 private TcpSimplexServerHostEnvironment()
 {
     var protocol = new TcpCustomServerProtocolSetup(8085, new NullAuthenticationProvider(), true);
     _host = new ZyanComponentHost("RecreateClientConnectionTestHost_TcpSimplex", protocol);
     _host.RegisterComponent<ISampleServer, SampleServer>("SampleServer", ActivationType.SingleCall);
 }
Beispiel #50
0
        public void TestGenericWrapperOverZyan()
        {
            var serverProto = new IpcBinaryServerProtocolSetup("Test");
            var clientProto = new IpcBinaryClientProtocolSetup();

            var host = new ZyanComponentHost("TestServer", serverProto);
            host.RegisterComponent<INonGenericInterface>(() => new NonGenericWrapper(new GenericClass()), ActivationType.Singleton);

            var conn = new ZyanConnection("ipc://Test/TestServer");
            var proxy = conn.CreateProxy<INonGenericInterface>();

            // same as usual
            var test = new GenericWrapper(proxy);
            var prioritySet = false;

            // GetDefault
            Assert.AreEqual(default(int), test.GetDefault<int>());
            Assert.AreEqual(default(string), test.GetDefault<string>());
            Assert.AreEqual(default(Guid), test.GetDefault<Guid>());

            // Equals
            Assert.IsTrue(test.Equals(123, 123));
            Assert.IsFalse(test.Equals("Some", null));

            // GetVersion
            Assert.AreEqual("DoSomething wasn't called yet", test.GetVersion());

            // DoSomething
            test.DoSomething(123, 'x', "y");
            Assert.AreEqual("DoSomething: A = 123, B = x, C = y", test.GetVersion());

            // Compute
            var dt = test.Compute<Guid, DateTime>(Guid.Empty, 123, "123");
            Assert.AreEqual(default(DateTime), dt);

            // CreateGuid
            var guid = test.CreateGuid(dt, 12345);
            Assert.AreEqual("00003039-0001-0001-0000-000000000000", guid.ToString());

            // LastDate
            Assert.AreEqual(dt, test.LastDate);
            test.LastDate = dt = DateTime.Now;
            Assert.AreEqual(dt, test.LastDate);

            // Name
            Assert.AreEqual("GenericClass, priority = 123", test.Name);

            // add OnPrioritySet
            EventHandler<EventArgs> handler = (s, a) => prioritySet = true;
            test.OnPrioritySet += handler;
            Assert.IsFalse(prioritySet);

            // Priority
            test.Priority = 321;
            Assert.IsTrue(prioritySet);
            Assert.AreEqual("GenericClass, priority = 321", test.Name);

            // remove OnPrioritySet
            prioritySet = false;
            test.OnPrioritySet -= handler;
            test.Priority = 111;
            Assert.IsFalse(prioritySet);
        }