Пример #1
0
        public Ice.ObjectPrx register(string Name, Ice.Object servant, bool icegrid = true)
        {
            // register an object to local Ice adapter and yellowpage service (IceGrid)

            Ice.Identity iceid = Communicator.stringToIdentity(Name);
            logger.Info("Registering: " + Name);//+ " with ice_id: " + iceid.ToString());
            Ice.ObjectPrx proxy;
            try
            {
                proxy = _Adapter.add(servant, iceid);
            }
            catch (Ice.AlreadyRegisteredException ex)
            {
                logger.Error("The name of this holon: " + iceid.ToString() + " is allready used in local adapter");
                //maybe I could try to change name but there is probably something wrong
                throw (ex);
            }

            // It is very important to deregister objects before closing!!
            // Otherwise ghost links are created
            IceGrid.AdminPrx admin = getIceGridAdmin();
            try
            {
                admin.addObjectWithType(proxy, servant.ice_id());
            }
            catch (IceGrid.ObjectExistsException)
            {
                admin.updateObject(proxy);
            }
            _ServantIds.Add(iceid);
            return(proxy);
        }
Пример #2
0
        private void btndynamicDetect_Click(object sender, RoutedEventArgs e)
        {
            var sb = new StringBuilder();

            sb.Append("threshold".ElementText("0.5"));
            sb.Append("rtspId".ElementText("1"));
            sb.Append("rtspPath".ElementText("rtsp://*****:*****@192.0.0.64:554/h264/ch1/main/av_stream"));
            sb.Append("responseType".ElementBegin());
            if (ckbCallback.IsChecked.Value)
            {
                sb.Append("type".ElementText("callback"));
            }
            else
            {
                sb.Append("type".ElementText("messageQueue"));
            }

            sb.Append("size".ElementText("10"));
            sb.Append("responseType".ElementEnd());
            sb.Append("maxImageCount".ElementText("3"));
            sb.Append("frames".ElementText("5"));
            var data = sb.ToString();
            var xml  = GetXml("dynamicDetect", data);

            var content = facePxy.send(xml);

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(content);

            var code = doc.GetNodeText("code");

            Item("code->" + code);

            if (ckbCallback.IsChecked.Value)
            {
                callbackAdapter = ic.createObjectAdapterWithEndpoints("callback-receiver", "default");
                Ice.Object callbackServant = new ConnectorDisp(Item);

                callbackAdapter.add(callbackServant, ic.stringToIdentity("callbackReceiver"));
                callbackAdapter.activate();

                ConnectionListenerPrx listenerPxy = null;

                var objectPxy = callbackAdapter.createProxy(ic.stringToIdentity("callbackReceiver"));
                listenerPxy = ConnectionListenerPrxHelper.checkedCast(objectPxy);

                facePxy.initConnectionListener(listenerPxy);

                Item("set callback ok");
            }
        }
Пример #3
0
        /// <summary>
        /// Represents a connection to R2D2. On construction, this object creates a two-way
        /// connection with the bot. To properly shutdown the connection, make sure that
        /// the Dispose method is called; this is especially important if you wish to create a
        /// new BotConnection later.
        /// </summary>
        /// <param name="botToBase">Object implementing functions that receive from the bot</param>
        /// <param name="hostname">Hostname of the bo.</param>
        public BotConnection(BotToBaseDisp_ botToBase, string hostname = "R2D2")
        {
            try {
                Console.WriteLine("Starting server");
                communicator = Ice.Util.initialize();

                Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints(
                    "BotToBaseAdapter", "tcp -p " + BOT_TO_BASE_PORT);
                adapter.add(botToBase, communicator.stringToIdentity("BotToBaseImpl"));
                adapter.activate();

                Console.WriteLine("Connecting to R2D2");
                Ice.ObjectPrx prx = communicator.stringToProxy(
                    string.Format("BaseToBotImpl:tcp -h {0} -p {1}", hostname, BASE_TO_BOT_PORT));
                BotProxy = BaseToBotPrxHelper.checkedCast(prx);
                if (BotProxy == null)
                    throw new ApplicationException("Invalid proxy");

                // Pings are necessary to ensure that the connection is live.
                // We want R2D2 to stop immediately if the connection goes dead.
                new Thread(pinger).Start();

            } catch {
                if (communicator != null) { communicator.destroy(); }
                throw;
            }
        }
Пример #4
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            _Reference          = this;
            this.IsMouseVisible = true;
            Mouse.WindowHandle  = Window.Handle;
            graphics.PreferredBackBufferHeight = 800;
            graphics.PreferredBackBufferWidth  = 800;

            Content.RootDirectory = "Content";
            if (!Map.DeserializeFromXML(out _Map, this.Content.RootDirectory))
            {
                _Map = new Map();
                _Map.initEmpty();
                Map.SerializeToXML(ref _Map, this.Content.RootDirectory);
            }
            _Bot = new Robot(_Map);
            _Bot.changeState(Robot.RobotStates.PositionMode);

            Ice.Properties         properties = Ice.Util.createProperties();
            Ice.InitializationData initData   = new Ice.InitializationData();
            initData.properties = properties;

            _Communicator = Ice.Util.initialize(initData);
            _Adapter      = _Communicator.createObjectAdapterWithEndpoints("Simulator", "tcp -h localhost -p 55001");
            _DataHandler  = new communication.DataHandler(_Bot);
            _Adapter.add(_DataHandler, _Communicator.stringToIdentity("Simulator"));
            _Adapter.activate();

            graphics.ApplyChanges();
            base.Initialize();
        }
Пример #5
0
        /// <summary>
        /// Represents a connection to R2D2. On construction, this object creates a two-way
        /// connection with the bot. To properly shutdown the connection, make sure that
        /// the Dispose method is called; this is especially important if you wish to create a
        /// new BotConnection later.
        /// </summary>
        /// <param name="botToBase">Object implementing functions that receive from the bot</param>
        /// <param name="hostname">Hostname of the bo.</param>
        public BotConnection(BotToBaseDisp_ botToBase, string hostname = "R2D2")
        {
            try {
                Console.WriteLine("Starting server");
                communicator = Ice.Util.initialize();

                Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints(
                    "BotToBaseAdapter", "tcp -p " + BOT_TO_BASE_PORT);
                adapter.add(botToBase, communicator.stringToIdentity("BotToBaseImpl"));
                adapter.activate();

                Console.WriteLine("Connecting to R2D2");
                Ice.ObjectPrx prx = communicator.stringToProxy(
                    string.Format("BaseToBotImpl:tcp -h {0} -p {1}", hostname, BASE_TO_BOT_PORT));
                BotProxy = BaseToBotPrxHelper.checkedCast(prx);
                if (BotProxy == null)
                {
                    throw new ApplicationException("Invalid proxy");
                }

                // Pings are necessary to ensure that the connection is live.
                // We want R2D2 to stop immediately if the connection goes dead.
                new Thread(pinger).Start();
            } catch {
                if (communicator != null)
                {
                    communicator.destroy();
                }
                throw;
            }
        }
Пример #6
0
        static void Main(string[] args)
        {
            int status = 0;

            Ice.Communicator ic = null;

            ic = Ice.Util.initialize(ref args);

            Ice.ObjectAdapter adapter = ic.createObjectAdapterWithEndpoints("SimplePrinterAdapter", "default -p 10000");

            Ice.Object obj = new PrinterI();

            adapter.add(obj, ic.stringToIdentity("SimplePrinter"));

            adapter.activate();

            Console.WriteLine("started");

            ic.waitForShutdown();

            if (ic != null)
            {
                ic.destroy();
                status = 1;
            }

            Environment.Exit(status);
        }
Пример #7
0
        public static void registerEvent(ActionDisp_ action)
        {
            Ice.Communicator ic    = Ice.Application.communicator();
            Ice.ObjectPrx    base_ = Adapter.Instance.add(
                action, ic.stringToIdentity(action.getEventType()));
            ActionPrx proxy = ActionPrxHelper.checkedCast(base_);

            actionList.Add(proxy);
        }
Пример #8
0
        /// <summary>
        /// 初始化连接
        /// </summary>
        /// <returns></returns>
        public bool Init()
        {
            try
            {
                Ice.InitializationData intiData = new Ice.InitializationData();

                Ice.Properties properties = Ice.Util.createProperties();

                properties.setProperty("Ice.MessageSizeMax", "104857600");
                properties.setProperty("Ice.ThreadPool.SizeMax", "100");
                intiData.properties = properties;

                ic = Ice.Util.initialize(intiData);

                // 连接
                Ice.ObjectPrx objectPrx = ic.stringToProxy(string.Format("ID_TransDataFromClientRPC:tcp -h {0} -p {1} -t 5000",
                                                                         EEMSConfigHelper.GetValueByCommomConfig("config/CollectClient/DataServerIp", "127.0.0.1"),
                                                                         EEMSConfigHelper.GetValueByCommomConfig("config/CollectClient/DataServerPort", "40010")));

                Client = CSTransDataFromClientPrxHelper.checkedCast(objectPrx);
                // 代理
                Ice.ObjectAdapter adapter = ic.createObjectAdapterWithEndpoints("ID_TransDataFromClientRPC", string.Format("tcp -h {0} -p {1} -t 5000",
                                                                                                                           EEMSConfigHelper.GetValueByCommomConfig("config/CollectClient/DataClientIp", "127.0.0.1"),
                                                                                                                           EEMSConfigHelper.GetValueByCommomConfig("config/CollectClient/DataClientPort", "42000")));

                CallbackClientI callbackClientI = new CallbackClientI();

                callbackClientI.TransDataToClientHandler += callbackClientI_TransDataToClientHandler;

                Ice.Object obj = callbackClientI;

                adapter.add(obj, ic.stringToIdentity("ID_TransDataFromClientRPC"));

                adapter.activate();

                CallbackClientPrx call = CallbackClientPrxHelper.uncheckedCast(adapter.createProxy(ic.stringToIdentity("ID_TransDataFromClientRPC")));

                Client.RegistClient(ClientID, call, 1000);

                return(true);
            }
            catch (Exception e)
            {
                // 初始化失败
                Dispose();
                LogHelper.Instance.WirteErrorMsg(e.Message);
                return(false);
            }
        }
Пример #9
0
 static void Main(string[] args)
 {
     try
     {
         Ice.Communicator  communicator = Ice.Util.initialize();
         Ice.ObjectAdapter adapter      = communicator.createObjectAdapterWithEndpoints(
             "converter", "tcp -p 10000");
         adapter.add(new ConverterI(), communicator.stringToIdentity("converter"));
         adapter.activate();
         communicator.waitForShutdown();
         communicator.destroy();
     }
     catch (System.Exception ex)
     {
         System.Console.Error.WriteLine(ex);
         System.Environment.Exit(1);
     }
 }
Пример #10
0
 public static int Main(string[] args)
 {
     try
     {
         Ice.Communicator  communicator = Ice.Util.initialize(ref args);
         Ice.ObjectAdapter adapter      = communicator.createObjectAdapterWithEndpoints("Hello", "tcp -p 10000");
         adapter.add(new HelloI(), communicator.stringToIdentity("hello"));
         adapter.activate();
         communicator.waitForShutdown();
         communicator.destroy();
         return(0);
     }
     catch (System.Exception ex)
     {
         System.Console.Error.WriteLine(ex);
         return(1);
     }
 }
Пример #11
0
 public static void createServer(String proxyName)
 {
     try
     {
         Ice.Communicator  communicator = Ice.Util.initialize();
         Ice.ObjectAdapter adapter      = communicator.createObjectAdapterWithEndpoints(
             "proxyName", "tcp -p 10003");
         adapter.add(new RemoteLogI(), communicator.stringToIdentity(proxyName));
         adapter.activate();
         communicator.waitForShutdown();
         communicator.destroy();
     }
     catch (System.Exception ex)
     {
         System.Console.Error.WriteLine(ex);
         System.Environment.Exit(1);
     }
 }
Пример #12
0
        /// <summary>
        /// 初始化连接
        /// </summary>
        /// <returns></returns>
        public bool Init()
        {
            try
            {
                lock (lockData)
                {
                    Ice.InitializationData intiData = new Ice.InitializationData();

                    Ice.Properties properties = Ice.Util.createProperties();

                    properties.setProperty("Ice.MessageSizeMax", "104857600");

                    intiData.properties = properties;

                    ic = Ice.Util.initialize(intiData);

                    // 连接
                    Ice.ObjectPrx objectPrx = ic.stringToProxy(string.Format("{0}:tcp -h {1} -p {2} -t 5000", NMCommunicationRPCId.value,
                                                                             EEMSConfigHelper.GetValueByCommomConfig("config/CommonConfig/netagent_ip", "127.0.0.1"),
                                                                             EEMSConfigHelper.GetValueByCommomConfig("config/CommonConfig/netagent_port", "40050")));

                    client = NMServerPrxHelper.checkedCast(objectPrx);

                    // 代理
                    Ice.ObjectAdapter adapter = ic.createObjectAdapterWithEndpoints(NMCommunicationRPCId.value, string.Format("tcp -h {0} -p {1} -t 5000",
                                                                                                                              EEMSConfigHelper.GetValueByCommomConfig("config/CollectClient/WarnInfoLocalIp", "127.0.0.1"),
                                                                                                                              EEMSConfigHelper.GetValueByCommomConfig("config/CollectClient/WarnInfoClentPort", "42050")));

                    NMClientI clientI = new NMClientI();

                    clientI.ReceiveDataHandler += clientI_ReceiveDataHandler;

                    Ice.Object obj = clientI;

                    adapter.add(obj, ic.stringToIdentity(NMCommunicationRPCId.value));

                    adapter.activate();

                    NMClientPrx call = NMClientPrxHelper.uncheckedCast(adapter.createProxy(ic.stringToIdentity(NMCommunicationRPCId.value)));

                    client.NMRegistClient(clientID, call);

                    IsConnect = true;
                }

                return(true);
            }
            catch (Exception e)
            {
                // 初始化失败
                client = null;
                LogHelper.Instance.WirteErrorMsg(e.Message);
                return(false);
            }
            finally
            {
                if (!isThreadStart)
                {
                    isThreadStart = true;
                    CheckConnectThread();
                }
            }
        }