Пример #1
0
        /// <summary>
        /// Construtor.
        /// </summary>
        /// <param name="name">O nome da faceta.</param>
        /// <param name="interfaceName">O tipo da faceta (repositoryID).</param>
        /// <param name="servant">O objeto CORBA que representa a faceta.</param>
        /// <exception cref="ArgumentException">Caso os argumentos estejam
        /// incorretos</exception>
        /// <exception cref="ArgumentNullException">Caso os argumentos estejam
        /// nulos</exception>
        public Facet(string name, string interfaceName, MarshalByRefObject servant)
        {
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentException("O campo 'name' não pode ser nulo ou vazio.", "name");
            }
            if (String.IsNullOrEmpty(interfaceName))
            {
                throw new ArgumentException("O campo 'interfaceName' não pode ser nulo ou vazio.", "interfaceName");
            }
            if (!CheckInterface(interfaceName))
            {
                throw new ArgumentException("O campo 'interfaceName' não está de acordo com o padrão", "interfaceName");
            }
            if (servant == null)
            {
                throw new ArgumentNullException("servant", "O campo 'servant' não pode ser nulo.");
            }
            if (!IiopNetUtil.CheckInterface(servant, interfaceName))
            {
                string errorMsg = String.Format("O campo 'servant' não suporta a interface {0}", interfaceName);
                throw new ArgumentException(errorMsg);
            }

            this.name          = name;
            this.interfaceName = interfaceName;
            this.reference     = servant;
            Activate();
        }
Пример #2
0
        /// <summary>
        /// Conecta uma faceta a um receptáculo.
        /// </summary>
        /// <param name="receptacle">
        /// O nome do receptáculo que se deseja conectar.
        /// </param>
        /// <param name="obj">
        /// A referência para a faceta que se deseja conectar.
        /// </param>
        /// <exception cref="InvalidName">
        /// Caso o nome do receptáculo seja inválido.
        /// </exception>
        /// <exception cref="InvalidConnection">
        /// Caso a conexão não possa ser estabelecida, este erro pode acontecer
        /// caso o <c>obj</c> não implemente a interface do receptáculo.
        /// </exception>
        /// <exception cref="AlreadyConnected">
        /// Caso a faceta já esteja conectada.
        /// </exception>
        /// <exception cref="ExceededConnectionLimit">
        /// Caso o número de conexões tenha excedido o limite configurado.
        /// </exception>
        public int connect(string receptacle, MarshalByRefObject obj)
        {
            IDictionary <string, Receptacle> receptacles =
                context.GetReceptacles();

            if (!receptacles.ContainsKey(receptacle))
            {
                throw new InvalidName {
                          name = receptacle
                }
            }
            ;

            Receptacle rec = receptacles[receptacle];

            if ((!rec.IsMultiple) &&
                (rec.GetConnectionsSize() > 0))
            {
                throw new AlreadyConnected();
            }

            if (!IiopNetUtil.CheckInterface(obj, rec.InterfaceName))
            {
                throw new InvalidConnection();
            }

            int id = rec.AddConnections(obj);

            logger.InfoFormat("Conexão {0} adicionada ao receptáculo '{1}'", id,
                              receptacle);
            return(id);
        }
Пример #3
0
        public void GetRepositoryIdTest()
        {
            Type   type     = typeof(IComponent);
            string expected = "IDL:scs/core/IComponent:1.0";
            string actual   = IiopNetUtil.GetRepositoryId(type);

            Assert.AreEqual(expected, actual);
        }
Пример #4
0
 /// <summary>
 /// Desativa a faceta
 /// </summary>
 /// <exception cref="SCSException"></exception>
 internal void Deactivate()
 {
     try {
         IiopNetUtil.DeactivateFacet(reference);
     }
     catch (System.Security.SecurityException e) {
         throw new SCSException("Falha na desativação da Faceta", e);
     }
 }
Пример #5
0
        public void CheckInterfaceTest4()
        {
            MarshalByRefObject icomponentObj = icomponetFacet as MarshalByRefObject;
            Type type     = icomponentType;
            bool expected = true;
            bool actual   = IiopNetUtil.CheckInterface(icomponentObj, type);

            Assert.AreEqual(expected, actual);
        }
Пример #6
0
        public void CheckInterfaceTest3()
        {
            MarshalByRefObject icomponentObj = icomponetFacet as MarshalByRefObject;
            string             repositoryId  = "1.0:openbus/null:IDL";
            bool expected = false;
            bool actual   = IiopNetUtil.CheckInterface(icomponentObj, repositoryId);

            Assert.AreEqual(expected, actual);
        }
Пример #7
0
        public void CheckInterface1()
        {
            MarshalByRefObject icomponentObj = icomponetFacet as MarshalByRefObject;
            string             repositoryId  = Repository.GetRepositoryID(icomponentType);
            bool expected = true;
            bool actual   = IiopNetUtil.CheckInterface(icomponentObj, repositoryId);

            Assert.AreEqual(expected, actual);
        }
Пример #8
0
        public void CheckInterfaceTest6()
        {
            MarshalByRefObject icomponentObj = icomponetFacet as MarshalByRefObject;
            Type type     = typeof(Nullable);
            bool expected = false;
            bool actual   = IiopNetUtil.CheckInterface(icomponentObj, type);

            Assert.AreEqual(expected, actual);
        }
Пример #9
0
        public void CheckInterface2()
        {
            MarshalByRefObject icomponentObj = icomponetFacet as MarshalByRefObject;
            Type   imetaInterfaceType        = typeof(IMetaInterface);
            string repositoryId = Repository.GetRepositoryID(imetaInterfaceType);
            bool   expected     = false;
            bool   actual       = IiopNetUtil.CheckInterface(icomponentObj, repositoryId);

            Assert.AreEqual(expected, actual);
        }
Пример #10
0
 /// <summary>
 /// Ativa a faceta.
 /// </summary>
 /// <exception cref="SCSException"></exception>
 private void Activate()
 {
     try {
         IiopNetUtil.ActivateFacet(reference);
     }
     catch (System.Security.SecurityException e) {
         throw new SCSException("Falha na ativação da Faceta", e);
     }
     catch (System.Runtime.Remoting.RemotingException e) {
         throw new SCSException("Falha na ativação da Faceta", e);
     }
 }
Пример #11
0
        /// <summary>
        /// Define um servant. Caso já exista um servant definido, o método
        /// desativa o servant anterior antes de ativar o novo servant.
        /// </summary>
        /// <param name="servant"></param>
        public void UpdateReference(MarshalByRefObject servant)
        {
            if (servant == null)
            {
                throw new ArgumentNullException("servant", "O campo 'servant' não pode ser nulo.");
            }
            if (!IiopNetUtil.CheckInterface(servant, interfaceName))
            {
                string errorMsg = String.Format("O campo 'servant' não suporta a interface {0}", interfaceName);
                throw new ArgumentException(errorMsg);
            }

            this.reference = servant;
            Activate();
        }
        /// <summary>
        /// Adiciona as facetas do arquivo de descrição ao componente.
        /// </summary>
        /// <param name="context">O componente</param>
        /// <exception cref="SCSException">Caso ocorra um erro na criação das facetas.</exception>
        private void AddFacets(ComponentContext context)
        {
            XmlNodeList facetsNodeList =
                xmlComponent.GetElementsByTagName(FACET_ELEMENT);

            foreach (XmlNode facetNode in facetsNodeList)
            {
                String  name            = facetNode[FACET_NAME].InnerText;
                String  interfaceName   = facetNode[FACET_REP_ID].InnerText;
                XmlNode servantNode     = facetNode[FACET_SERVANT];
                String  servantName     = servantNode.InnerText;
                String  servantAssembly = servantNode.Attributes[FACET_SERVANT_ASSEMBLY_ATTRIBUTE].InnerText;
                String  type            = String.Format("{0}, {1}", servantName, servantAssembly);

                MarshalByRefObject servant = InstantiateServant(type, context);
                if (!IiopNetUtil.CheckInterface(servant, interfaceName))
                {
                    string errorMsg = String.Format(
                        "A faceta '{0}' não suporta a interface '{1}'", name, interfaceName);
                    throw new SCSException(errorMsg);
                }
                if (context.GetFacetByName(name) != null)
                {
                    logger.Info(String.Format("A faceta {0} foi atualizada.", name));
                    try {
                        context.UpdateFacet(name, servant);
                    }
                    catch (ArgumentException e) {
                        throw new SCSException(e.Message);
                    }
                }
                else
                {
                    logger.Debug(String.Format("Adicionando a faceta {0}", name));
                    context.AddFacet(name, interfaceName, servant);
                }
            }
        }
Пример #13
0
        /// <summary>
        /// Adiciona as facetas básicas à lista de Facetas criadas pelo usuário.
        /// </summary>
        private void AddBasicFacets()
        {
            Type   icomponentType          = typeof(IComponent);
            string icomponentName          = icomponentType.Name;
            string icomponentInterfaceName = IiopNetUtil.GetRepositoryId(icomponentType);

            if (!facets.ContainsKey(icomponentName))
            {
                IComponent         icomponent        = new IComponentServant(this);
                MarshalByRefObject icomponentServant = icomponent as MarshalByRefObject;
                AddFacet(icomponentName, icomponentInterfaceName, icomponentServant);
                logger.DebugFormat("Faceta '{0}' adicionada com sucesso", icomponentName);
            }

            Type   ireceptacleType          = typeof(IReceptacles);
            string ireceptacleName          = ireceptacleType.Name;
            string ireceptacleInterfaceName = IiopNetUtil.GetRepositoryId(ireceptacleType);

            if (!facets.ContainsKey(ireceptacleName))
            {
                IReceptacles       receptacle        = new IReceptaclesServant(this);
                MarshalByRefObject receptacleServant = receptacle as MarshalByRefObject;
                AddFacet(ireceptacleName, ireceptacleInterfaceName, receptacleServant);
                logger.DebugFormat("Faceta '{0}' adicionada com sucesso", ireceptacleName);
            }

            Type   imetaInterfaceType          = typeof(IMetaInterface);
            string imetaInterfaceName          = imetaInterfaceType.Name;
            string imetaInterfaceInterfaceName = IiopNetUtil.GetRepositoryId(imetaInterfaceType);

            if (!facets.ContainsKey(imetaInterfaceName))
            {
                IMetaInterface     metaInterface        = new IMetaInterfaceServant(this);
                MarshalByRefObject metaInterfaceServant = metaInterface as MarshalByRefObject;
                AddFacet(imetaInterfaceName, imetaInterfaceInterfaceName, metaInterfaceServant);
                logger.DebugFormat("Faceta '{0}' adicionada com sucesso", imetaInterfaceName);
            }
        }