コード例 #1
0
        private static void Main(String[] args)
        {
            // Obtém dados através dos argumentos
            _host       = args[0];
            _port       = Convert.ToUInt16(args[1]);
            _entity     = args[2];
            _privateKey = Crypto.ReadKeyFile(args[3]);
            _interval   = Convert.ToInt32(args.Length > 4 ? args[4] : "1");

            // Registra handler para o caso do processo ser finalizado
            AppDomain.CurrentDomain.ProcessExit += CurrentDomainProcessExit;

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

            // Cria a faceta Clock para o componente
            ClockImpl clock = new ClockImpl();

            _component.AddFacet("Clock", Repository.GetRepositoryID(typeof(Clock)),
                                clock);

            // Inicia thread que tenta conectar ao barramento
            ThreadStart ts = ConnectToOpenBus;
            Thread      t  = new Thread(ts)
            {
                IsBackground = true
            };

            t.Start();

            // Realiza trabalho independente do OpenBus
            while (true)
            {
                clock.getTimeInTicks();
                //        Console.WriteLine(String.Format("Hora atual: {0:HH:mm:ss}", DateTime.Now));
                Thread.Sleep(_interval);
            }
        }
コード例 #2
0
        /// <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);
                }
            }
        }