context: // **********************************************************************
  //
  // Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved.
  //
  // This copy of Ice is licensed to you under the terms described in the
  // ICE_LICENSE file included in this distribution.
  //
  // **********************************************************************
  
  using System;
  using System.Collections.Generic;
  using System.Diagnostics;
  using System.Threading;
  using System.Threading.Tasks;
  using Test;
  
  public class AllTests : TestCommon.AllTests
  {
      private class Cookie
      {
          public Cookie(int i)
          {
              val = i;
          }
  
          public int val;
      }
  
      public class Progress : IProgress<bool>
      {
          public Progress(Action<bool> report)
          {
              _report = report;
          }
  
          public void Report(bool sentSynchronously)
          {
              _report(sentSynchronously);
          }
  
          Action<bool> _report;
      }
  
      public class ProgresCallback : IProgress<bool>
      {
          public bool Sent
          {
              get
              {
                  lock(this)
                  {
                      return _sent;
                  }
              }
              set
              {
                  lock(this)
                  {
                      _sent = value;
                  }
              }
          }
  
          public bool SentSynchronously
          {
              get
              {
                  lock(this)
                  {
                      return _sentSynchronously;
                  }
              }
              set
              {
                  lock(this)
                  {
                      _sentSynchronously = value;
                  }
              }
          }
  
          public void Report(bool sentSynchronously)
          {
              SentSynchronously = sentSynchronously;
              Sent = true;
          }
  
          private bool _sent = false;
          private bool _sentSynchronously = false;
      }
  
      private class CallbackBase
      {
          internal CallbackBase()
          {
              _called = false;
          }
  
          public virtual void check()
          {
              lock(this)
              {
                  while(!_called)
                  {
                      System.Threading.Monitor.Wait(this);
                  }
                  _called = false;
              }
          }
  
          public virtual void called()
          {
              lock(this)
              {
                  Debug.Assert(!_called);
                  _called = true;
                  System.Threading.Monitor.Pulse(this);
              }
          }
  
          private bool _called;
      }
  
      private class AsyncCallback : CallbackBase
      {
          public AsyncCallback()
          {
          }
  
          public AsyncCallback(Cookie cookie)
          {
              _cookie = cookie;
          }
  
          public void
          isA(Ice.AsyncResult result)
          {
              test(result.AsyncState == _cookie);
              test(result.getProxy().end_ice_isA(result));
              called();
          }
  
          public void
          ping(Ice.AsyncResult result)
          {
              test(result.AsyncState == _cookie);
              result.getProxy().end_ice_ping(result);
              called();
          }
  
          public void
          id(Ice.AsyncResult result)
          {
              test(result.AsyncState == _cookie);
              test(result.getProxy().end_ice_id(result).Equals("::Test::TestIntf"));
              called();
          }
  
          public void
          ids(Ice.AsyncResult result)
          {
              test(result.AsyncState == _cookie);
              test(result.getProxy().end_ice_ids(result).Length == 2);
              called();
          }
  
          public void
          connection(Ice.AsyncResult result)
          {
              test(result.AsyncState == _cookie);
              test(result.getProxy().end_ice_getConnection(result) != null);
              called();
          }
  
          public void
          op(Ice.AsyncResult result)
          {
              test(result.AsyncState == _cookie);
              TestIntfPrxHelper.uncheckedCast(result.getProxy()).end_op(result);
              called();
          }
  
          public void
          opWithResult(Ice.AsyncResult result)
          {
              test(result.AsyncState == _cookie);
              test(TestIntfPrxHelper.uncheckedCast(result.getProxy()).end_opWithResult(result) == 15);
              called();
          }
  
          public void
          opWithUE(Ice.AsyncResult result)
          {
              test(result.AsyncState == _cookie);
              try
              {
                  TestIntfPrxHelper.uncheckedCast(result.getProxy()).end_opWithUE(result);
                  test(false);
              }
              catch(TestIntfException)
              {
                  called();
              }
              catch(Ice.Exception)
              {
                  test(false);
              }
          }
  
          public void
          isAEx(Ice.AsyncResult result)
          {
              test(result.AsyncState == _cookie);
              try
              {
                  result.getProxy().end_ice_isA(result);
                  test(false);
              }
              catch(Ice.NoEndpointException)
              {
                  called();
              }
              catch(Ice.Exception)
              {
                  test(false);
              }
          }
  
          public void
          pingEx(Ice.AsyncResult result)
          {
              test(result.AsyncState == _cookie);
              try
              {
                  result.getProxy().end_ice_ping(result);
                  test(false);
              }
              catch(Ice.NoEndpointException)
              {
                  called();
              }
              catch(Ice.Exception)
              {
                  test(false);
              }
          }
  
          public void
          idEx(Ice.AsyncResult result)
          {
              test(result.AsyncState == _cookie);
              try
              {
                  result.getProxy().end_ice_id(result);
                  test(false);
              }
              catch(Ice.NoEndpointException)
              {
                  called();
              }
              catch(Ice.Exception)
              {
                  test(false);
              }
          }
  
          public void
          idsEx(Ice.AsyncResult result)
          {
              test(result.AsyncState == _cookie);
              try
              {
                  result.getProxy().end_ice_ids(result);
                  test(false);
              }
              catch(Ice.NoEndpointException)
              {
                  called();
              }
              catch(Ice.Exception)
              {
                  test(false);
              }
          }
  
          public void
          connectionEx(Ice.AsyncResult result)
          {
              test(result.AsyncState == _cookie);
              try
              {
                  result.getProxy().end_ice_getConnection(result);
                  test(false);
              }
              catch(Ice.NoEndpointException)
              {
                  called();
              }
              catch(Ice.Exception)
              {
                  test(false);
              }
          }
  
          public void
          opEx(Ice.AsyncResult result)
          {
              test(result.AsyncState == _cookie);
              try
              {
                  TestIntfPrxHelper.uncheckedCast(result.getProxy()).end_op(result);
                  test(false);
              }
              catch(Ice.NoEndpointException)
              {
                  called();
              }
              catch(Ice.Exception)
              {
                  test(false);
              }
          }
  
          private Cookie _cookie;
      }
  
      private class ResponseCallback : CallbackBase
      {
          public ResponseCallback()
          {
          }
  
          public void
          isA(bool r)
          {
              test(r);
              called();
          }
  
          public void
          ping()
          {
              called();
          }
  
          public void
          id(string id)
          {
              test(id.Equals("::Test::TestIntf"));
              called();
          }
  
          public void
          ids(string[] ids)
          {
              test(ids.Length == 2);
              called();
          }
  
          public void
          connection(Ice.Connection conn)
          {
              test(conn != null);
              called();
          }
  
          public void
          op()
          {
              called();
          }
  
          public void
          opWithResult(int r)
          {
              test(r == 15);
              called();
          }
  
          public void
          opWithUE(Ice.Exception e)
          {
              try
              {
                  throw e;
              }
              catch(TestIntfException)
              {
                  called();
              }
              catch(Ice.Exception)
              {
                  test(false);
              }
          }
  
      }
  
      private class ExceptionCallback : CallbackBase
      {
          public ExceptionCallback()
          {
          }
  
          public void
          isA(bool r)
          {
              test(false);
          }
  
          public void
          ping()
          {
              test(false);
          }
  
          public void
          id(string id)
          {
              test(false);
          }
  
          public void
          ids(string[] ids)
          {
              test(false);
          }
  
          public void
          connection(Ice.Connection conn)
          {
              test(false);
          }
  
          public void
          op()
          {
              test(false);
          }
  
          public void
          opWithUE(Ice.Exception e)
          {
              try
              {
                  throw e;
              }
              catch(TestIntfException)
              {
                  called();
              }
              catch(Ice.Exception)
              {
                  test(false);
              }
          }
  
          public void
          ex(Ice.Exception ex)
          {
              test(ex is Ice.NoEndpointException);
              called();
          }
  
          public void
          noEx(Ice.Exception ex)
          {
              test(false);
          }
      }
  
      private class SentCallback : CallbackBase
      {
          public SentCallback()
          {
              _thread = Thread.CurrentThread;
          }
  
          public void
          isA(bool r)
          {
          }
  
          public void
          ping()
          {
          }
  
          public void
          id(string s)
          {
          }
  
          public void
          ids(string[] s)
          {
          }
  
          public void
          opAsync(Ice.AsyncResult r)
          {
          }
  
          public void
          op()
          {
          }
  
          public void
          ex(Ice.Exception ex)
          {
          }
  
          public void
          sentAsync(Ice.AsyncResult r)
          {
              test(r.sentSynchronously() && _thread == Thread.CurrentThread ||
                   !r.sentSynchronously() && _thread != Thread.CurrentThread);
              called();
          }
  
          public void
          sent(bool ss)
          {
              test(ss && _thread == Thread.CurrentThread || !ss && _thread != Thread.CurrentThread);
  
              called();
          }
  
          Thread _thread;
      }
  
      private class FlushCallback : CallbackBase
      {
          public FlushCallback()
          {
              _thread = Thread.CurrentThread;
          }
  
          public FlushCallback(Cookie cookie)
          {
              _thread = Thread.CurrentThread;
              _cookie = cookie;
          }
  
          public void
          completedAsync(Ice.AsyncResult r)
          {
              test(false);
          }
  
          public void
          exception(Ice.Exception ex)
          {
              test(false);
          }
  
          public void
          sentAsync(Ice.AsyncResult r)
          {
              test(r.AsyncState == _cookie);
              test(r.sentSynchronously() && _thread == Thread.CurrentThread ||
                   !r.sentSynchronously() && _thread != Thread.CurrentThread);
              called();
          }
  
          public void
          sent(bool sentSynchronously)
          {
              test(sentSynchronously && _thread == Thread.CurrentThread ||
                   !sentSynchronously && _thread != Thread.CurrentThread);
              called();
          }
  
          Cookie _cookie;
          Thread _thread;
      }
  
      private class FlushExCallback : CallbackBase
      {
          public FlushExCallback()
          {
          }
  
          public FlushExCallback(Cookie cookie)
          {
              _cookie = cookie;
          }
  
          public void
          completedAsync(Ice.AsyncResult r)
          {
              test(r.AsyncState == _cookie);
              try
              {
                  if(r.getConnection() != null)
                  {
                      r.getConnection().end_flushBatchRequests(r);
                  }
                  else
                  {
                      r.getProxy().end_ice_flushBatchRequests(r);
                  }
                  test(false);
              }
              catch(Ice.LocalException)
              {
                  called();
              }
          }
  
          public void
          exception(Ice.Exception ex)
          {
              called();
          }
  
          public void
          sentAsync(Ice.AsyncResult r)
          {
              test(false);
          }
  
          public void
          sent(bool sentSynchronously)
          {
              test(false);
          }
  
          Cookie _cookie;
      }
  
      enum ThrowType { LocalException, UserException, OtherException };
  
      private class Thrower : CallbackBase
      {
          public Thrower(ThrowType t)
          {
              _t = t;
          }
  
          public void
          opAsync(Ice.AsyncResult r)
          {
              called();
              throwEx();
          }
  
          public void
          op()
          {
              called();
              throwEx();
          }
  
          public void
          noOp()
          {
          }
  
          public void
          ex(Ice.Exception ex)
          {
              called();
              throwEx();
          }
  
          public void
          sent(bool ss)
          {
              called();
              throwEx();
          }
  
          private void
          throwEx()
          {
              switch(_t)
              {
              case ThrowType.LocalException:
              {
                  throw new Ice.ObjectNotExistException();
              }
              case ThrowType.UserException:
              {
                  throw new TestIntfException();
              }
              case ThrowType.OtherException:
              {
                  throw new Exception();
              }
              default:
              {
                  Debug.Assert(false);
                  break;
              }
              }
          }
  
          ThrowType _t;
      }
  
      public static void allTests(TestCommon.Application app, bool collocated)
      {
          Ice.Communicator communicator = app.communicator();
          string sref = "test:" + app.getTestEndpoint(0);
          Ice.ObjectPrx obj = communicator.stringToProxy(sref);
          test(obj != null);
  
          Test.TestIntfPrx p = Test.TestIntfPrxHelper.uncheckedCast(obj);
          sref = "testController:" + app.getTestEndpoint(1);
          obj = communicator.stringToProxy(sref);
          test(obj != null);
  
          Test.TestIntfControllerPrx testController = Test.TestIntfControllerPrxHelper.uncheckedCast(obj);
  
          Write("testing async invocation...");
          Flush();
          {
              Dictionary<string, string> ctx = new Dictionary<string, string>();
  
              test(p.ice_isAAsync("::Test::TestIntf").Result);
              test(p.ice_isAAsync("::Test::TestIntf", ctx).Result);
  
              p.ice_pingAsync().Wait();
              p.ice_pingAsync(ctx).Wait();
  
              test(p.ice_idAsync().Result.Equals("::Test::TestIntf"));
              test(p.ice_idAsync(ctx).Result.Equals("::Test::TestIntf"));
  
              test(p.ice_idsAsync().Result.Length == 2);
              test(p.ice_idsAsync(ctx).Result.Length == 2);
  
              if(!collocated)
              {
                  test(p.ice_getConnectionAsync().Result != null);
              }
  
              p.opAsync().Wait();
              p.opAsync(ctx).Wait();
  
              test(p.opWithResultAsync().Result == 15);
              test(p.opWithResultAsync(ctx).Result == 15);
  
              try
              {
                  p.opWithUEAsync().Wait();
                  test(false);
              }
              catch(AggregateException ae)
              {
                  ae.Handle(ex => ex is Test.TestIntfException);
              }
  
              try
              {
                  p.opWithUEAsync(ctx).Wait();
                  test(false);
              }
              catch(AggregateException ae)
              {
                  ae.Handle(ex => ex is Test.TestIntfException);
              }
          }
          WriteLine("ok");
  
          Write("testing async/await...");
          Flush();
          {
              Task.Run(async () =>
                  {
                      Dictionary<string, string> ctx = new Dictionary<string, string>();
  
                      test(await p.ice_isAAsync("::Test::TestIntf"));
                      test(await p.ice_isAAsync("::Test::TestIntf", ctx));
  
                      await p.ice_pingAsync();
                      await p.ice_pingAsync(ctx);
  
                      var id = await p.ice_idAsync();
                      test(id.Equals("::Test::TestIntf"));
                      id = await p.ice_idAsync(ctx);
                      test(id.Equals("::Test::TestIntf"));
  
                      var ids = await p.ice_idsAsync();
                      test(ids.Length == 2);
                      ids = await p.ice_idsAsync(ctx);
                      test(ids.Length == 2);
  
                      if(!collocated)
                      {
                          var conn = await p.ice_getConnectionAsync();
                          test(conn != null);
                      }
  
                      await p.opAsync();
                      await p.opAsync(ctx);
  
                      var result = await p.opWithResultAsync();
                      test(result == 15);
                      result = await p.opWithResultAsync(ctx);
                      test(result == 15);
  
                      try
                      {
                          await p.opWithUEAsync();
                          test(false);
                      }
                      catch(System.Exception ex)
                      {
                          test(ex is Test.TestIntfException);
                      }
  
                      try
                      {
                          await p.opWithUEAsync(ctx);
                          test(false);
                      }
                      catch(System.Exception ex)
                      {
                          test(ex is Test.TestIntfException);
                      }
                  }).Wait();
          }
          WriteLine("ok");
  
          Write("testing async continuations...");
          Flush();
          {
              Dictionary<string, string> ctx = new Dictionary<string, string>();
  
              p.ice_isAAsync("::Test::TestIntf").ContinueWith(previous =>
                  {
                      test(previous.Result);
                  }).Wait();
  
              p.ice_isAAsync("::Test::TestIntf", ctx).ContinueWith(previous =>
                  {
                      test(previous.Result);
                  }).Wait();
  
              p.ice_pingAsync().ContinueWith(previous =>
                  {
                      previous.Wait();
                  }).Wait();
  
              p.ice_pingAsync(ctx).ContinueWith(previous =>
                  {
                      previous.Wait();
                  }).Wait();
  
              p.ice_idAsync().ContinueWith(previous =>
                  {
                      test(previous.Result.Equals("::Test::TestIntf"));
                  }).Wait();
  
              p.ice_idAsync(ctx).ContinueWith(previous =>
                  {
                      test(previous.Result.Equals("::Test::TestIntf"));
                  }).Wait();
  
              p.ice_idsAsync().ContinueWith(previous =>
                  {
                      test(previous.Result.Length == 2);
                  }).Wait();
  
              p.ice_idsAsync(ctx).ContinueWith(previous =>
                  {
                      test(previous.Result.Length == 2);
                  }).Wait();
  
              if(!collocated)
              {
                  p.ice_getConnectionAsync().ContinueWith(previous =>
                      {
                          test(previous.Result != null);
                      }).Wait();
              }
  
              p.opAsync().ContinueWith(previous => previous.Wait()).Wait();
              p.opAsync(ctx).ContinueWith(previous => previous.Wait()).Wait();
  
              p.opWithResultAsync().ContinueWith(previous =>
                  {
                      test(previous.Result == 15);
                  }).Wait();
  
              p.opWithResultAsync(ctx).ContinueWith(previous =>
                  {
                      test(previous.Result == 15);
                  }).Wait();
  
              p.opWithUEAsync().ContinueWith(previous =>
                  {
                      try
                      {
                          previous.Wait();
                      }
                      catch(AggregateException ae)
                      {
                          ae.Handle(ex => ex is Test.TestIntfException);
                      }
                  }).Wait();
  
              p.opWithUEAsync(ctx).ContinueWith(previous =>
                  {
                      try
                      {
                          previous.Wait();
                      }
                      catch(AggregateException ae)
                      {
                          ae.Handle(ex => ex is Test.TestIntfException);
                      }
                  }).Wait();
          }
          WriteLine("ok");
  
          Write("testing begin/end invocation... ");
          Flush();
          {
              Ice.AsyncResult result;
              Dictionary<string, string> ctx = new Dictionary<string, string>();
  
              result = p.begin_ice_isA("::Test::TestIntf");
              test(p.end_ice_isA(result));
              result = p.begin_ice_isA("::Test::TestIntf", ctx);
              test(p.end_ice_isA(result));
  
              result = p.begin_ice_ping();
              p.end_ice_ping(result);
              result = p.begin_ice_ping(ctx);
              p.end_ice_ping(result);
  
              result = p.begin_ice_id();
              test(p.end_ice_id(result).Equals("::Test::TestIntf"));
              result = p.begin_ice_id(ctx);
              test(p.end_ice_id(result).Equals("::Test::TestIntf"));
  
              result = p.begin_ice_ids();
              test(p.end_ice_ids(result).Length == 2);
              result = p.begin_ice_ids(ctx);
              test(p.end_ice_ids(result).Length == 2);
  
              if(!collocated)
              {
                  result = p.begin_ice_getConnection();
                  test(p.end_ice_getConnection(result) != null);
              }
  
              result = p.begin_op();
              p.end_op(result);
              result = p.begin_op(ctx);
              p.end_op(result);
  
              result = p.begin_opWithResult();
              test(p.end_opWithResult(result) == 15);
              result = p.begin_opWithResult(ctx);
              test(p.end_opWithResult(result) == 15);
  
              result = p.begin_opWithUE();
              try
              {
                  p.end_opWithUE(result);
                  test(false);
              }
              catch(Test.TestIntfException)
              {
              }
              result = p.begin_opWithUE(ctx);
              try
              {
                  p.end_opWithUE(result);
                  test(false);
              }
              catch(Test.TestIntfException)
              {
              }
          }
          WriteLine("ok");
  
          Write("testing async callback... ");
          Flush();
          {
              AsyncCallback cb = new AsyncCallback();
              Dictionary<string, string> ctx = new Dictionary<string, string>();
              Cookie cookie = new Cookie(5);
              AsyncCallback cbWC = new AsyncCallback(cookie);
  
              p.begin_ice_isA("::Test::TestIntf", cb.isA, null);
              cb.check();
              p.begin_ice_isA("::Test::TestIntf", cbWC.isA, cookie);
              cbWC.check();
              p.begin_ice_isA("::Test::TestIntf", ctx, cb.isA, null);
              cb.check();
              p.begin_ice_isA("::Test::TestIntf", ctx, cbWC.isA, cookie);
              cbWC.check();
  
              p.begin_ice_ping(cb.ping, null);
              cb.check();
              p.begin_ice_ping(cbWC.ping, cookie);
              cbWC.check();
              p.begin_ice_ping(ctx, cb.ping, null);
              cb.check();
              p.begin_ice_ping(ctx, cbWC.ping, cookie);
              cbWC.check();
  
              p.begin_ice_id(cb.id, null);
              cb.check();
              p.begin_ice_id(cbWC.id, cookie);
              cbWC.check();
              p.begin_ice_id(ctx, cb.id, null);
              cb.check();
              p.begin_ice_id(ctx, cbWC.id, cookie);
              cbWC.check();
  
              p.begin_ice_ids(cb.ids, null);
              cb.check();
              p.begin_ice_ids(cbWC.ids, cookie);
              cbWC.check();
              p.begin_ice_ids(ctx, cb.ids, null);
              cb.check();
              p.begin_ice_ids(ctx, cbWC.ids, cookie);
              cbWC.check();
  
              if(!collocated)
              {
                  p.begin_ice_getConnection(cb.connection, null);
                  cb.check();
                  p.begin_ice_getConnection(cbWC.connection, cookie);
                  cbWC.check();
              }
  
              p.begin_op(cb.op, null);
              cb.check();
              p.begin_op(cbWC.op, cookie);
              cbWC.check();
              p.begin_op(ctx, cb.op, null);
              cb.check();
              p.begin_op(ctx, cbWC.op, cookie);
              cbWC.check();
  
              p.begin_opWithResult(cb.opWithResult, null);
              cb.check();
              p.begin_opWithResult(cbWC.opWithResult, cookie);
              cbWC.check();
              p.begin_opWithResult(ctx, cb.opWithResult, null);
              cb.check();
              p.begin_opWithResult(ctx, cbWC.opWithResult, cookie);
              cbWC.check();
  
              p.begin_opWithUE(cb.opWithUE, null);
              cb.check();
              p.begin_opWithUE(cbWC.opWithUE, cookie);
              cbWC.check();
              p.begin_opWithUE(ctx, cb.opWithUE, null);
              cb.check();
              p.begin_opWithUE(ctx, cbWC.opWithUE, cookie);
              cbWC.check();
          }
          WriteLine("ok");
  
          Write("testing response callback... ");
          Flush();
          {
              ResponseCallback cb = new ResponseCallback();
              Dictionary<string, string> ctx = new Dictionary<string, string>();
  
              p.begin_ice_isA("::Test::TestIntf").whenCompleted(cb.isA, null);
              cb.check();
              p.begin_ice_isA("::Test::TestIntf", ctx).whenCompleted(cb.isA, null);
              cb.check();
  
              p.begin_ice_ping().whenCompleted(cb.ping, null);
              cb.check();
              p.begin_ice_ping(ctx).whenCompleted(cb.ping, null);
              cb.check();
  
              p.begin_ice_id().whenCompleted(cb.id, null);
              cb.check();
              p.begin_ice_id(ctx).whenCompleted(cb.id, null);
              cb.check();
  
              p.begin_ice_ids().whenCompleted(cb.ids, null);
              cb.check();
              p.begin_ice_ids(ctx).whenCompleted(cb.ids, null);
              cb.check();
  
              if(!collocated)
              {
                  p.begin_ice_getConnection().whenCompleted(cb.connection, null);
                  cb.check();
              }
  
              p.begin_op().whenCompleted(cb.op, null);
              cb.check();
              p.begin_op(ctx).whenCompleted(cb.op, null);
              cb.check();
  
              p.begin_opWithResult().whenCompleted(cb.opWithResult, null);
              cb.check();
              p.begin_opWithResult(ctx).whenCompleted(cb.opWithResult, null);
              cb.check();
  
              p.begin_opWithUE().whenCompleted(cb.op, cb.opWithUE);
              cb.check();
              p.begin_opWithUE(ctx).whenCompleted(cb.op, cb.opWithUE);
              cb.check();
          }
          WriteLine("ok");
  
          Write("testing lambda callback... ");
          Flush();
          {
              ResponseCallback cb = new ResponseCallback();
              Dictionary<string, string> ctx = new Dictionary<string, string>();
  
              p.begin_ice_isA("::Test::TestIntf").whenCompleted(
                  (bool r) =>
                  {
                      cb.isA(r);
                  }, null);
              cb.check();
              p.begin_ice_isA("::Test::TestIntf", ctx).whenCompleted(
                  (bool r) =>
                  {
                      cb.isA(r);
                  }, null);
              cb.check();
  
              p.begin_ice_ping().whenCompleted(
                  () =>
                  {
                      cb.ping();
                  }, null);
              cb.check();
              p.begin_ice_ping(ctx).whenCompleted(
                  () =>
                  {
                      cb.ping();
                  }, null);
              cb.check();
  
              p.begin_ice_id().whenCompleted(
                  (string id) =>
                  {
                      cb.id(id);
                  }, null);
              cb.check();
              p.begin_ice_id(ctx).whenCompleted(
                  (string id) =>
                  {
                      cb.id(id);
                  }, null);
              cb.check();
  
              p.begin_ice_ids().whenCompleted(
                  (string[] ids) =>
                  {
                      cb.ids(ids);
                  }, null);
              cb.check();
              p.begin_ice_ids(ctx).whenCompleted(
                  (string[] ids) =>
                  {
                      cb.ids(ids);
                  }, null);
              cb.check();
  
              if(!collocated)
              {
                  p.begin_ice_getConnection().whenCompleted(
                      (Ice.Connection conn) =>
                      {
                          cb.connection(conn);
                      }, null);
                  cb.check();
              }
  
              p.begin_op().whenCompleted(
                  () =>
                  {
                      cb.op();
                  }, null);
              cb.check();
              p.begin_op(ctx).whenCompleted(
                  () =>
                  {
                      cb.op();
                  }, null);
              cb.check();
  
              p.begin_opWithResult().whenCompleted(
  
gt:                 (int r) =>