private static async void helloAsync(HelloPrx hello) { try { await hello.sayHelloAsync(5000); } catch (RequestCanceledException) { Console.Error.WriteLine("RequestCanceledException"); } catch (Exception ex) { Console.Error.WriteLine("sayHello AMI call failed:"); Console.Error.WriteLine(ex); } }
public static int Main(string[] args) { try { Ice.Communicator communicator = Ice.Util.initialize(ref args); HelloPrx hello = HelloPrxHelper.checkedCast(communicator.stringToProxy("hello:tcp -p 10000")); hello.sayHello(); communicator.destroy(); return(0); } catch (System.Exception ex) { System.Console.Error.WriteLine(ex); return(1); } }
private async void helloAsync(HelloPrx hello) { try { await hello.sayHelloAsync(5000); } catch (AggregateException ae) { if (ae.InnerException is RequestCanceledException) { Console.Error.WriteLine("RequestCanceledException"); } else { Console.Error.WriteLine("sayHello AMI call failed:"); Console.Error.WriteLine(ae.InnerException); } } }
private async void helloAsync(HelloPrx hello) { try { await hello.sayHelloAsync(5000); } catch(AggregateException ae) { if(ae.InnerException is RequestCanceledException) { Console.Error.WriteLine("RequestCanceledException"); } else { Console.Error.WriteLine("sayHello AMI call failed:"); Console.Error.WriteLine(ae.InnerException); } } }
public override int run(string[] args) { if (args.Length > 0) { Console.Error.WriteLine(appName() + ": too many arguments"); return(1); } HelloPrx hello = HelloPrxHelper.uncheckedCast(communicator().propertyToProxy("Hello.Proxy")); if (hello == null) { Console.Error.WriteLine("Hello.Proxy not found"); return(1); } hello.sayHello(); return(0); }
public static void allTests(global::Test.TestHelper helper) { Communicator communicator = helper.communicator(); var manager = ServerManagerPrx.Parse($"ServerManager :{helper.getTestEndpoint(0)}", communicator); var locator = TestLocatorPrx.UncheckedCast(communicator.getDefaultLocator()); Console.WriteLine("registry checkedcast"); var registry = TestLocatorRegistryPrx.CheckedCast(locator.getRegistry()); test(registry != null); var output = helper.getWriter(); output.Write("testing stringToProxy... "); output.Flush(); var @base = IObjectPrx.Parse("test @ TestAdapter", communicator); var base2 = IObjectPrx.Parse("test @ TestAdapter", communicator); var base3 = IObjectPrx.Parse("test", communicator); var base4 = IObjectPrx.Parse("ServerManager", communicator); var base5 = IObjectPrx.Parse("test2", communicator); var base6 = IObjectPrx.Parse("test @ ReplicatedAdapter", communicator); output.WriteLine("ok"); output.Write("testing ice_locator and ice_getLocator... "); test(default(ProxyIdentityComparer).Compare(@base.Locator, communicator.getDefaultLocator()) == 0); var anotherLocator = LocatorPrx.Parse("anotherLocator", communicator); @base = @base.Clone(locator: anotherLocator); test(default(ProxyIdentityComparer).Compare(@base.Locator, anotherLocator) == 0); communicator.setDefaultLocator(null); @base = IObjectPrx.Parse("test @ TestAdapter", communicator); test(@base.Locator == null); @base = @base.Clone(locator: anotherLocator); test(default(ProxyIdentityComparer).Compare(@base.Locator, anotherLocator) == 0); communicator.setDefaultLocator(locator); @base = IObjectPrx.Parse("test @ TestAdapter", communicator); test(default(ProxyIdentityComparer).Compare(@base.Locator, communicator.getDefaultLocator()) == 0); // // We also test ice_router/ice_getRouter(perhaps we should add a // test/Ice/router test?) // test(@base.Router == null); var anotherRouter = RouterPrx.Parse("anotherRouter", communicator); @base = @base.Clone(router: anotherRouter); test(default(ProxyIdentityComparer).Compare(@base.Router, anotherRouter) == 0); var router = RouterPrx.Parse("dummyrouter", communicator); communicator.setDefaultRouter(router); @base = IObjectPrx.Parse("test @ TestAdapter", communicator); test(default(ProxyIdentityComparer).Compare(@base.Router, communicator.getDefaultRouter()) == 0); communicator.setDefaultRouter(null); @base = IObjectPrx.Parse("test @ TestAdapter", communicator); test(@base.Router == null); output.WriteLine("ok"); output.Write("starting server... "); output.Flush(); manager.startServer(); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); var obj = Test.TestIntfPrx.CheckedCast(@base); test(obj != null); var obj2 = Test.TestIntfPrx.CheckedCast(base2); test(obj2 != null); var obj3 = Test.TestIntfPrx.CheckedCast(base3); test(obj3 != null); var obj4 = Test.ServerManagerPrx.CheckedCast(base4); test(obj4 != null); var obj5 = Test.TestIntfPrx.CheckedCast(base5); test(obj5 != null); var obj6 = Test.TestIntfPrx.CheckedCast(base6); test(obj6 != null); output.WriteLine("ok"); output.Write("testing id@AdapterId indirect proxy... "); output.Flush(); obj.shutdown(); manager.startServer(); try { obj2.IcePing(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing id@ReplicaGroupId indirect proxy... "); output.Flush(); obj.shutdown(); manager.startServer(); try { obj6.IcePing(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing identity indirect proxy... "); output.Flush(); obj.shutdown(); manager.startServer(); try { obj3.IcePing(); } catch (LocalException) { test(false); } try { obj2.IcePing(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj2.IcePing(); } catch (LocalException) { test(false); } try { obj3.IcePing(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj2.IcePing(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj3.IcePing(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj5 = Test.TestIntfPrx.CheckedCast(base5); obj5.IcePing(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing proxy with unknown identity... "); output.Flush(); try { @base = IObjectPrx.Parse("unknown/unknown", communicator); @base.IcePing(); test(false); } catch (NotRegisteredException ex) { test(ex.kindOfObject.Equals("object")); test(ex.id.Equals("unknown/unknown")); } output.WriteLine("ok"); output.Write("testing proxy with unknown adapter... "); output.Flush(); try { @base = IObjectPrx.Parse("test @ TestAdapterUnknown", communicator); @base.IcePing(); test(false); } catch (NotRegisteredException ex) { test(ex.kindOfObject.Equals("object adapter")); test(ex.id.Equals("TestAdapterUnknown")); } output.WriteLine("ok"); output.Write("testing locator cache timeout... "); output.Flush(); var basencc = IObjectPrx.Parse("test@TestAdapter", communicator).Clone(connectionCached: false); int count = locator.getRequestCount(); basencc.Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. test(++count == locator.getRequestCount()); basencc.Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. test(++count == locator.getRequestCount()); basencc.Clone(locatorCacheTimeout: 2).IcePing(); // 2s timeout. test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1300); // 1300ms basencc.Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout. test(++count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. count += 2; test(count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 2).IcePing(); // 2s timeout test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1300); // 1300ms IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout count += 2; test(count == locator.getRequestCount()); IObjectPrx.Parse("test@TestAdapter", communicator).Clone(locatorCacheTimeout: -1).IcePing(); test(count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: -1).IcePing(); test(count == locator.getRequestCount()); IObjectPrx.Parse("test@TestAdapter", communicator).IcePing(); test(count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).IcePing(); test(count == locator.getRequestCount()); test(IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 99).LocatorCacheTimeout == 99); output.WriteLine("ok"); output.Write("testing proxy from server... "); output.Flush(); obj = TestIntfPrx.Parse("test@TestAdapter", communicator); var hello = obj.getHello(); test(hello.AdapterId.Equals("TestAdapter")); hello.sayHello(); hello = obj.getReplicatedHello(); test(hello.AdapterId.Equals("ReplicatedAdapter")); hello.sayHello(); output.WriteLine("ok"); output.Write("testing locator request queuing... "); output.Flush(); hello = obj.getReplicatedHello().Clone(locatorCacheTimeout: 0, connectionCached: false); count = locator.getRequestCount(); hello.IcePing(); test(++count == locator.getRequestCount()); List <Task> results = new List <Task>(); for (int i = 0; i < 1000; i++) { results.Add(hello.sayHelloAsync()); } Task.WaitAll(results.ToArray()); results.Clear(); test(locator.getRequestCount() > count && locator.getRequestCount() < count + 999); if (locator.getRequestCount() > count + 800) { output.Write("queuing = " + (locator.getRequestCount() - count)); } count = locator.getRequestCount(); hello = hello.Clone(adapterId: "unknown"); for (int i = 0; i < 1000; i++) { results.Add(hello.sayHelloAsync().ContinueWith((Task t) => { try { t.Wait(); } catch (AggregateException ex) when(ex.InnerException is Ice.NotRegisteredException) { } })); } Task.WaitAll(results.ToArray()); results.Clear(); // XXX: // Take into account the retries. test(locator.getRequestCount() > count && locator.getRequestCount() < count + 1999); if (locator.getRequestCount() > count + 800) { output.Write("queuing = " + (locator.getRequestCount() - count)); } output.WriteLine("ok"); output.Write("testing adapter locator cache... "); output.Flush(); try { IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); test(false); } catch (NotRegisteredException ex) { test(ex.kindOfObject == "object adapter"); test(ex.id.Equals("TestAdapter3")); } registry.setAdapterDirectProxy("TestAdapter3", locator.findAdapterById("TestAdapter")); try { IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); registry.setAdapterDirectProxy("TestAdapter3", IObjectPrx.Parse($"dummy:{helper.getTestEndpoint(99)}", communicator)); IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); } catch (LocalException) { test(false); } try { IObjectPrx.Parse("test@TestAdapter3", communicator).Clone(locatorCacheTimeout: 0).IcePing(); test(false); } catch (LocalException) { } try { IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); test(false); } catch (LocalException) { } registry.setAdapterDirectProxy("TestAdapter3", locator.findAdapterById("TestAdapter")); try { IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing well-known object locator cache... "); output.Flush(); registry.addObject(IObjectPrx.Parse("test3@TestUnknown", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); test(false); } catch (NotRegisteredException ex) { test(ex.kindOfObject == "object adapter"); test(ex.id.Equals("TestUnknown")); } registry.addObject(IObjectPrx.Parse("test3@TestAdapter4", communicator)); // Update registry.setAdapterDirectProxy("TestAdapter4", IObjectPrx.Parse($"dummy:{helper.getTestEndpoint(99)}", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); test(false); } catch (LocalException) { } registry.setAdapterDirectProxy("TestAdapter4", locator.findAdapterById("TestAdapter")); try { IObjectPrx.Parse("test3", communicator).IcePing(); } catch (LocalException) { test(false); } registry.setAdapterDirectProxy("TestAdapter4", IObjectPrx.Parse($"dummy:{helper.getTestEndpoint(99)}", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); } catch (LocalException) { test(false); } try { IObjectPrx.Parse("test@TestAdapter4", communicator).Clone(locatorCacheTimeout: 0).IcePing(); test(false); } catch (LocalException) { } try { IObjectPrx.Parse("test@TestAdapter4", communicator).IcePing(); test(false); } catch (LocalException) { } try { IObjectPrx.Parse("test3", communicator).IcePing(); test(false); } catch (LocalException) { } registry.addObject(IObjectPrx.Parse("test3@TestAdapter", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); } catch (LocalException) { test(false); } registry.addObject(IObjectPrx.Parse("test4", communicator)); try { IObjectPrx.Parse("test4", communicator).IcePing(); test(false); } catch (NoEndpointException) { } output.WriteLine("ok"); output.Write("testing locator cache background updates... "); output.Flush(); { Dictionary <string, string> properties = communicator.GetProperties(); properties["Ice.BackgroundLocatorCacheUpdates"] = "1"; Communicator ic = helper.initialize(properties); registry.setAdapterDirectProxy("TestAdapter5", locator.findAdapterById("TestAdapter")); registry.addObject(IObjectPrx.Parse("test3@TestAdapter", communicator)); count = locator.getRequestCount(); IObjectPrx.Parse("test@TestAdapter5", ic).Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. IObjectPrx.Parse("test3", ic).Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. count += 3; test(count == locator.getRequestCount()); registry.setAdapterDirectProxy("TestAdapter5", null); registry.addObject(IObjectPrx.Parse($"test3:{helper.getTestEndpoint(99)}", communicator)); IObjectPrx.Parse("test@TestAdapter5", ic).Clone(locatorCacheTimeout: 10).IcePing(); // 10s timeout. IObjectPrx.Parse("test3", ic).Clone(locatorCacheTimeout: 10).IcePing(); // 10s timeout. test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1200); // The following request should trigger the background // updates but still use the cached endpoints and // therefore succeed. IObjectPrx.Parse("test@TestAdapter5", ic).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout. IObjectPrx.Parse("test3", ic).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout. try { while (true) { IObjectPrx.Parse("test@TestAdapter5", ic).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout. System.Threading.Thread.Sleep(10); } } catch (LocalException) { // Expected to fail once they endpoints have been updated in the background. } try { while (true) { IObjectPrx.Parse("test3", ic).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout. System.Threading.Thread.Sleep(10); } } catch (LocalException) { // Expected to fail once they endpoints have been updated in the background. } ic.destroy(); } output.WriteLine("ok"); output.Write("testing proxy from server after shutdown... "); output.Flush(); hello = obj.getReplicatedHello(); obj.shutdown(); manager.startServer(); hello.sayHello(); output.WriteLine("ok"); output.Write("testing object migration... "); output.Flush(); hello = HelloPrx.Parse("hello", communicator); obj.migrateHello(); hello.GetConnection().close(ConnectionClose.GracefullyWithWait); hello.sayHello(); obj.migrateHello(); hello.sayHello(); obj.migrateHello(); hello.sayHello(); output.WriteLine("ok"); output.Write("testing locator encoding resolution... "); output.Flush(); hello = HelloPrx.Parse("hello", communicator); count = locator.getRequestCount(); IObjectPrx.Parse("test@TestAdapter", communicator).Clone(encodingVersion: Util.Encoding_1_1).IcePing(); test(count == locator.getRequestCount()); IObjectPrx.Parse("test@TestAdapter10", communicator).Clone(encodingVersion: Util.Encoding_1_0).IcePing(); test(++count == locator.getRequestCount()); IObjectPrx.Parse("test -e 1.0@TestAdapter10-2", communicator).IcePing(); test(++count == locator.getRequestCount()); output.WriteLine("ok"); output.Write("shutdown server... "); output.Flush(); obj.shutdown(); output.WriteLine("ok"); output.Write("testing whether server is gone... "); output.Flush(); try { obj2.IcePing(); test(false); } catch (LocalException) { } try { obj3.IcePing(); test(false); } catch (LocalException) { } try { obj5.IcePing(); test(false); } catch (LocalException) { } output.WriteLine("ok"); output.Write("testing indirect proxies to collocated objects... "); output.Flush(); communicator.SetProperty("Hello.AdapterId", Guid.NewGuid().ToString()); ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("Hello", "default"); var id = new Identity(Guid.NewGuid().ToString(), ""); adapter.Add(new HelloI(), id); adapter.Activate(); // Ensure that calls on the well-known proxy is collocated. HelloPrx?helloPrx = HelloPrx.Parse("\"" + id.ToString(communicator.ToStringMode) + "\"", communicator); test(helloPrx.GetConnection() == null); // Ensure that calls on the indirect proxy (with adapter ID) is collocated helloPrx = HelloPrx.CheckedCast(adapter.CreateIndirectProxy(id)); test(helloPrx != null && helloPrx.GetConnection() == null); // Ensure that calls on the direct proxy is collocated helloPrx = HelloPrx.CheckedCast(adapter.CreateDirectProxy(id)); test(helloPrx != null && helloPrx.GetConnection() == null); output.WriteLine("ok"); output.Write("shutdown server manager... "); output.Flush(); manager.shutdown(); output.WriteLine("ok"); }
private static int run(Ice.Communicator communicator) { HelloPrx twoway = HelloPrxHelper.checkedCast( communicator.propertyToProxy("Hello.Proxy").ice_twoway().ice_secure(false)); if (twoway == null) { Console.Error.WriteLine("invalid proxy"); return(1); } HelloPrx oneway = (HelloPrx)twoway.ice_oneway(); HelloPrx batchOneway = (HelloPrx)twoway.ice_batchOneway(); HelloPrx datagram = (HelloPrx)twoway.ice_datagram(); HelloPrx batchDatagram = (HelloPrx)twoway.ice_batchDatagram(); bool secure = false; int timeout = -1; int delay = 0; menu(); string line = null; do { try { Console.Out.Write("==> "); Console.Out.Flush(); line = Console.In.ReadLine(); if (line == null) { break; } if (line.Equals("t")) { twoway.sayHello(delay); } else if (line.Equals("o")) { oneway.sayHello(delay); } else if (line.Equals("O")) { batchOneway.sayHello(delay); } else if (line.Equals("d")) { if (secure) { Console.WriteLine("secure datagrams are not supported"); } else { datagram.sayHello(delay); } } else if (line.Equals("D")) { if (secure) { Console.WriteLine("secure datagrams are not supported"); } else { batchDatagram.sayHello(delay); } } else if (line.Equals("f")) { batchOneway.ice_flushBatchRequests(); if (!secure) { batchDatagram.ice_flushBatchRequests(); } } else if (line.Equals("T")) { if (timeout == -1) { timeout = 2000; } else { timeout = -1; } twoway = (HelloPrx)twoway.ice_invocationTimeout(timeout); oneway = (HelloPrx)oneway.ice_invocationTimeout(timeout); batchOneway = (HelloPrx)batchOneway.ice_invocationTimeout(timeout); if (timeout == -1) { Console.WriteLine("timeout is now switched off"); } else { Console.WriteLine("timeout is now set to 2000ms"); } } else if (line.Equals("P")) { if (delay == 0) { delay = 2500; } else { delay = 0; } if (delay == 0) { Console.WriteLine("server delay is now deactivated"); } else { Console.WriteLine("server delay is now set to 2500ms"); } } else if (line.Equals("S")) { secure = !secure; twoway = (HelloPrx)twoway.ice_secure(secure); oneway = (HelloPrx)oneway.ice_secure(secure); batchOneway = (HelloPrx)batchOneway.ice_secure(secure); datagram = (HelloPrx)datagram.ice_secure(secure); batchDatagram = (HelloPrx)batchDatagram.ice_secure(secure); if (secure) { Console.WriteLine("secure mode is now on"); } else { Console.WriteLine("secure mode is now off"); } } else if (line.Equals("s")) { twoway.shutdown(); } else if (line.Equals("x")) { // Nothing to do } else if (line.Equals("?")) { menu(); } else { Console.WriteLine("unknown command `" + line + "'"); menu(); } } catch (System.Exception ex) { Console.Error.WriteLine(ex); } }while (!line.Equals("x")); return(0); }
public override int run(string[] args) { if (args.Length > 0) { Console.Error.WriteLine(appName() + ": too many arguments"); return(1); } try { communicator().getPluginManager().getPlugin("IceSSL"); _haveSSL = true; } catch (Ice.NotRegisteredException) { } HelloPrx twoway = HelloPrxHelper.checkedCast(communicator().stringToProxy("hello")); if (twoway == null) { Console.Error.WriteLine("invalid proxy"); return(1); } HelloPrx oneway = (HelloPrx)twoway.ice_oneway(); HelloPrx batchOneway = (HelloPrx)twoway.ice_batchOneway(); HelloPrx datagram = (HelloPrx)twoway.ice_datagram(); HelloPrx batchDatagram = (HelloPrx)twoway.ice_batchDatagram(); bool secure = false; int timeout = -1; int delay = 0; menu(); string line = null; do { try { Console.Out.Write("==> "); Console.Out.Flush(); line = Console.In.ReadLine(); if (line == null) { break; } if (line.Equals("t")) { twoway.sayHello(delay); } else if (line.Equals("o")) { oneway.sayHello(delay); } else if (line.Equals("O")) { batchOneway.sayHello(delay); } else if (line.Equals("d")) { if (secure) { Console.WriteLine("secure datagrams are not supported"); } else { datagram.sayHello(delay); } } else if (line.Equals("D")) { if (secure) { Console.WriteLine("secure datagrams are not supported"); } else { batchDatagram.sayHello(delay); } } else if (line.Equals("f")) { batchOneway.ice_flushBatchRequests(); batchDatagram.ice_flushBatchRequests(); } else if (line.Equals("T")) { if (timeout == -1) { timeout = 2000; } else { timeout = -1; } twoway = (HelloPrx)twoway.ice_invocationTimeout(timeout); oneway = (HelloPrx)oneway.ice_invocationTimeout(timeout); batchOneway = (HelloPrx)batchOneway.ice_invocationTimeout(timeout); if (timeout == -1) { Console.WriteLine("timeout is now switched off"); } else { Console.WriteLine("timeout is now set to 2000ms"); } } else if (line.Equals("P")) { if (delay == 0) { delay = 2500; } else { delay = 0; } if (delay == 0) { Console.WriteLine("server delay is now deactivated"); } else { Console.WriteLine("server delay is now set to 2500ms"); } } else if (_haveSSL && line.Equals("S")) { secure = !secure; twoway = (HelloPrx)twoway.ice_secure(secure); oneway = (HelloPrx)oneway.ice_secure(secure); batchOneway = (HelloPrx)batchOneway.ice_secure(secure); datagram = (HelloPrx)datagram.ice_secure(secure); batchDatagram = (HelloPrx)batchDatagram.ice_secure(secure); if (secure) { Console.WriteLine("secure mode is now on"); } else { Console.WriteLine("secure mode is now off"); } } else if (line.Equals("s")) { twoway.shutdown(); } else if (line.Equals("x")) { // Nothing to do } else if (line.Equals("?")) { menu(); } else { Console.WriteLine("unknown command `" + line + "'"); menu(); } } catch (System.Exception ex) { Console.Error.WriteLine(ex); } }while (!line.Equals("x")); return(0); }
public override int run(string[] args) { if (args.Length > 0) { Console.Error.WriteLine(appName() + ": too many arguments"); return(1); } HelloPrx hello = HelloPrxHelper.checkedCast(communicator().propertyToProxy("Hello.Proxy")); if (hello == null) { Console.Error.WriteLine("invalid proxy"); return(1); } menu(); string line = null; do { try { Console.Out.Write("==> "); Console.Out.Flush(); line = Console.In.ReadLine(); if (line == null) { break; } if (line.Equals("i")) { hello.sayHello(0); } else if (line.Equals("d")) { hello.begin_sayHello(5000).whenCompleted( () => { }, (Ice.Exception ex) => { if (ex is RequestCanceledException) { Console.Error.WriteLine("RequestCanceledException"); } else { Console.Error.WriteLine("sayHello AMI call failed:"); Console.Error.WriteLine(ex); } }); } else if (line.Equals("s")) { hello.shutdown(); } else if (line.Equals("x")) { // Nothing to do } else if (line.Equals("?")) { menu(); } else { Console.Out.WriteLine("unknown command `" + line + "'"); menu(); } } catch (Ice.Exception ex) { Console.Error.WriteLine(ex); } }while(!line.Equals("x")); return(0); }
public override int run(string[] args) { if (args.Length > 0) { Console.Error.WriteLine(appName() + ": too many arguments"); return(1); } // // Get the hello proxy. We configure the proxy to not cache the // server connection with the proxy and to disable the locator // cache. With this configuration, the IceGrid locator will be // queried for each invocation on the proxy and the invocation // will be sent over the server connection matching the returned // endpoints. // Ice.ObjectPrx obj = communicator().stringToProxy("hello"); obj = obj.ice_connectionCached(false); obj = obj.ice_locatorCacheTimeout(0); HelloPrx hello = HelloPrxHelper.checkedCast(obj); if (hello == null) { Console.Error.WriteLine("invalid proxy"); return(1); } while (true) { Console.Out.Write("enter the number of iterations: "); Console.Out.Flush(); string line = Console.In.ReadLine(); if (line == null || line.Equals("x")) { break; } int count = Convert.ToInt32(line); Console.Out.Write("enter the delay between each greetings (in ms): "); Console.Out.Flush(); line = Console.In.ReadLine(); if (line == null || line.Equals("x")) { break; } int delay = Convert.ToInt32(line); if (delay < 0) { delay = 500; // 500 milli-seconds } for (int i = 0; i < count; i++) { Console.Out.WriteLine(hello.getGreeting()); System.Threading.Thread.Sleep(delay); } } return(0); }
public override int run(string[] args) { if (args.Length > 0) { Console.Error.WriteLine(appName() + ": too many arguments"); return(1); } string name; do { Console.Out.Write("Please enter your name ==> "); Console.Out.Flush(); name = Console.In.ReadLine(); if (name == null) { return(1); } name = name.Trim(); }while(name.Length == 0); var basePrx = communicator().propertyToProxy("SessionFactory.Proxy"); var factory = SessionFactoryPrxHelper.checkedCast(basePrx); if (factory == null) { Console.Error.WriteLine("invalid proxy"); return(1); } SessionPrx session = factory.create(name); var refresh = new SessionRefreshThread(communicator().getLogger(), 5000, session); var refreshThread = new Thread(new ThreadStart(refresh.run)); refreshThread.Start(); var hellos = new List <HelloPrx>(); menu(); try { bool destroy = true; bool shutdown = false; while (true) { Console.Out.Write("==> "); Console.Out.Flush(); var line = Console.In.ReadLine(); if (line == null) { break; } if (line.Length > 0 && Char.IsDigit(line[0])) { int index = Int32.Parse(line); if (index < hellos.Count) { HelloPrx hello = hellos[index]; hello.sayHello(); } else { Console.Out.WriteLine("Index is too high. " + hellos.Count + " hello objects exist so far.\n" + "Use `c' to create a new hello object."); } } else if (line.Equals("c")) { hellos.Add(session.createHello()); Console.Out.WriteLine("Created hello object " + (hellos.Count - 1)); } else if (line.Equals("s")) { destroy = false; shutdown = true; break; } else if (line.Equals("x")) { break; } else if (line.Equals("t")) { destroy = false; break; } else if (line.Equals("?")) { menu(); } else { Console.Out.WriteLine("Unknown command `" + line + "'."); menu(); } } // // The refresher thread must be terminated before destroy is // called, otherwise it might get ObjectNotExistException. refresh // is set to 0 so that if session.destroy() raises an exception // the thread will not be re-terminated and re-joined. // refresh.terminate(); refreshThread.Join(); refresh = null; if (destroy) { session.destroy(); } if (shutdown) { factory.shutdown(); } } catch (Exception) { // // The refresher thread must be terminated in the event of a // failure. // if (refresh != null) { refresh.terminate(); refreshThread.Join(); refresh = null; } throw; } return(0); }
private static int run(Ice.Communicator communicator) { HelloPrx hello = null; try { hello = HelloPrxHelper.checkedCast(communicator.stringToProxy("hello")); } catch (Ice.NotRegisteredException) { var query = IceGrid.QueryPrxHelper.checkedCast(communicator.stringToProxy("DemoIceGrid/Query")); hello = HelloPrxHelper.checkedCast(query.findObjectByType("::Demo::Hello")); } if (hello == null) { Console.WriteLine("couldn't find a `::Demo::Hello' object"); return(1); } menu(); string line = null; do { try { Console.Write("==> "); Console.Out.Flush(); line = Console.In.ReadLine(); if (line == null) { break; } if (line.Equals("t")) { hello.sayHello(); } else if (line.Equals("s")) { hello.shutdown(); } else if (line.Equals("x")) { // Nothing to do } else if (line.Equals("?")) { menu(); } else { Console.WriteLine("unknown command `" + line + "'"); menu(); } } catch (Ice.LocalException ex) { Console.WriteLine(ex); } }while(!line.Equals("x")); return(0); }
public override int run(string[] args) { if (args.Length > 0) { Console.Error.WriteLine(appName() + ": too many arguments"); return(1); } HelloPrx hello = null; try { hello = HelloPrxHelper.checkedCast(communicator().stringToProxy("hello")); } catch (Ice.NotRegisteredException) { IceGrid.QueryPrx query = IceGrid.QueryPrxHelper.checkedCast(communicator().stringToProxy("DemoIceGrid/Query")); hello = HelloPrxHelper.checkedCast(query.findObjectByType("::Demo::Hello")); } if (hello == null) { Console.WriteLine("couldn't find a `::Demo::Hello' object"); return(1); } menu(); string line = null; do { try { Console.Write("==> "); Console.Out.Flush(); line = Console.In.ReadLine(); if (line == null) { break; } if (line.Equals("t")) { hello.sayHello(); } else if (line.Equals("s")) { hello.shutdown(); } else if (line.Equals("x")) { // Nothing to do } else if (line.Equals("?")) { menu(); } else { Console.WriteLine("unknown command `" + line + "'"); menu(); } } catch (Ice.LocalException ex) { Console.WriteLine(ex); } }while(!line.Equals("x")); return(0); }
public static void allTests(TestCommon.Application app) { Ice.Communicator communicator = app.communicator(); ServerManagerPrx manager = ServerManagerPrxHelper.checkedCast( communicator.stringToProxy("ServerManager :" + app.getTestEndpoint(0))); test(manager != null); TestLocatorPrx locator = TestLocatorPrxHelper.uncheckedCast(communicator.getDefaultLocator()); test(locator != null); TestLocatorRegistryPrx registry = TestLocatorRegistryPrxHelper.checkedCast(locator.getRegistry()); test(registry != null); Write("testing stringToProxy... "); Flush(); Ice.ObjectPrx @base = communicator.stringToProxy("test @ TestAdapter"); Ice.ObjectPrx base2 = communicator.stringToProxy("test @ TestAdapter"); Ice.ObjectPrx base3 = communicator.stringToProxy("test"); Ice.ObjectPrx base4 = communicator.stringToProxy("ServerManager"); Ice.ObjectPrx base5 = communicator.stringToProxy("test2"); Ice.ObjectPrx base6 = communicator.stringToProxy("test @ ReplicatedAdapter"); WriteLine("ok"); Write("testing ice_locator and ice_getLocator... "); test(Ice.Util.proxyIdentityCompare(@base.ice_getLocator(), communicator.getDefaultLocator()) == 0); Ice.LocatorPrx anotherLocator = Ice.LocatorPrxHelper.uncheckedCast(communicator.stringToProxy("anotherLocator")); @base = @base.ice_locator(anotherLocator); test(Ice.Util.proxyIdentityCompare(@base.ice_getLocator(), anotherLocator) == 0); communicator.setDefaultLocator(null); @base = communicator.stringToProxy("test @ TestAdapter"); test(@base.ice_getLocator() == null); @base = @base.ice_locator(anotherLocator); test(Ice.Util.proxyIdentityCompare(@base.ice_getLocator(), anotherLocator) == 0); communicator.setDefaultLocator(locator); @base = communicator.stringToProxy("test @ TestAdapter"); test(Ice.Util.proxyIdentityCompare(@base.ice_getLocator(), communicator.getDefaultLocator()) == 0); // // We also test ice_router/ice_getRouter (perhaps we should add a // test/Ice/router test?) // test(@base.ice_getRouter() == null); Ice.RouterPrx anotherRouter = Ice.RouterPrxHelper.uncheckedCast(communicator.stringToProxy("anotherRouter")); @base = @base.ice_router(anotherRouter); test(Ice.Util.proxyIdentityCompare(@base.ice_getRouter(), anotherRouter) == 0); Ice.RouterPrx router = Ice.RouterPrxHelper.uncheckedCast(communicator.stringToProxy("dummyrouter")); communicator.setDefaultRouter(router); @base = communicator.stringToProxy("test @ TestAdapter"); test(Ice.Util.proxyIdentityCompare(@base.ice_getRouter(), communicator.getDefaultRouter()) == 0); communicator.setDefaultRouter(null); @base = communicator.stringToProxy("test @ TestAdapter"); test(@base.ice_getRouter() == null); WriteLine("ok"); Write("starting server... "); Flush(); manager.startServer(); WriteLine("ok"); Write("testing checked cast... "); Flush(); TestIntfPrx obj = TestIntfPrxHelper.checkedCast(@base); test(obj != null); TestIntfPrx obj2 = TestIntfPrxHelper.checkedCast(base2); test(obj2 != null); TestIntfPrx obj3 = TestIntfPrxHelper.checkedCast(base3); test(obj3 != null); ServerManagerPrx obj4 = ServerManagerPrxHelper.checkedCast(base4); test(obj4 != null); TestIntfPrx obj5 = TestIntfPrxHelper.checkedCast(base5); test(obj5 != null); TestIntfPrx obj6 = TestIntfPrxHelper.checkedCast(base6); test(obj6 != null); WriteLine("ok"); Write("testing id@AdapterId indirect proxy... "); Flush(); obj.shutdown(); manager.startServer(); try { obj2.ice_ping(); } catch (Ice.LocalException) { test(false); } WriteLine("ok"); Write("testing id@ReplicaGroupId indirect proxy... "); Flush(); obj.shutdown(); manager.startServer(); try { obj6.ice_ping(); } catch (Ice.LocalException) { test(false); } WriteLine("ok"); Write("testing identity indirect proxy... "); Flush(); obj.shutdown(); manager.startServer(); try { obj3.ice_ping(); } catch (Ice.LocalException) { test(false); } try { obj2.ice_ping(); } catch (Ice.LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj2.ice_ping(); } catch (Ice.LocalException) { test(false); } try { obj3.ice_ping(); } catch (Ice.LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj2.ice_ping(); } catch (Ice.LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj3.ice_ping(); } catch (Ice.LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj5 = TestIntfPrxHelper.checkedCast(base5); obj5.ice_ping(); } catch (Ice.LocalException) { test(false); } WriteLine("ok"); Write("testing proxy with unknown identity... "); Flush(); try { @base = communicator.stringToProxy("unknown/unknown"); @base.ice_ping(); test(false); } catch (Ice.NotRegisteredException ex) { test(ex.kindOfObject.Equals("object")); test(ex.id.Equals("unknown/unknown")); } WriteLine("ok"); Write("testing proxy with unknown adapter... "); Flush(); try { @base = communicator.stringToProxy("test @ TestAdapterUnknown"); @base.ice_ping(); test(false); } catch (Ice.NotRegisteredException ex) { test(ex.kindOfObject.Equals("object adapter")); test(ex.id.Equals("TestAdapterUnknown")); } WriteLine("ok"); Write("testing locator cache timeout... "); Flush(); int count = locator.getRequestCount(); communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache. test(++count == locator.getRequestCount()); communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache. test(++count == locator.getRequestCount()); communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout. test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1200); // 1200ms communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout. test(++count == locator.getRequestCount()); communicator.stringToProxy("test").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache. count += 2; test(count == locator.getRequestCount()); communicator.stringToProxy("test").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1200); // 1200ms communicator.stringToProxy("test").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout count += 2; test(count == locator.getRequestCount()); communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(-1).ice_ping(); test(count == locator.getRequestCount()); communicator.stringToProxy("test").ice_locatorCacheTimeout(-1).ice_ping(); test(count == locator.getRequestCount()); communicator.stringToProxy("test@TestAdapter").ice_ping(); test(count == locator.getRequestCount()); communicator.stringToProxy("test").ice_ping(); test(count == locator.getRequestCount()); test(communicator.stringToProxy("test").ice_locatorCacheTimeout(99).ice_getLocatorCacheTimeout() == 99); WriteLine("ok"); Write("testing proxy from server... "); Flush(); obj = TestIntfPrxHelper.checkedCast(communicator.stringToProxy("test@TestAdapter")); HelloPrx hello = obj.getHello(); test(hello.ice_getAdapterId().Equals("TestAdapter")); hello.sayHello(); hello = obj.getReplicatedHello(); test(hello.ice_getAdapterId().Equals("ReplicatedAdapter")); hello.sayHello(); WriteLine("ok"); Write("testing locator request queuing... "); Flush(); hello = (HelloPrx)obj.getReplicatedHello().ice_locatorCacheTimeout(0).ice_connectionCached(false); count = locator.getRequestCount(); hello.ice_ping(); test(++count == locator.getRequestCount()); List <Ice.AsyncResult <Test.Callback_Hello_sayHello> > results = new List <Ice.AsyncResult <Test.Callback_Hello_sayHello> >(); for (int i = 0; i < 1000; i++) { Ice.AsyncResult <Test.Callback_Hello_sayHello> result = hello.begin_sayHello(). whenCompleted( () => { }, (Ice.Exception ex) => { test(false); }); results.Add(result); } foreach (Ice.AsyncResult <Test.Callback_Hello_sayHello> result in results) { result.waitForCompleted(); } results.Clear(); test(locator.getRequestCount() > count && locator.getRequestCount() < count + 999); if (locator.getRequestCount() > count + 800) { Write("queuing = " + (locator.getRequestCount() - count)); } count = locator.getRequestCount(); hello = (HelloPrx)hello.ice_adapterId("unknown"); for (int i = 0; i < 1000; i++) { Ice.AsyncResult <Test.Callback_Hello_sayHello> result = hello.begin_sayHello(). whenCompleted( () => { test(false); }, (Ice.Exception ex) => { test(ex is Ice.NotRegisteredException); }); results.Add(result); } foreach (Ice.AsyncResult <Test.Callback_Hello_sayHello> result in results) { result.waitForCompleted(); } results.Clear(); // XXX: // Take into account the retries. test(locator.getRequestCount() > count && locator.getRequestCount() < count + 1999); if (locator.getRequestCount() > count + 800) { Write("queuing = " + (locator.getRequestCount() - count)); } WriteLine("ok"); Write("testing adapter locator cache... "); Flush(); try { communicator.stringToProxy("test@TestAdapter3").ice_ping(); test(false); } catch (Ice.NotRegisteredException ex) { test(ex.kindOfObject == "object adapter"); test(ex.id.Equals("TestAdapter3")); } registry.setAdapterDirectProxy("TestAdapter3", locator.findAdapterById("TestAdapter")); try { communicator.stringToProxy("test@TestAdapter3").ice_ping(); registry.setAdapterDirectProxy("TestAdapter3", communicator.stringToProxy("dummy:tcp")); communicator.stringToProxy("test@TestAdapter3").ice_ping(); } catch (Ice.LocalException) { test(false); } try { communicator.stringToProxy("test@TestAdapter3").ice_locatorCacheTimeout(0).ice_ping(); test(false); } catch (Ice.LocalException) { } try { communicator.stringToProxy("test@TestAdapter3").ice_ping(); test(false); } catch (Ice.LocalException) { } registry.setAdapterDirectProxy("TestAdapter3", locator.findAdapterById("TestAdapter")); try { communicator.stringToProxy("test@TestAdapter3").ice_ping(); } catch (Ice.LocalException) { test(false); } WriteLine("ok"); Write("testing well-known object locator cache... "); Flush(); registry.addObject(communicator.stringToProxy("test3@TestUnknown")); try { communicator.stringToProxy("test3").ice_ping(); test(false); } catch (Ice.NotRegisteredException ex) { test(ex.kindOfObject == "object adapter"); test(ex.id.Equals("TestUnknown")); } registry.addObject(communicator.stringToProxy("test3@TestAdapter4")); // Update registry.setAdapterDirectProxy("TestAdapter4", communicator.stringToProxy("dummy:tcp")); try { communicator.stringToProxy("test3").ice_ping(); test(false); } catch (Ice.LocalException) { } registry.setAdapterDirectProxy("TestAdapter4", locator.findAdapterById("TestAdapter")); try { communicator.stringToProxy("test3").ice_ping(); } catch (Ice.LocalException) { test(false); } registry.setAdapterDirectProxy("TestAdapter4", communicator.stringToProxy("dummy:tcp")); try { communicator.stringToProxy("test3").ice_ping(); } catch (Ice.LocalException) { test(false); } try { communicator.stringToProxy("test@TestAdapter4").ice_locatorCacheTimeout(0).ice_ping(); test(false); } catch (Ice.LocalException) { } try { communicator.stringToProxy("test@TestAdapter4").ice_ping(); test(false); } catch (Ice.LocalException) { } try { communicator.stringToProxy("test3").ice_ping(); test(false); } catch (Ice.LocalException) { } registry.addObject(communicator.stringToProxy("test3@TestAdapter")); try { communicator.stringToProxy("test3").ice_ping(); } catch (Ice.LocalException) { test(false); } registry.addObject(communicator.stringToProxy("test4")); try { communicator.stringToProxy("test4").ice_ping(); test(false); } catch (Ice.NoEndpointException) { } WriteLine("ok"); Write("testing locator cache background updates... "); Flush(); { Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = communicator.getProperties().ice_clone_(); initData.properties.setProperty("Ice.BackgroundLocatorCacheUpdates", "1"); Ice.Communicator ic = Ice.Util.initialize(initData); registry.setAdapterDirectProxy("TestAdapter5", locator.findAdapterById("TestAdapter")); registry.addObject(communicator.stringToProxy("test3@TestAdapter")); count = locator.getRequestCount(); ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache. ic.stringToProxy("test3").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache. count += 3; test(count == locator.getRequestCount()); registry.setAdapterDirectProxy("TestAdapter5", null); registry.addObject(communicator.stringToProxy("test3:tcp")); ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(10).ice_ping(); // 10s timeout. ic.stringToProxy("test3").ice_locatorCacheTimeout(10).ice_ping(); // 10s timeout. test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1200); // The following request should trigger the background // updates but still use the cached endpoints and // therefore succeed. ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout. ic.stringToProxy("test3").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout. try { while (true) { ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout. System.Threading.Thread.Sleep(10); } } catch (Ice.LocalException) { // Expected to fail once they endpoints have been updated in the background. } try { while (true) { ic.stringToProxy("test3").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout. System.Threading.Thread.Sleep(10); } } catch (Ice.LocalException) { // Expected to fail once they endpoints have been updated in the background. } ic.destroy(); } WriteLine("ok"); Write("testing proxy from server after shutdown... "); Flush(); hello = obj.getReplicatedHello(); obj.shutdown(); manager.startServer(); hello.sayHello(); WriteLine("ok"); Write("testing object migration... "); Flush(); hello = HelloPrxHelper.checkedCast(communicator.stringToProxy("hello")); obj.migrateHello(); hello.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); hello.sayHello(); obj.migrateHello(); hello.sayHello(); obj.migrateHello(); hello.sayHello(); WriteLine("ok"); Write("testing locator encoding resolution... "); Flush(); hello = HelloPrxHelper.checkedCast(communicator.stringToProxy("hello")); count = locator.getRequestCount(); communicator.stringToProxy("test@TestAdapter").ice_encodingVersion(Ice.Util.Encoding_1_1).ice_ping(); test(count == locator.getRequestCount()); communicator.stringToProxy("test@TestAdapter10").ice_encodingVersion(Ice.Util.Encoding_1_0).ice_ping(); test(++count == locator.getRequestCount()); communicator.stringToProxy("test -e 1.0@TestAdapter10-2").ice_ping(); test(++count == locator.getRequestCount()); WriteLine("ok"); Write("shutdown server... "); Flush(); obj.shutdown(); WriteLine("ok"); Write("testing whether server is gone... "); Flush(); try { obj2.ice_ping(); test(false); } catch (Ice.LocalException) { } try { obj3.ice_ping(); test(false); } catch (Ice.LocalException) { } try { obj5.ice_ping(); test(false); } catch (Ice.LocalException) { } WriteLine("ok"); Write("testing indirect proxies to collocated objects... "); Flush(); // // Set up test for calling a collocated object through an // indirect, adapterless reference. // Ice.Properties properties = communicator.getProperties(); properties.setProperty("Ice.PrintAdapterReady", "0"); Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("Hello", "tcp -h *"); adapter.setLocator(locator); Ice.Identity id = new Ice.Identity(); id.name = Guid.NewGuid().ToString(); registry.addObject(adapter.add(new HelloI(), id)); adapter.activate(); HelloPrx helloPrx = HelloPrxHelper.checkedCast( communicator.stringToProxy("\"" + communicator.identityToString(id) + "\"")); test(helloPrx.ice_getConnection() == null); adapter.deactivate(); WriteLine("ok"); Write("shutdown server manager... "); Flush(); manager.shutdown(); WriteLine("ok"); }
public static void write__(IceInternal.BasicStream os__, HelloPrx v__) { os__.writeProxy(v__); }
public override int run(string[] args) { if (args.Length > 0) { Console.Error.WriteLine(appName() + ": too many arguments"); return(1); } HelloPrx hello = HelloPrxHelper.checkedCast(communicator().propertyToProxy("Hello.Proxy")); if (hello == null) { Console.Error.WriteLine("invalid proxy"); return(1); } menu(); string line = null; do { try { Console.Out.Write("==> "); Console.Out.Flush(); line = Console.In.ReadLine(); if (line == null) { break; } if (line.Equals("t")) { hello.sayHello(); } else if (line.Equals("s")) { hello.shutdown(); } else if (line.Equals("x")) { // Nothing to do } else if (line.Equals("?")) { menu(); } else { Console.WriteLine("unknown command `" + line + "'"); menu(); } } catch (System.Exception ex) { Console.Error.WriteLine(ex); } }while (!line.Equals("x")); return(0); }
public override int run(string[] args) { if (args.Length > 0) { Console.Error.WriteLine(appName() + ": too many arguments"); return(1); } try { communicator().getPluginManager().getPlugin("IceSSL"); _haveSSL = true; } catch (Ice.NotRegisteredException) { } HelloPrx twoway = HelloPrxHelper.checkedCast( communicator().propertyToProxy("Hello.Proxy").ice_twoway().ice_timeout(-1).ice_secure(false)); if (twoway == null) { Console.Error.WriteLine("invalid proxy"); return(1); } HelloPrx oneway = HelloPrxHelper.uncheckedCast(twoway.ice_oneway()); HelloPrx batchOneway = HelloPrxHelper.uncheckedCast(twoway.ice_batchOneway()); HelloPrx datagram = HelloPrxHelper.uncheckedCast(twoway.ice_datagram()); HelloPrx batchDatagram = HelloPrxHelper.uncheckedCast(twoway.ice_batchDatagram()); bool secure = false; menu(); string line = null; do { try { Console.Out.Write("==> "); Console.Out.Flush(); line = Console.In.ReadLine(); if (line == null) { break; } if (line.Equals("t")) { twoway.sayHello(); } else if (line.Equals("o")) { oneway.sayHello(); } else if (line.Equals("O")) { batchOneway.sayHello(); } else if (line.Equals("d")) { if (secure) { Console.WriteLine("secure datagrams are not supported"); } else { datagram.sayHello(); } } else if (line.Equals("D")) { if (secure) { Console.WriteLine("secure datagrams are not supported"); } else { batchDatagram.sayHello(); } } else if (line.Equals("f")) { batchOneway.ice_flushBatchRequests(); batchDatagram.ice_flushBatchRequests(); } else if (_haveSSL && line.Equals("S")) { secure = !secure; twoway = HelloPrxHelper.uncheckedCast(twoway.ice_secure(secure)); oneway = HelloPrxHelper.uncheckedCast(oneway.ice_secure(secure)); batchOneway = HelloPrxHelper.uncheckedCast(batchOneway.ice_secure(secure)); datagram = HelloPrxHelper.uncheckedCast(datagram.ice_secure(secure)); batchDatagram = HelloPrxHelper.uncheckedCast(batchDatagram.ice_secure(secure)); if (secure) { Console.WriteLine("secure mode is now on"); } else { Console.WriteLine("secure mode is now off"); } } else if (line.Equals("x")) { // Nothing to do } else if (line.Equals("?")) { menu(); } else { Console.WriteLine("unknown command `" + line + "'"); menu(); } } catch (System.Exception ex) { Console.Error.WriteLine(ex); } }while (!line.Equals("x")); return(0); }