Пример #1
0
Файл: Client.cs Проект: yzun/ice
    private static void allTests(Ice.Communicator communicator)
    {
        Console.Out.Write("testing equals() for Slice structures... ");
        Console.Out.Flush();

        //
        // Define some default values.
        //
        C  def_cls = new C(5);
        S1 def_s   = new S1("name");

        string[] def_ss = new string[] { "one", "two", "three" };
        int[]    def_il = new int[3];
        def_il[0] = 1;
        def_il[1] = 2;
        def_il[2] = 3;
        Dictionary <string, string> def_sd = new Dictionary <string, string>();

        def_sd.Add("abc", "def");
        var def_prx = Ice.IObjectPrx.Parse("test", communicator);
        S2  def_s2  = new S2(true, 98, 99, 100, 101, 1.0f, 2.0, "string", def_ss, def_il, def_sd, def_s, def_cls, def_prx);

        //
        // Compare default-constructed structures.
        //
        {
            test(new S2().Equals(new S2()));
        }

        Console.Out.WriteLine("ok");
    }
Пример #2
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);
 }
Пример #3
0
 //
 // Only for use by Instance.
 //
 internal OutgoingConnectionFactory(Ice.Communicator communicator)
 {
     _communicator        = communicator;
     _destroyed           = false;
     _monitor             = new FactoryACMMonitor(communicator, communicator.ClientACM);
     _pendingConnectCount = 0;
 }
Пример #4
0
 internal LoggerAdminI(Ice.Communicator communicator, LoggerAdminLoggerI logger)
 {
     _maxLogCount   = communicator.GetPropertyAsInt("Ice.Admin.Logger.KeepLogs") ?? 100;
     _maxTraceCount = communicator.GetPropertyAsInt("Ice.Admin.Logger.KeepTraces") ?? 100;
     _traceLevel    = communicator.GetPropertyAsInt("Ice.Trace.Admin.Logger") ?? 0;
     _logger        = logger;
 }
Пример #5
0
        private static Ice.Communicator createSendLogCommunicator(Ice.Communicator communicator, Ice.Logger logger)
        {
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.logger     = logger;
            initData.properties = Ice.Util.createProperties();

            Ice.Properties mainProps = communicator.Properties;

            copyProperties("Ice.Default.Locator", mainProps, initData.properties);
            copyProperties("Ice.Plugin.IceSSL", mainProps, initData.properties);
            copyProperties("IceSSL.", mainProps, initData.properties);

            string[] extraProps = mainProps.getPropertyAsList("Ice.Admin.Logger.Properties");

            if (extraProps.Length > 0)
            {
                for (int i = 0; i < extraProps.Length; ++i)
                {
                    string p = extraProps[i];
                    if (!p.StartsWith("--"))
                    {
                        extraProps[i] = "--" + p;
                    }
                }
                initData.properties.parseCommandLineOptions("", extraProps);
            }
            return(Ice.Util.initialize(initData));
        }
Пример #6
0
        /// <summary>
        /// Connect to ICE interface on running Murmur server
        /// </summary>
        /// <param name="address">murmur server address</param>
        /// <param name="port">ice port</param>
        /// <param name="secret">ice password</param>
        /// <param name="timeout"></param>
        /// <returns>object of murmur server</returns>
        public MetaPrx Connect(string address, int port, string secret, string callbackAddress = "127.0.0.1", int callbackPort = 0, int timeout = 1000)
        {
            this.timeout = timeout;

            // initialize
            run(new string[] { });

            ic = Ice.Util.initialize(_data);

            // set ice secret
            if (!string.IsNullOrEmpty(secret))
            {
                ic.getImplicitContext().put("secret", secret);
            }

            try
            {
                var connectionString = string.Format("Meta:tcp -h {0} -p {1} -t {2}", address, port, timeout);

                // Create a proxy
                var obj = ic.stringToProxy(connectionString);

                // Tests whether the target object of this proxy can be reached.
                obj.ice_ping();

                // initialize metadata of murmur server
                _meta = MetaPrxHelper.uncheckedCast(obj);


                var portString         = (callbackPort > 0) ? string.Format("-p {0}", callbackPort) : "";
                var connectionStringCB = string.Format("tcp -h {0} {1} -t {2}", callbackAddress, portString, timeout);

                // Create the callback adapter
                ic.getProperties().setProperty("Ice.PrintAdapterReady", "0");
                _adapter = ic.createObjectAdapterWithEndpoints("Callback.Client", connectionStringCB);
                _adapter.activate();

                _meta.ice_ping();
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.ToString());
                throw new MurmurPlugin.ConnectionRefusedException();
            }

            // FIXME: check for valid ice secret, because getLogLen() is working only if "icesecretwrite" is valid
            //  (there a secure hole - get methods allowed if "icesecretread" is not set)
            //  if secret is invalid it throws UnmarshalOutOfBoundsException();
            try
            {
                // set allowhtml property to the server to check ice writesecret
                _meta.getAllServers()[0].setConf("allowhtml", "true");
            }
            catch
            {
                throw new MurmurPlugin.InvalidSecretException();
            }

            return(_meta);
        }
Пример #7
0
        public static void ValidateProperties(string prefix, Ice.Communicator communicator)
        {
            Dictionary <string, string> props = communicator.GetProperties(forPrefix: prefix);
            var unknownProps = new List <string>();

            foreach (string prop in props.Keys)
            {
                bool valid = false;
                foreach (string suffix in _suffixes)
                {
                    if (IceUtilInternal.StringUtil.Match(prop, prefix + suffix, false))
                    {
                        valid = true;
                        break;
                    }
                }

                if (!valid)
                {
                    unknownProps.Add(prop);
                }
            }

            if (unknownProps.Count != 0 && (communicator.GetPropertyAsBool("Ice.Warn.UnknownProperties") ?? true))
            {
                var message = new StringBuilder("found unknown IceMX properties for `");
                message.Append(prefix[0..^ 1]);
Пример #8
0
 /// <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);
 }
Пример #9
0
        //
        // Change this proxy's communicator, while keeping its invocation timeout
        //
        private static RemoteLoggerPrx changeCommunicator(Ice.RemoteLoggerPrx prx, Ice.Communicator communicator)
        {
            if (prx == null)
            {
                return(null);
            }

            return(RemoteLoggerPrx.Parse(prx.ToString(), communicator).Clone(invocationTimeout: prx.InvocationTimeout));
        }
Пример #10
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);
        }
Пример #11
0
 public TransportInstance(Ice.Communicator communicator, EndpointType type, string transport, bool secure)
 {
     Communicator  = communicator;
     TraceLevel    = Communicator.TraceLevels.Network;
     TraceCategory = Communicator.TraceLevels.NetworkCat;
     Logger        = Communicator.Logger;
     Type          = type;
     Transport     = transport;
     Secure        = secure;
 }
Пример #12
0
        private Dictionary <string, Regex> ParseRule(Ice.Communicator communicator, string name)
        {
            var pats = new Dictionary <string, Regex>();
            Dictionary <string, string> rules = communicator.GetProperties(forPrefix: $"{name}.");

            foreach (KeyValuePair <string, string> e in rules)
            {
                pats.Add(e.Key.Substring(name.Length + 1), new Regex(e.Value));
            }
            return(pats);
        }
Пример #13
0
    public static void allTests(Test.TestHelper helper)
    {
        Ice.Communicator communicator = helper.communicator();
        string           sref         = "test:" + helper.getTestEndpoint(0);
        var obj = IObjectPrx.Parse(sref, communicator);

        test(obj != null);

        int proxyPort = communicator.Properties.getPropertyAsInt("Ice.HTTPProxyPort");

        if (proxyPort == 0)
        {
            proxyPort = communicator.Properties.getPropertyAsInt("Ice.SOCKSProxyPort");
        }

        Test.TestIntfPrx testPrx = Test.TestIntfPrx.CheckedCast(obj);
        var output = helper.getWriter();

        output.Write("testing connection... ");
        output.Flush();
        {
            testPrx.IcePing();
        }
        output.WriteLine("ok");

        output.Write("testing connection information... ");
        output.Flush();
        {
            Ice.IPConnectionInfo info = getIPConnectionInfo(testPrx.GetConnection().getInfo());
            test(info.remotePort == proxyPort); // make sure we are connected to the proxy port.
        }
        output.WriteLine("ok");

        output.Write("shutting down server... ");
        output.Flush();
        {
            testPrx.shutdown();
        }
        output.WriteLine("ok");

        output.Write("testing connection failure... ");
        output.Flush();
        {
            try
            {
                testPrx.IcePing();
                test(false);
            }
            catch (Ice.LocalException)
            {
            }
        }
        output.WriteLine("ok");
    }
Пример #14
0
        public async Task Connect(string[] args)
        {
            await Task.Yield();

            communicator = Ice.Util.initialize(ref args);
            Ice.Identity id    = new Ice.Identity();
            var          proxy = communicator.stringToProxy("Server:default -h localhost -p 10000");

            _server = ServerPrxHelper.checkedCast(proxy);
            adapter = communicator.createObjectAdapterWithEndpoints("TreeDiagramClient", "default -p 10008");
            adapter.activate();
            serverEvent = ServerEventPrxHelper.uncheckedCast(
                adapter.addWithUUID(
                    lib.Provider.serviceProvider.GetRequiredService <lib.IceBridge.ServerEvent>()));
            _server.initEvent(uuid, serverEvent);
        }
Пример #15
0
 protected OutgoingAsyncBase(Ice.Communicator communicator, IOutgoingAsyncCompletionCallback completionCallback,
                             Ice.OutputStream?os = null, Ice.InputStream?iss = null)
 {
     Communicator       = communicator;
     sentSynchronously_ = false;
     Synchronous        = false;
     _doneInSent        = false;
     _alreadySent       = false;
     State = 0;
     Os    = os ?? new Ice.OutputStream(communicator, Ice.Util.CurrentProtocolEncoding);
     Is    = iss ?? new Ice.InputStream(communicator, Ice.Util.CurrentProtocolEncoding);
     _completionCallback = completionCallback;
     if (_completionCallback != null)
     {
         _completionCallback.Init(this);
     }
 }
Пример #16
0
 protected OutgoingAsyncBase(Ice.Communicator communicator, IOutgoingAsyncCompletionCallback completionCallback,
                             OutgoingRequestFrame?requestFrame = null, List <ArraySegment <byte> >?requestData = null,
                             Ice.InputStream?iss = null)
 {
     Communicator      = communicator;
     SentSynchronously = false;
     Synchronous       = false;
     _doneInSent       = false;
     _alreadySent      = false;
     State             = 0;
     RequestFrame      = requestFrame;
     RequestData       = requestData;
     Is = iss ?? new Ice.InputStream(communicator, Ice.Ice1Definitions.Encoding);
     _completionCallback = completionCallback;
     if (_completionCallback != null)
     {
         _completionCallback.Init(this);
     }
 }
Пример #17
0
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            string[] args = new string[1] {
                "arg"
            };
            //try
            //{
            //    ic = Ice.Util.initialize(ref args);
            //    if (ic == null)
            //    {
            //        Debug.Assert(false, "初始化失败");
            //        return;
            //    }

            //    Ice.ObjectPrx pxy = ic.stringToProxy("myface:default -p 9996");
            //    facePxy = FaceRecognitionPrxHelper.checkedCast(pxy);
            //    if (facePxy == null)
            //    {
            //        Debug.Assert(false, "代理为空");
            //        return;
            //    }
            //}
            //catch (System.Exception ex)
            //{
            //    Debug.Assert(false, "初始化失败");
            //    return;
            //}

            Task.Factory.StartNew(() =>
            {
                client = new Client(Item);
                client.main(args, "config.client");
            });

            Task.Factory.StartNew(() =>
            {
                Thread.Sleep(1000);
                this.ic      = client.ic;
                this.facePxy = client.facePxy;
            });
        }
Пример #18
0
 public static int Main(string[] args)
 {
     try
     {
         using (Ice.Communicator communicator = Ice.Util.initialize(ref args))
         {
             var adapter =
                 communicator.createObjectAdapterWithEndpoints("SimplePrinterAdapter",
                                                               "default -h localhost -p 10000");
             adapter.add(new PrinterI(), Ice.Util.stringToIdentity("SimplePrinter"));
             adapter.activate();
             communicator.waitForShutdown();
         }
     }
     catch (System.Exception ex)
     {
         Console.Error.WriteLine(ex);
         return(1);
     }
     return(0);
 }
Пример #19
0
        public async static Task StartService(string[] args)
        {
            Console.WriteLine("StartIceServer");
            await Task.Yield();

            var config = Config.IceAdapterConfig.Config;

            Console.WriteLine($"IceServer.name = \"{config.name}\"");
            using (Ice.Communicator communicator = Ice.Util.initialize(ref args))
                using (IceService iceService = new IceService())
                {
                    iceService.start(config.name, communicator, args);
                    Console.WriteLine("Ice server listening");
                    await iceService.client.Connect(args);

                    await Task.Factory.StartNew(() =>
                    {
                        communicator.waitForShutdown();
                    });
                }
        }
Пример #20
0
        public LookupI(LocatorRegistryI registry, LookupPrx lookup, Ice.Communicator communicator)
        {
            _registry          = registry;
            _lookup            = lookup;
            _timeout           = communicator.GetPropertyAsInt("IceDiscovery.Timeout") ?? 300;
            _retryCount        = communicator.GetPropertyAsInt("IceDiscovery.RetryCount") ?? 3;
            _latencyMultiplier = communicator.GetPropertyAsInt("IceDiscovery.LatencyMultiplier") ?? 1;
            _domainId          = communicator.GetProperty("IceDiscovery.DomainId") ?? "";
            _timer             = lookup.Communicator.timer();

            //
            // Create one lookup proxy per endpoint from the given proxy. We want to send a multicast
            // datagram on each endpoint.
            //
            var single = new Ice.Endpoint[1];

            foreach (var endpt in lookup.Endpoints)
            {
                single[0] = endpt;
                _lookups[lookup.Clone(endpoints: single)] = null;
            }
            Debug.Assert(_lookups.Count > 0);
        }
Пример #21
0
        internal void destroy()
        {
            Ice.Communicator sendLogCommunicator = null;

            lock (this)
            {
                if (!_destroyed)
                {
                    _destroyed           = true;
                    sendLogCommunicator  = _sendLogCommunicator;
                    _sendLogCommunicator = null;
                }
            }

            //
            // Destroy outside lock to avoid deadlock when there are outstanding two-way log calls sent to
            // remote loggers
            //
            if (sendLogCommunicator != null)
            {
                sendLogCommunicator.destroy();
            }
        }
Пример #22
0
 public BasePluginFail(Ice.Communicator communicator)
 {
     _communicator = communicator;
     _initialized = false;
     _destroyed = false;
 }
Пример #23
0
    allTests(Test.TestHelper helper, int num)
    {
        var output = helper.getWriter();

        Ice.Communicator      communicator    = helper.communicator();
        List <IControllerPrx> proxies         = new List <IControllerPrx>();
        List <IControllerPrx> indirectProxies = new List <IControllerPrx>();

        for (int i = 0; i < num; ++i)
        {
            string id = "controller" + i;
            proxies.Add(IControllerPrx.Parse(id, communicator));
            indirectProxies.Add(IControllerPrx.Parse($"{id}@control{i}", communicator));
        }

        output.Write("testing indirect proxies... ");
        output.Flush();
        {
            foreach (IControllerPrx prx in indirectProxies)
            {
                prx.IcePing();
            }
        }
        output.WriteLine("ok");

        output.Write("testing well-known proxies... ");
        output.Flush();
        {
            foreach (IControllerPrx prx in proxies)
            {
                prx.IcePing();
            }
        }
        output.WriteLine("ok");

        output.Write("testing object adapter registration... ");
        output.Flush();
        {
            try
            {
                IObjectPrx.Parse("object @ oa1", communicator).IcePing();
                test(false);
            }
            catch (NoEndpointException)
            {
            }

            proxies[0].activateObjectAdapter("oa", "oa1", "");

            try
            {
                IObjectPrx.Parse("object @ oa1", communicator).IcePing();
                test(false);
            }
            catch (ObjectNotExistException)
            {
            }

            proxies[0].deactivateObjectAdapter("oa");

            try
            {
                IObjectPrx.Parse("object @ oa1", communicator).IcePing();
                test(false);
            }
            catch (NoEndpointException)
            {
            }
        }
        output.WriteLine("ok");

        output.Write("testing object adapter migration...");
        output.Flush();
        {
            proxies[0].activateObjectAdapter("oa", "oa1", "");
            proxies[0].addObject("oa", "object");
            IObjectPrx.Parse("object @ oa1", communicator).IcePing();
            proxies[0].removeObject("oa", "object");
            proxies[0].deactivateObjectAdapter("oa");

            proxies[1].activateObjectAdapter("oa", "oa1", "");
            proxies[1].addObject("oa", "object");
            IObjectPrx.Parse("object @ oa1", communicator).IcePing();
            proxies[1].removeObject("oa", "object");
            proxies[1].deactivateObjectAdapter("oa");
        }
        output.WriteLine("ok");

        output.Write("testing object migration...");
        output.Flush();
        {
            proxies[0].activateObjectAdapter("oa", "oa1", "");
            proxies[1].activateObjectAdapter("oa", "oa2", "");

            proxies[0].addObject("oa", "object");
            IObjectPrx.Parse("object @ oa1", communicator).IcePing();
            IObjectPrx.Parse("object", communicator).IcePing();
            proxies[0].removeObject("oa", "object");

            proxies[1].addObject("oa", "object");
            IObjectPrx.Parse("object @ oa2", communicator).IcePing();
            IObjectPrx.Parse("object", communicator).IcePing();
            proxies[1].removeObject("oa", "object");

            try
            {
                IObjectPrx.Parse("object @ oa1", communicator).IcePing();
            }
            catch (ObjectNotExistException)
            {
            }
            try
            {
                IObjectPrx.Parse("object @ oa2", communicator).IcePing();
            }
            catch (ObjectNotExistException)
            {
            }

            proxies[0].deactivateObjectAdapter("oa");
            proxies[1].deactivateObjectAdapter("oa");
        }
        output.WriteLine("ok");

        output.Write("testing replica groups...");
        output.Flush();
        {
            proxies[0].activateObjectAdapter("oa", "oa1", "rg");
            proxies[1].activateObjectAdapter("oa", "oa2", "rg");
            proxies[2].activateObjectAdapter("oa", "oa3", "rg");

            proxies[0].addObject("oa", "object");
            proxies[1].addObject("oa", "object");
            proxies[2].addObject("oa", "object");

            IObjectPrx.Parse("object @ oa1", communicator).IcePing();
            IObjectPrx.Parse("object @ oa2", communicator).IcePing();
            IObjectPrx.Parse("object @ oa3", communicator).IcePing();

            IObjectPrx.Parse("object @ rg", communicator).IcePing();

            List <string> adapterIds = new List <string>();
            adapterIds.Add("oa1");
            adapterIds.Add("oa2");
            adapterIds.Add("oa3");
            ITestIntfPrx intf = ITestIntfPrx.Parse("object", communicator).Clone(
                connectionCached: false,
                locatorCacheTimeout: 0);
            while (adapterIds.Count > 0)
            {
                adapterIds.Remove(intf.getAdapterId());
            }

            while (true)
            {
                adapterIds.Add("oa1");
                adapterIds.Add("oa2");
                adapterIds.Add("oa3");
                intf = ITestIntfPrx.Parse("object @ rg", communicator).Clone(connectionCached: false);
                int nRetry = 100;
                while (adapterIds.Count > 0 && --nRetry > 0)
                {
                    adapterIds.Remove(intf.getAdapterId());
                }
                if (nRetry > 0)
                {
                    break;
                }

                // The previous locator lookup probably didn't return all the replicas... try again.
                IObjectPrx.Parse("object @ rg", communicator).Clone(locatorCacheTimeout: 0).IcePing();
            }

            proxies[0].deactivateObjectAdapter("oa");
            proxies[1].deactivateObjectAdapter("oa");
            test(ITestIntfPrx.Parse("object @ rg", communicator).getAdapterId().Equals("oa3"));
            proxies[2].deactivateObjectAdapter("oa");

            proxies[0].activateObjectAdapter("oa", "oa1", "rg");
            proxies[0].addObject("oa", "object");
            test(ITestIntfPrx.Parse("object @ rg", communicator).getAdapterId().Equals("oa1"));
            proxies[0].deactivateObjectAdapter("oa");
        }
        output.WriteLine("ok");

        output.Write("testing invalid lookup endpoints... ");
        output.Flush();
        {
            string multicast;
            if (communicator.GetProperty("Ice.IPv6") == "1")
            {
                multicast = "\"ff15::1\"";
            }
            else
            {
                multicast = "239.255.0.1";
            }

            {
                var properties = communicator.GetProperties();
                properties["IceDiscovery.Lookup"] = $"udp -h {multicast} --interface unknown";
                Communicator comm = new Communicator(properties);
                test(comm.GetDefaultLocator() != null);
                try
                {
                    IObjectPrx.Parse("controller0@control0", comm).IcePing();
                    test(false);
                }
                catch (LocalException)
                {
                }
                comm.Destroy();
            }
            {
                var    properties = communicator.GetProperties();
                string intf       = communicator.GetProperty("IceDiscovery.Interface") ?? "";
                if (intf != "")
                {
                    intf = $" --interface \"{intf}\"";
                }
                string port = communicator.GetProperty("IceDiscovery.Port") ?? "";
                properties["IceDiscovery.Lookup"] =
                    $"udp -h {multicast} --interface unknown:udp -h {multicast} -p {port}{intf}";
                Communicator comm = new Communicator(properties);
                test(comm.GetDefaultLocator() != null);
                IObjectPrx.Parse("controller0@control0", comm).IcePing();
                comm.Destroy();
            }
        }
        output.WriteLine("ok");

        output.Write("shutting down... ");
        output.Flush();
        foreach (IControllerPrx prx in proxies)
        {
            prx.shutdown();
        }
        output.WriteLine("ok");
    }
Пример #24
0
 PluginI(string name, Ice.Communicator communicator)
 {
     _name         = name;
     _communicator = communicator;
 }
Пример #25
0
 create(Ice.Communicator communicator, string name, string[] args)
 {
     return(new PluginI(name, communicator));
 }
Пример #26
0
    public static TestIntfPrx allTests(Test.TestHelper helper, bool collocated)
    {
        Ice.Communicator communicator = helper.communicator();
        var output = helper.getWriter();

        output.Write("testing stringToProxy... ");
        output.Flush();
        string @ref  = "Test:" + helper.getTestEndpoint(0) + " -t 2000";
        var    @base = IObjectPrx.Parse(@ref, communicator);

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

        output.Write("testing checked cast... ");
        output.Flush();
        TestIntfPrx testPrx = TestIntfPrx.CheckedCast(@base);

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

        output.Write("base... ");
        output.Flush();
        {
            try
            {
                testPrx.baseAsBase();
                test(false);
            }
            catch (Base b)
            {
                test(b.b.Equals("Base.b"));
                test(b.GetType().FullName.Equals("Test.Base"));
            }
            catch (System.Exception)
            {
                test(false);
            }
        }
        output.WriteLine("ok");

        output.Write("base (AMI)... ");
        output.Flush();
        {
            try
            {
                testPrx.baseAsBaseAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (Base b)
                {
                    test(b.b.Equals("Base.b"));
                    test(b.GetType().Name.Equals("Base"));
                }
                catch (System.Exception)
                {
                    test(false);
                }
            }
        }
        output.WriteLine("ok");

        output.Write("slicing of unknown derived... ");
        output.Flush();
        {
            try
            {
                testPrx.unknownDerivedAsBase();
                test(false);
            }
            catch (Base b)
            {
                test(b.b.Equals("UnknownDerived.b"));
                test(b.GetType().FullName.Equals("Test.Base"));
            }
            catch (System.Exception)
            {
                test(false);
            }
        }
        output.WriteLine("ok");

        output.Write("slicing of unknown derived (AMI)... ");
        output.Flush();
        {
            try
            {
                testPrx.unknownDerivedAsBaseAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (Base b)
                {
                    test(b.b.Equals("UnknownDerived.b"));
                    test(b.GetType().Name.Equals("Base"));
                }
                catch (System.Exception)
                {
                    test(false);
                }
            }
        }
        output.WriteLine("ok");

        output.Write("non-slicing of known derived as base... ");
        output.Flush();
        {
            try
            {
                testPrx.knownDerivedAsBase();
                test(false);
            }
            catch (KnownDerived k)
            {
                test(k.b.Equals("KnownDerived.b"));
                test(k.kd.Equals("KnownDerived.kd"));
                test(k.GetType().FullName.Equals("Test.KnownDerived"));
            }
            catch (System.Exception)
            {
                test(false);
            }
        }
        output.WriteLine("ok");

        output.Write("non-slicing of known derived as base (AMI)... ");
        output.Flush();
        {
            try
            {
                testPrx.knownDerivedAsBaseAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (KnownDerived k)
                {
                    test(k.b.Equals("KnownDerived.b"));
                    test(k.kd.Equals("KnownDerived.kd"));
                    test(k.GetType().Name.Equals("KnownDerived"));
                }
                catch (System.Exception)
                {
                    test(false);
                }
            }
        }
        output.WriteLine("ok");

        output.Write("non-slicing of known derived as derived... ");
        output.Flush();
        {
            try
            {
                testPrx.knownDerivedAsKnownDerived();
                test(false);
            }
            catch (KnownDerived k)
            {
                test(k.b.Equals("KnownDerived.b"));
                test(k.kd.Equals("KnownDerived.kd"));
                test(k.GetType().FullName.Equals("Test.KnownDerived"));
            }
            catch (System.Exception)
            {
                test(false);
            }
        }
        output.WriteLine("ok");

        output.Write("non-slicing of known derived as derived (AMI)... ");
        output.Flush();
        {
            try
            {
                testPrx.knownDerivedAsKnownDerivedAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (KnownDerived k)
                {
                    test(k.b.Equals("KnownDerived.b"));
                    test(k.kd.Equals("KnownDerived.kd"));
                    test(k.GetType().Name.Equals("KnownDerived"));
                }
                catch (System.Exception)
                {
                    test(false);
                }
            }
        }
        output.WriteLine("ok");

        output.Write("slicing of unknown intermediate as base... ");
        output.Flush();
        {
            try
            {
                testPrx.unknownIntermediateAsBase();
                test(false);
            }
            catch (Base b)
            {
                test(b.b.Equals("UnknownIntermediate.b"));
                test(b.GetType().FullName.Equals("Test.Base"));
            }
            catch (System.Exception)
            {
                test(false);
            }
        }
        output.WriteLine("ok");

        output.Write("slicing of unknown intermediate as base (AMI)... ");
        output.Flush();
        {
            try
            {
                testPrx.unknownIntermediateAsBaseAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (Base b)
                {
                    test(b.b.Equals("UnknownIntermediate.b"));
                    test(b.GetType().Name.Equals("Base"));
                }
                catch (System.Exception)
                {
                    test(false);
                }
            }
        }
        output.WriteLine("ok");

        output.Write("slicing of known intermediate as base... ");
        output.Flush();
        {
            try
            {
                testPrx.knownIntermediateAsBase();
                test(false);
            }
            catch (KnownIntermediate ki)
            {
                test(ki.b.Equals("KnownIntermediate.b"));
                test(ki.ki.Equals("KnownIntermediate.ki"));
                test(ki.GetType().FullName.Equals("Test.KnownIntermediate"));
            }
            catch (System.Exception)
            {
                test(false);
            }
        }
        output.WriteLine("ok");

        output.Write("slicing of known intermediate as base (AMI)... ");
        output.Flush();
        {
            try
            {
                testPrx.knownIntermediateAsBaseAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (KnownIntermediate ki)
                {
                    test(ki.b.Equals("KnownIntermediate.b"));
                    test(ki.ki.Equals("KnownIntermediate.ki"));
                    test(ki.GetType().Name.Equals("KnownIntermediate"));
                }
                catch (System.Exception)
                {
                    test(false);
                }
            }
        }
        output.WriteLine("ok");

        output.Write("slicing of known most derived as base... ");
        output.Flush();
        {
            try
            {
                testPrx.knownMostDerivedAsBase();
                test(false);
            }
            catch (KnownMostDerived kmd)
            {
                test(kmd.b.Equals("KnownMostDerived.b"));
                test(kmd.ki.Equals("KnownMostDerived.ki"));
                test(kmd.kmd.Equals("KnownMostDerived.kmd"));
                test(kmd.GetType().FullName.Equals("Test.KnownMostDerived"));
            }
            catch (System.Exception)
            {
                test(false);
            }
        }
        output.WriteLine("ok");

        output.Write("slicing of known most derived as base (AMI)... ");
        output.Flush();
        {
            try
            {
                testPrx.knownMostDerivedAsBaseAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (KnownMostDerived kmd)
                {
                    test(kmd.b.Equals("KnownMostDerived.b"));
                    test(kmd.ki.Equals("KnownMostDerived.ki"));
                    test(kmd.kmd.Equals("KnownMostDerived.kmd"));
                    test(kmd.GetType().Name.Equals("KnownMostDerived"));
                }
                catch (System.Exception)
                {
                    test(false);
                }
            }
        }
        output.WriteLine("ok");

        output.Write("non-slicing of known intermediate as intermediate... ");
        output.Flush();
        {
            try
            {
                testPrx.knownIntermediateAsKnownIntermediate();
                test(false);
            }
            catch (KnownIntermediate ki)
            {
                test(ki.b.Equals("KnownIntermediate.b"));
                test(ki.ki.Equals("KnownIntermediate.ki"));
                test(ki.GetType().FullName.Equals("Test.KnownIntermediate"));
            }
            catch (System.Exception)
            {
                test(false);
            }
        }
        output.WriteLine("ok");

        output.Write("non-slicing of known intermediate as intermediate (AMI)... ");
        output.Flush();
        {
            try
            {
                testPrx.knownIntermediateAsKnownIntermediateAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (KnownIntermediate ki)
                {
                    test(ki.b.Equals("KnownIntermediate.b"));
                    test(ki.ki.Equals("KnownIntermediate.ki"));
                    test(ki.GetType().Name.Equals("KnownIntermediate"));
                }
                catch (System.Exception)
                {
                    test(false);
                }
            }
        }
        output.WriteLine("ok");

        output.Write("non-slicing of known most derived as intermediate... ");
        output.Flush();
        {
            try
            {
                testPrx.knownMostDerivedAsKnownIntermediate();
                test(false);
            }
            catch (KnownMostDerived kmd)
            {
                test(kmd.b.Equals("KnownMostDerived.b"));
                test(kmd.ki.Equals("KnownMostDerived.ki"));
                test(kmd.kmd.Equals("KnownMostDerived.kmd"));
                test(kmd.GetType().FullName.Equals("Test.KnownMostDerived"));
            }
            catch (System.Exception)
            {
                test(false);
            }
        }
        output.WriteLine("ok");

        output.Write("non-slicing of known most derived as intermediate (AMI)... ");
        output.Flush();
        {
            try
            {
                testPrx.knownMostDerivedAsKnownIntermediateAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (KnownMostDerived kmd)
                {
                    test(kmd.b.Equals("KnownMostDerived.b"));
                    test(kmd.ki.Equals("KnownMostDerived.ki"));
                    test(kmd.kmd.Equals("KnownMostDerived.kmd"));
                    test(kmd.GetType().Name.Equals("KnownMostDerived"));
                }
                catch (System.Exception)
                {
                    test(false);
                }
            }
        }
        output.WriteLine("ok");

        output.Write("non-slicing of known most derived as most derived... ");
        output.Flush();
        {
            try
            {
                testPrx.knownMostDerivedAsKnownMostDerived();
                test(false);
            }
            catch (KnownMostDerived kmd)
            {
                test(kmd.b.Equals("KnownMostDerived.b"));
                test(kmd.ki.Equals("KnownMostDerived.ki"));
                test(kmd.kmd.Equals("KnownMostDerived.kmd"));
                test(kmd.GetType().FullName.Equals("Test.KnownMostDerived"));
            }
            catch (System.Exception)
            {
                test(false);
            }
        }
        output.WriteLine("ok");

        output.Write("non-slicing of known most derived as most derived (AMI)... ");
        output.Flush();
        {
            try
            {
                testPrx.knownMostDerivedAsKnownMostDerivedAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (KnownMostDerived kmd)
                {
                    test(kmd.b.Equals("KnownMostDerived.b"));
                    test(kmd.ki.Equals("KnownMostDerived.ki"));
                    test(kmd.kmd.Equals("KnownMostDerived.kmd"));
                    test(kmd.GetType().Name.Equals("KnownMostDerived"));
                }
                catch (System.Exception)
                {
                    test(false);
                }
            }
        }
        output.WriteLine("ok");

        output.Write("slicing of unknown most derived, known intermediate as base... ");
        output.Flush();
        {
            try
            {
                testPrx.unknownMostDerived1AsBase();
                test(false);
            }
            catch (KnownIntermediate ki)
            {
                test(ki.b.Equals("UnknownMostDerived1.b"));
                test(ki.ki.Equals("UnknownMostDerived1.ki"));
                test(ki.GetType().FullName.Equals("Test.KnownIntermediate"));
            }
            catch (System.Exception)
            {
                test(false);
            }
        }
        output.WriteLine("ok");

        output.Write("slicing of unknown most derived, known intermediate as base (AMI)... ");
        output.Flush();
        {
            try
            {
                testPrx.unknownMostDerived1AsBaseAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (KnownIntermediate ki)
                {
                    test(ki.b.Equals("UnknownMostDerived1.b"));
                    test(ki.ki.Equals("UnknownMostDerived1.ki"));
                    test(ki.GetType().Name.Equals("KnownIntermediate"));
                }
                catch (System.Exception)
                {
                    test(false);
                }
            }
        }
        output.WriteLine("ok");

        output.Write("slicing of unknown most derived, known intermediate as intermediate... ");
        output.Flush();
        {
            try
            {
                testPrx.unknownMostDerived1AsKnownIntermediate();
                test(false);
            }
            catch (KnownIntermediate ki)
            {
                test(ki.b.Equals("UnknownMostDerived1.b"));
                test(ki.ki.Equals("UnknownMostDerived1.ki"));
                test(ki.GetType().FullName.Equals("Test.KnownIntermediate"));
            }
            catch (System.Exception)
            {
                test(false);
            }
        }
        output.WriteLine("ok");

        output.Write("slicing of unknown most derived, known intermediate as intermediate (AMI)... ");
        output.Flush();
        {
            try
            {
                testPrx.unknownMostDerived1AsKnownIntermediateAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (KnownIntermediate ki)
                {
                    test(ki.b.Equals("UnknownMostDerived1.b"));
                    test(ki.ki.Equals("UnknownMostDerived1.ki"));
                    test(ki.GetType().Name.Equals("KnownIntermediate"));
                }
                catch (System.Exception)
                {
                    test(false);
                }
            }
        }
        output.WriteLine("ok");

        output.Write("slicing of unknown most derived, unknown intermediate thrown as base... ");
        output.Flush();
        {
            try
            {
                testPrx.unknownMostDerived2AsBase();
                test(false);
            }
            catch (Base b)
            {
                test(b.b.Equals("UnknownMostDerived2.b"));
                test(b.GetType().FullName.Equals("Test.Base"));
            }
            catch (System.Exception)
            {
                test(false);
            }
        }
        output.WriteLine("ok");

        output.Write("slicing of unknown most derived, unknown intermediate thrown as base (AMI)... ");
        output.Flush();
        {
            try
            {
                testPrx.unknownMostDerived2AsBaseAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (Base b)
                {
                    test(b.b.Equals("UnknownMostDerived2.b"));
                    test(b.GetType().Name.Equals("Base"));
                }
                catch (System.Exception)
                {
                    test(false);
                }
            }
        }
        output.WriteLine("ok");

        output.Write("unknown most derived in compact format... ");
        output.Flush();
        {
            try
            {
                testPrx.unknownMostDerived2AsBaseCompact();
                test(false);
            }
            catch (Base)
            {
                //
                // For the 1.0 encoding, the unknown exception is sliced to Base.
                //
                test(testPrx.EncodingVersion.Equals(Ice.Util.Encoding_1_0));
            }
            catch (Ice.UnknownUserException)
            {
                //
                // A MarshalException is raised for the compact format because the
                // most-derived type is unknown and the exception cannot be sliced.
                //
                test(!testPrx.EncodingVersion.Equals(Ice.Util.Encoding_1_0));
            }
            catch (Ice.OperationNotExistException)
            {
            }
            catch (System.Exception)
            {
                test(false);
            }
        }
        output.WriteLine("ok");

        output.Write("preserved exceptions... ");
        output.Flush();
        {
            try
            {
                testPrx.unknownPreservedAsBase();
                test(false);
            }
            catch (Base ex)
            {
                if (testPrx.EncodingVersion.Equals(Ice.Util.Encoding_1_0))
                {
                    test(ex.ice_getSlicedData() == null);
                }
                else
                {
                    Ice.SlicedData slicedData = ex.ice_getSlicedData();
                    test(slicedData != null);
                    test(slicedData.slices.Length == 2);
                    test(slicedData.slices[1].typeId.Equals("::Test::SPreserved1"));
                    test(slicedData.slices[0].typeId.Equals("::Test::SPreserved2"));
                }
            }

            try
            {
                testPrx.unknownPreservedAsKnownPreserved();
                test(false);
            }
            catch (KnownPreserved ex)
            {
                test(ex.kp.Equals("preserved"));
                if (testPrx.EncodingVersion.Equals(Ice.Util.Encoding_1_0))
                {
                    test(ex.ice_getSlicedData() == null);
                }
                else
                {
                    Ice.SlicedData slicedData = ex.ice_getSlicedData();
                    test(slicedData != null);
                    test(slicedData.slices.Length == 2);
                    test(slicedData.slices[1].typeId.Equals("::Test::SPreserved1"));
                    test(slicedData.slices[0].typeId.Equals("::Test::SPreserved2"));
                }
            }

            Ice.ObjectAdapter adapter = communicator.createObjectAdapter("");
            RelayPrx          relay   = adapter.Add(new RelayI());
            adapter.Activate();
            testPrx.GetConnection().setAdapter(adapter);

            try
            {
                testPrx.relayKnownPreservedAsBase(relay);
                test(false);
            }
            catch (KnownPreservedDerived ex)
            {
                test(ex.b.Equals("base"));
                test(ex.kp.Equals("preserved"));
                test(ex.kpd.Equals("derived"));
            }
            catch (Ice.OperationNotExistException)
            {
            }
            catch (System.Exception)
            {
                test(false);
            }

            try
            {
                testPrx.relayKnownPreservedAsKnownPreserved(relay);
                test(false);
            }
            catch (KnownPreservedDerived ex)
            {
                test(ex.b.Equals("base"));
                test(ex.kp.Equals("preserved"));
                test(ex.kpd.Equals("derived"));
            }
            catch (Ice.OperationNotExistException)
            {
            }
            catch (System.Exception)
            {
                test(false);
            }

            try
            {
                testPrx.relayUnknownPreservedAsBase(relay);
                test(false);
            }
            catch (Preserved2 ex)
            {
                test(ex.b.Equals("base"));
                test(ex.kp.Equals("preserved"));
                test(ex.kpd.Equals("derived"));
                test(ex.p1.ice_id().Equals(PreservedClass.ice_staticId()));
                PreservedClass pc = ex.p1 as PreservedClass;
                test(pc.bc.Equals("bc"));
                test(pc.pc.Equals("pc"));
                test(ex.p2 == ex.p1);
            }
            catch (KnownPreservedDerived ex)
            {
                //
                // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved.
                //
                test(testPrx.EncodingVersion.Equals(Ice.Util.Encoding_1_0));
                test(ex.b.Equals("base"));
                test(ex.kp.Equals("preserved"));
                test(ex.kpd.Equals("derived"));
            }
            catch (Ice.OperationNotExistException)
            {
            }
            catch (System.Exception)
            {
                test(false);
            }

            try
            {
                testPrx.relayUnknownPreservedAsKnownPreserved(relay);
                test(false);
            }
            catch (Preserved2 ex)
            {
                test(ex.b.Equals("base"));
                test(ex.kp.Equals("preserved"));
                test(ex.kpd.Equals("derived"));
                test(ex.p1.ice_id().Equals(PreservedClass.ice_staticId()));
                PreservedClass pc = ex.p1 as PreservedClass;
                test(pc.bc.Equals("bc"));
                test(pc.pc.Equals("pc"));
                test(ex.p2 == ex.p1);
            }
            catch (KnownPreservedDerived ex)
            {
                //
                // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved.
                //
                test(testPrx.EncodingVersion.Equals(Ice.Util.Encoding_1_0));
                test(ex.b.Equals("base"));
                test(ex.kp.Equals("preserved"));
                test(ex.kpd.Equals("derived"));
            }
            catch (Ice.OperationNotExistException)
            {
            }
            catch (System.Exception)
            {
                test(false);
            }

            adapter.Destroy();
        }
        output.WriteLine("ok");

        return(testPrx);
    }
Пример #27
0
        internal void Initialize()
        {
            if (_initialized)
            {
                return;
            }

            Ice.Communicator ic = Communicator();
            //
            // Check for a default directory. We look in this directory for
            // files mentioned in the configuration.
            //
            _defaultDir = ic.GetProperty("IceSSL.DefaultDir") ?? "";

            string        certStoreLocation = ic.GetProperty("IceSSL.CertStoreLocation") ?? "CurrentUser";
            StoreLocation storeLocation;

            if (certStoreLocation == "CurrentUser")
            {
                storeLocation = StoreLocation.CurrentUser;
            }
            else if (certStoreLocation == "LocalMachine")
            {
                storeLocation = StoreLocation.LocalMachine;
            }
            else
            {
                _logger.Warning($"Invalid IceSSL.CertStoreLocation value `{certStoreLocation}' adjusted to `CurrentUser'");
                storeLocation = StoreLocation.CurrentUser;
            }
            _useMachineContext = certStoreLocation == "LocalMachine";

            //
            // Protocols selects which protocols to enable, by default we only enable TLS1.0
            // TLS1.1 and TLS1.2 to avoid security issues with SSLv3
            //
            string[]? protocols = ic.GetPropertyAsList("IceSSL.Protocols");
            if (protocols != null)
            {
                _protocols = ParseProtocols(protocols);
            }
            else
            {
                _protocols = 0;
                foreach (int v in Enum.GetValues(typeof(SslProtocols)))
                {
                    if (v > (int)SslProtocols.Ssl3 && v != (int)SslProtocols.Default)
                    {
                        _protocols |= (SslProtocols)v;
                    }
                }
            }
            //
            // CheckCertName determines whether we compare the name in a peer's
            // certificate against its hostname.
            //
            _checkCertName = ic.GetPropertyAsInt("IceSSL.CheckCertName") > 0;

            //
            // VerifyDepthMax establishes the maximum length of a peer's certificate
            // chain, including the peer's certificate. A value of 0 means there is
            // no maximum.
            //
            _verifyDepthMax = ic.GetPropertyAsInt("IceSSL.VerifyDepthMax") ?? 3;

            //
            // CheckCRL determines whether the certificate revocation list is checked, and how strictly.
            //
            _checkCRL = ic.GetPropertyAsInt("IceSSL.CheckCRL") ?? 0;

            //
            // Check for a certificate verifier.
            //
            string?certVerifierClass = ic.GetProperty("IceSSL.CertVerifier");

            if (certVerifierClass != null)
            {
                if (_verifier != null)
                {
                    throw new InvalidOperationException("IceSSL: certificate verifier already installed");
                }

                Type?cls = _facade.FindType(certVerifierClass);
                if (cls == null)
                {
                    throw new InvalidConfigurationException(
                              $"IceSSL: unable to load certificate verifier class `{certVerifierClass}'");
                }

                try
                {
                    _verifier = (ICertificateVerifier)IceInternal.AssemblyUtil.CreateInstance(cls);
                }
                catch (Exception ex)
                {
                    throw new LoadException(
                              $"IceSSL: unable to instantiate certificate verifier class `{certVerifierClass}", ex);
                }
            }

            //
            // Check for a password callback.
            //
            string?passwordCallbackClass = ic.GetProperty("IceSSL.PasswordCallback");

            if (passwordCallbackClass != null)
            {
                if (_passwordCallback != null)
                {
                    throw new InvalidOperationException("IceSSL: password callback already installed");
                }

                Type?cls = _facade.FindType(passwordCallbackClass);
                if (cls == null)
                {
                    throw new InvalidConfigurationException(
                              $"IceSSL: unable to load password callback class `{passwordCallbackClass}'");
                }

                try
                {
                    _passwordCallback = (IPasswordCallback)IceInternal.AssemblyUtil.CreateInstance(cls);
                }
                catch (Exception ex)
                {
                    throw new LoadException(
                              $"IceSSL: unable to load password callback class {passwordCallbackClass}", ex);
                }
            }

            //
            // If the user hasn't supplied a certificate collection, we need to examine
            // the property settings.
            //
            if (_certs == null)
            {
                //
                // If IceSSL.CertFile is defined, load a certificate from a file and
                // add it to the collection.
                //
                // TODO: tracing?
                _certs = new X509Certificate2Collection();
                string?      certFile    = ic.GetProperty("IceSSL.CertFile");
                string?      passwordStr = ic.GetProperty("IceSSL.Password");
                string?      findCert    = ic.GetProperty("IceSSL.FindCert");
                const string findPrefix  = "IceSSL.FindCert.";
                Dictionary <string, string> findCertProps = ic.GetProperties(forPrefix: findPrefix);

                if (certFile != null)
                {
                    if (!CheckPath(ref certFile))
                    {
                        throw new FileNotFoundException($"IceSSL: certificate file not found: `{certFile}'", certFile);
                    }

                    SecureString?password = null;
                    if (passwordStr != null)
                    {
                        password = CreateSecureString(passwordStr);
                    }
                    else if (_passwordCallback != null)
                    {
                        password = _passwordCallback.GetPassword(certFile);
                    }

                    try
                    {
                        X509Certificate2    cert;
                        X509KeyStorageFlags importFlags;
                        if (_useMachineContext)
                        {
                            importFlags = X509KeyStorageFlags.MachineKeySet;
                        }
                        else
                        {
                            importFlags = X509KeyStorageFlags.UserKeySet;
                        }

                        if (password != null)
                        {
                            cert = new X509Certificate2(certFile, password, importFlags);
                        }
                        else
                        {
                            cert = new X509Certificate2(certFile, "", importFlags);
                        }
                        _certs.Add(cert);
                    }
                    catch (CryptographicException ex)
                    {
                        throw new InvalidConfigurationException(
                                  $"IceSSL: error while attempting to load certificate from `{certFile}'", ex);
                    }
                }
                else if (findCert != null)
                {
                    string certStore = ic.GetProperty("IceSSL.CertStore") ?? "My";
                    _certs.AddRange(FindCertificates("IceSSL.FindCert", storeLocation, certStore, findCert));
                    if (_certs.Count == 0)
                    {
                        throw new InvalidConfigurationException("IceSSL: no certificates found");
                    }
                }
                else if (findCertProps.Count > 0)
                {
                    //
                    // If IceSSL.FindCert.* properties are defined, add the selected certificates
                    // to the collection.
                    //
                    foreach (KeyValuePair <string, string> entry in findCertProps)
                    {
                        string name = entry.Key;
                        string val  = entry.Value;
                        if (val.Length > 0)
                        {
                            string        storeSpec = name.Substring(findPrefix.Length);
                            StoreLocation storeLoc  = 0;
                            StoreName     storeName = 0;
                            string?       sname     = null;
                            ParseStore(name, storeSpec, ref storeLoc, ref storeName, ref sname);
                            if (sname == null)
                            {
                                sname = storeName.ToString();
                            }
                            X509Certificate2Collection coll = FindCertificates(name, storeLoc, sname, val);
                            _certs.AddRange(coll);
                        }
                    }
                    if (_certs.Count == 0)
                    {
                        throw new InvalidConfigurationException("IceSSL: no certificates found");
                    }
                }
            }

            if (_caCerts == null)
            {
                string?certAuthFile = ic.GetProperty("IceSSL.CAs");
                if (certAuthFile == null)
                {
                    certAuthFile = ic.GetProperty("IceSSL.CertAuthFile");
                }

                if (certAuthFile != null || (ic.GetPropertyAsInt("IceSSL.UsePlatformCAs") ?? 0) <= 0)
                {
                    _caCerts = new X509Certificate2Collection();
                }

                if (certAuthFile != null)
                {
                    if (!CheckPath(ref certAuthFile))
                    {
                        throw new FileNotFoundException("IceSSL: CA certificate file not found: `{certAuthFile}'",
                                                        certAuthFile);
                    }

                    try
                    {
                        using FileStream fs = File.OpenRead(certAuthFile);
                        byte[] data = new byte[fs.Length];
                        fs.Read(data, 0, data.Length);

                        string strbuf = "";
                        try
                        {
                            strbuf = System.Text.Encoding.UTF8.GetString(data);
                        }
                        catch (Exception)
                        {
                            // Ignore
                        }

                        if (strbuf.Length == data.Length)
                        {
                            int  size, startpos, endpos = 0;
                            bool first = true;
                            while (true)
                            {
                                startpos = strbuf.IndexOf("-----BEGIN CERTIFICATE-----", endpos);
                                if (startpos != -1)
                                {
                                    endpos = strbuf.IndexOf("-----END CERTIFICATE-----", startpos);
                                    size   = endpos - startpos + "-----END CERTIFICATE-----".Length;
                                }
                                else if (first)
                                {
                                    startpos = 0;
                                    endpos   = strbuf.Length;
                                    size     = strbuf.Length;
                                }
                                else
                                {
                                    break;
                                }

                                byte[] cert = new byte[size];
                                Buffer.BlockCopy(data, startpos, cert, 0, size);
                                _caCerts !.Import(cert);
                                first = false;
                            }
                        }
                        else
                        {
                            _caCerts !.Import(data);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidConfigurationException(
                                  $"IceSSL: error while attempting to load CA certificate from {certAuthFile}", ex);
                    }
                }
            }
            _initialized = true;
        }
Пример #28
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
    }
Пример #29
0
 public void run(Ice.Communicator communicator)
Пример #30
0
    allTestsWithDeploy(Test.TestHelper helper)
    {
        Ice.Communicator communicator = helper.communicator();
        Console.Out.Write("testing stringToProxy... ");
        Console.Out.Flush();
        IObjectPrx @base = IObjectPrx.Parse("test @ TestAdapter", communicator);

        test(@base != null);
        IObjectPrx @base2 = IObjectPrx.Parse("test", communicator);

        test(@base2 != null);
        Console.Out.WriteLine("ok");

        Console.Out.Write("testing checked cast... ");
        Console.Out.Flush();
        ITestIntfPrx obj = ITestIntfPrx.CheckedCast(@base);

        test(obj.Equals(@base));
        ITestIntfPrx obj2 = ITestIntfPrx.CheckedCast(@base2);

        test(obj2.Equals(@base2));
        Console.Out.WriteLine("ok");

        Console.Out.Write("pinging server... ");
        Console.Out.Flush();
        obj.IcePing();
        obj2.IcePing();
        Console.Out.WriteLine("ok");

        Console.Out.Write("testing encoding versioning... ");
        Console.Out.Flush();
        Console.Out.WriteLine("ok");

        Console.Out.Write("testing reference with unknown identity... ");
        Console.Out.Flush();
        try
        {
            IObjectPrx.Parse("unknown/unknown", communicator).IcePing();
            test(false);
        }
        catch (NotRegisteredException ex)
        {
            test(ex.KindOfObject.Equals("object"));
            test(ex.Id.Equals("unknown/unknown"));
        }
        Console.Out.WriteLine("ok");

        Console.Out.Write("testing reference with unknown adapter... ");
        Console.Out.Flush();
        try
        {
            IObjectPrx.Parse("test @ TestAdapterUnknown", communicator).IcePing();
            test(false);
        }
        catch (NotRegisteredException ex)
        {
            test(ex.KindOfObject.Equals("object adapter"));
            test(ex.Id.Equals("TestAdapterUnknown"));
        }
        Console.Out.WriteLine("ok");

        IceGrid.IRegistryPrx registry = IceGrid.IRegistryPrx.Parse(
            communicator.GetDefaultLocator().Identity.Category + "/Registry", communicator);
        IceGrid.IAdminSessionPrx session = registry.CreateAdminSession("foo", "bar");
        session.GetConnection().SetACM(registry.GetACMTimeout(), null, ACMHeartbeat.HeartbeatAlways);

        IceGrid.IAdminPrx admin = session.GetAdmin();
        admin.EnableServer("server", false);
        admin.StopServer("server");

        Console.Out.Write("testing whether server is still reachable... ");
        Console.Out.Flush();
        try
        {
            obj = ITestIntfPrx.CheckedCast(@base);
            test(false);
        }
        catch (Ice.NoEndpointException)
        {
        }
        try
        {
            obj2 = ITestIntfPrx.CheckedCast(@base2);
            test(false);
        }
        catch (Ice.NoEndpointException)
        {
        }

        try
        {
            admin.EnableServer("server", true);
        }
        catch (IceGrid.ServerNotExistException)
        {
            test(false);
        }
        catch (IceGrid.NodeUnreachableException)
        {
            test(false);
        }

        try
        {
            obj = ITestIntfPrx.CheckedCast(@base);
        }
        catch (Ice.NoEndpointException)
        {
            test(false);
        }
        try
        {
            obj2 = ITestIntfPrx.CheckedCast(@base2);
        }
        catch (Ice.NoEndpointException)
        {
            test(false);
        }
        Console.Out.WriteLine("ok");

        try
        {
            admin.StopServer("server");
        }
        catch (IceGrid.ServerNotExistException)
        {
            test(false);
        }
        catch (IceGrid.ServerStopException)
        {
            test(false);
        }
        catch (IceGrid.NodeUnreachableException)
        {
            test(false);
        }

        session.Destroy();
    }
Пример #31
0
 public BasePlugin(Ice.Communicator communicator)
 {
     _communicator = communicator;
 }
Пример #32
0
    private static void allTests(Ice.Communicator communicator)
    {
        Console.Out.Write("testing equals() for Slice structures... ");
        Console.Out.Flush();

        //
        // Define some default values.
        //
        C  def_cls = new C(5);
        S1 def_s   = new S1("name");

        string[] def_ss = new string[] { "one", "two", "three" };
        int[]    def_il = new int[3];
        def_il[0] = 1;
        def_il[1] = 2;
        def_il[2] = 3;
        Dictionary <string, string> def_sd = new Dictionary <string, string>();

        def_sd.Add("abc", "def");
        var def_prx = Ice.IObjectPrx.Parse("test", communicator);
        S2  def_s2  = new S2(true, (byte)98, (short)99, 100, 101, (float)1.0, 2.0, "string", def_ss, def_il, def_sd,
                             def_s, def_cls, def_prx);

        //
        // Compare default-constructed structures.
        //
        {
            test(new S2().Equals(new S2()));
        }

        //
        // Change one primitive member at a time.
        //
        {
            S2 v;

            v = (S2)def_s2.Clone();
            test(v.Equals(def_s2));

            v    = (S2)def_s2.Clone();
            v.bo = false;
            test(!v.Equals(def_s2));

            v = (S2)def_s2.Clone();
            v.by--;
            test(!v.Equals(def_s2));

            v = (S2)def_s2.Clone();
            v.sh--;
            test(!v.Equals(def_s2));

            v = (S2)def_s2.Clone();
            v.i--;
            test(!v.Equals(def_s2));

            v = (S2)def_s2.Clone();
            v.l--;
            test(!v.Equals(def_s2));

            v = (S2)def_s2.Clone();
            v.f--;
            test(!v.Equals(def_s2));

            v = (S2)def_s2.Clone();
            v.d--;
            test(!v.Equals(def_s2));

            v     = (S2)def_s2.Clone();
            v.str = "";
            test(!v.Equals(def_s2));
        }

        //
        // String member
        //
        {
            S2 v1, v2;

            v1     = (S2)def_s2.Clone();
            v1.str = (string)def_s2.str.Clone();
            test(v1.Equals(def_s2));

            v1     = (S2)def_s2.Clone();
            v2     = (S2)def_s2.Clone();
            v1.str = null;
            test(!v1.Equals(v2));

            v1     = (S2)def_s2.Clone();
            v2     = (S2)def_s2.Clone();
            v2.str = null;
            test(!v1.Equals(v2));

            v1     = (S2)def_s2.Clone();
            v2     = (S2)def_s2.Clone();
            v1.str = null;
            v2.str = null;
            test(v1.Equals(v2));
        }

        //
        // Sequence member
        //
        {
            S2 v1, v2;

            v1    = (S2)def_s2.Clone();
            v1.ss = (string[])def_s2.ss.Clone();
            test(v1.Equals(def_s2));

            v1    = (S2)def_s2.Clone();
            v2    = (S2)def_s2.Clone();
            v1.ss = null;
            test(!v1.Equals(v2));

            v1    = (S2)def_s2.Clone();
            v2    = (S2)def_s2.Clone();
            v2.ss = null;
            test(!v1.Equals(v2));
        }

        //
        // Custom sequence member
        //
        {
            S2 v1, v2;

            v1    = (S2)def_s2.Clone();
            v1.il = (int[])def_s2.il.Clone();
            test(v1.Equals(def_s2));

            v1    = (S2)def_s2.Clone();
            v1.il = new int[3] {
                0, 0, 0
            };
            test(!v1.Equals(def_s2));

            v1    = (S2)def_s2.Clone();
            v2    = (S2)def_s2.Clone();
            v1.il = null;
            test(!v1.Equals(v2));

            v1    = (S2)def_s2.Clone();
            v2    = (S2)def_s2.Clone();
            v2.il = null;
            test(!v1.Equals(v2));
        }

        //
        // Dictionary member
        //
        {
            S2 v1, v2;

            v1    = (S2)def_s2.Clone();
            v1.sd = new Dictionary <string, string>(def_s2.sd);
            test(v1.Equals(def_s2));

            v1    = (S2)def_s2.Clone();
            v1.sd = new Dictionary <string, string>();
            test(!v1.Equals(def_s2));

            v1    = (S2)def_s2.Clone();
            v2    = (S2)def_s2.Clone();
            v1.sd = null;
            test(!v1.Equals(v2));

            v1    = (S2)def_s2.Clone();
            v2    = (S2)def_s2.Clone();
            v2.sd = null;
            test(!v1.Equals(v2));
        }

        //
        // Struct member
        //
        {
            S2 v1, v2;

            v1   = (S2)def_s2.Clone();
            v1.s = (S1)def_s2.s.Clone();
            test(v1.Equals(def_s2));

            v1   = (S2)def_s2.Clone();
            v1.s = new S1("name");
            test(v1.Equals(def_s2));

            v1   = (S2)def_s2.Clone();
            v1.s = new S1("noname");
            test(!v1.Equals(def_s2));

            v1   = (S2)def_s2.Clone();
            v2   = (S2)def_s2.Clone();
            v1.s = null;
            test(!v1.Equals(v2));

            v1   = (S2)def_s2.Clone();
            v2   = (S2)def_s2.Clone();
            v2.s = null;
            test(!v1.Equals(v2));
        }

        //
        // Class member
        //
        {
            S2 v1, v2;

            v1     = (S2)def_s2.Clone();
            v1.cls = (C)def_s2.cls.Clone();
            test(!v1.Equals(def_s2));

            v1     = (S2)def_s2.Clone();
            v2     = (S2)def_s2.Clone();
            v1.cls = null;
            test(!v1.Equals(v2));

            v1     = (S2)def_s2.Clone();
            v2     = (S2)def_s2.Clone();
            v2.cls = null;
            test(!v1.Equals(v2));
        }

        //
        // Proxy member
        //
        {
            S2 v1, v2;

            v1     = (S2)def_s2.Clone();
            v1.prx = IObjectPrx.Parse("test", communicator);
            test(v1.Equals(def_s2));

            v1     = (S2)def_s2.Clone();
            v1.prx = IObjectPrx.Parse("test2", communicator);
            test(!v1.Equals(def_s2));

            v1     = (S2)def_s2.Clone();
            v2     = (S2)def_s2.Clone();
            v1.prx = null;
            test(!v1.Equals(v2));

            v1     = (S2)def_s2.Clone();
            v2     = (S2)def_s2.Clone();
            v2.prx = null;
            test(!v1.Equals(v2));
        }

        Console.Out.WriteLine("ok");
    }