Beispiel #1
0
    public string sayHello() {
      try {
        Connection conn = _context.GetCurrentConnection();
        Logger.Info("Refazendo o login da entidade: " + _entity);
        conn.Logout();
        conn.LoginByCertificate(_entity, _key);
        CallerChain chain = _context.CallerChain;
        string caller = chain.Caller.entity;
        Logger.Info("Chamada recebida de " + caller);

        ServiceProperty[] properties = {new ServiceProperty("reloggedjoin.role", "server")};

        _context.JoinChain(chain);

        Logger.Info("Buscando servidor Hello relogged join");
        List<ServiceOfferDesc> offers =
          Utils.FindOffer(ORBInitializer.Context.OfferRegistry, properties, 1, 10, 1);
        foreach (ServiceOfferDesc desc in offers) {
          string found = Utils.GetProperty(desc.properties,
                                           "openbus.offer.entity");
          Logger.Info("Serviço encontrado da entidade " + found);
          Hello hello = desc.service_ref.getFacetByName("Hello") as Hello;
          return hello.sayHello();
        }
      }
      catch (Exception e) {
        Logger.Info(e);
      }
      return "Erro ao utilizar o serviço Hello!";
    }
Beispiel #2
0
        public void notifyTrigger()
        {
            OpenBusContext context = ORBInitializer.Context;
            CallerChain    chain   = context.CallerChain;

            if (_timerId.Equals(chain.Caller.id))
            {
                Console.WriteLine(Resources.MultiplexingTimerNotificationReceived);
                if (chain.Originators.Length != 1 ||
                    !chain.Originators[0].id.Equals(_loginId))
                {
                    Console.WriteLine(
                        Resources.MultiplexingTimerNotificationOutOfOriginalCall);
                }
            }
            else
            {
                Console.WriteLine(Resources.MultiplexingUnexpectedNotification);
                Console.WriteLine(Resources.MultiplexingUnexpectedNotificationFrom +
                                  chain.Caller.id);
                Console.WriteLine(
                    Resources.MultiplexingUnexpectedNotificationShouldBeFrom + _timerId);
            }
            --MultiplexingClient.Pending;
            if (MultiplexingClient.Pending == 0)
            {
                _waitingThread.Interrupt();
            }
        }
Beispiel #3
0
        public void setForward(string to)
        {
            CallerChain chain = ORBInitializer.Context.CallerChain;
            string      user  = chain.Caller.entity;

            Logger.Fatal("setup forward to " + to + " by " + user);
            _forwardsOf.TryAdd(user, new Forward(chain, to));
        }
        public void newTrigger(double timeout, Callback cb)
        {
            OpenBusContext context = ORBInitializer.Context;
            Connection     conn    = context.GetCurrentConnection();
            CallerChain    chain   = context.CallerChain;

            // Inicia thread para realizar a chamada remota na callback
            new Thread(() => NotifyTrigger(conn, chain, timeout, cb)).Start();
        }
Beispiel #5
0
        public static string ToString(CallerChain chain)
        {
            string ret = String.Empty;

            for (int i = 0; i < chain.Originators.Length; i++)
            {
                ret += chain.Originators[i].entity + "->";
            }
            return(ret + chain.Caller.entity);
        }
        public void unsubscribe()
        {
            CallerChain chain = _context.CallerChain;
            string      user  = chain.Caller.entity;

            Logger.Fatal("unsubscription by " + user);
            lock (_subscribers) {
                _subscribers.Remove(user);
            }
        }
Beispiel #7
0
        public string getForward()
        {
            CallerChain chain = ORBInitializer.Context.CallerChain;
            string      user  = chain.Caller.entity;
            Forward     forward;

            if (_forwardsOf.TryGetValue(user, out forward))
            {
                return(forward.To);
            }
            throw new NoForward();
        }
Beispiel #8
0
        public void showMessage(string message)
        {
            CallerChain chain = ORBInitializer.Context.CallerChain;

            if (!chain.Caller.entity.Equals(_entity))
            {
                Console.WriteLine(Resources.CallChainRefuseMessage +
                                  ChainToString.ToString(chain));
                throw new Unauthorized();
            }
            Console.WriteLine(Resources.CallChainAcceptMessage +
                              ChainToString.ToString(chain) + ": " + message);
        }
Beispiel #9
0
        public void cancelForward(string to)
        {
            CallerChain chain = ORBInitializer.Context.CallerChain;
            string      user  = chain.Caller.entity;

            lock (_forwardsOf) {
                Forward forward;
                if (_forwardsOf.TryGetValue(user, out forward))
                {
                    Logger.Fatal("cancel forward to " + forward.To + " by " + user);
                    _forwardsOf.TryRemove(user, out forward);
                }
            }
        }
Beispiel #10
0
        public string[] listCallerLogins()
        {
            CallerChain    chain = _context.CallerChain;
            IList <String> list  = new List <String>();

            foreach (LoginInfo info in chain.Originators)
            {
                list.Add(info.id);
            }
            list.Add(chain.Caller.id);
            string[] array = new string[list.Count];
            list.CopyTo(array, 0);
            return(array);
        }
        public void JoinChain(CallerChain chain)
        {
            if (chain == null)
            {
                chain = CallerChain;
            }
            Current current = GetPICurrent();

            try {
                current.set_slot(_joinedChainSlotId, chain);
            }
            catch (InvalidSlot e) {
                Logger.Fatal("Falha inesperada ao acessar o slot da joined chain.", e);
                throw;
            }
        }
Beispiel #12
0
        public void post(string to, string message)
        {
            CallerChain chain = ORBInitializer.Context.CallerChain;
            string      from  = ChainToString(chain);

            Logger.Fatal("post to " + to + " by " + from);
            List <PostDesc> inbox;

            if (!_inboxOf.TryGetValue(to, out inbox))
            {
                inbox = new List <PostDesc>();
                _inboxOf.TryAdd(to, inbox);
            }
            lock (inbox) {
                inbox.Add(new PostDesc(from, message));
            }
        }
 public byte[] EncodeChain(CallerChain chain)
 {
     try {
         CallerChainImpl chainImpl     = (CallerChainImpl)chain;
         int             i             = 0;
         VersionedData?  actualVersion = null;
         VersionedData?  legacyVersion = null;
         if (!chainImpl.Legacy)
         {
             // se não é legacy, tem a versão atual. Pode ter a versão legacy ou não.
             TypeCode signedChainTC = _orb.create_tc_for_type(typeof(SignedData));
             Any      any           = new Any(chainImpl.Signed.Chain, signedChainTC);
             byte[]   encoded       = _codec.encode_value(any);
             actualVersion = new VersionedData(ExportVersion.ConstVal, encoded);
             i++;
         }
         if (chainImpl.Signed.LegacyChain.encoded != null)
         {
             ExportedCallChain exported = new ExportedCallChain(chainImpl.BusId,
                                                                chainImpl.Signed.LegacyChain);
             TypeCode exportedChainTC = _orb.create_tc_for_type(typeof(ExportedCallChain));
             Any      any             = new Any(exported, exportedChainTC);
             byte[]   legacyEncoded   = _codec.encode_value(any);
             legacyVersion = new VersionedData(CurrentVersion.ConstVal, legacyEncoded);
             i++;
         }
         VersionedData[] versions = new VersionedData[i];
         // A ordem das versões exportadas IMPORTA. A 2.1 deve vir antes da 2.0.
         if (legacyVersion != null)
         {
             versions[--i] = legacyVersion.Value;
         }
         if (actualVersion != null)
         {
             versions[--i] = actualVersion.Value;
         }
         return(EncodeExportedVersions(versions, _magicTagCallChain));
     }
     catch (InvalidTypeForEncoding e) {
         const string message =
             "Falha inesperada ao codificar uma cadeia para exportação.";
         Logger.Error(message, e);
         throw new OpenBusInternalException(message, e);
     }
 }
Beispiel #14
0
        public string sayHello()
        {
            string ret = String.Empty;

            try {
                CallerChain callerChain = ORBInitializer.Context.CallerChain;
                if (callerChain != null)
                {
                    String entity = callerChain.Caller.entity;
                    ret = String.Format("Hello {0}@{1}!", entity,
                                        callerChain.BusId);
                    Logger.Info(ret);
                    return(ret);
                }
            }
            catch (Exception e) {
                Logger.Info(e);
            }
            return(ret);
        }
Beispiel #15
0
        public string sayHello()
        {
            CallerChain chain = ORBInitializer.Context.CallerChain;

            if (chain == null)
            {
                // cliente deve receber um CORBA::Unknown
                throw new NullReferenceException();
            }
            Connection conn = ORBInitializer.Context.GetCurrentConnection();

            if ((chain.BusId != conn.BusId) ||
                (!chain.Caller.id.Equals(conn.Login.Value.id)) ||
                (chain.Originators.Length != 0) ||
                (!chain.Target.Equals(conn.Login.Value.entity)))
            {
                // cliente deve receber um CORBA::Unknown
                throw new InvalidOperationException();
            }
            return("");
        }
Beispiel #16
0
        public PostDesc[] receivePosts()
        {
            CallerChain chain = ORBInitializer.Context.CallerChain;
            string      owner = chain.Originators.Length > 0
                       ? chain.Originators[0].entity
                       : chain.Caller.entity;

            Logger.Fatal("download of messages of " + owner + " by " +
                         ChainToString(chain));
            List <PostDesc> inbox;

            if (_inboxOf.TryRemove(owner, out inbox))
            {
                PostDesc[] descs;
                lock (inbox) {
                    descs = inbox.ToArray();
                }
                return(descs);
            }
            return(new PostDesc[0]);
        }
Beispiel #17
0
 internal Forward(CallerChain chain, string to)
 {
     Chain = chain;
     To    = to;
 }
Beispiel #18
0
        public void showMessage(string message)
        {
            CallerChain chain = ORBInitializer.Context.CallerChain;

            Console.WriteLine(Resources.CallChainProxyForwardingMessage +
                              ChainToString.ToString(chain));
            OpenBusContext context = ORBInitializer.Context;

            context.JoinChain(chain);
            foreach (ServiceOfferDesc offer in Proxy.Offers)
            {
                try {
                    MarshalByRefObject messengerObj =
                        offer.service_ref.getFacet(_messengerType);
                    if (messengerObj == null)
                    {
                        Console.WriteLine(Resources.FacetNotFoundInOffer);
                        continue;
                    }
                    Messenger messenger = messengerObj as Messenger;
                    if (messenger == null)
                    {
                        Console.WriteLine(Resources.FacetFoundWrongType);
                        continue;
                    }
                    Console.WriteLine(Resources.OfferFound);
                    // utiliza o serviço
                    messenger.showMessage(message);
                    return;
                }
                catch (Unauthorized) {
                }
                catch (Unavailable) {
                }
                catch (TRANSIENT) {
                    Console.WriteLine(Resources.ServiceTransientErrorMsg);
                }
                catch (COMM_FAILURE) {
                    Console.WriteLine(Resources.ServiceCommFailureErrorMsg);
                }
                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 ?? e as NO_PERMISSION;
                    bool   found = false;
                    string msg   = String.Empty;
                    switch (npe.Minor)
                    {
                    case NoLoginCode.ConstVal:
                        msg   = Resources.NoLoginCodeErrorMsg;
                        found = true;
                        break;

                    case UnknownBusCode.ConstVal:
                        msg   = Resources.UnknownBusCodeErrorMsg;
                        found = true;
                        break;

                    case UnverifiedLoginCode.ConstVal:
                        msg   = Resources.UnverifiedLoginCodeErrorMsg;
                        found = true;
                        break;

                    case InvalidRemoteCode.ConstVal:
                        msg   = Resources.InvalidRemoteCodeErrorMsg;
                        found = true;
                        break;
                    }
                    if (found)
                    {
                        Console.WriteLine(msg);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            Console.WriteLine(Resources.CallChainProxyUnavailableMessage);
            throw new Unavailable();
        }
Beispiel #19
0
        private static void Main()
        {
            string hostName         = DemoConfig.Default.busHostName;
            ushort hostPort         = DemoConfig.Default.busHostPort;
            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();
            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);

            const string userLogin = "******";

            byte[] userPassword = new ASCIIEncoding().GetBytes(userLogin);

            conn.LoginByPassword(userLogin, userPassword, "testing");

            // propriedades geradas automaticamente
            ServiceProperty prop1 = new ServiceProperty("openbus.component.interface", Repository.GetRepositoryID(typeof(HelloProxy)));
            // propriedade definida pelo servidor hello
            ServiceProperty prop2 = new ServiceProperty("offer.domain",
                                                        "Interoperability Tests");

            ServiceProperty[]       properties = { prop1, prop2 };
            List <ServiceOfferDesc> offers     =
                Utils.FindOffer(ORBInitializer.Context.OfferRegistry, properties, 1, 10, 1);

            bool foundOne = false;

            foreach (ServiceOfferDesc serviceOfferDesc in offers)
            {
                try {
                    string found = Utils.GetProperty(serviceOfferDesc.properties, "openbus.offer.entity");
                    Console.WriteLine("Entidade encontrada: " + found);
                    MarshalByRefObject helloProxyObj =
                        serviceOfferDesc.service_ref.getFacet(
                            Repository.GetRepositoryID(typeof(HelloProxy)));
                    if (helloProxyObj == null)
                    {
                        Console.WriteLine(
                            "Não foi possível encontrar uma faceta com esse nome.");
                        continue;
                    }
                    HelloProxy helloProxy = helloProxyObj as HelloProxy;
                    if (helloProxy == null)
                    {
                        Console.WriteLine("Faceta encontrada não implementa HelloProxy.");
                        continue;
                    }
                    foundOne = true;
                    String loginEntity = Utils.GetProperty(serviceOfferDesc.properties,
                                                           "openbus.offer.entity");
                    CallerChain  chain        = context.MakeChainFor(loginEntity);
                    byte[]       encodedChain = context.EncodeChain(chain);
                    const string expected     = "Hello " + userLogin + "!";
                    Assert.AreEqual(helloProxy.fetchHello(encodedChain), expected);
                }
                catch (TRANSIENT) {
                    Console.WriteLine(
                        "Uma das ofertas obtidas é de um cliente inativo. Tentando a próxima.");
                }
            }
            conn.Logout();
            Assert.IsTrue(foundOne);
            Console.WriteLine("Fim.");
        }
        private static void NotifyTrigger(Connection current, CallerChain chain,
                                          double timeout, Callback cb)
        {
            Thread.Sleep(Convert.ToInt32(timeout * 1000));
            OpenBusContext context = ORBInitializer.Context;

            context.SetCurrentConnection(current);
            context.JoinChain(chain);
            try {
                // utiliza o serviço
                cb.notifyTrigger();
            }
            catch (TRANSIENT) {
                Console.WriteLine(Resources.ServiceTransientErrorMsg);
            }
            catch (COMM_FAILURE) {
                Console.WriteLine(Resources.ServiceCommFailureErrorMsg);
            }
            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 ?? e as NO_PERMISSION;
                bool   found   = false;
                string message = String.Empty;
                switch (npe.Minor)
                {
                case NoLoginCode.ConstVal:
                    message = Resources.NoLoginCodeErrorMsg;
                    found   = true;
                    break;

                case UnknownBusCode.ConstVal:
                    message = Resources.UnknownBusCodeErrorMsg;
                    found   = true;
                    break;

                case UnverifiedLoginCode.ConstVal:
                    message = Resources.UnverifiedLoginCodeErrorMsg;
                    found   = true;
                    break;

                case InvalidRemoteCode.ConstVal:
                    message = Resources.InvalidRemoteCodeErrorMsg;
                    found   = true;
                    break;
                }
                if (found)
                {
                    Console.WriteLine(message);
                }
                else
                {
                    throw;
                }
            }
        }