Beispiel #1
1
        static void Main(string[] args)
        {
            var host = new ZyanComponentHost("ZyanDemo", 12800);
            host.RegisterComponent<IHellow, HellowServer>();

            Console.ReadLine();
        }
Beispiel #2
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 #3
1
 public static void StartServer(TestContext ctx)
 {
     ZyanHost = new ZyanComponentHost("HeartbeatServer", new NullServerProtocolSetup(5678)
     {
         AuthenticationProvider = new JohnGaltAuthenticationProvider()
     });
 }
Beispiel #4
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 #5
1
        /// <summary>
        /// Creates a new instance of the ZyanDispatcher class.
        /// </summary>
        /// <param name="host">Component host</param>
        public ZyanDispatcher(ZyanComponentHost host)
        {
            if (host == null)
                throw new ArgumentNullException("host");

            _host = host;
        }
Beispiel #6
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))
                    {
                    }
                });
            }
        }
Beispiel #7
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);
                }
            }
        }
Beispiel #8
0
        public void Dispose()
        {
            if (_ipcBinaryHost != null)
            {
                _ipcBinaryHost.Dispose();
                _ipcBinaryHost = null;
            }

            if (_tcpBinaryHost != null)
            {
                _tcpBinaryHost.Dispose();
                _tcpBinaryHost = null;
            }

            if (_tcpCustomHost != null)
            {
                _tcpCustomHost.Dispose();
                _tcpCustomHost = null;
            }

            if (_tcpDuplexHost != null)
            {
                _tcpDuplexHost.Dispose();
                _tcpDuplexHost = null;
            }

            if (_httpCustomHost != null)
            {
                _httpCustomHost.Dispose();
                _httpCustomHost = null;
            }
        }
Beispiel #9
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 #10
0
 public static void StartServer(TestContext ctx)
 {
     ZyanHost = new ZyanComponentHost("HeartbeatServer", new NullServerProtocolSetup(5678)
     {
         AuthenticationProvider = new JohnGaltAuthenticationProvider()
     });
 }
        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");
            }
        }
        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);
                }
        }
            private TcpSimplexServerHostEnvironment()
            {
                var protocol = new TcpCustomServerProtocolSetup(8085, new NullAuthenticationProvider(), true);

                _host = new ZyanComponentHost("RecreateClientConnectionTestHost_TcpSimplex", protocol);
                _host.RegisterComponent <ISampleServer, SampleServer>("SampleServer", ActivationType.SingleCall);
            }
            private TcpDuplexServerHostEnvironment()
            {
                var protocol = new TcpDuplexServerProtocolSetup(8092, new NullAuthenticationProvider(), true);

                _host = new ZyanComponentHost("TcpExConnectionLockRegressionTestHost_TcpDuplex", protocol);
                _host.RegisterComponent <ISampleServer, SampleServer>("SampleServer", ActivationType.SingleCall);
            }
            private TcpDuplexServerHostEnvironment()
            {
                var protocol = new TcpDuplexServerProtocolSetup(8088, new CustomAuthenticationProvider(), true);

                _host = new ZyanComponentHost("CustomAuthenticationTestHost_TcpDuplex", protocol);
                _host.RegisterComponent <ISampleServer, SampleServer>("SampleServer", ActivationType.SingleCall);
            }
Beispiel #16
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 #17
0
 public static void StopServer()
 {
     if (ZyanHost != null)
     {
         ZyanHost.Dispose();
         ZyanHost = null;
     }
 }
Beispiel #18
0
 public void Dispose()
 {
     if (_host != null)
     {
         _host.Dispose();
         _host = null;
     }
 }
 private void Dispose(bool disposing)
 {
     if (disposing && host != null)
     {
         host.Dispose();
         host = null;
     }
 }
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
 private void Dispose(bool disposing)
 {
     if (disposing && host != null)
     {
         host.Dispose();
         host = null;
     }
 }
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
        private EventServer()
        {
            _catalog = new ComponentCatalog();
            _catalog.RegisterComponent <IEventComponentSingleton, EventComponentSingleton>(ActivationType.Singleton);
            _catalog.RegisterComponent <IEventComponentSingleCall, EventComponentSingleCall>(ActivationType.SingleCall);
            _catalog.RegisterComponent <ICallbackComponentSingleton, CallbackComponentSingleton>(ActivationType.Singleton);
            _catalog.RegisterComponent <ICallbackComponentSingleCall, CallbackComponentSingleCall>(ActivationType.SingleCall);
            _catalog.RegisterComponent <IRequestResponseCallbackSingleCall, RequestResponseCallbackSingleCall>(ActivationType.SingleCall);
            _catalog.RegisterComponent <ITimerTriggeredEvent, TimerTriggeredEvent>(ActivationType.Singleton);

            // Setting compression threshold to 1 byte means that all messages will be compressed.
            // This setting should not be used in production code because smaller packets will grow in size.
            // By default, Zyan only compresses messages larger than 64 kilobytes.
            var tcpBinaryProtocol = new TcpBinaryServerProtocolSetup(8082);

            tcpBinaryProtocol.AddServerSinkBeforeFormatter(new CompressionServerChannelSinkProvider(1, CompressionMethod.LZF));
            _tcpBinaryHost = new ZyanComponentHost("TcpBinaryEventTest", tcpBinaryProtocol, _catalog);

            var ipcBinaryProtocol = new IpcBinaryServerProtocolSetup("IpcTestServer");

            ipcBinaryProtocol.AddServerSinkBeforeFormatter(new CompressionServerChannelSinkProvider(1, CompressionMethod.DeflateStream));
            _ipcBinaryHost = new ZyanComponentHost("IpcBinaryEventTest", ipcBinaryProtocol, _catalog);

            var tcpCustomProtocol = new TcpCustomServerProtocolSetup(8083, new NullAuthenticationProvider(), true)
            {
                CompressionThreshold = 1,
                CompressionMethod    = CompressionMethod.DeflateStream
            };

            _tcpCustomHost = new ZyanComponentHost("TcpCustomEventTest", tcpCustomProtocol, _catalog);

            var tcpDuplexProtocol = new TcpDuplexServerProtocolSetup(8084, new NullAuthenticationProvider(), true)
            {
                CompressionThreshold = 1,
                CompressionMethod    = CompressionMethod.DeflateStream
            };

            tcpDuplexProtocol.AddChannelSetting("bindTo", "127.0.0.1");

            _tcpDuplexHost = new ZyanComponentHost("TcpDuplexEventTest", tcpDuplexProtocol, _catalog);

            var httpCustomProtocol = new HttpCustomServerProtocolSetup(8085, new NullAuthenticationProvider(), true)
            {
                CompressionThreshold = 1,
                CompressionMethod    = CompressionMethod.LZF
            };

            _httpCustomHost = new ZyanComponentHost("HttpCustomEventTest", httpCustomProtocol, _catalog);

            var nullChannelProtocol = new NullServerProtocolSetup(1234);

            _nullChannelHost = new ZyanComponentHost("NullEventTest", nullChannelProtocol, _catalog);

            // use legacy blocking events mode because we check the handlers synchronously
            ZyanSettings.LegacyBlockingEvents        = true;
            ZyanSettings.LegacyBlockingSubscriptions = true;
        }
Beispiel #24
0
        /// <summary>
        /// Konstruktor.
        /// </summary>
        /// <param name="host">Komponentenhost</param>
        public ZyanDispatcher(ZyanComponentHost host)
        {
            // Wenn kein Komponentenhost übergeben wurde ...
            if (host == null)
                // Ausnahme werfen
                throw new ArgumentNullException("host");

            // Host übernehmen
            _host = host;
        }
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
            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 #27
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();
            }
        }
        public static void StartServer(TestContext ctx)
        {
            ZyanComponentHost.LegacyBlockingEvents = true;

            var serverSetup = new NullServerProtocolSetup(4567);

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

            ZyanConnection = new ZyanConnection("null://NullChannel:4567/EventFilterServer");
        }
Beispiel #29
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);
        }
        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 #31
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 #32
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 #33
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 #34
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();
            }
        }
Beispiel #35
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);
        }
        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 #37
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 #38
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 #40
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 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);
            }
        }
        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 #43
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 #44
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 #45
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", new DataWrapper());

            ZyanConnection = new ZyanConnection("null://NullChannel:5432/SampleQueryableServer");
        }
Beispiel #46
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);
        }
Beispiel #47
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 #48
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 #49
0
        public override void Publish()
        {
            // Create the QueryHandler
            IQueryHandler queryHandler = new ZyanObjectQueryHandler(ObjectSource);

            #region Start the WCF server
            #if !MONO
            var wcfServer = new ServerQueryWcfHandler(queryHandler);
            var binding = ServiceHelper.GetDefaultBinding();

            string serviceUri = ServiceHelper.GetServiceUri(null, null, Artefacts.ServiceConstants.ObjectsServiceName);
            wcfServer.Start(binding, serviceUri);
            #endif
            #endregion

            #region Start the Zyan server

            // change service name to avoid conflict with Remoting service
            var serviceName = Artefacts.ServiceConstants.ZyanServicePrefix + Artefacts.ServiceConstants.ObjectsServiceName;
            var protocol = ZyanConstants.GetDefaultServerProtocol(ZyanConstants.DefaultServicePort);
            var host = new ZyanComponentHost(serviceName, protocol);
            host.RegisterQueryHandler(queryHandler);

            #endregion

            #region Start the remoting server

            var remotingServer = new ServerQueryRemotingHandlerObjects(queryHandler);
            // Register default channel for remote access
            Hashtable properties = new Hashtable();
            properties["name"] = Artefacts.ServiceConstants.ObjectsServiceName;
            properties["port"] = Artefacts.ServiceConstants.ObjectsPort;
            IChannel currentChannel = RemotingConstants.GetDefaultChannel(properties);
            ChannelServices.RegisterChannel(currentChannel, false);
            remotingServer.Start(Artefacts.ServiceConstants.ObjectsServiceName, false);

            #endregion
        }
Beispiel #50
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 #51
0
 public void Dispose()
 {
     if (_host != null)
     {
         _host.Dispose();
         _host = null;
     }
 }
Beispiel #52
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 #53
0
        private EventServer()
        {
            _catalog = new ComponentCatalog();
            _catalog.RegisterComponent<IEventComponentSingleton, EventComponentSingleton>(ActivationType.Singleton);
            _catalog.RegisterComponent<IEventComponentSingleCall, EventComponentSingleCall>(ActivationType.SingleCall);
            _catalog.RegisterComponent<ICallbackComponentSingleton, CallbackComponentSingleton>(ActivationType.Singleton);
            _catalog.RegisterComponent<ICallbackComponentSingleCall, CallbackComponentSingleCall>(ActivationType.SingleCall);
            _catalog.RegisterComponent<IRequestResponseCallbackSingleCall, RequestResponseCallbackSingleCall>(ActivationType.SingleCall);
            _catalog.RegisterComponent<ITimerTriggeredEvent, TimerTriggeredEvent>(ActivationType.Singleton);

            // Setting compression threshold to 1 byte means that all messages will be compressed.
            // This setting should not be used in production code because smaller packets will grow in size.
            // By default, Zyan only compresses messages larger than 64 kilobytes.
            var tcpBinaryProtocol = new TcpBinaryServerProtocolSetup(8082);
            tcpBinaryProtocol.AddServerSinkBeforeFormatter(new CompressionServerChannelSinkProvider(1, CompressionMethod.LZF));
            _tcpBinaryHost = new ZyanComponentHost("TcpBinaryEventTest", tcpBinaryProtocol, _catalog);

            var ipcBinaryProtocol = new IpcBinaryServerProtocolSetup("IpcTestServer");
            ipcBinaryProtocol.AddServerSinkBeforeFormatter(new CompressionServerChannelSinkProvider(1, CompressionMethod.DeflateStream));
            _ipcBinaryHost = new ZyanComponentHost("IpcBinaryEventTest", ipcBinaryProtocol, _catalog);

            var tcpCustomProtocol = new TcpCustomServerProtocolSetup(8083, new NullAuthenticationProvider(), true)
            {
             				CompressionThreshold = 1,
                CompressionMethod = CompressionMethod.DeflateStream
            };
            _tcpCustomHost = new ZyanComponentHost("TcpCustomEventTest", tcpCustomProtocol, _catalog);

            var tcpDuplexProtocol = new TcpDuplexServerProtocolSetup(8084, new NullAuthenticationProvider(), true)
            {
                CompressionThreshold = 1,
                CompressionMethod = CompressionMethod.DeflateStream
            };
            tcpDuplexProtocol.AddChannelSetting("bindTo", "127.0.0.1");

            _tcpDuplexHost = new ZyanComponentHost("TcpDuplexEventTest", tcpDuplexProtocol, _catalog);

            var httpCustomProtocol = new HttpCustomServerProtocolSetup(8085, new NullAuthenticationProvider(), true)
            {
                CompressionThreshold = 1,
                CompressionMethod = CompressionMethod.LZF
            };
            _httpCustomHost = new ZyanComponentHost("HttpCustomEventTest", httpCustomProtocol, _catalog);

            var nullChannelProtocol = new NullServerProtocolSetup(1234);
            _nullChannelHost = new ZyanComponentHost("NullEventTest", nullChannelProtocol, _catalog);

            // use legacy blocking events mode because we check the handlers synchronously
            ZyanComponentHost.LegacyBlockingEvents = true;
        }
 internal ZyanMessageServer(IMessageReceiver messageReceiver, int port)
 {
     receiver = (MessageReceiver)messageReceiver;
     host = new ZyanComponentHost("OrderService", port);
 }
Beispiel #55
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 #56
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 #57
0
        public void Dispose()
        {
            if (_ipcBinaryHost != null)
            {
                _ipcBinaryHost.Dispose();
                _ipcBinaryHost = null;
            }

            if (_tcpBinaryHost != null)
            {
                _tcpBinaryHost.Dispose();
                _tcpBinaryHost = null;
            }

            if (_tcpCustomHost != null)
            {
                _tcpCustomHost.Dispose();
                _tcpCustomHost = null;
            }

            if (_tcpDuplexHost != null)
            {
                _tcpDuplexHost.Dispose();
                _tcpDuplexHost = null;
            }

            if (_httpCustomHost != null)
            {
                _httpCustomHost.Dispose();
                _httpCustomHost = null;
            }
        }
Beispiel #58
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);
        }
 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);
            }
        }