コード例 #1
0
ファイル: Service.cs プロジェクト: ZQuanLi/Test
 /// <summary>
 /// 启动客户端并得到服务对象
 /// </summary>
 /// <param name="port"></param>
 /// <returns></returns>
 public static communicationPrx Client(int port = 10000)
 {
     if (service == null)
     {
         //string[] args = null;
         //int status = 0;
         Ice.Communicator ic = null;
         //调用Ice::initialize 初始化Ice run time。
         ic = Ice.Util.initialize();
         //
         //获取远地打印机的代理。我们调用通信器的stringToProxy
         //创建一个代理,所用参数是"SimplePrinter:default -
         //p 10000"。注意,这个串包含的是对象标识和服务器所用的端口号
         Ice.ObjectPrx obj = ic.stringToProxy("SimplePrinter:default -p " + port);
         //stringToProxy 返回的代理的类型是Ice::ObjectPrx,这种类型
         //位于接口和类的继承树的根部。但要实际与我们的打印机交谈,我们需
         //要的是Printer 接口、而不是Object 接口的代理。为此,我们需要调
         //用PrinterPrxHelper.checkedCast 进行向下转换。这个方法会
         //发送一条消息给服务器,实际询问“这是Printer 接口的代理吗?”如
         //果是,这个调用就会返回Printer 的一个代理;如果代理代表的是其他
         //类型的接口,这个调用就会返回一个空代理。
         service = communicationPrxHelper.checkedCast(obj);
         //测试向下转换是否成功,如果不成功,就抛出出错消息,终止客户。
         if (service == null)
         {
             throw new ApplicationException("Invalid proxy");
         }
         //我们的地址空间里有了一个活的代理,可以调用printString 方法,
         //把享誉已久的 "Hello World!" 串传给它。服务器会在它的终端上打印这个串。
     }
     return(service);
 }
コード例 #2
0
        private void btndynamicDetect_Click(object sender, RoutedEventArgs e)
        {
            //回调EndPoint的写法
            //1."default -h 192.168.1.116 -p 9991"
            //2."default"
            string endpoints = "default -h 192.168.1.116 -p 9991";

            callbackAdapter = ic.createObjectAdapterWithEndpoints("callback-client", endpoints);

            Ice.Object servant = new ClientCallbackI(Item);
            callbackAdapter.add(servant, ic.stringToIdentity("callbackReceiver"));
            callbackAdapter.activate();

            ClientCallbackReceiverPrx receiverPrx = null;

            Ice.Identity identity = ic.stringToIdentity("callbackReceiver");
            //代理一定要通过adapter对象创建
            Ice.ObjectPrx pxy = callbackAdapter.createProxy(identity);
            receiverPrx = ClientCallbackReceiverPrxHelper.uncheckedCast(pxy);


            var result = facePxy.dynamicDetect("rtspPath", receiverPrx, 0.4f, 100, 4);

            lbResult.Items.Clear();
            Item("code:" + result.code);
            Item("message:" + result.message);
        }
コード例 #3
0
        protected DataServantPrx GetDataServant()
        {
            try
            {
                lock (this)
                {
                    if (_dataServant != null)
                    {
                        _dataServant.ice_ping();
                        return(_dataServant);
                    }

                    if (_ic == null)
                    {
                        InitializationData icData = new InitializationData();
                        Ice.Properties     icProp = Util.createProperties();
                        icProp.setProperty("Ice.ACM.Client", "0");
                        icProp.setProperty("Ice.MessageSizeMax", "2097152");//2gb in kb
                        icData.properties = icProp;
                        Communicator ic = Util.initialize(icData);

                        if (ic != null)
                        {
                            _ic = ic;
                        }
                    }

                    if (_ic != null)
                    {
                        string         endpoint = string.Format("AASDataServer/DataServant:tcp -h {0} -p {1}", ServerIP, ICEPort);
                        Ice.ObjectPrx  obj      = _ic.stringToProxy(endpoint);
                        DataServantPrx client   = DataServantPrxHelper.checkedCast(obj);
                        if (client == null)
                        {
                            AASClient.Program.logger.LogRunning("DataServerClient:无法获得有效数据服务器接口");
                            return(null);
                        }

                        client.ice_ping();
                        _dataServant = client;

                        return(_dataServant);
                    }
                }
            }
            catch (Ice.ConnectionRefusedException)
            {
                //计算机积极拒绝,认为未部署鱼头,不进行记录。
                //Program.logger.LogRunning("DataServerClient:数据服务器连接失败\r\n  {0}", ex.InnerException.Message);
            }
            catch (Exception ex)
            {
                _dataServant = null;
                Program.logger.LogInfo(string.Format("DataServerClient:数据服务器连接失败\r\n  Message:{0}\r\n  StackTrace:{1}", ex.Message, ex.StackTrace));
            }
            return(null);
        }
コード例 #4
0
ファイル: client.cs プロジェクト: asdlei99/old-qreal-branches
    public override int run(string[] argc)
    {
        // Terminate cleanly on receipt of a signal
        //
        shutdownOnInterrupt();

        Ice.ObjectPrx obj     = communicator().stringToProxy("RepoApi:default -p 6667");
        RepoApiPrx    repoApi = RepoApiPrxHelper.checkedCast(obj);

        if (repoApi == null)
        {
            throw new ApplicationException("Invalid proxy");
        }
        Console.WriteLine(repoApi.ice_id());

        /*string[] typesList = repoClient.getAllTypes();
         * Console.WriteLine("Count: " + typesList.Length);
         * foreach (string type in typesList)
         * {
         *      RealTypeIcePrx realType = repoClient.getTypeById(type);
         *      Console.WriteLine("Type N" + type + ", Name: " + realType.getName()
         + ", Description: " + realType.getDescription()
         + ", Ident: " + realType.ice_getIdentity().name);
         + }*/

        string name = repoApi.name(ROOTID.value);

        Console.WriteLine(name);

        string[] children = repoApi.children(ROOTID.value);
        foreach (string child in children)
        {
            Console.WriteLine("Child: " + child + '\n');
        }



        if (interrupted())
        {
            Console.Error.WriteLine(appName() + ": terminating");
        }
        return(0);
    }
コード例 #5
0
    public static TestIntfPrx allTests(Ice.Communicator communicator)
#endif
    {
        Write("testing stringToProxy... ");
        Flush();
        string @ref = "asm:default -p 12010";

        Ice.ObjectPrx @base = communicator.stringToProxy(@ref);
        test(@base != null);
        WriteLine("ok");

        Write("testing checked cast... ");
        Flush();
        TestIntfPrx obj = TestIntfPrxHelper.checkedCast(@base);

        test(obj != null);
        test(obj.Equals(@base));
        WriteLine("ok");

        Write("testing ice_ids... ");
        Flush();
        try
        {
            Ice.ObjectPrx o = communicator.stringToProxy("category/locate:default -p 12010");
            o.ice_ids();
            test(false);
        }
        catch (UnknownUserException ex)
        {
            test(ex.unknown.Equals("::Test::TestIntfUserException"));
        }
        catch (System.Exception)
        {
            test(false);
        }

        try
        {
            Ice.ObjectPrx o = communicator.stringToProxy("category/finished:default -p 12010");
            o.ice_ids();
            test(false);
        }
        catch (UnknownUserException ex)
        {
            test(ex.unknown.Equals("::Test::TestIntfUserException"));
        }
        catch (System.Exception)
        {
            test(false);
        }
        WriteLine("ok");

        Write("testing servant locator...");
        Flush();
        @base = communicator.stringToProxy("category/locate:default -p 12010");
        obj   = TestIntfPrxHelper.checkedCast(@base);
        try
        {
            TestIntfPrxHelper.checkedCast(communicator.stringToProxy("category/unknown:default -p 12010"));
        }
        catch (ObjectNotExistException)
        {
        }
        WriteLine("ok");

        Write("testing default servant locator...");
        Flush();
        @base = communicator.stringToProxy("anothercat/locate:default -p 12010");
        obj   = TestIntfPrxHelper.checkedCast(@base);
        @base = communicator.stringToProxy("locate:default -p 12010");
        obj   = TestIntfPrxHelper.checkedCast(@base);
        try
        {
            TestIntfPrxHelper.checkedCast(communicator.stringToProxy("anothercat/unknown:default -p 12010"));
        }
        catch (ObjectNotExistException)
        {
        }
        try
        {
            TestIntfPrxHelper.checkedCast(communicator.stringToProxy("unknown:default -p 12010"));
        }
        catch (ObjectNotExistException)
        {
        }
        WriteLine("ok");

        Write("testing locate exceptions... ");
        Flush();
        @base = communicator.stringToProxy("category/locate:default -p 12010");
        obj   = TestIntfPrxHelper.checkedCast(@base);
        testExceptions(obj);
        WriteLine("ok");

        Write("testing finished exceptions... ");
        Flush();
        @base = communicator.stringToProxy("category/finished:default -p 12010");
        obj   = TestIntfPrxHelper.checkedCast(@base);
        testExceptions(obj);

        //
        // Only call these for category/finished.
        //
        try
        {
            obj.asyncResponse();
        }
        catch (TestIntfUserException)
        {
            test(false);
        }
        catch (TestImpossibleException)
        {
            //
            // Called by finished().
            //
        }

        //
        // Only call these for category/finished.
        //
        try
        {
            obj.asyncException();
        }
        catch (TestIntfUserException)
        {
            test(false);
        }
        catch (TestImpossibleException)
        {
            //
            // Called by finished().
            //
        }

        WriteLine("ok");

        Write("testing servant locator removal... ");
        Flush();
        @base = communicator.stringToProxy("test/activation:default -p 12010");
        TestActivationPrx activation = TestActivationPrxHelper.checkedCast(@base);

        activation.activateServantLocator(false);
        try
        {
            obj.ice_ping();
            test(false);
        }
        catch (ObjectNotExistException)
        {
            WriteLine("ok");
        }
        Write("testing servant locator addition... ");
        Flush();
        activation.activateServantLocator(true);
        try
        {
            obj.ice_ping();
            WriteLine("ok");
        }
        catch (System.Exception)
        {
            test(false);
        }
#if SILVERLIGHT
        obj.shutdown();
#else
        return(obj);
#endif
    }
コード例 #6
0
        /// <summary>
        /// Method setProperty
        /// </summary>
        /// <param name="propertyName">A  string</param>
        /// <param name="value">A  Ferda.Modules.PropertyValue</param>
        /// <param name="__current">An Ice.Current</param>
        public override void setProperty(String propertyName, PropertyValue value, Current __current)
        {
            if (! (propertyName == "value"))
            {
                throw new Ferda.Modules.NameNotExistError();
            }
            if (value!=null && !value.ice_isA(this.propertyClassIceId))
            {
                throw new Ferda.Modules.BadTypeError();
            }

            if(propertyValuePrx != null && propertySetByValue)
                adapter.remove(propertyValuePrx.ice_getIdentity());
            this.propertySetByValue = true;
            propertyValue = value;
            propertyValuePrx = this.adapter.addWithUUID(value);
        }
コード例 #7
0
 /// <summary>
 /// Method setConnection
 /// </summary>
 /// <param name="socketName">A  string</param>
 /// <param name="otherModule">A  Ferda.Modules.BoxModulePrx</param>
 /// <param name="__current">An Ice.Current</param>
 public override void setConnection(String socketName, BoxModulePrx otherModule, Current __current)
 {
     if (! (socketName == "value"))
     {
         throw new Ferda.Modules.NameNotExistError();
     }
     if(propertyValuePrx!= null && !propertySetByValue)
     {
         throw new Modules.ConnectionExistsError();
     }
     Ice.ObjectPrx prx = otherModule.getFunctions();
     if(!prx.ice_isA(this.propertyFunctionsIceIds[0]))
         throw new Ferda.Modules.BadTypeError();
     if(propertyValuePrx != null && propertySetByValue)
         adapter.remove(propertyValuePrx.ice_getIdentity());
     this.propertyValuePrx = prx;
     connectedBox = otherModule;
     this.propertySetByValue = false;
 }