private static int run(string[] args, Ice.Communicator communicator) { communicator.getProperties().setProperty("TestAdapter.Endpoints", "default"); Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter"); adapter.add(new decimalI(), Ice.Util.stringToIdentity("test")); adapter.add(new Test1I(), Ice.Util.stringToIdentity("test1")); adapter.add(new Test2I(), Ice.Util.stringToIdentity("test2")); adapter.activate(); Console.Out.Write("testing operation name... "); Console.Out.Flush(); @abstract.@decimalPrx p = @[email protected]( adapter.createProxy(Ice.Util.stringToIdentity("test"))); p.@default(); Console.Out.WriteLine("ok"); Console.Out.Write("testing System as module name... "); Console.Out.Flush(); @abstract.System.TestPrx t1 = @abstract.System.TestPrxHelper.uncheckedCast( adapter.createProxy(Ice.Util.stringToIdentity("test1"))); t1.op(); System.TestPrx t2 = System.TestPrxHelper.uncheckedCast( adapter.createProxy(Ice.Util.stringToIdentity("test2"))); t2.op(); Console.Out.WriteLine("ok"); Console.Out.Write("testing types... "); Console.Out.Flush(); testtypes(); Console.Out.WriteLine("ok"); return(0); }
/// <summary> /// Join the game server. Once active, this officially joins the game. /// </summary> /// <param name="key">Key given by the main communicator after calling /// RequestJoinGameServer().</param> /// <returns>True if successful; false otherwise.</returns> public bool JoinServer(string key) { bool result = false; try { lock (this) { adapter.activate(); ClientEventCallbackPrx clientCallback = ClientEventCallbackPrxHelper. uncheckedCast(adapter.createProxy(clientIdentity)); ClockSynchronizerPrx clockCallback = ClockSynchronizerPrxHelper. uncheckedCast(adapter.createProxy(clockIdentity)); session = auth.JoinServer(key, clockCallback, clientCallback); // Configure the proxy. session = GameInfoPrxHelper.uncheckedCast( session.ice_router(router)); sessionOneway = GameInfoPrxHelper.uncheckedCast( session.ice_oneway()); Refresh(); timerThread = new Thread(new ThreadStart(TimeTicker)); timerThread.Start(); if (KeepAlive) { keepAliveTimer = new Timer(new TimerCallback(OnKeepAlive), null, KeepAliveInterval, KeepAliveInterval); } pinger = new Pinger(session); } result = true; } catch (Ice.IllegalIdentityException e) { logger.Error("JoinServer() No callbacks registered: {0}", e); throw new InvalidValueException("You must register callbacks first."); } catch (Exceptions.PermissionDeniedException e) { logger.Info("JoinServer() Failed (permission denied): {0}", e.reason); } catch (Ice.Exception e) { logger.Error("JoinServer() Ice.Exception: {0}", e); } catch (System.Exception e) { logger.Error("JoinServer() System.Exception: {0}", e); } return(result); }
public override int run(string[] args) { // // Register the server manager. The server manager creates a new // 'server' (a server isn't a different process, it's just a new // communicator and object adapter). // Ice.Properties properties = communicator().getProperties(); properties.setProperty("Ice.ThreadPool.Server.Size", "2"); properties.setProperty("ServerManagerAdapter.Endpoints", getTestEndpoint(0) + ":udp"); Ice.ObjectAdapter adapter = communicator().createObjectAdapter("ServerManagerAdapter"); // // We also register a sample server locator which implements the // locator interface, this locator is used by the clients and the // 'servers' created with the server manager interface. // ServerLocatorRegistry registry = new ServerLocatorRegistry(); Ice.Object @object = new ServerManagerI(registry, _initData, this); adapter.add(@object, Ice.Util.stringToIdentity("ServerManager")); registry.addObject(adapter.createProxy(Ice.Util.stringToIdentity("ServerManager"))); Ice.LocatorRegistryPrx registryPrx = Ice.LocatorRegistryPrxHelper.uncheckedCast( adapter.add(registry, Ice.Util.stringToIdentity("registry"))); ServerLocator locator = new ServerLocator(registry, registryPrx); adapter.add(locator, Ice.Util.stringToIdentity("locator")); adapter.activate(); communicator().waitForShutdown(); return(0); }
public override int run(string[] args) { if (args.Length > 0) { Console.Error.WriteLine(appName() + ": too many arguments"); return(1); } NestedPrx nested = NestedPrxHelper.checkedCast(communicator().propertyToProxy("Nested.Proxy")); if (nested == null) { Console.Error.WriteLine("invalid proxy"); return(1); } Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Nested.Client"); NestedPrx self = NestedPrxHelper.uncheckedCast(adapter.createProxy(communicator().stringToIdentity("nestedClient"))); adapter.add(new NestedI(self), communicator().stringToIdentity("nestedClient")); adapter.activate(); Console.Out.WriteLine("Note: The maximum nesting level is sz * 2, with sz being"); Console.Out.WriteLine("the maximum number of threads in the server thread pool. If"); Console.Out.WriteLine("you specify a value higher than that, the application will"); Console.Out.WriteLine("block or timeout."); Console.Out.WriteLine(); string s = null; do { try { Console.Out.Write("enter nesting level or 'x' for exit: "); Console.Out.Flush(); s = Console.In.ReadLine(); if (s == null) { break; } int level = System.Int32.Parse(s); if (level > 0) { nested.nestedCall(level, self); } } catch (System.FormatException) { } catch (System.Exception ex) { Console.Error.WriteLine(ex); } }while(!s.Equals("x")); return(0); }
private void btndynamicDetect_Click(object sender, RoutedEventArgs e) { var sb = new StringBuilder(); sb.Append("threshold".ElementText("0.5")); sb.Append("rtspId".ElementText("1")); sb.Append("rtspPath".ElementText("rtsp://*****:*****@192.0.0.64:554/h264/ch1/main/av_stream")); sb.Append("responseType".ElementBegin()); if (ckbCallback.IsChecked.Value) { sb.Append("type".ElementText("callback")); } else { sb.Append("type".ElementText("messageQueue")); } sb.Append("size".ElementText("10")); sb.Append("responseType".ElementEnd()); sb.Append("maxImageCount".ElementText("3")); sb.Append("frames".ElementText("5")); var data = sb.ToString(); var xml = GetXml("dynamicDetect", data); var content = facePxy.send(xml); XmlDocument doc = new XmlDocument(); doc.LoadXml(content); var code = doc.GetNodeText("code"); Item("code->" + code); if (ckbCallback.IsChecked.Value) { callbackAdapter = ic.createObjectAdapterWithEndpoints("callback-receiver", "default"); Ice.Object callbackServant = new ConnectorDisp(Item); callbackAdapter.add(callbackServant, ic.stringToIdentity("callbackReceiver")); callbackAdapter.activate(); ConnectionListenerPrx listenerPxy = null; var objectPxy = callbackAdapter.createProxy(ic.stringToIdentity("callbackReceiver")); listenerPxy = ConnectionListenerPrxHelper.checkedCast(objectPxy); facePxy.initConnectionListener(listenerPxy); Item("set callback ok"); } }
public override void GetProxy() { remote = GuiDataHubPrxHelper.uncheckedCast(m_objectPrx); dataHubCB = new DataHubCallbackI(); dataHubCB.DataChange += new DataChangeHander(CallBack); Ice.ObjectAdapter adapter = Communicator.createObjectAdapter("DataHubCB"); adapter.add(dataHubCB, Communicator.stringToIdentity("callbackReceiver")); adapter.activate(); dataCallback = GuiDataUpdaterPrxHelper.uncheckedCast( adapter.createProxy(Communicator.stringToIdentity("callbackReceiver"))); }
/// <summary> /// 初始化连接 /// </summary> /// <returns></returns> public bool Init() { try { Ice.InitializationData intiData = new Ice.InitializationData(); Ice.Properties properties = Ice.Util.createProperties(); properties.setProperty("Ice.MessageSizeMax", "104857600"); properties.setProperty("Ice.ThreadPool.SizeMax", "100"); intiData.properties = properties; ic = Ice.Util.initialize(intiData); // 连接 Ice.ObjectPrx objectPrx = ic.stringToProxy(string.Format("ID_TransDataFromClientRPC:tcp -h {0} -p {1} -t 5000", EEMSConfigHelper.GetValueByCommomConfig("config/CollectClient/DataServerIp", "127.0.0.1"), EEMSConfigHelper.GetValueByCommomConfig("config/CollectClient/DataServerPort", "40010"))); Client = CSTransDataFromClientPrxHelper.checkedCast(objectPrx); // 代理 Ice.ObjectAdapter adapter = ic.createObjectAdapterWithEndpoints("ID_TransDataFromClientRPC", string.Format("tcp -h {0} -p {1} -t 5000", EEMSConfigHelper.GetValueByCommomConfig("config/CollectClient/DataClientIp", "127.0.0.1"), EEMSConfigHelper.GetValueByCommomConfig("config/CollectClient/DataClientPort", "42000"))); CallbackClientI callbackClientI = new CallbackClientI(); callbackClientI.TransDataToClientHandler += callbackClientI_TransDataToClientHandler; Ice.Object obj = callbackClientI; adapter.add(obj, ic.stringToIdentity("ID_TransDataFromClientRPC")); adapter.activate(); CallbackClientPrx call = CallbackClientPrxHelper.uncheckedCast(adapter.createProxy(ic.stringToIdentity("ID_TransDataFromClientRPC"))); Client.RegistClient(ClientID, call, 1000); return(true); } catch (Exception e) { // 初始化失败 Dispose(); LogHelper.Instance.WirteErrorMsg(e.Message); return(false); } }
public override int run(string[] args) { if (args.Length > 0) { System.Console.Error.WriteLine(appName() + ": too many arguments"); return(1); } Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Nested.Server"); NestedPrx self = NestedPrxHelper.uncheckedCast(adapter.createProxy(communicator().stringToIdentity("nestedServer"))); adapter.add(new NestedI(self), communicator().stringToIdentity("nestedServer")); adapter.activate(); communicator().waitForShutdown(); return(0); }
private void Setcallback() { callbackAdapter = FaceServices.FaceProxy.Ic.createObjectAdapterWithEndpoints("callback-receiver", "default"); Ice.Object callbackServant = new ConnectorDisp(FaceBack); callbackAdapter.add(callbackServant, FaceServices.FaceProxy.Ic.stringToIdentity("callbackReceiver")); callbackAdapter.activate(); ConnectionListenerPrx listenerPxy = null; var objectPxy = callbackAdapter.createProxy(FaceServices.FaceProxy.Ic.stringToIdentity("callbackReceiver")); listenerPxy = ConnectionListenerPrxHelper.checkedCast(objectPxy); FaceServices.FaceProxy.initConnectionListener(listenerPxy); Item("set callback ok"); }
private static int Init() { int result = 0; try { Ice.Communicator communicator = Ice.Util.initialize("config.client"); sender = CallbackSenderPrxHelper.checkedCast(communicator.propertyToProxy("CallbackSender.Proxy"). ice_twoway().ice_timeout(-1).ice_secure(false)); if (sender == null) { Console.Error.WriteLine("invalid proxy"); result = 0; } adapter = communicator.createObjectAdapter("Callback.Client"); adapter.add(new CallbackReceiverI(), Ice.Util.stringToIdentity("callbackReceiver")); adapter.activate(); receiver = CallbackReceiverPrxHelper.uncheckedCast( adapter.createProxy(Ice.Util.stringToIdentity("callbackReceiver"))); Console.WriteLine("server connected"); result = 1; } catch (Exception ex) { Console.Error.WriteLine(ex); Console.WriteLine("connection failed"); result = 0; } return(result); }
/// <summary> /// 初始化连接 /// </summary> /// <returns></returns> public bool Init() { try { lock (lockData) { Ice.InitializationData intiData = new Ice.InitializationData(); Ice.Properties properties = Ice.Util.createProperties(); properties.setProperty("Ice.MessageSizeMax", "104857600"); intiData.properties = properties; ic = Ice.Util.initialize(intiData); // 连接 Ice.ObjectPrx objectPrx = ic.stringToProxy(string.Format("{0}:tcp -h {1} -p {2} -t 5000", NMCommunicationRPCId.value, EEMSConfigHelper.GetValueByCommomConfig("config/CommonConfig/netagent_ip", "127.0.0.1"), EEMSConfigHelper.GetValueByCommomConfig("config/CommonConfig/netagent_port", "40050"))); client = NMServerPrxHelper.checkedCast(objectPrx); // 代理 Ice.ObjectAdapter adapter = ic.createObjectAdapterWithEndpoints(NMCommunicationRPCId.value, string.Format("tcp -h {0} -p {1} -t 5000", EEMSConfigHelper.GetValueByCommomConfig("config/CollectClient/WarnInfoLocalIp", "127.0.0.1"), EEMSConfigHelper.GetValueByCommomConfig("config/CollectClient/WarnInfoClentPort", "42050"))); NMClientI clientI = new NMClientI(); clientI.ReceiveDataHandler += clientI_ReceiveDataHandler; Ice.Object obj = clientI; adapter.add(obj, ic.stringToIdentity(NMCommunicationRPCId.value)); adapter.activate(); NMClientPrx call = NMClientPrxHelper.uncheckedCast(adapter.createProxy(ic.stringToIdentity(NMCommunicationRPCId.value))); client.NMRegistClient(clientID, call); IsConnect = true; } return(true); } catch (Exception e) { // 初始化失败 client = null; LogHelper.Instance.WirteErrorMsg(e.Message); return(false); } finally { if (!isThreadStart) { isThreadStart = true; CheckConnectThread(); } } }
public override int run(string[] args) { if (args.Length > 0) { Console.Error.WriteLine(appName() + ": too many arguments"); return(1); } CallbackSenderPrx sender = CallbackSenderPrxHelper.checkedCast( communicator().propertyToProxy("CallbackSender.Proxy"). ice_twoway().ice_timeout(-1).ice_secure(false)); if (sender == null) { Console.Error.WriteLine("invalid proxy"); return(1); } Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Client"); adapter.add(new CallbackReceiverI(), communicator().stringToIdentity("callbackReceiver")); adapter.activate(); CallbackReceiverPrx receiver = CallbackReceiverPrxHelper.uncheckedCast( adapter.createProxy(communicator().stringToIdentity("callbackReceiver"))); menu(); string line = null; do { try { Console.Out.Write("==> "); Console.Out.Flush(); line = Console.In.ReadLine(); if (line == null) { break; } if (line.Equals("t")) { sender.initiateCallback(receiver); } else if (line.Equals("s")) { sender.shutdown(); } else if (line.Equals("x")) { // Nothing to do } else if (line.Equals("?")) { menu(); } else { Console.Out.WriteLine("unknown command `" + line + "'"); menu(); } } catch (System.Exception ex) { Console.Error.WriteLine(ex); } }while(!line.Equals("x")); return(0); }
/// <summary> /// Initializes a new instance of the /// <see cref="T:Ferda.Modules.BoxModuleI"/> class. /// </summary> /// <param name="boxInfo">The box info.</param> /// <param name="myIdentity">My identity.</param> /// <param name="myFactoryProxy">My factory proxy.</param> /// <param name="manager">The manager.</param> /// <param name="adapter">The adapter.</param> /// <param name="localePrefs">The localization preferences.</param> public BoxModuleI(IBoxInfo boxInfo, Ice.Identity myIdentity, BoxModuleFactoryPrx myFactoryProxy, Ferda.ModulesManager.ManagersEnginePrx manager, Ice.ObjectAdapter adapter, string[] localePrefs) { System.Diagnostics.Debug.WriteLine("BoxModuleI Constructor (entering): " + boxInfo.Identifier); // initializes inner fields by specified parameters this.boxInfo = boxInfo; this.iceIdentity = myIdentity; this.stringIceIdentity = Ice.Util.identityToString(IceIdentity); this.myFactoryProxy = myFactoryProxy; this.manager = manager; this.adapter = adapter; this.localePrefs = localePrefs; // add the new box module to the specified adapter adapter.add(this, this.iceIdentity); // get my proxy this.myProxy = BoxModulePrxHelper.uncheckedCast(adapter.createProxy(myIdentity)); // initializes box module`s functions object this.boxInfo.CreateFunctions(this, out this.functionsIceObj, out this.functionsIObj); this.functionsIObj.setBoxModuleInfo(this, this.boxInfo); this.functionsObjPrx = Ice.ObjectPrxHelper.uncheckedCast(adapter.addWithUUID(this.functionsIceObj)); // initializes properties this.properties = new Dictionary<string, PropertyValue>(); foreach (string propertyName in boxInfo.GetPropertiesNames()) { if (!boxInfo.IsPropertyReadOnly(propertyName)) { this.setProperty(propertyName, boxInfo.GetPropertyDefaultValue(propertyName)); } } // initializes sockets (connections and functions) this.connections = new Dictionary<string, Dictionary<string, BoxModulePrx>>(); foreach (string socketName in boxInfo.GetSocketNames()) { connections[socketName] = new Dictionary<string, BoxModulePrx>(); } System.Diagnostics.Debug.WriteLine("BoxModuleI Constructor (leaving): " + this.boxInfo.Identifier); }
allTests(Ice.Communicator communicator) { Ice.ObjectAdapter oa = communicator.createObjectAdapterWithEndpoints("MyOA", "tcp -h localhost"); oa.activate(); Ice.Object servant = new MyObjectI(); // // Register default servant with category "foo" // oa.addDefaultServant(servant, "foo"); // // Start test // Console.Out.Write("testing single category... "); Console.Out.Flush(); Ice.Object r = oa.findDefaultServant("foo"); test(r == servant); r = oa.findDefaultServant("bar"); test(r == null); Ice.Identity identity = new Ice.Identity(); identity.category = "foo"; string[] names = new string[] { "foo", "bar", "x", "y", "abcdefg" }; Test.MyObjectPrx prx = null; for (int idx = 0; idx < 5; ++idx) { identity.name = names[idx]; prx = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity)); prx.ice_ping(); test(prx.getName() == names[idx]); } identity.name = "ObjectNotExist"; prx = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity)); try { prx.ice_ping(); test(false); } catch (Ice.ObjectNotExistException) { // Expected } try { prx.getName(); test(false); } catch (Ice.ObjectNotExistException) { // Expected } identity.name = "FacetNotExist"; prx = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity)); try { prx.ice_ping(); test(false); } catch (Ice.FacetNotExistException) { // Expected } try { prx.getName(); test(false); } catch (Ice.FacetNotExistException) { // Expected } identity.category = "bar"; for (int idx = 0; idx < 5; idx++) { identity.name = names[idx]; prx = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity)); try { prx.ice_ping(); test(false); } catch (Ice.ObjectNotExistException) { // Expected } try { prx.getName(); test(false); } catch (Ice.ObjectNotExistException) { // Expected } } oa.removeDefaultServant("foo"); identity.category = "foo"; prx = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity)); try { prx.ice_ping(); } catch (Ice.ObjectNotExistException) { // Expected } Console.Out.WriteLine("ok"); Console.Out.Write("testing default category... "); Console.Out.Flush(); oa.addDefaultServant(servant, ""); r = oa.findDefaultServant("bar"); test(r == null); r = oa.findDefaultServant(""); test(r == servant); for (int idx = 0; idx < 5; ++idx) { identity.name = names[idx]; prx = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity)); prx.ice_ping(); test(prx.getName() == names[idx]); } Console.Out.WriteLine("ok"); }
public static Test.TestIntfPrx allTests(global::Test.TestHelper helper) { Ice.Communicator communicator = helper.communicator(); var output = helper.getWriter(); output.Write("testing stringToProxy... "); output.Flush(); string @ref = "test:" + helper.getTestEndpoint(0); Ice.ObjectPrx @base = communicator.stringToProxy(@ref); test(@base != null); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); var obj = Test.TestIntfPrxHelper.checkedCast(@base); test(obj != null); test(obj.Equals(@base)); output.WriteLine("ok"); { output.Write("creating/destroying/recreating object adapter... "); output.Flush(); Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default"); try { communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default"); test(false); } catch (Ice.AlreadyRegisteredException) { } adapter.destroy(); // // Use a different port than the first adapter to avoid an "address already in use" error. // adapter = communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default"); adapter.destroy(); output.WriteLine("ok"); } output.Write("creating/activating/deactivating object adapter in one operation... "); output.Flush(); obj.transient(); obj.end_transient(obj.begin_transient()); output.WriteLine("ok"); { output.Write("testing connection closure... "); output.Flush(); for (int i = 0; i < 10; ++i) { Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = communicator.getProperties().ice_clone_(); Ice.Communicator comm = Ice.Util.initialize(initData); comm.stringToProxy("test:" + helper.getTestEndpoint(0)).begin_ice_ping(); comm.destroy(); } output.WriteLine("ok"); } output.Write("testing object adapter published endpoints... "); output.Flush(); { communicator.getProperties().setProperty("PAdapter.PublishedEndpoints", "tcp -h localhost -p 12345 -t 30000"); Ice.ObjectAdapter adapter = communicator.createObjectAdapter("PAdapter"); test(adapter.getPublishedEndpoints().Length == 1); Ice.Endpoint endpt = adapter.getPublishedEndpoints()[0]; test(endpt.ToString().Equals("tcp -h localhost -p 12345 -t 30000")); Ice.ObjectPrx prx = communicator.stringToProxy("dummy:tcp -h localhost -p 12346 -t 20000:tcp -h localhost -p 12347 -t 10000"); adapter.setPublishedEndpoints(prx.ice_getEndpoints()); test(adapter.getPublishedEndpoints().Length == 2); Ice.Identity id = new Ice.Identity(); id.name = "dummy"; test(IceUtilInternal.Arrays.Equals(adapter.createProxy(id).ice_getEndpoints(), prx.ice_getEndpoints())); test(IceUtilInternal.Arrays.Equals(adapter.getPublishedEndpoints(), prx.ice_getEndpoints())); adapter.refreshPublishedEndpoints(); test(adapter.getPublishedEndpoints().Length == 1); test(adapter.getPublishedEndpoints()[0].Equals(endpt)); communicator.getProperties().setProperty("PAdapter.PublishedEndpoints", "tcp -h localhost -p 12345 -t 20000"); adapter.refreshPublishedEndpoints(); test(adapter.getPublishedEndpoints().Length == 1); test(adapter.getPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 12345 -t 20000")); adapter.destroy(); test(adapter.getPublishedEndpoints().Length == 0); } output.WriteLine("ok"); if (obj.ice_getConnection() != null) { output.Write("testing object adapter with bi-dir connection... "); output.Flush(); Ice.ObjectAdapter adapter = communicator.createObjectAdapter(""); obj.ice_getConnection().setAdapter(adapter); obj.ice_getConnection().setAdapter(null); adapter.deactivate(); try { obj.ice_getConnection().setAdapter(adapter); test(false); } catch (Ice.ObjectAdapterDeactivatedException) { } output.WriteLine("ok"); } output.Write("testing object adapter with router... "); output.Flush(); { Ice.Identity routerId = new Ice.Identity(); routerId.name = "router"; Ice.RouterPrx router = Ice.RouterPrxHelper.uncheckedCast(@base.ice_identity(routerId).ice_connectionId("rc")); Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithRouter("", router); test(adapter.getPublishedEndpoints().Length == 1); test(adapter.getPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 23456 -t 30000")); adapter.refreshPublishedEndpoints(); test(adapter.getPublishedEndpoints().Length == 1); test(adapter.getPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 23457 -t 30000")); try { adapter.setPublishedEndpoints(router.ice_getEndpoints()); test(false); } catch (ArgumentException) { // Expected. } adapter.destroy(); try { routerId.name = "test"; router = Ice.RouterPrxHelper.uncheckedCast(@base.ice_identity(routerId)); communicator.createObjectAdapterWithRouter("", router); test(false); } catch (Ice.OperationNotExistException) { // Expected: the "test" object doesn't implement Ice::Router! } try { router = Ice.RouterPrxHelper.uncheckedCast(communicator.stringToProxy("test:" + helper.getTestEndpoint(1))); communicator.createObjectAdapterWithRouter("", router); test(false); } catch (Ice.ConnectFailedException) { } } output.WriteLine("ok"); output.Write("testing object adapter creation with port in use... "); output.Flush(); { var adapter1 = communicator.createObjectAdapterWithEndpoints("Adpt1", helper.getTestEndpoint(10)); try { communicator.createObjectAdapterWithEndpoints("Adpt2", helper.getTestEndpoint(10)); test(false); } catch (Ice.LocalException) { // Expected can't re-use the same endpoint. } adapter1.destroy(); } output.WriteLine("ok"); output.Write("deactivating object adapter in the server... "); output.Flush(); obj.deactivate(); output.WriteLine("ok"); output.Write("testing whether server is gone... "); output.Flush(); try { obj.ice_timeout(100).ice_ping(); // Use timeout to speed up testing on Windows test(false); } catch (Ice.LocalException) { output.WriteLine("ok"); } return(obj); }
public override int run(string[] args) { var nodeMap = NodeMapPrxHelper.checkedCast(communicator().propertyToProxy("Node.Proxy")); if (nodeMap == null) { Console.Error.WriteLine("invalid proxy"); return(1); } var userMap = UserMapPrxHelper.checkedCast(communicator().propertyToProxy("User.Proxy")); if (userMap == null) { Console.Error.WriteLine("invalid proxy"); return(1); } var graphMap = GraphMapPrxHelper.checkedCast(communicator().propertyToProxy("Graph.Proxy")); if (graphMap == null) { Console.Error.WriteLine("invalid proxy"); return(1); } Console.WriteLine("輸入名字:"); string user_name = Console.ReadLine(); if (userMap.Register(user_name) == false) { System.Console.WriteLine("已被註冊!"); Thread.Sleep(2000); return(1); } //註冊回傳 Ice.ObjectAdapter adapter = communicator().createObjectAdapter("UserCallback.Client"); adapter.add(new UserCallBackI(), Ice.Util.stringToIdentity("callbackReceiver")); adapter.activate(); UserCallBackPrx callbackPrx = UserCallBackPrxHelper.uncheckedCast(adapter.createProxy(Ice.Util.stringToIdentity("callbackReceiver"))); Dictionary <string, string> ctx = new Dictionary <string, string> { { "user_name", user_name } }; userMap.SetupCallback(callbackPrx, ctx); menu(); MyNode[] allnodes = new MyNode[10000]; MyGraph[] allgraphs = new MyGraph[10000]; string line = null; do { try { Console.Out.Write("==> "); Console.Out.Flush(); line = Console.In.ReadLine(); if (line == null) { break; } if (line.Equals("g")) { Console.WriteLine("輸入訊息:"); string msg = Console.ReadLine(); userMap.SendGreeting(msg, ctx); Console.Out.Flush(); } if (line.Equals("lg")) { allgraphs = graphMap.GetAllMaps(ctx); foreach (var graph in allgraphs) { Console.WriteLine($"GraphName:{graph.GraphName}"); } Console.Out.Flush(); } if (line.Equals("cg")) { Console.WriteLine("圖名稱:"); string graphName = Console.ReadLine(); graphMap.CreateGraph(graphName, ctx); Console.Out.Flush(); } if (line.Equals("eg")) { Console.WriteLine("圖名稱:"); string graphName = Console.ReadLine(); MyGraph editGraph = graphMap.GetAllMaps(ctx).FirstOrDefault(p => p.GraphName == graphName); if (editGraph == null) { Console.WriteLine("此圖不存在"); } else { Console.WriteLine("新名稱:"); string newName = Console.ReadLine(); graphMap.EditGraph(editGraph, newName, ctx); } Console.Out.Flush(); } if (line.Equals("rg")) { Console.WriteLine("圖名稱:"); string graphName = Console.ReadLine(); graphMap.DeleteGraph(graphName, ctx); Console.Out.Flush(); } if (line.Equals("l")) { Console.WriteLine("圖名稱:"); string graphName = Console.ReadLine(); allnodes = graphMap.GetAllNodes(graphName, ctx); foreach (var node in allnodes) { Console.WriteLine($"Id:{node.NodeId} NodeText:{node.NodeText} ParetnId:{node.ParentId}"); } Console.Out.Flush(); } if (line.Equals("c")) { Console.WriteLine("圖名稱:"); string graphName = Console.ReadLine(); MyGraph editGraph = graphMap.GetAllMaps(ctx).FirstOrDefault(p => p.GraphName == graphName); if (editGraph == null) { Console.WriteLine("此圖不存在"); } else { Console.WriteLine("Node Id:"); string id = Console.ReadLine(); Console.WriteLine("節點描述:"); string text = Console.ReadLine(); MyNode node = new MyNode { NodeId = id, NodeText = text, ParentId = "root" }; if (graphMap.GetAllNodes(graphName, ctx).Length > 0) { Console.WriteLine("父節點 Id:"); node.ParentId = Console.ReadLine(); } nodeMap.CreateNode(graphName, node, ctx); } Console.Out.Flush(); } if (line.Equals("e")) { Console.WriteLine("圖名稱:"); string graphName = Console.ReadLine(); MyGraph editGraph = graphMap.GetAllMaps(ctx).FirstOrDefault(p => p.GraphName == graphName); if (editGraph == null) { Console.WriteLine("此圖不存在"); } else { Console.WriteLine("Node Id:"); string id = Console.ReadLine(); MyNode editNode = graphMap.GetAllNodes(graphName, ctx).FirstOrDefault(p => p.NodeId == id); if (editNode == null) { Console.WriteLine("此Id不存在"); } else { Console.WriteLine("節點描述:"); editNode.NodeText = Console.ReadLine(); nodeMap.EditNode(graphName, editNode, ctx); } } Console.Out.Flush(); } if (line.Equals("m")) { Console.WriteLine("圖名稱:"); string graphName = Console.ReadLine(); MyGraph editGraph = graphMap.GetAllMaps(ctx).FirstOrDefault(p => p.GraphName == graphName); if (editGraph == null) { Console.WriteLine("此圖不存在"); } else { Console.WriteLine("Node Id:"); string id = Console.ReadLine(); MyNode editNode = graphMap.GetAllNodes(graphName, ctx).FirstOrDefault(p => p.NodeId == id); if (editNode == null) { Console.WriteLine("此Id不存在"); } else { Console.WriteLine("父節點 Id:"); editNode.ParentId = Console.ReadLine(); nodeMap.MoveNode(graphName, editNode, ctx); } } Console.Out.Flush(); } if (line.Equals("r")) { Console.WriteLine("圖名稱:"); string graphName = Console.ReadLine(); MyGraph editGraph = graphMap.GetAllMaps(ctx).FirstOrDefault(p => p.GraphName == graphName); if (editGraph == null) { Console.WriteLine("此圖不存在"); } else { Console.WriteLine("Node Id:"); string id = Console.ReadLine(); nodeMap.DeleteNode(graphName, id, ctx); } Console.Out.Flush(); } else if (line.Equals("s")) { userMap.shutdown(); } else if (line.Equals("x")) { userMap.Unregister(ctx); // Nothing to do } else if (line.Equals("?")) { menu(); } else { //Console.WriteLine("unknown command `" + line + "'"); //menu(); } } catch (Exception ex) { Console.Error.WriteLine(ex); } }while (!line.Equals("x")); return(0); }
getAdmin() { Ice.ObjectAdapter adapter = null; string serverId = null; Ice.LocatorPrx defaultLocator = null; lock (this) { if (_state == StateDestroyed) { throw new Ice.CommunicatorDestroyedException(); } string adminOA = "Ice.Admin"; if (_adminAdapter != null) { return(_adminAdapter.createProxy(_adminIdentity)); } else if (_initData.properties.getProperty(adminOA + ".Endpoints").Length == 0) { return(null); } else { serverId = _initData.properties.getProperty("Ice.Admin.ServerId"); string instanceName = _initData.properties.getProperty("Ice.Admin.InstanceName"); defaultLocator = _referenceFactory.getDefaultLocator(); if ((defaultLocator != null && serverId.Length > 0) || instanceName.Length > 0) { if (_adminIdentity == null) { if (instanceName.Length == 0) { instanceName = System.Guid.NewGuid().ToString(); } _adminIdentity = new Ice.Identity("admin", instanceName); // // Afterwards, _adminIdentity is read-only // } // // Create OA // _adminAdapter = _objectAdapterFactory.createObjectAdapter(adminOA, null); // // Add all facets to OA // Dictionary <string, Ice.Object> filteredFacets = new Dictionary <string, Ice.Object>(); foreach (KeyValuePair <string, Ice.Object> entry in _adminFacets) { if (_adminFacetFilter.Count == 0 || _adminFacetFilter.Contains(entry.Key)) { _adminAdapter.addFacet(entry.Value, _adminIdentity, entry.Key); } else { filteredFacets.Add(entry.Key, entry.Value); } } _adminFacets = filteredFacets; adapter = _adminAdapter; } } } if (adapter == null) { return(null); } else { try { adapter.activate(); } catch (Ice.LocalException) { // // We cleanup _adminAdapter, however this error is not recoverable // (can't call again getAdmin() after fixing the problem) // since all the facets (servants) in the adapter are lost // adapter.destroy(); lock (this) { _adminAdapter = null; } throw; } Ice.ObjectPrx admin = adapter.createProxy(_adminIdentity); if (defaultLocator != null && serverId.Length > 0) { Ice.ProcessPrx process = Ice.ProcessPrxHelper.uncheckedCast(admin.ice_facet("Process")); try { // // Note that as soon as the process proxy is registered, the communicator might be // shutdown by a remote client and admin facets might start receiving calls. // defaultLocator.getRegistry().setServerProcessProxy(serverId, process); } catch (Ice.ServerNotFoundException) { if (_traceLevels.location >= 1) { System.Text.StringBuilder s = new System.Text.StringBuilder(); s.Append("couldn't register server `" + serverId + "' with the locator registry:\n"); s.Append("the server is not known to the locator registry"); _initData.logger.trace(_traceLevels.locationCat, s.ToString()); } throw new Ice.InitializationException("Locator knows nothing about server '" + serverId + "'"); } catch (Ice.LocalException ex) { if (_traceLevels.location >= 1) { System.Text.StringBuilder s = new System.Text.StringBuilder(); s.Append("couldn't register server `" + serverId + "' with the locator registry:\n" + ex); _initData.logger.trace(_traceLevels.locationCat, s.ToString()); } throw; // TODO: Shall we raise a special exception instead of a non obvious local exception? } if (_traceLevels.location >= 1) { System.Text.StringBuilder s = new System.Text.StringBuilder(); s.Append("registered server `" + serverId + "' with the locator registry"); _initData.logger.trace(_traceLevels.locationCat, s.ToString()); } } return(admin); } }