Exemplo n.º 1
0
 /// <summary>
 /// 启动服务
 /// </summary>
 /// <param name="iceObj"></param>
 /// <param name="port"></param>
 /// <returns></returns>
 public static bool Start(Ice.Object iceObj, int port = 10000)
 {
     if (iceObj == null)
     {
         throw new ApplicationException("Invalid obj");
     }
     if (run == false)
     {
         Ice.Communicator ic = null;
         //初始化Ice runtime ,将args传递给这个调用,是因为服务器可能
         //有run time感兴趣的命令行参数,返回的是一个Ice.Communicator
         //它是Ice run time的主句柄
         ic = Ice.Util.initialize();
         //调用createObjectAdapterWithEndpoints创建一个对象适配器,传入的参数为SimplePrinter(适配器名称)
         //和default -p 10000或者是适配器使用缺省协议TCP/IP在端口10000侦听到来的请求
         Ice.ObjectAdapter adapter = ic.createObjectAdapterWithEndpoints("SimplePrinter", "default -p " + port);
         //这时,服务器端run time 已经初始化,我们实例化一个PrinterI 对
         //象,为我们的Printer 接口创建一个servant。
         //Ice.Object obj = new PrinterI();
         //我们调用适配器的add,告诉它有了一个新的servant ;传给add 的参
         //数是我们刚才实例化的servant,再加上一个标识符。在这里,
         //"SimplePrinter" 串是servant 的名字(如果我们有多个打印机,每个
         //打印机都会有不同的名字,更正确的说法是,都会有不同的对象标识)。
         adapter.add(iceObj, Ice.Util.stringToIdentity("SimplePrinter"));
         //我们调用适配器的activate 方法激活适配器(适配器一开
         //始是在扣留(holding)状态创建的;这种做法在下面这样的情况下很
         //有用:如果我们有多个servant,它们共享同一个适配器,而在所有
         //servant 实例化之前我们不想处理请求)。一旦适配器被激活,服务器就
         //会开始处理来自客户的请求。
         adapter.activate();
         run = true;
     }
     return(run);
 }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
        public override int run(string[] args)
        {
            Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Face");
            Ice.Object        servant = new MyFace();
            adapter.add(servant, communicator().stringToIdentity("myface"));
            adapter.activate();

            Console.Out.WriteLine("server start...");
            var task = CloudAPI.MegviiCloud.Login();

            if (task.Result)
            {
                var taskSatus = CloudAPI.MegviiCloud.GetAccountStatus();
                var status    = taskSatus.Result;
                Console.Out.WriteLine("剩余调用次数:" + status.data.limitation.quota);
                Console.Out.WriteLine("cloud compare service start...");
            }
            communicator().waitForShutdown();
            Console.Out.WriteLine("ending...");
            return(0);
        }
Exemplo n.º 4
0
        public override int run(string[] args)
        {
            Ice.Communicator ic = null;
            try
            {
                ic = Ice.Util.initialize(ref args);
                _registry = new HashRegistryImpl();
                _registry.SetCommunicator(ic);
                _adapter = ic.createObjectAdapterWithEndpoints("HashRegistry", args[0]);
                _adapter.add(_registry, ic.stringToIdentity("HashRegistry"));
                _adapter.activate();
                Console.WriteLine("Wystartowalen HashRegistry");
                ic.waitForShutdown();

                if (interrupted())
                    Console.WriteLine ("Koniec");
            } catch (System.Exception ex) {
                Console.WriteLine(ex);
            }

            return 0;
        }
Exemplo n.º 5
0
        public override int run(string []args)
        {
            HashModuleImpl srvHashModule = new HashModuleImpl();
            try
            {
                string endpoint = args[0];
                Ice.Communicator ic = Ice.Util.initialize(ref args);

                if (args.Length > 0)
                {
                    Console.WriteLine("service id: " + endpoint);
                    //srvHashModule.ID = Int32.Parse(args[0]);
                }

                /*
                Client cln = new Client(ic);
                _clientThread = new Thread(new ThreadStart(cln.Run));
                _clientThread.Start();
                */

                //polacz sie z registry
                //TODO: zweryfikować nazwę registry

                Ice.ObjectPrx obj = ic.stringToProxy (@"HashRegistry: tcp -h localhost -p 1231");
                Console.WriteLine("Registry proxy created");
                if (obj == null)
                {
                    Console.WriteLine("Created proxy is null");
                    return -1;
                }
                HashRegisterPrx registryModule = HashRegisterPrxHelper.checkedCast(obj.ice_twoway());
                if(registryModule == null)
                {
                    Console.WriteLine("Invalid proxy");
                    return -2;
                }

                //poproś o nadanie nazwy od naszego rejestru
                _hashNodeId = registryModule.getHashId(endpoint);
                srvHashModule.ID = _hashNodeId;

                //zarejestruj usługę w registry o otrzymanej nazwie:
                //_adapter.add(srvHashModule, Ice.Util.stringToIdentity(_myName));
                _adapter = ic.createObjectAdapterWithEndpoints("IceHash", endpoint);
                _adapter.add(srvHashModule, ic.stringToIdentity("IceHash"));
                _adapter.activate();
                Console.WriteLine("Wystartowalem serwer " + _hashNodeId);
                HashPrx local = HashPrxHelper.uncheckedCast(ic.stringToProxy(@"IceHash:" + endpoint));
                srvHashModule.SetOwnProxy(local);

                //sleep
                //Thread.Sleep(5 * 1000);

                //poproś o ileś nazw innych węzłów żeby pobrać dane
                int count = registryModule.getIceHashNodesCount();
                NodeInfo[] nodesInfo = registryModule.getIceHashNodesInfo(_hashNodeId, (int)((double)count * 0.5));
                Ice.ObjectPrx hashObj;
                if (nodesInfo.Length > 0)
                {
                    foreach(NodeInfo node in nodesInfo)
                    {
                        hashObj = ic.stringToProxy (@"IceHash:" + node.endpoint);
                        if (hashObj == null)
                        {
                            Console.WriteLine("IceHash proxy with endpoint {0} is null", node.endpoint);
                            return -1;
                        }
                        HashPrx hashModule = HashPrxHelper.checkedCast(hashObj.ice_twoway());
                        if(hashModule == null)
                        {
                            Console.WriteLine("Invalid proxy");
                            return -2;
                        }
                        Console.WriteLine("Utworzono proxy do IceHash:{0}", node.endpoint);
                        if (node.type == NodeType.Predecessor)
                        {
                            srvHashModule.SetPredecessor(hashModule);
                            HashPrx predecessor = srvHashModule.GetPredecessor();
                            RegisterResponse response = predecessor.SrvRegister(_hashNodeId, local);
                            srvHashModule.SetValues(response.values);
                            srvHashModule.SetRange(response.keysRange);
                            Console.WriteLine("Ustawiam lokalny range ({0}, {1})",
                            response.keysRange.startRange, response.keysRange.endRange);
                            srvHashModule.AddDirectNeighbors(node.id, hashModule);
                        }
                        else if (node.id != _hashNodeId)
                        {
                            Console.WriteLine("Dodaje hashProxy dla node {0}", node.id);
                            srvHashModule.AddDirectNeighbors(node.id, hashModule);
                        }
                    }
                }
                else
                {
                    //pierwszy wezel
                }

                if (srvHashModule.SrvGetRange().endRange == Int32.MaxValue)
                {
                    try
                    {
                        HashPrx prx = srvHashModule.SrvLookup(0);
                        if (prx == null)
                            Console.WriteLine("Lookup zwrocil null'a");
                        int nodeId = prx.SrvGetNodeId();
                        if (nodeId != _hashNodeId)
                            srvHashModule.AddDirectNeighbors(prx.SrvGetNodeId(), prx);
                    } catch (System.Exception) {
                        Console.WriteLine("Nie udalo sie dodac wezla 0");
                    }
                }
                srvHashModule.SetInitialized(true);
                ic.waitForShutdown();
            } catch (System.Exception ex) {
                Console.WriteLine(ex);
            }

            return 0;
        }
Exemplo n.º 6
0
        private void AddService(ref Ice.ObjectAdapter adapter)
        {
            var provider = lib.Provider.serviceProvider;

            adapter.add(provider.GetRequiredService <lib.IceBridge.Server>(), Ice.Util.stringToIdentity("Server"));
        }