context: // **********************************************************************
  //
  // Copyright (c) 2003-2015 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 Glacier2;
  using Test;
  using System;
  using System.Collections.Generic;
  using System.Diagnostics;
  using System.Reflection;
  
  [assembly: CLSCompliant(true)]
  
  [assembly: AssemblyTitle("IceTest")]
  [assembly: AssemblyDescription("Ice test")]
  [assembly: AssemblyCompany("ZeroC, Inc.")]
  
  public class Client
  {
      public class App : Ice.Application
      {
          public override int run(string[] args)
          {
              Ice.ObjectPrx routerBase;
  
              {
                  Console.Out.Write("testing stringToProxy for router... ");
                  Console.Out.Flush();
                  routerBase = communicator().stringToProxy("Glacier2/router:default -p 12347");
                  Console.Out.WriteLine("ok");
              }
  
              Glacier2.RouterPrx router;
  
              {
                  Console.Out.Write("testing checked cast for router... ");
                  Console.Out.Flush();
                  router = Glacier2.RouterPrxHelper.checkedCast(routerBase);
                  test(router != null);
                  Console.Out.WriteLine("ok");
              }
  
  
              {
                  Console.Out.Write("testing router finder... ");
                  Console.Out.Flush();
                  Ice.RouterFinderPrx finder = Ice.RouterFinderPrxHelper.uncheckedCast(
                      communicator().stringToProxy("Ice/RouterFinder:default -p 12347"));
                  test(finder.getRouter().ice_getIdentity().Equals(router.ice_getIdentity()));
                  Console.Out.WriteLine("ok");
              }
  
              {
                  Console.Out.Write("installing router with communicator... ");
                  Console.Out.Flush();
                  communicator().setDefaultRouter(router);
                  Console.Out.WriteLine("ok");
              }
  
              {
                  Console.Out.Write("getting the session timeout... ");
                  Console.Out.Flush();
                  long timeout = router.getSessionTimeout();
                  test(timeout == 30);
                  Console.Out.WriteLine("ok");
              }
  
              Ice.ObjectPrx @base;
  
              {
                  Console.Out.Write("testing stringToProxy for server object... ");
                  Console.Out.Flush();
                  @base = communicator().stringToProxy("c1/callback:tcp -p 12010");
                  Console.Out.WriteLine("ok");
              }
  
              {
                  Console.Out.Write("trying to ping server before session creation... ");
                  Console.Out.Flush();
                  try
                  {
                      @base.ice_ping();
                      test(false);
                  }
                  catch(Ice.ConnectionLostException)
                  {
                      Console.Out.WriteLine("ok");
                  }
                  catch(Ice.SocketException)
                  {
                      test(false);
                  }
              }
  
  
              {
                  Console.Out.Write("trying to create session with wrong password... ");
                  Console.Out.Flush();
                  try
                  {
                      router.createSession("userid", "xxx");
                      test(false);
                  }
                  catch(Glacier2.PermissionDeniedException)
                  {
                      Console.Out.WriteLine("ok");
                  }
                  catch(Glacier2.CannotCreateSessionException)
                  {
                      test(false);
                  }
              }
  
              {
                  Console.Out.Write("trying to destroy non-existing session... ");
                  Console.Out.Flush();
                  try
                  {
                      router.destroySession();
                      test(false);
                  }
                  catch(Glacier2.SessionNotExistException)
                  {
                      Console.Out.WriteLine("ok");
                  }
              }
  
              {
                  Console.Out.Write("creating session with correct password... ");
                  Console.Out.Flush();
                  try
                  {
                      router.createSession("userid", "abc123");
                  }
                  catch(Glacier2.PermissionDeniedException)
                  {
                      test(false);
                  }
                  catch(Glacier2.CannotCreateSessionException)
                  {
                      test(false);
                  }
                  Console.Out.WriteLine("ok");
              }
  
              {
                  Console.Out.Write("trying to create a second session... ");
                  Console.Out.Flush();
                  try
                  {
                      router.createSession("userid", "abc123");
                      test(false);
                  }
                  catch(Glacier2.PermissionDeniedException)
                  {
                      test(false);
                  }
                  catch(Glacier2.CannotCreateSessionException)
                  {
                      Console.Out.WriteLine("ok");
                  }
              }
  
              {
                  Console.Out.Write("pinging server after session creation... ");
                  Console.Out.Flush();
                  @base.ice_ping();
                  Console.Out.WriteLine("ok");
              }
  
              CallbackPrx twoway;
  
              {
                  Console.Out.Write("testing checked cast for server object... ");
                  Console.Out.Flush();
                  twoway = CallbackPrxHelper.checkedCast(@base);
                  test(twoway != null);
                  Console.Out.WriteLine("ok");
              }
  
              Ice.ObjectAdapter adapter;
  
              {
                  Console.Out.Write("creating and activating callback receiver adapter... ");
                  Console.Out.Flush();
                  communicator().getProperties().setProperty("Ice.PrintAdapterReady", "0");
                  adapter = communicator().createObjectAdapterWithRouter("CallbackReceiverAdapter", router);
                  adapter.activate();
                  Console.Out.WriteLine("ok");
              }
  
              String category;
  
              {
                  Console.Out.Write("getting category from router... ");
                  Console.Out.Flush();
                  category = router.getCategoryForClient();
                  Console.Out.WriteLine("ok");
              }
  
              CallbackReceiverI callbackReceiverImpl;
              Ice.Object callbackReceiver;
              CallbackReceiverPrx twowayR;
              CallbackReceiverPrx fakeTwowayR;
  
              {
                  Console.Out.Write("creating and adding callback receiver object... ");
                  Console.Out.Flush();
                  callbackReceiverImpl = new CallbackReceiverI();
                  callbackReceiver = callbackReceiverImpl;
                  Ice.Identity callbackReceiverIdent = new Ice.Identity();
                  callbackReceiverIdent.name = "callbackReceiver";
                  callbackReceiverIdent.category = category;
                  twowayR = CallbackReceiverPrxHelper.uncheckedCast(adapter.add(callbackReceiver, callbackReceiverIdent));
  
gt:                 Ice.Identity fakeCallbackReceiverIdent = new Ice.Identity();