public void buildTest1()
        {
            ComponentId      componetId = new ComponentId("Test1", 1, 0, 0, ".Net FrameWork 3.5");
            ComponentContext expected   = new DefaultComponentContext(componetId);

            String             name          = "IComponent_1";
            String             interfaceName = "IDL:scs/core/IComponent:1.0";
            MarshalByRefObject servant       = new IComponentServant(expected);

            expected.AddFacet(name, interfaceName, servant);
            name          = "IComponent_2";
            interfaceName = "IDL:scs/core/IComponent:1.0";
            servant       = new IComponentServant(expected);
            expected.AddFacet(name, interfaceName, servant);
            name          = "IMetaInterface_3";
            interfaceName = "IDL:scs/core/IMetaInterface:1.0";
            servant       = new IMetaInterfaceServant(expected);
            expected.AddFacet(name, interfaceName, servant);

            String              componentModel       = Resources.Component1;
            TextReader          file                 = new StringReader(componentModel);
            XmlTextReader       componentInformation = new XmlTextReader(file);
            XmlComponentBuilder target               = new XmlComponentBuilder(componentInformation);
            ComponentContext    actual               = target.build();

            Assert.IsTrue(expected.Equals(actual));
        }
Пример #2
0
        public void DefaultComponentContextConstructorTest()
        {
            ComponentId             componentId = new ComponentId("Component1", 1, 0, 0, "none");
            DefaultComponentContext expected    = new DefaultComponentContext(componentId);

            Assert.IsNotNull(expected);
        }
        private static void Main(String[] args)
        {
            // Registra handler para o caso do processo ser finalizado
            AppDomain.CurrentDomain.ProcessExit += CurrentDomainProcessExit;

            // Obtém dados através dos argumentos
            string host = args[0];
            ushort port = Convert.ToUInt16(args[1]);

            _entity     = args[2];
            _privateKey = Crypto.ReadKeyFile(args[3]);
            _interval   = Convert.ToInt32(args.Length > 4 ? args[4] : "1");

            // Cria o componente que conterá as facetas do servidor
            ORBInitializer.InitORB();
            ComponentContext component =
                new DefaultComponentContext(new ComponentId("dedicatedclock", 1, 0, 0, ".net"));

            // Cria a faceta Clock para o componente
            component.AddFacet("Clock", Repository.GetRepositoryID(typeof(Clock)),
                               new ClockImpl());

            // Define propriedades para a oferta de serviço a ser registrada no barramento
            IComponent ic = component.GetIComponent();

            ServiceProperty[] properties =
            {
                new ServiceProperty("offer.domain",
                                    "Demo Dedicated Clock")
            };

            // Cria conexão e a define como conexão padrão tanto para entrada como saída.
            OpenBusContext context = ORBInitializer.Context;

            _conn = context.ConnectByAddress(host, port);
            context.SetDefaultConnection(_conn);

            // Cria registrador e adiciona a callback de login inválido
            _registerer          = new Registerer(ic, properties, _interval);
            _conn.OnInvalidLogin = InvalidLogin;

            // Faz o login e registra no barramento
            try {
                _conn.OnInvalidLogin(_conn, new LoginInfo());
            }
            catch (Exception e) {
                Console.WriteLine(e);
            }
            finally {
                if (!_conn.Login.HasValue || Offer == null)
                {
                    Exit(1);
                }
            }

            // Mantém a thread ativa para aguardar requisições
            Console.WriteLine(Resources.ServerOK);
            Thread.Sleep(Timeout.Infinite);
        }
Пример #4
0
        public void FacetConstructorTest5()
        {
            ComponentId      componentId = new ComponentId("Component1", 1, 0, 0, "none");
            ComponentContext context     = new DefaultComponentContext(componentId);

            string             interfaceName = typeof(IMetaInterface).Name;
            MarshalByRefObject servant       = new IComponentServant(context);
            Facet target = new Facet(facetName, interfaceName, servant);
        }
Пример #5
0
        public void getComponentIdTest()
        {
            ComponentId       expected = new ComponentId("Name", 10, 10, 10, "none");
            ComponentContext  context  = new DefaultComponentContext(expected);
            IComponentServant target   = new IComponentServant(context);
            ComponentId       actual   = target.getComponentId();

            Assert.AreEqual(expected.name, actual.name);
        }
Пример #6
0
        public static void BeforeClass(TestContext testContext)
        {
            facetName     = "Faceta";
            interfaceName = Repository.GetRepositoryID(typeof(IMetaInterface));

            ComponentId      componentId = new ComponentId("Component1", 1, 0, 0, "none");
            ComponentContext context     = new DefaultComponentContext(componentId);

            servant = new IMetaInterfaceServant(context);
        }
        public void buildTest5()
        {
            ComponentId      componetId = new ComponentId("Test1", 1, 0, 0, ".Net FrameWork 3.5");
            ComponentContext expected   = new DefaultComponentContext(componetId);

            String              componentModel       = Resources.Component8;
            TextReader          file                 = new StringReader(componentModel);
            XmlTextReader       componentInformation = new XmlTextReader(file);
            XmlComponentBuilder builder              = new XmlComponentBuilder(componentInformation);
            ComponentContext    target               = builder.build();
        }
        public void buildTest3()
        {
            ComponentId      componetId = new ComponentId("Test1", 1, 0, 0, ".Net FrameWork 3.5");
            ComponentContext expected   = new DefaultComponentContext(componetId);

            String              componentModel       = Resources.Component6;
            TextReader          file                 = new StringReader(componentModel);
            XmlTextReader       componentInformation = new XmlTextReader(file);
            XmlComponentBuilder builder              = new XmlComponentBuilder(componentInformation);
            ComponentContext    actual               = builder.build();

            Assert.IsTrue(expected.Equals(actual));
        }
Пример #9
0
        public void GetComponentIdTest()
        {
            string                  name     = "componetName";
            byte                    major    = 10;
            byte                    minor    = 20;
            byte                    patch    = 30;
            string                  spec     = "none";
            ComponentId             expected = new ComponentId(name, major, minor, patch, spec);
            DefaultComponentContext target   = new DefaultComponentContext(expected);
            ComponentId             actual   = target.GetComponentId();

            Assert.AreEqual(expected, actual);
        }
        public void buildTest4()
        {
            ComponentId      componetId = new ComponentId("Test1", 1, 0, 0, ".Net FrameWork 3.5");
            ComponentContext expected   = new DefaultComponentContext(componetId);

            String              componentModel       = Resources.Component7;
            TextReader          file                 = new StringReader(componentModel);
            XmlTextReader       componentInformation = new XmlTextReader(file);
            XmlComponentBuilder builder              = new XmlComponentBuilder(componentInformation);
            ComponentContext    target               = builder.build();

            Assert.IsInstanceOfType(target, typeof(MockComponentContext));
        }
Пример #11
0
        public static void BeforeClass(TestContext testContext)
        {
            name          = "Faceta";
            interfaceName = Repository.GetRepositoryID(typeof(IComponent));
            isMultiple    = false;

            ComponentId      componentId = new ComponentId("Component1", 1, 0, 0, "none");
            ComponentContext context     = new DefaultComponentContext(componentId);

            connections = new List <MarshalByRefObject>();

            for (int i = 0; i < 5; i++)
            {
                MarshalByRefObject connection = new IComponentServant(context);
                connections.Add(connection);
            }
        }
        public void buildTest2()
        {
            ComponentId      componetId = new ComponentId("Test1", 1, 0, 0, ".Net FrameWork 3.5");
            ComponentContext expected   = new DefaultComponentContext(componetId);

            String name          = "Receptacle1";
            String interfaceName = "IDL:scs/core/IMetaInterface:1.0";

            expected.AddReceptacle(name, interfaceName, false);
            name          = "Receptacle2";
            interfaceName = "IDL:scs/core/IMetaInterface:1.0";
            expected.AddReceptacle(name, interfaceName, true);
            name          = "Receptacle3";
            interfaceName = "IDL:scs/core/IComponent:1.0";
            expected.AddReceptacle(name, interfaceName, false);

            String              componentModel       = Resources.Component5;
            TextReader          file                 = new StringReader(componentModel);
            XmlTextReader       componentInformation = new XmlTextReader(file);
            XmlComponentBuilder target               = new XmlComponentBuilder(componentInformation);
            ComponentContext    actual               = target.build();

            Assert.IsTrue(expected.Equals(actual));
        }
Пример #13
0
        private static void Main(String[] args)
        {
            // Registra handler para o caso do processo ser finalizado
            AppDomain.CurrentDomain.ProcessExit += CurrentDomainProcessExit;

            // Obtém dados através dos argumentos
            string host   = args[0];
            ushort port   = Convert.ToUInt16(args[1]);
            string entity = args[2];
            AsymmetricCipherKeyPair privateKey = Crypto.ReadKeyFile(args[3]);

            // Associa uma callback de escolha de conexão de despacho
            ORBInitializer.InitORB();
            OpenBusContext context = ORBInitializer.Context;

            context.OnCallDispatch = Dispatch;

            // Cria 3 conexões com o mesmo barramento, uma para cada componente.
            for (int i = 0; i < 3; i++)
            {
                ComponentContext component =
                    new DefaultComponentContext(new ComponentId("Timer", 1, 0, 0, ".net"));

                // Cria a faceta Timer para o componente
                TimerImpl timer = new TimerImpl();
                component.AddFacet("Timer", Repository.GetRepositoryID(typeof(Timer)),
                                   timer);

                // Define propriedades para a oferta de serviço a ser registrada no barramento
                IComponent        ic         = component.GetIComponent();
                ServiceProperty[] properties =
                {
                    new ServiceProperty(
                        "offer.domain",
                        "Demo Multiplexing")
                };

                // Cria a conexão e a define como conexão corrente
                Connection conn = context.ConnectByAddress(host, port);
                context.SetCurrentConnection(conn);

                // Associa a conexão à URI do servant para que a callback possa escolher
                lock (Connections){
                    Connections.Add(RemotingServices.GetObjectUri(timer), conn);
                }

                bool failed = true;
                try {
                    // Faz o login
                    conn.LoginByCertificate(entity, privateKey);
                    // Registra a oferta no barramento
                    Offers.Add(conn, context.OfferRegistry.registerService(ic, properties));
                    failed = false;
                }
                // Login
                catch (AccessDenied) {
                    Console.WriteLine(Resources.ServerAccessDenied);
                }
                catch (MissingCertificate) {
                    Console.WriteLine(Resources.MissingCertificateForEntity + entity);
                }
                // Registro
                catch (UnauthorizedFacets) {
                    Console.WriteLine(Resources.UnauthorizedFacets);
                }
                // Barramento
                catch (ServiceFailure e) {
                    Console.WriteLine(Resources.BusServiceFailureErrorMsg);
                    Console.WriteLine(e);
                }
                catch (TRANSIENT) {
                    Console.WriteLine(Resources.BusTransientErrorMsg);
                }
                catch (COMM_FAILURE) {
                    Console.WriteLine(Resources.BusCommFailureErrorMsg);
                }
                catch (Exception e) {
                    NO_PERMISSION npe = null;
                    if (e is TargetInvocationException)
                    {
                        // caso seja uma exceção lançada pelo SDK, será uma NO_PERMISSION
                        npe = e.InnerException as NO_PERMISSION;
                    }
                    if ((npe == null) && (!(e is NO_PERMISSION)))
                    {
                        // caso não seja uma NO_PERMISSION não é uma exceção esperada então deixamos passar.
                        throw;
                    }
                    npe = npe ?? (NO_PERMISSION)e;
                    if (npe.Minor == NoLoginCode.ConstVal)
                    {
                        Console.WriteLine(Resources.NoLoginCodeErrorMsg);
                    }
                    else
                    {
                        throw;
                    }
                }
                finally {
                    if (failed)
                    {
                        Exit(1);
                    }
                }
            }

            // Mantém a thread ativa para aguardar requisições
            Console.WriteLine(Resources.ServerOK);
            Thread.Sleep(Timeout.Infinite);
        }
Пример #14
0
        private static void Main(String[] args)
        {
            // Registra handler para o caso do processo ser finalizado
            AppDomain.CurrentDomain.ProcessExit += CurrentDomainProcessExit;

            // Obtém dados através dos argumentos
            string host   = args[0];
            ushort port   = Convert.ToUInt16(args[1]);
            string entity = args[2];
            AsymmetricCipherKeyPair privateKey = Crypto.ReadKeyFile(args[3]);

            // Cria o componente que conterá as facetas do servidor
            ORBInitializer.InitORB();
            ComponentContext component =
                new DefaultComponentContext(new ComponentId("messenger", 1, 0, 0, ".net"));

            // Cria a faceta Messenger para o componente
            component.AddFacet("Messenger",
                               Repository.GetRepositoryID(typeof(Messenger)),
                               new MessengerImpl(entity));

            // Define propriedades para a oferta de serviço a ser registrada no barramento
            IComponent ic = component.GetIComponent();

            ServiceProperty[] properties =
            {
                new ServiceProperty("offer.domain",
                                    "Demo CallChain"),
                new ServiceProperty("offer.role",
                                    "mensageiro real")
            };

            // Cria conexão e a define como conexão padrão tanto para entrada como saída.
            // O uso exclusivo da conexão padrão (sem uso de current e callback de despacho) só é recomendado para aplicações que criem apenas uma conexão e desejem utilizá-la em todos os casos. Para situações diferentes, consulte o manual do SDK OpenBus e/ou outras demos.
            OpenBusContext context = ORBInitializer.Context;

            _conn = context.ConnectByAddress(host, port);
            context.SetDefaultConnection(_conn);

            bool failed = true;

            try {
                // Faz o login
                _conn.LoginByCertificate(entity, privateKey);
                // Registra a oferta no barramento
                _offer = context.OfferRegistry.registerService(ic, properties);
                failed = false;
            }
            // Login
            catch (AccessDenied) {
                Console.WriteLine(Resources.ServerAccessDenied);
            }
            catch (MissingCertificate) {
                Console.WriteLine(Resources.MissingCertificateForEntity + entity);
            }
            // Registro
            catch (UnauthorizedFacets) {
                Console.WriteLine(Resources.UnauthorizedFacets);
            }
            // Barramento
            catch (ServiceFailure e) {
                Console.WriteLine(Resources.BusServiceFailureErrorMsg);
                Console.WriteLine(e);
            }
            catch (TRANSIENT) {
                Console.WriteLine(Resources.BusTransientErrorMsg);
            }
            catch (COMM_FAILURE) {
                Console.WriteLine(Resources.BusCommFailureErrorMsg);
            }
            catch (Exception e) {
                NO_PERMISSION npe = null;
                if (e is TargetInvocationException)
                {
                    // caso seja uma exceção lançada pelo SDK, será uma NO_PERMISSION
                    npe = e.InnerException as NO_PERMISSION;
                }
                if ((npe == null) && (!(e is NO_PERMISSION)))
                {
                    // caso não seja uma NO_PERMISSION não é uma exceção esperada então deixamos passar.
                    throw;
                }
                npe = npe ?? (NO_PERMISSION)e;
                if (npe.Minor == NoLoginCode.ConstVal)
                {
                    Console.WriteLine(Resources.NoLoginCodeErrorMsg);
                }
                else
                {
                    throw;
                }
            }
            finally {
                if (failed)
                {
                    Exit(1);
                }
            }

            // Mantém a thread ativa para aguardar requisições
            Console.WriteLine(Resources.ServerOK);
            Thread.Sleep(Timeout.Infinite);
        }
        private static void Main()
        {
            //TextWriterTraceListener writer = new TextWriterTraceListener(Console.Out);
            //Debug.Listeners.Add(writer);
            //Trace.Listeners.Add(writer);

            AppDomain.CurrentDomain.ProcessExit += CurrentDomainProcessExit;
            string hostName = DemoConfig.Default.busHostName;
            ushort hostPort = DemoConfig.Default.busHostPort;

            _privateKey = Crypto.ReadKeyFile(DemoConfig.Default.privateKey);
            bool   useSSL           = DemoConfig.Default.useSSL;
            string clientUser       = DemoConfig.Default.clientUser;
            string clientThumbprint = DemoConfig.Default.clientThumbprint;
            string serverUser       = DemoConfig.Default.serverUser;
            string serverThumbprint = DemoConfig.Default.serverThumbprint;
            ushort serverSSLPort    = DemoConfig.Default.serverSSLPort;
            ushort serverOpenPort   = DemoConfig.Default.serverOpenPort;
            string busIORFile       = DemoConfig.Default.busIORFile;

            if (useSSL)
            {
                Utils.InitSSLORB(clientUser, clientThumbprint, serverUser, serverThumbprint, serverSSLPort, serverOpenPort, true, true, "required", false, false);
            }
            else
            {
                ORBInitializer.InitORB();
            }

/*
 *    ConsoleAppender appender = new ConsoleAppender {
 *      Threshold = Level.Off,
 *      Layout =
 *        new SimpleLayout(),
 *    };
 *    BasicConfigurator.Configure(appender);
 */
            //FileInfo logFileInfo = new FileInfo(DemoConfig.Default.openbusLogFile);
            //XmlConfigurator.ConfigureAndWatch(logFileInfo);

            ConnectionProperties props = new ConnectionPropertiesImpl();

            props.AccessKey = _privateKey;
            OpenBusContext context = ORBInitializer.Context;

            if (useSSL)
            {
                string ior = File.ReadAllText(busIORFile);
                _conn = context.ConnectByReference((MarshalByRefObject)OrbServices.CreateProxy(typeof(MarshalByRefObject), ior), props);
            }
            else
            {
                _conn = context.ConnectByAddress(hostName, hostPort, props);
            }
            context.SetDefaultConnection(_conn);

            ComponentContext component =
                new DefaultComponentContext(new ComponentId("hello", 1, 0, 0, ".net"));

            component.AddFacet("Hello", Repository.GetRepositoryID(typeof(Hello)),
                               new HelloImpl());

            _conn.LoginByCertificate(Entity, _privateKey);

            _ic         = component.GetIComponent();
            _properties = new[] {
                new ServiceProperty("offer.domain",
                                    "Interoperability Tests")
            };
            _offer = context.OfferRegistry.registerService(_ic, _properties);
            _conn.OnInvalidLogin = InvalidLogin;

            Logger.Fatal("Servidor no ar.");
            Thread.Sleep(Timeout.Infinite);
        }
Пример #16
0
        private static void Main()
        {
            AppDomain.CurrentDomain.ProcessExit += CurrentDomainProcessExit;
            string hostName = DemoConfig.Default.busHostName;
            ushort hostPort = DemoConfig.Default.busHostPort;

            _privateKey = Crypto.ReadKeyFile(DemoConfig.Default.privateKey);
            bool   useSSL           = DemoConfig.Default.useSSL;
            string clientUser       = DemoConfig.Default.clientUser;
            string clientThumbprint = DemoConfig.Default.clientThumbprint;
            string serverUser       = DemoConfig.Default.serverUser;
            string serverThumbprint = DemoConfig.Default.serverThumbprint;
            ushort serverSSLPort    = DemoConfig.Default.serverSSLPort;
            ushort serverOpenPort   = DemoConfig.Default.serverOpenPort;
            string busIORFile       = DemoConfig.Default.busIORFile;

            if (useSSL)
            {
                Utils.InitSSLORB(clientUser, clientThumbprint, serverUser, serverThumbprint, serverSSLPort, serverOpenPort, true, true, "required", false, false);
            }
            else
            {
                ORBInitializer.InitORB();
            }

/*
 *    ConsoleAppender appender = new ConsoleAppender {
 *      Threshold = Level.Fatal,
 *      Layout =
 *        new SimpleLayout(),
 *    };
 *    BasicConfigurator.Configure(appender);
 */
            ConnectionProperties props = new ConnectionPropertiesImpl();

            props.AccessKey = _privateKey;
            OpenBusContext context = ORBInitializer.Context;

            if (useSSL)
            {
                string ior = File.ReadAllText(busIORFile);
                _conn = context.ConnectByReference((MarshalByRefObject)OrbServices.CreateProxy(typeof(MarshalByRefObject), ior), props);
            }
            else
            {
                _conn = context.ConnectByAddress(hostName, hostPort, props);
            }
            context.SetDefaultConnection(_conn);

            _conn.LoginByCertificate(Entity, _privateKey);

            Messenger messenger = GetMessenger();

            if (messenger == null)
            {
                Logger.Fatal(
                    "Não foi possível encontrar um Messenger no barramento.");
                Console.Read();
                return;
            }

            ComponentContext component =
                new DefaultComponentContext(new ComponentId("Forwarder", 1, 0, 0, ".net"));

            _forwarder = new ForwarderImpl(messenger);
            component.AddFacet("forwarder",
                               Repository.GetRepositoryID(typeof(Forwarder)),
                               _forwarder);

            _ic         = component.GetIComponent();
            _properties = new[] {
                new ServiceProperty("offer.domain",
                                    "Interoperability Tests")
            };
            _offer = context.OfferRegistry.registerService(_ic, _properties);
            _conn.OnInvalidLogin = InvalidLogin;

            Logger.Fatal("Forwarder no ar.");

            Thread.Sleep(Timeout.Infinite);
        }
Пример #17
0
        private static void Main()
        {
            AppDomain.CurrentDomain.ProcessExit += CurrentDomainProcessExit;
            string hostName = DemoConfig.Default.busHostName;
            ushort hostPort = DemoConfig.Default.busHostPort;

            _privateKey = Crypto.ReadKeyFile(DemoConfig.Default.privateKey);
            bool   useSSL           = DemoConfig.Default.useSSL;
            string clientUser       = DemoConfig.Default.clientUser;
            string clientThumbprint = DemoConfig.Default.clientThumbprint;
            string serverUser       = DemoConfig.Default.serverUser;
            string serverThumbprint = DemoConfig.Default.serverThumbprint;
            ushort serverSSLPort    = DemoConfig.Default.serverSSLPort;
            ushort serverOpenPort   = DemoConfig.Default.serverOpenPort;
            string busIORFile       = DemoConfig.Default.busIORFile;

            if (useSSL)
            {
                Utils.InitSSLORB(clientUser, clientThumbprint, serverUser, serverThumbprint, serverSSLPort, serverOpenPort, true, true, "required", false, false);
            }
            else
            {
                ORBInitializer.InitORB();
            }

            ConnectionProperties props = new ConnectionPropertiesImpl();

            props.AccessKey = _privateKey;
            OpenBusContext context = ORBInitializer.Context;
            Connection     conn;

            if (useSSL)
            {
                string ior = File.ReadAllText(busIORFile);
                conn = context.ConnectByReference((MarshalByRefObject)OrbServices.CreateProxy(typeof(MarshalByRefObject), ior), props);
            }
            else
            {
                conn = context.ConnectByAddress(hostName, hostPort, props);
            }
            context.SetDefaultConnection(conn);

            conn.LoginByCertificate(Entity, _privateKey);

            ComponentContext component =
                new DefaultComponentContext(new ComponentId("Hello", 1, 0, 0, ".net"));
            HelloProxyImpl hello = new HelloProxyImpl(Entity, _privateKey);

            component.AddFacet("Hello",
                               Repository.GetRepositoryID(typeof(Hello)),
                               hello);

            _ic         = component.GetIComponent();
            _properties = new[] {
                new ServiceProperty("offer.domain",
                                    "Interoperability Tests"),
                new ServiceProperty("reloggedjoin.role",
                                    "proxy")
            };
            context.OfferRegistry.registerService(_ic, _properties);
            conn.OnInvalidLogin = InvalidLogin;

            Logger.Info("Hello Proxy no ar.");

            Thread.Sleep(Timeout.Infinite);
        }
Пример #18
0
        private static void Main()
        {
            string hostName  = DemoConfig.Default.busHostName;
            ushort hostPort  = DemoConfig.Default.busHostPort;
            ushort hostPort2 = DemoConfig.Default.bus2HostPort;

            _privateKey = Crypto.ReadKeyFile(DemoConfig.Default.privateKey);
            bool   useSSL           = DemoConfig.Default.useSSL;
            string clientUser       = DemoConfig.Default.clientUser;
            string clientThumbprint = DemoConfig.Default.clientThumbprint;
            string serverUser       = DemoConfig.Default.serverUser;
            string serverThumbprint = DemoConfig.Default.serverThumbprint;
            ushort serverSSLPort    = DemoConfig.Default.serverSSLPort;
            ushort serverOpenPort   = DemoConfig.Default.serverOpenPort;
            string busIORFile       = DemoConfig.Default.busIORFile;
            string bus2IORFile      = DemoConfig.Default.bus2IORFile;

            if (useSSL)
            {
                Utils.InitSSLORB(clientUser, clientThumbprint, serverUser, serverThumbprint, serverSSLPort, serverOpenPort, true, true, "required", false, false);
            }
            else
            {
                ORBInitializer.InitORB();
            }

/*
 *    ConsoleAppender appender = new ConsoleAppender {
 *      Threshold = Level.All,
 *      Layout =
 *        new SimpleLayout(),
 *    };
 *    BasicConfigurator.Configure(appender);
 */
            OpenBusContext context = ORBInitializer.Context;

            // connect to the bus
            ConnectionProperties props = new ConnectionPropertiesImpl();

            props.AccessKey = _privateKey;
            Connection conn2AtBus1;
            Connection conn3AtBus1;

            if (useSSL)
            {
                string ior  = File.ReadAllText(busIORFile);
                string ior2 = File.ReadAllText(bus2IORFile);
                _conn1AtBus1 = context.ConnectByReference((MarshalByRefObject)OrbServices.CreateProxy(typeof(MarshalByRefObject), ior), props);
                conn2AtBus1  = context.ConnectByReference((MarshalByRefObject)OrbServices.CreateProxy(typeof(MarshalByRefObject), ior), props);
                conn3AtBus1  = context.ConnectByReference((MarshalByRefObject)OrbServices.CreateProxy(typeof(MarshalByRefObject), ior), props);
                _connAtBus2  = context.ConnectByReference((MarshalByRefObject)OrbServices.CreateProxy(typeof(MarshalByRefObject), ior2), props);
            }
            else
            {
                _conn1AtBus1 = context.ConnectByAddress(hostName, hostPort, props);
                conn2AtBus1  = context.ConnectByAddress(hostName, hostPort, props);
                conn3AtBus1  = context.ConnectByAddress(hostName, hostPort, props);
                _connAtBus2  = context.ConnectByAddress(hostName, hostPort2, props);
            }

            // create service SCS component
            ComponentId      id        = new ComponentId("Hello", 1, 0, 0, ".net");
            ComponentContext component = new DefaultComponentContext(id);

            component.AddFacet("Hello", Repository.GetRepositoryID(typeof(Hello)),
                               new HelloImpl());
            _ic = component.GetIComponent();

            // login to the bus
            _conn1AtBus1.LoginByCertificate(Entity, _privateKey);
            conn2AtBus1.LoginByCertificate(Entity, _privateKey);
            conn3AtBus1.LoginByCertificate(Entity, _privateKey);
            _connAtBus2.LoginByCertificate(Entity, _privateKey);

            // set incoming connections
            context.OnCallDispatch = Dispatch;

            RegisterThreadStart start1 = new RegisterThreadStart(_conn1AtBus1,
                                                                 component.
                                                                 GetIComponent());
            Thread thread1 = new Thread(start1.Run);

            thread1.Start();
            _conn1AtBus1.OnInvalidLogin = InvalidLogin;

            RegisterThreadStart start2 = new RegisterThreadStart(conn2AtBus1,
                                                                 component.
                                                                 GetIComponent());
            Thread thread2 = new Thread(start2.Run);

            thread2.Start();
            conn2AtBus1.OnInvalidLogin = InvalidLogin;

            RegisterThreadStart start3 = new RegisterThreadStart(conn3AtBus1,
                                                                 component.
                                                                 GetIComponent());
            Thread thread3 = new Thread(start3.Run);

            thread3.Start();
            conn3AtBus1.OnInvalidLogin = InvalidLogin;

            context.SetCurrentConnection(_connAtBus2);
            context.OfferRegistry.registerService(_ic, ServiceProperties);
            _connAtBus2.OnInvalidLogin = InvalidLogin;

            Logger.Info("Servidor no ar.");

            Thread.Sleep(Timeout.Infinite);
        }
Пример #19
0
        static void Main()
        {
            log4net.Config.XmlConfigurator.Configure();

            Console.WriteLine("Pressione 'enter' quando o componente Ping estiver no ar.");
            Console.ReadLine();

            OrbServices.CreateAndRegisterIiopChannel(0);

            ComponentId      pongComponentId = new ComponentId("PingPong", 1, 0, 0, "");
            ComponentContext pongContext     = new DefaultComponentContext(pongComponentId);

            MarshalByRefObject pongServant   = new PongServant(pongContext);
            string             pingpongRepID = Repository.GetRepositoryID(typeof(PingPongServer));

            //Criando o component Pong.
            pongContext.AddFacet("Pong", pingpongRepID, pongServant);
            pongContext.AddReceptacle("PingRec", pingpongRepID, false);

            String       pingIorPath = Pong.Properties.Resources.IorFilename;
            StreamReader stream      = new StreamReader(pingIorPath);
            String       pingIor;

            try {
                pingIor = stream.ReadToEnd();
            }
            finally {
                stream.Close();
            }

            //Recuperar a faceta Ping.
            OrbServices        orb           = OrbServices.GetSingleton();
            IComponent         pingComponent = orb.string_to_object(pingIor) as IComponent;
            MarshalByRefObject pingObj       = pingComponent.getFacetByName("Ping");

            //Recuperar a faceta Pong.
            IComponent         pongComponent = pongContext.GetIComponent();
            MarshalByRefObject pongObj       = pongComponent.getFacetByName("Pong");

            //Conectar o Ping em Pong.
            IReceptacles pingIReceptacles = pingComponent.getFacetByName("IReceptacles") as IReceptacles;

            pingIReceptacles.connect("PongRec", pongObj);

            //Conectar o Pong em Ping.
            IReceptacles pongIReceptacles = pongComponent.getFacetByName("IReceptacles") as IReceptacles;

            pongIReceptacles.connect("PingRec", pingObj);

            Console.WriteLine("Executando ping e pong no Componente Ping");
            PingPongServer pingServer = pingComponent.getFacet(pingpongRepID) as PingPongServer;

            pingServer.ping();
            pingServer.pong();
            Console.WriteLine("--\n");

            Console.WriteLine("Executando ping e pong no Componente Pong");
            PingPongServer pongServer = pongComponent.getFacet(pingpongRepID) as PingPongServer;

            pongServer.ping();
            pongServer.pong();
            Console.WriteLine("--\n");

            MarshalByRefObject pingMetaInterfaceObj = pingComponent.getFacetByName("IMetaInterface");
            IMetaInterface     pingMetaInterface    = pingMetaInterfaceObj as IMetaInterface;

            FacetDescription[] PingFacets = pingMetaInterface.getFacets();
            foreach (var facet in PingFacets)
            {
                Console.WriteLine(facet.name + " --- " + facet.interface_name);
            }

            Console.WriteLine("Fim");
            Console.ReadLine();
        }