Beispiel #1
0
    public static void ResendUserMail(ResendEmailPayload payload, ResponseCallback callback, ResponseFallback fallback)
    {
        HttpClient httpClient = new HttpClient();

        Request request = new Request(HttpClient.Method.POST, Route.RESEND_MAIL_ROUTE, payload);

        httpClient.Request(
            request,
            (statusCode, response) => {
            ResendEmailResponse resendEmailResponse = Deserialize(response);
            callback(resendEmailResponse);
        },
            (statusCode, error) => {
            if (statusCode == StatusCodes.CODE_VALIDATION_ERROR)
            {
                ValidationError validationError = ErrorDeserilizer.DeserializeValidationErrorData(error);
                fallback(statusCode, validationError);
            }
            else
            {
                GenericError genericError = ErrorDeserilizer.DeserializeGenericErrorData(error);
                fallback(statusCode, genericError);
            }
        }
            );
    }
Beispiel #2
0
        /**
         * Request URL
         *
         * @param List<string> request of url directories.
         * @respCallback is a delegate to get async JSON response back
         */
        private void _request(List <string> url_components, ResponseCallback respCallback, ResponseType type)
        {
            try
            {
                StringBuilder url = new StringBuilder();

                // Add Origin To The Request
                url.Append(this.ORIGIN);

                // Generate URL with UTF-8 Encoding
                foreach (string url_bit in url_components)
                {
                    url.Append("/");
                    url.Append(_encodeURIcomponent(url_bit));
                }
                HttpWebRequest request        = (HttpWebRequest)WebRequest.Create(url.ToString());
                RequestState   myRequestState = new RequestState();
                myRequestState.request  = request;
                myRequestState.cb       = respCallback;
                myRequestState.respType = type;
                if (type == ResponseType.Subscribe)
                {
                    myRequestState.channel = url_components[2];
                }
                IAsyncResult result = (IAsyncResult)request.BeginGetResponse(requestCallBack, myRequestState);
            }
            catch (Exception)
            {
            }
        }
Beispiel #3
0
    public static void DepositUserFunds(DepositPayload payload, ResponseCallback callback, ResponseFallback fallback)
    {
        HttpClient httpClient = new HttpClient();

        Request request = new Request(HttpClient.Method.POST, Route.DEPOSIT_ROUTE, payload);

        httpClient.Request(
            request,
            (statusCode, response) => {
            DepositResponse depositResponse = Deserialize(response);
            callback(depositResponse);
        },
            (statusCode, error) => {
            if (statusCode == StatusCodes.CODE_VALIDATION_ERROR)
            {
                ValidationError validationError = ErrorDeserilizer.DeserializeValidationErrorData(error);
                fallback(statusCode, validationError);
            }
            else
            {
                GenericError genericError = ErrorDeserilizer.DeserializeGenericErrorData(error);
                fallback(statusCode, genericError);
            }
        }
            );
    }
Beispiel #4
0
 public static void Invoke(string methodId,IPeer peer,ResponseCallback responseCallback, params object[] objects) {
     Invoke(methodId, peer, responseCallback, (serializable) => {
         foreach (var item in objects) {
             serializable.SerializableObject(item);
         }
     });
 }
Beispiel #5
0
 public static void Invoke(string methodId, IPeer peer, ResponseCallback responseCallback, Action<ISerializable> action) {
     using (var serializable = new Serializable(null)) {
         action?.Invoke(serializable);
         var rpcInvoke = new RpcInvoke("", methodId);
         RpcProxy.Invoke(MessageType.RpcInvoke, rpcInvoke, serializable.WriteStream, peer, responseCallback);
     }
 }
        static public void AsynPost(string url, byte[] data, ResponseCallback callback, object state, CookieCollection cookie)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            if (cookie != null)
            {
                request.CookieContainer = new CookieContainer();
                request.CookieContainer.Add(cookie);
            }
            request.AllowAutoRedirect = true;
            request.Method            = "POST";
            request.ContentType       = "application/x-www-form-urlencoded";
            request.ContentLength     = data.Length;

            AsynResp resp = new AsynResp
            {
                Request  = request,
                Callback = callback,
                Response = new ResponseObject
                {
                    State = state
                }
            };
            AsynRequestStream ars = new AsynRequestStream
            {
                Data = data,
                Resp = resp
            };

            request.BeginGetRequestStream(new AsyncCallback(RequestStreamCallback), ars);
        }
        public void SendMessage(short opCode, ISerializablePacket packet, ResponseCallback responseCallback,
                                int timeoutSecs)
        {
            var message = MessageHelper.Create(opCode, packet.ToBytes());

            SendMessage(message, responseCallback, timeoutSecs, EDeliveryMethod.Reliable);
        }
Beispiel #8
0
    public static void ForgotUserPassword(ForgotPasswordPayload payload, ResponseCallback callback, ResponseFallback fallback)
    {
        HttpClient httpClient = new HttpClient();

        Request request = new Request(HttpClient.Method.POST, Route.FORGOT_PASSWORD_ROUTE, payload);

        httpClient.Request(
            request,
            (statusCode, response) => {
            ForgotPasswordResponse forgotPasswordResponse = Deserialize(response);
            callback(forgotPasswordResponse);
        },
            (statusCode, error) => {
            if (statusCode == StatusCodes.CODE_VALIDATION_ERROR)
            {
                ValidationError validationError = ErrorDeserilizer.DeserializeValidationErrorData(error);
                fallback(statusCode, validationError);
            }
            else
            {
                GenericError genericError = ErrorDeserilizer.DeserializeGenericErrorData(error);
                fallback(statusCode, genericError);
            }
        }
            );
    }
Beispiel #9
0
    // ----------------------------

    /**
     * Basic Connect function is used to create the SDK instance and attempt to the connect
     * to the server. The dataPath is necessary for identifying where on the system queued
     * up telemetry data should be stored. The clientId is a simple key used to identify the
     * game and associated data. The URI indicates the server we should be connecting to.
     * Optionally, you can specify a function to be called when the request is successful.
     */
    public void Connect(string dataPath, string clientId, string uri = "", ResponseCallback cb = null)
    {
        string deviceUUID = SystemInfo.deviceUniqueIdentifier;

        if (cb != null)
        {
            mConnect_CBList.Add(cb);
        }
        else
        {
            ResponseCallback tempCB = ResponseCallback_Stub;
            mConnect_CBList.Add(tempCB);
        }

        if (mInstSet)
        {
            GlasslabSDK_Connect(mInst, clientId, uri);
        }
        else
        {
            mInst    = GlasslabSDK_CreateInstance(clientId, deviceUUID, dataPath, uri);
            mInstSet = true;

            iPhone.SetNoBackupFlag(dataPath + "/glasslabsdk.db");
        }
    }
            public InternalMessage(Slave slave, byte func, byte[] writeBuffer, int writeSize, int readSize, ResponseCallback callback)
            {
                byte[] crc = new byte[2];

                this.slave = slave;
                if (writeBuffer != null)
                {
                    this.writeBuffer = new byte[5 + writeSize];
                }
                else
                {
                    this.writeBuffer = new byte[5];
                }
                this.responseLength = 5 + readSize;
                this.readBuffer     = new byte[responseLength];
                this.callback       = callback;

                this.writeBuffer[0] = slave.address;
                this.writeBuffer[1] = func;
                this.writeBuffer[2] = (byte)this.writeBuffer.Length;

                if (writeBuffer != null)
                {
                    Array.Copy(writeBuffer, 0, this.writeBuffer, 3, writeSize);
                }

                crc16(ref this.writeBuffer, ref crc);
                this.writeBuffer[this.writeBuffer.Length - 2] = crc[0];
                this.writeBuffer[this.writeBuffer.Length - 1] = crc[1];
            }
Beispiel #11
0
    public static void ValidateStakeAmount(StakePayload payload, ResponseCallback callback, ResponseFallback fallback)
    {
        HttpClient httpClient = new HttpClient();

        Request request = new Request(HttpClient.Method.POST, Route.VALIDATE_STAKE_ROUTE, payload);

        httpClient.Request(
            request,
            (statusCode, response) => {
            ValidateStakeResponse validateResponse = Deserialize(response);
            callback(validateResponse);
        },
            (statusCode, error) => {
            if (statusCode == StatusCodes.CODE_VALIDATION_ERROR)
            {
                ValidationError validationError = ErrorDeserilizer.DeserializeValidationErrorData(error);
                fallback(statusCode, validationError);
            }
            else
            {
                GenericError genericError = ErrorDeserilizer.DeserializeGenericErrorData(error);
                fallback(statusCode, genericError);
            }
        }
            );
    }
Beispiel #12
0
 public bool OnMessage(string message, Source Sender, bool isAdmin, ResponseCallback callback)
 {
     if (Sender.FromGroup == 0)
     {
         return(false);
     }
     lock (Data)
     {
         if (!Data.ContainsKey(Sender.FromGroup))
         {
             Data[Sender.FromGroup] = new Dictionary <long, int>();
         }
         Dictionary <long, int> dic = Data[Sender.FromGroup];
         if (!dic.ContainsKey(Sender.FromQQ))
         {
             dic[Sender.FromQQ] = 1;
         }
         else
         {
             ++dic[Sender.FromQQ];
         }
         Save();
     }
     return(false);
 }
Beispiel #13
0
        /// <summary>
        /// 连接交易服务器
        /// </summary>
        /// <param name="frontAddress"></param>
        /// <param name="brokerID"></param>
        /// <param name="userID"></param>
        /// <param name="password"></param>
        public void Connect(string[] frontAddress, string brokerID, string userID, string password, bool restart = true)
        {
            this.BrokerID  = brokerID;
            this.AccountID = userID;
            this.Password  = password;

            //创建Trader实例
            try
            {
                //创建
                _instance = (IntPtr)Process(IntPtr.Zero, (int)XSpeedRequestAction.TraderApiCreate, 0, null);

                ResponseCallback callback = new ResponseCallback(ResponseHandler);
                //回调地址
                IntPtr hFunc = Marshal.GetFunctionPointerForDelegate(this.callback);

                //注册前置机地址
                string address = frontAddress[0];

                if (address.StartsWith("tcp://", StringComparison.OrdinalIgnoreCase) == false)
                {
                    address = "tcp://" + address;
                }

                this.FrontAddress = address;

                //创建
                Process(_instance, (int)XSpeedRequestAction.TraderApiInit, hFunc, new StringBuilder(this.FrontAddress));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #14
0
    public static void GetUserHistory(ResponseCallback callback, ResponseFallback fallback)
    {
        HttpClient httpClient = new HttpClient();

        Request request = new Request(HttpClient.Method.GET, Route.GET_HISTORY_ROUTE);

        httpClient.Request(
            request,
            (statusCode, response) => {
            HistoryResponse historyResponse = Deserialize(response);

            callback(historyResponse);
        },
            (statusCode, error) => {
            if (statusCode == StatusCodes.CODE_VALIDATION_ERROR)
            {
                ValidationError validationError = ErrorDeserilizer.DeserializeValidationErrorData(error);
                fallback(statusCode, validationError);
            }
            else
            {
                GenericError genericError = ErrorDeserilizer.DeserializeGenericErrorData(error);
                fallback(statusCode, genericError);
            }
        }
            );
    }
Beispiel #15
0
        public void InteractRequest(string senderEntityId, string receiverEntityId, string bodyS, ResponseCallback callback)
        {
            string requestId = System.Guid.NewGuid().ToString();

            responseCallbacks[requestId] = callback;
            _Interact("request", senderEntityId, receiverEntityId, requestId, bodyS);
        }
Beispiel #16
0
 public Response(ResponseCallback callback, int sendCode, int customCode)
 {
     this.callback   = callback;
     this.sendCode   = sendCode;
     this.customCode = customCode;
     headerCode      = 0;
 }
Beispiel #17
0
        public bool OnMessage(string message, Source Sender, bool isAdmin, ResponseCallback callback)
        {
            string lower = message.ToLower();

            foreach (string alias in Alias)
            {
                if (lower.StartsWith(alias))
                {
                    try
                    {
                        Run(new CommandArgs()
                        {
                            Arg      = message.Substring(alias.Length),
                            Callback = callback,
                            IsAdmin  = isAdmin,
                            Source   = Sender
                        });
                    }
                    catch (Exception e)
                    {
                        callback($"Unhandled exception : {e}");
                    }
                    return(true);
                }
            }
            return(false);
        }
        public void SendMessage(short opCode, ISerializablePacket packet, ResponseCallback responseCallback,
                                int timeoutSecs)
        {
            var msg = MessageHelper.Create(opCode, packet.ToBytes());

            Peer.SendMessage(msg, responseCallback, timeoutSecs);
        }
Beispiel #19
0
        /**
         * _subscribe - Private Interface
         *
         * @param Dictionary<string, object> args
         *  args contains channel name and Procedure function callback and timetoken
         */
        private void _subscribe(Dictionary <string, object> args)
        {
            clsPubnubCrypto pc = new clsPubnubCrypto(this.CIPHER_KEY);

            string           channel      = args["channel"].ToString();
            ResponseCallback respCallback = (ResponseCallback)args["callback"];
            object           timetoken    = args["timestamp"];

            //  Begin Recusive Subscribe
            try
            {
                // Build URL
                List <string> url = new List <string>();
                url.Add("subscribe");
                url.Add(this.SUBSCRIBE_KEY);
                url.Add(channel);
                url.Add("0");
                url.Add(timetoken.ToString());
                _request(url, respCallback, ResponseType.Subscribe);
            }
            catch
            {
                System.Threading.Thread.Sleep(1000);
                this._subscribe(args);
            }
        }
        void HandleAccountDataResponse(IPacketMsg packetMsg)
        {
            var msg = new ClientMsgProtobuf <CMsgClientRequestAccountDataResponse>(packetMsg);

            var callback = new ResponseCallback(msg.TargetJobID, msg.Body);

            Client.PostCallback(callback);
        }
Beispiel #21
0
        /**
         * Time
         *
         * Timestamp from PubNub Cloud.
         *@param respCallback gets the response back i.e time
         *
         */
        public void Time(ResponseCallback respCallback)
        {
            List <string> url = new List <string>();

            url.Add("time");
            url.Add("0");
            _request(url, respCallback, ResponseType.Time);
        }
        void HandleAccountDataResponse( IPacketMsg packetMsg )
        {
            var msg = new ClientMsgProtobuf<CMsgClientRequestAccountDataResponse>( packetMsg );

            var callback = new ResponseCallback( msg.TargetJobID, msg.Body );

            Client.PostCallback( callback );
        }
        public BaseClient()
        {
            this.callback = new ResponseCallback(ResponseHandler);

            InitEvents();
            InitResponseDataTypeMapping();

            queryTaskTimer = new Timer(new TimerCallback(this.ProcessQueryTask));
        }
Beispiel #24
0
        public void Get(string url, string queryString, ResponseCallback callback)
        {
            GetCallback = callback;

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url + "?" + queryString);
            request.Method = "GET";
            request.CookieContainer = _cookieContainer;
            request.BeginGetResponse(OnGetCallback, request);
        }
Beispiel #25
0
 public void Get(string url, Dictionary<string, object> queryParams, ResponseCallback callback)
 {
     string queryString = string.Empty;
     foreach (string key in queryParams.Keys)
     {
         queryString += string.Format("{0}={1}&", key, queryParams[key]);
     }
     Get(url, queryString, callback);
 }
	public void UpdateMatch(int matchId, string data, int nextPlayerTurn, ResponseCallback cb = null) {
		if (cb != null) {
			m_UpdateMatch_CBList.Add (cb);
		} else {
			ResponseCallback tempCB = ResponseCallback_Stub;
			m_UpdateMatch_CBList.Add (tempCB);
		}
		
		GlasslabSDK_UpdateMatch( mInst, matchId, data, nextPlayerTurn );
	}
	public void GetCourses(ResponseCallback cb = null) {
		if (cb != null) {
			mGetCourses_CBList.Add (cb);
		} else {
			ResponseCallback tempCB = ResponseCallback_Stub;
			mGetCourses_CBList.Add (tempCB);
		}
		
		GlasslabSDK_GetCourses (mInst);
	}
	public void EndSession(ResponseCallback cb = null) {
		if (cb != null) {
			mEndSession_CBList.Add (cb);
		} else {
			ResponseCallback tempCB = ResponseCallback_Stub;
			mEndSession_CBList.Add (tempCB);
		}
		
		GlasslabSDK_EndSession (mInst);
	}
	public void SaveGame( string gameData, ResponseCallback cb = null ) {
		if (cb != null) {
			m_GameSave_CBList.Add (cb);
		} else {
			ResponseCallback tempCB = ResponseCallback_Stub;
			m_GameSave_CBList.Add (tempCB);
		}
		
		GlasslabSDK_SaveGame( mInst, gameData );
	}
	public void DeleteSaveGame(ResponseCallback cb = null) {
		if (cb != null) {
			m_DeleteGameSave_CBList.Add (cb);
		} else {
			ResponseCallback tempCB = ResponseCallback_Stub;
			m_DeleteGameSave_CBList.Add (tempCB);
		}
		
		GlasslabSDK_DeleteSaveGame( mInst );
	}
Beispiel #31
0
 protected void ReqOtherServerInfo(EServerType type, ResponseCallback callback,
                                   EServerDetailPortType detailPortType = EServerDetailPortType.ServerPort)
 {
     _netClientXS.SendMessage(EMsgXS.S2X_ReqOtherServerInfo, new Msg_ReqOtherServerInfo()
     {
         ServerType = (byte)type,
         DetailType = (byte)detailPortType
     }, callback
                              );
 }
	public void GetUserInfo(ResponseCallback cb = null) {
		if (cb != null) {
			m_GetUserInfo_CBList.Add (cb);
		} else {
			ResponseCallback tempCB = ResponseCallback_Stub;
			m_GetUserInfo_CBList.Add (tempCB);
		}
		
		GlasslabSDK_GetUserInfo( mInst );
	}
	public void CreateMatch(int opponentId, ResponseCallback cb = null) {
		if (cb != null) {
			m_CreateMatch_CBList.Add (cb);
		} else {
			ResponseCallback tempCB = ResponseCallback_Stub;
			m_CreateMatch_CBList.Add (tempCB);
		}
		
		GlasslabSDK_CreateMatch( mInst, opponentId );
	}
        public void Request(byte requestByte, ResponseCallback responseCallback, byte fan, byte speed)
        {
            Job j = new Job();
            j.MessageType = requestByte;
            j.FinishCallback = responseCallback;
            j.FanPort = fan;
            j.FanSpeed = speed;

            waitingQueue.Enqueue(j);
            if (!worker.IsBusy)
            {
                worker.RunWorkerAsync(j);
            }
        }
Beispiel #35
0
        public CommLogic(MailClient mClient,
                         DoodleClient dClient,
                         TwilioClient tClient,
                         ResponseCallback callback)
        {
            mailClient = mClient;
            doodleClient = dClient;
            twilioClient = tClient;
            callbackFn = callback;

            // Start reading email from the appropriate IMap provider.
            // This creates its own long-running thread.
            imapReader = new ImapReader(mailClient.Imap, "INBOX", MessageCallback);
        }
        public void Request(byte requestByte, ResponseCallback responseCallback, byte fan, byte speed)
        {
            Response resp = new Response();

            if (requestByte == 1)
            {
                resp.answerBytes = new byte[] { 13, 12, 11, 10, 9, 8, 7, 6, 0 };
            }
            else
            {
                resp.answerBytes = new byte[] { 1, 0 };
            }
            responseCallback(resp);
        }
Beispiel #37
0
 // check right now for a response --- valid for channels where the response is remote without
 // a real-time notification/callback (like Doodle)
 public void CheckResponseImmediate(string requestId, 
                                    ChannelChoice channel,
                                    string requestMetadata,
                                    ResponseCallback callbackFn)
 {
     Debug.Assert(null != requestId);
     if (channel == ChannelChoice.EMAIL_DOODLE)
     {
         string answer = doodleClient.GetPollResult(requestId, requestMetadata);
         if (null != answer)
         {
             ServiceResponse response = new ServiceResponse();
             response.Id = requestId;
             response.Truthful = true;
             response.Answer = answer;
             callbackFn(response);
         }
     }
 }
Beispiel #38
0
        public void Post(string url, Dictionary<string, object> parameters, ResponseCallback callback)
        {
            PostCallback = callback;

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded"; 
            request.CookieContainer = _cookieContainer;

            string paramString = string.Empty;
            foreach (string key in parameters.Keys)
            {
                paramString += string.Format("{0}={1}&", key, parameters[key]);
            }
            Stream stream = request.GetRequestStream();
            byte[] datas = Encoding.UTF8.GetBytes(paramString);
            stream.Write(datas,0, datas.Length);
            stream.Close();

            request.BeginGetResponse(OnPostCallback, request);
        }
Beispiel #39
0
	public void Enroll(string courseCode, ResponseCallback cb = null) {
		if (cb != null) {
			mEnroll_CBList.Add (cb);
		} else {
			ResponseCallback tempCB = ResponseCallback_Stub;
			mEnroll_CBList.Add (tempCB);
		}
		
		GlasslabSDK_Enroll (mInst, courseCode);
	}
Beispiel #40
0
	public void Logout(ResponseCallback cb = null) {
		if (cb != null) {
			mLogout_CBList.Add (cb);
		} else {
			ResponseCallback tempCB = ResponseCallback_Stub;
			mLogout_CBList.Add (tempCB);
		}
		
		GlasslabSDK_Logout (mInst);
	}
Beispiel #41
0
 internal void GetResponse(string method, bool throwOnError, ResponseCallback callback)
 {
     Dictionary<string, string> parameters = new Dictionary<string, string>();
     GetResponse(method, parameters, throwOnError, callback);
 }
Beispiel #42
0
	public void DeleteSaveGame(ResponseCallback cb = null) {
		if (cb != null) {
			m_DeleteGameSave_CBList.Add (cb);
		} else {
			ResponseCallback tempCB = ResponseCallback_Stub;
			m_DeleteGameSave_CBList.Add (tempCB);
		}
		
		GlasslabSDK_DeleteSaveGame( mInst );
	}
Beispiel #43
0
	public void EndSession(ResponseCallback cb = null) {
		if (cb != null) {
			mEndSession_CBList.Add (cb);
		} else {
			ResponseCallback tempCB = ResponseCallback_Stub;
			mEndSession_CBList.Add (tempCB);
		}
		
		GlasslabSDK_EndSession (mInst);
	}
Beispiel #44
0
	// ----------------------------
	/**
	 * Public functions for making requests to the server and receiving response callbacks.
	 * All functions below are setup to receive a callback, if requested. These callbacks
	 * are triggered in the UpdateLoop thread function above.
	 */
	public void DeviceUpdate(ResponseCallback cb = null) {
		if (cb != null) {
			mDeviceUpdate_CBList.Add (cb);
		} else {
			ResponseCallback tempCB = ResponseCallback_Stub;
			mDeviceUpdate_CBList.Add (tempCB);
		}
		
		GlasslabSDK_DeviceUpdate (mInst);
	}
Beispiel #45
0
	// ----------------------------
	/**
	 * Basic Connect function is used to create the SDK instance and attempt to the connect
	 * to the server. The dataPath is necessary for identifying where on the system queued
	 * up telemetry data should be stored. The clientId is a simple key used to identify the
	 * game and associated data. The URI indicates the server we should be connecting to.
	 * Optionally, you can specify a function to be called when the request is successful.
	 */
	public void Connect( string dataPath, string clientId, string uri = "", ResponseCallback cb = null ) {
		string deviceUUID = SystemInfo.deviceUniqueIdentifier;
		
		if (cb != null) {
			mConnect_CBList.Add (cb);
		} else {
			ResponseCallback tempCB = ResponseCallback_Stub;
			mConnect_CBList.Add (tempCB);
		}
		
		if( mInstSet ) {
			GlasslabSDK_Connect( mInst, clientId, uri );
		}
		else {
			mInst = GlasslabSDK_CreateInstance (clientId, deviceUUID, dataPath, uri);
			mInstSet = true;
			
			iPhone.SetNoBackupFlag( dataPath + "/glasslabsdk.db" );
		}
	}
Beispiel #46
0
 internal void GetResponse(string method, ResponseCallback callback)
 {
     GetResponse(method, true, callback);
 }
Beispiel #47
0
    public static void allTests(Ice.Communicator communicator, bool collocated)
#endif
    {
#if SILVERLIGHT
        bool collocated = false;
#endif
        string sref = "test:default -p 12010";
        Ice.ObjectPrx obj = communicator.stringToProxy(sref);
        test(obj != null);

        Test.TestIntfPrx p = Test.TestIntfPrxHelper.uncheckedCast(obj);

        sref = "testController:default -p 12011";
        obj = communicator.stringToProxy(sref);
        test(obj != null);

        Test.TestIntfControllerPrx testController = Test.TestIntfControllerPrxHelper.uncheckedCast(obj);

        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(
                (int r) =>
                {
                    cb.opWithResult(r);
                }, null);
            cb.check();
            p.begin_opWithResult(ctx).whenCompleted(
                (int r) =>
                {
                    cb.opWithResult(r);
                }, null);
            cb.check();

            p.begin_opWithUE().whenCompleted(
                () =>
                {
                    cb.op();
                },
                (Ice.Exception ex) =>
                {
                    cb.opWithUE(ex);
                });
            cb.check();
            p.begin_opWithUE(ctx).whenCompleted(
                () =>
                {
                    cb.op();
                },
                (Ice.Exception ex) =>
                {
                    cb.opWithUE(ex);
                });
            cb.check();
        }
        WriteLine("ok");

        Write("testing local exceptions... ");
        Flush();
        {
            Test.TestIntfPrx indirect = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy"));
            Ice.AsyncResult r;

            r = indirect.begin_op();
            try
            {
                indirect.end_op(r);
                test(false);
            }
            catch(Ice.NoEndpointException)
            {
            }


            try
            {
                r = ((Test.TestIntfPrx)p.ice_oneway()).begin_opWithResult();
                test(false);
            }
            catch(System.ArgumentException)
            {
            }

            //
            // Check that CommunicatorDestroyedException is raised directly.
            //
            if(p.ice_getConnection() != null)
            {
                Ice.InitializationData initData = new Ice.InitializationData();
                initData.properties = communicator.getProperties().ice_clone_();
                Ice.Communicator ic = Ice.Util.initialize(initData);
                Ice.ObjectPrx o = ic.stringToProxy(p.ToString());
                Test.TestIntfPrx p2 = Test.TestIntfPrxHelper.checkedCast(o);
                ic.destroy();
                
                try
                {
                    p2.begin_op();
                    test(false);
                }
                catch(Ice.CommunicatorDestroyedException)
                {
                    // Expected.
                }
            }
        }
        WriteLine("ok");

        Write("testing local exceptions with async callback... ");
        Flush();
        {
            Test.TestIntfPrx i = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy"));
            AsyncCallback cb = new AsyncCallback();
            Cookie cookie = new Cookie(5);
            AsyncCallback cbWC = new AsyncCallback(cookie);

            i.begin_ice_isA("::Test::TestIntf", cb.isAEx, null);
            cb.check();
            i.begin_ice_isA("::Test::TestIntf", cbWC.isAEx, cookie);
            cbWC.check();

            i.begin_ice_ping(cb.pingEx, null);
            cb.check();
            i.begin_ice_ping(cbWC.pingEx, cookie);
            cbWC.check();

            i.begin_ice_id(cb.idEx, null);
            cb.check();
            i.begin_ice_id(cbWC.idEx, cookie);
            cbWC.check();

            i.begin_ice_ids(cb.idsEx, null);
            cb.check();
            i.begin_ice_ids(cbWC.idsEx, cookie);
            cbWC.check();

            if(!collocated)
            {
                i.begin_ice_getConnection(cb.connectionEx, null);
                cb.check();
                i.begin_ice_getConnection(cbWC.connectionEx, cookie);
                cbWC.check();
            }

            i.begin_op(cb.opEx, null);
            cb.check();
            i.begin_op(cbWC.opEx, cookie);
            cbWC.check();
        }
        WriteLine("ok");

        Write("testing local exceptions with response callback... ");
        Flush();
        {
            Test.TestIntfPrx i = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy"));
            ExceptionCallback cb = new ExceptionCallback();

            i.begin_ice_isA("::Test::TestIntf").whenCompleted(cb.isA, cb.ex);
            cb.check();

            i.begin_ice_ping().whenCompleted(cb.ping, cb.ex);
            cb.check();

            i.begin_ice_id().whenCompleted(cb.id, cb.ex);
            cb.check();

            i.begin_ice_ids().whenCompleted(cb.ids, cb.ex);
            cb.check();

            if(!collocated)
            {
                i.begin_ice_getConnection().whenCompleted(cb.connection, cb.ex);
                cb.check();
            }

            i.begin_op().whenCompleted(cb.op, cb.ex);
            cb.check();
        }
        WriteLine("ok");

        Write("testing local exceptions with lambda callback... ");
        Flush();
        {
            Test.TestIntfPrx i = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy"));
            ExceptionCallback cb = new ExceptionCallback();

            i.begin_ice_isA("::Test::TestIntf").whenCompleted(
                (bool r) =>
                {
                    cb.isA(r);
                },
                (Ice.Exception ex) =>
                {
                    cb.ex(ex);
                });
            cb.check();

            i.begin_ice_ping().whenCompleted(
                () =>
                {
                    cb.ping();
                },
                (Ice.Exception ex) =>
                {
                    cb.ex(ex);
                });
            cb.check();

            i.begin_ice_id().whenCompleted(
                (string id) =>
                {
                    cb.id(id);
                },
                (Ice.Exception ex) =>
                {
                    cb.ex(ex);
                });
            cb.check();

            i.begin_ice_ids().whenCompleted(
                (string[] ids) =>
                {
                    cb.ids(ids);
                },
                (Ice.Exception ex) =>
                {
                    cb.ex(ex);
                });
            cb.check();

            if(!collocated)
            {
                i.begin_ice_getConnection().whenCompleted(
                    (Ice.Connection conn) =>
                    {
                        cb.connection(conn);
                    },
                    (Ice.Exception ex) =>
                    {
                        cb.ex(ex);
                    });
                cb.check();
            }

            i.begin_op().whenCompleted(
                () =>
                {
                    cb.op();
                },
                (Ice.Exception ex) =>
                {
                    cb.ex(ex);
                });
            cb.check();
        }
        WriteLine("ok");

        Write("testing exception callback... ");
        Flush();
        {
            Test.TestIntfPrx i = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy"));
            ExceptionCallback cb = new ExceptionCallback();

            i.begin_ice_isA("::Test::TestIntf").whenCompleted(cb.ex);
            cb.check();

            i.begin_op().whenCompleted(cb.ex);
            cb.check();

            i.begin_opWithResult().whenCompleted(cb.ex);
            cb.check();

            i.begin_opWithUE().whenCompleted(cb.ex);
            cb.check();

            // Ensures no exception is called when response is received
            p.begin_ice_isA("::Test::TestIntf").whenCompleted(cb.noEx);
            p.begin_op().whenCompleted(cb.noEx);
            p.begin_opWithResult().whenCompleted(cb.noEx);

            // If response is a user exception, it should be received.
            p.begin_opWithUE().whenCompleted(cb.opWithUE);
            cb.check();
        }
        WriteLine("ok");

        Write("testing lambda exception callback... ");
        Flush();
        {
            Test.TestIntfPrx i = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy"));
            ExceptionCallback cb = new ExceptionCallback();

            i.begin_ice_isA("::Test::TestIntf").whenCompleted(
                (Ice.Exception ex) =>
                {
                    cb.ex(ex);
                });
            cb.check();

            i.begin_op().whenCompleted(
                (Ice.Exception ex) =>
                {
                    cb.ex(ex);
                });

            cb.check();

            i.begin_opWithResult().whenCompleted(
                (Ice.Exception ex) =>
                {
                    cb.ex(ex);
                });
            cb.check();

            i.begin_opWithUE().whenCompleted(
                (Ice.Exception ex) =>
                {
                    cb.ex(ex);
                });
            cb.check();

            // Ensures no exception is called when response is received
            p.begin_ice_isA("::Test::TestIntf").whenCompleted(
                (Ice.Exception ex) =>
                {
                    cb.noEx(ex);
                });
            p.begin_op().whenCompleted(
                 (Ice.Exception ex) =>
                {
                    cb.noEx(ex);
                });
            p.begin_opWithResult().whenCompleted(
                 (Ice.Exception ex) =>
                {
                    cb.noEx(ex);
                });

            // If response is a user exception, it should be received.
            p.begin_opWithUE().whenCompleted(
                 (Ice.Exception ex) =>
                {
                    cb.opWithUE(ex);
                });
            cb.check();
        }
        WriteLine("ok");

        Write("testing sent callback... ");
        Flush();
        {
            SentCallback cb = new SentCallback();

            p.begin_ice_isA("").whenCompleted(cb.isA, cb.ex).whenSent(cb.sent);
            cb.check();

            p.begin_ice_ping().whenCompleted(cb.ping, cb.ex).whenSent(cb.sent);
            cb.check();

            p.begin_ice_id().whenCompleted(cb.id, cb.ex).whenSent(cb.sent);
            cb.check();

            p.begin_ice_ids().whenCompleted(cb.ids, cb.ex).whenSent(cb.sent);
            cb.check();

            p.begin_op().whenCompleted(cb.op, cb.ex).whenSent(cb.sent);
            cb.check();

            p.begin_op(cb.opAsync, null).whenSent(cb.sentAsync);
            cb.check();

            p.begin_op().whenCompleted(cb.ex).whenSent(cb.sent);
            cb.check();

            List<SentCallback> cbs = new List<SentCallback>();
            byte[] seq = new byte[10024];
            (new System.Random()).NextBytes(seq);
            testController.holdAdapter();
            try
            {
                Ice.AsyncResult r;
                do
                {
                    SentCallback cb2 = new SentCallback();
                    r = p.begin_opWithPayload(seq).whenCompleted(cb2.ex).whenSent(cb2.sent);
                    cbs.Add(cb2);
                }
                while(r.sentSynchronously());
            }
            finally
            {
                testController.resumeAdapter();
            }
            foreach(SentCallback cb3 in cbs)
            {
                cb3.check();
            }
        }
        WriteLine("ok");

        Write("testing lambda sent callback... ");
        Flush();
        {
            SentCallback cb = new SentCallback();

            p.begin_ice_isA("").whenCompleted(
                (bool r) =>
                {
                    cb.isA(r);
                },
                (Ice.Exception ex) =>
                {
                    cb.ex(ex);
                }
            ).whenSent(
                (bool sentSynchronously) =>
                {
                    cb.sent(sentSynchronously);
                });
            cb.check();

            p.begin_ice_ping().whenCompleted(
                () =>
                {
                    cb.ping();
                },
                (Ice.Exception ex) =>
                {
                    cb.ex(ex);
                }
            ).whenSent(
                (bool sentSynchronously) =>
                {
                    cb.sent(sentSynchronously);
                });
            cb.check();

            p.begin_ice_id().whenCompleted(
                (string id) =>
                {
                    cb.id(id);
                },
                (Ice.Exception ex) =>
                {
                    cb.ex(ex);
                }
            ).whenSent(
                (bool sentSynchronously) =>
                {
                    cb.sent(sentSynchronously);
                });
            cb.check();

            p.begin_ice_ids().whenCompleted(
                (string[] ids) =>
                {
                    cb.ids(ids);
                },
                (Ice.Exception ex) =>
                {
                    cb.ex(ex);
                }
            ).whenSent(
                (bool sentSynchronously) =>
                {
                    cb.sent(sentSynchronously);
                });
            cb.check();

            p.begin_op().whenCompleted(
                () =>
                {
                    cb.op();
                },
                (Ice.Exception ex) =>
                {
                    cb.ex(ex);
                }
            ).whenSent(
                (bool sentSynchronously) =>
                {
                    cb.sent(sentSynchronously);
                });
            cb.check();

            p.begin_op(cb.opAsync, null).whenSent(
                (Ice.AsyncResult r) =>
                {
                    cb.sentAsync(r);
                });
            cb.check();

            p.begin_op().whenCompleted(
                (Ice.Exception ex) =>
                {
                    cb.ex(ex);
                }
            ).whenSent(
                (bool sentSynchronously) =>
                {
                    cb.sent(sentSynchronously);
                });
            cb.check();

            List<SentCallback> cbs = new List<SentCallback>();
            byte[] seq = new byte[10024];
            (new System.Random()).NextBytes(seq);
            testController.holdAdapter();
            try
            {
                Ice.AsyncResult r;
                do
                {
                    SentCallback cb2 = new SentCallback();
                    r = p.begin_opWithPayload(seq).whenCompleted(
                        (Ice.Exception ex) =>
                        {
                            cb2.ex(ex);
                        }
                    ).whenSent(
                        (bool sentSynchronously) =>
                        {
                            cb2.sent(sentSynchronously);
                        });
                    cbs.Add(cb2);
                }
                while(r.sentSynchronously());
            }
            finally
            {
                testController.resumeAdapter();
            }
            foreach(SentCallback cb3 in cbs)
            {
                cb3.check();
            }
        }
        WriteLine("ok");

        Write("testing illegal arguments... ");
        Flush();
        {
            Ice.AsyncResult result;

            result = p.begin_op();
            p.end_op(result);
            try
            {
                p.end_op(result);
                test(false);
            }
            catch(System.ArgumentException)
            {
            }

            result = p.begin_op();
            try
            {
                p.end_opWithResult(result);
                test(false);
            }
            catch(System.ArgumentException)
            {
            }

            try
            {
                p.end_op(null);
                test(false);
            }
            catch(System.ArgumentException)
            {
            }
        }
        WriteLine("ok");

        Write("testing unexpected exceptions from callback... ");
        Flush();
        {
            Test.TestIntfPrx q = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy"));
            ThrowType[] throwEx = new ThrowType[]{ ThrowType.LocalException, ThrowType.UserException,
                                                   ThrowType.OtherException };

            for(int i = 0; i < 3; ++i)
            {
                Thrower cb = new Thrower(throwEx[i]);

                p.begin_op(cb.opAsync, null);
                cb.check();

                p.begin_op().whenCompleted(cb.op, null);
                cb.check();

                q.begin_op().whenCompleted(cb.op, cb.ex);
                cb.check();

                p.begin_op().whenCompleted(cb.noOp, cb.ex).whenSent(cb.sent);
                cb.check();

                q.begin_op().whenCompleted(cb.ex);
                cb.check();
            }
        }
        WriteLine("ok");

        Write("testing unexpected exceptions from callback with lambda... ");
        Flush();
        {
            Test.TestIntfPrx q = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy"));
            ThrowType[] throwEx = new ThrowType[]{ ThrowType.LocalException, ThrowType.UserException,
                                                   ThrowType.OtherException };

            for(int i = 0; i < 3; ++i)
            {
                Thrower cb = new Thrower(throwEx[i]);

                p.begin_op().whenCompleted(
                    () =>
                    {
                        cb.op();
                    }, null);
                cb.check();

                q.begin_op().whenCompleted(
                    () =>
                    {
                        cb.op();
                    },
                    (Ice.Exception ex) =>
                    {
                        cb.ex(ex);
                    });
                cb.check();

                p.begin_op().whenCompleted(
                    () =>
                    {
                        cb.noOp();
                    },
                    (Ice.Exception ex) =>
                    {
                        cb.ex(ex);
                    }
                ).whenSent(
                    (bool sentSynchronously) =>
                    {
                        cb.sent(sentSynchronously);
                    });
                cb.check();

                q.begin_op().whenCompleted(
                    (Ice.Exception ex) =>
                    {
                        cb.ex(ex);
                    });
                cb.check();
            }
        }
        WriteLine("ok");

        Write("testing batch requests with proxy... ");
        Flush();
        {
            test(p.ice_batchOneway().begin_ice_flushBatchRequests().sentSynchronously());

            Cookie cookie = new Cookie(5);

            {
                //
                // AsyncResult.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                b1.opBatch();
                b1.opBatch();
                FlushCallback cb = new FlushCallback(cookie);
                Ice.AsyncResult r = b1.begin_ice_flushBatchRequests(cb.completedAsync, cookie);
                r.whenSent(cb.sentAsync);
                cb.check();
                test(r.isSent());
                test(r.IsCompleted);
                test(p.waitForBatch(2));
            }

            if(p.ice_getConnection() != null)
            {
                //
                // AsyncResult exception.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                b1.opBatch();
                b1.ice_getConnection().close(false);
                FlushExCallback cb = new FlushExCallback(cookie);
                Ice.AsyncResult r = b1.begin_ice_flushBatchRequests(cb.completedAsync, cookie);
                r.whenSent(cb.sentAsync);
                cb.check();
                test(!r.isSent());
                test(r.IsCompleted);
                test(p.opBatchCount() == 0);
            }

            {
                //
                // Type-safe.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                b1.opBatch();
                b1.opBatch();
                FlushCallback cb = new FlushCallback();
                Ice.AsyncResult r = b1.begin_ice_flushBatchRequests();
                r.whenCompleted(cb.exception);
                r.whenSent(cb.sent);
                cb.check();
                test(r.isSent());
                test(r.IsCompleted);
                test(p.waitForBatch(2));
            }

            if(p.ice_getConnection() != null)
            {
                //
                // Type-safe exception.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                b1.opBatch();
                b1.ice_getConnection().close(false);
                FlushExCallback cb = new FlushExCallback();
                Ice.AsyncResult r = b1.begin_ice_flushBatchRequests();
                r.whenCompleted(cb.exception);
                r.whenSent(cb.sent);
                cb.check();
                test(!r.isSent());
                test(r.IsCompleted);
                test(p.opBatchCount() == 0);
            }
        }
        WriteLine("ok");

        Write("testing batch requests with proxy and lambda... ");
        Flush();
        {
            test(p.ice_batchOneway().begin_ice_flushBatchRequests().sentSynchronously());

            Cookie cookie = new Cookie(5);

            {
                //
                // AsyncResult.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                b1.opBatch();
                b1.opBatch();
                FlushCallback cb = new FlushCallback(cookie);
                Ice.AsyncResult r = b1.begin_ice_flushBatchRequests(
                    (Ice.AsyncResult result) =>
                    {
                        cb.completedAsync(result);
                    }, cookie);
                r.whenSent(
                    (Ice.AsyncResult result) =>
                    {
                        cb.sentAsync(result);
                    });
                cb.check();
                test(r.isSent());
                test(r.IsCompleted);
                test(p.waitForBatch(2));

                FlushCallback cb2 = new FlushCallback(cookie);
                Ice.AsyncResult r2 = b1.begin_ice_flushBatchRequests(
                    (Ice.AsyncResult result) =>
                    {
                        cb2.completedAsync(result);
                    }, cookie);
                r2.whenSent(
                    (Ice.AsyncResult result) =>
                    {
                        cb2.sentAsync(result);
                    });
                cb2.check();
                test(r2.isSent());
                test(r2.IsCompleted);
            }

            if(p.ice_getConnection() != null)
            {
                //
                // AsyncResult exception.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                b1.opBatch();
                b1.ice_getConnection().close(false);
                FlushExCallback cb = new FlushExCallback(cookie);
                Ice.AsyncResult r = b1.begin_ice_flushBatchRequests(
                    (Ice.AsyncResult result) =>
                    {
                        cb.completedAsync(result);
                    }, cookie);
                r.whenSent(
                    (Ice.AsyncResult result) =>
                    {
                        cb.sentAsync(result);
                    });
                cb.check();
                test(!r.isSent());
                test(r.IsCompleted);
                test(p.opBatchCount() == 0);
            }

            {
                //
                // Type-safe.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                b1.opBatch();
                b1.opBatch();
                FlushCallback cb = new FlushCallback();
                Ice.AsyncResult r = b1.begin_ice_flushBatchRequests();
                r.whenCompleted(
                    (Ice.Exception ex) =>
                    {
                        cb.exception(ex);
                    });
                r.whenSent(
                    (bool sentSynchronously) =>
                    {
                        cb.sent(sentSynchronously);
                    });
                cb.check();
                test(r.isSent());
                test(r.IsCompleted);
                test(p.waitForBatch(2));
            }

            if(p.ice_getConnection() != null)
            {
                //
                // Type-safe exception.
                //
                test(p.opBatchCount() == 0);
                TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                b1.opBatch();
                b1.ice_getConnection().close(false);
                FlushExCallback cb = new FlushExCallback();
                Ice.AsyncResult r = b1.begin_ice_flushBatchRequests();
                r.whenCompleted(
                    (Ice.Exception ex) =>
                    {
                        cb.exception(ex);
                    });
                r.whenSent(
                    (bool sentSynchronously) =>
                    {
                        cb.sent(sentSynchronously);
                    });
                cb.check();
                test(!r.isSent());
                test(r.IsCompleted);
                test(p.opBatchCount() == 0);
            }
        }
        WriteLine("ok");

        if(p.ice_getConnection() != null)
        {
            Write("testing batch requests with connection... ");
            Flush();
            {
                Cookie cookie = new Cookie(5);

                {
                    //
                    // AsyncResult.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    b1.opBatch();
                    b1.opBatch();
                    FlushCallback cb = new FlushCallback(cookie);
                    Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests(cb.completedAsync, cookie);
                    r.whenSent(cb.sentAsync);
                    cb.check();
                    test(r.isSent());
                    test(r.IsCompleted);
                    test(p.waitForBatch(2));
                }

                {
                    //
                    // AsyncResult exception.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    b1.opBatch();
                    b1.ice_getConnection().close(false);
                    FlushExCallback cb = new FlushExCallback(cookie);
                    Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests(cb.completedAsync, cookie);
                    r.whenSent(cb.sentAsync);
                    cb.check();
                    test(!r.isSent());
                    test(r.IsCompleted);
                    test(p.opBatchCount() == 0);
                }

                {
                    //
                    // Type-safe.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    b1.opBatch();
                    b1.opBatch();
                    FlushCallback cb = new FlushCallback();
                    Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests();
                    r.whenCompleted(cb.exception);
                    r.whenSent(cb.sent);
                    cb.check();
                    test(r.isSent());
                    test(r.IsCompleted);
                    test(p.waitForBatch(2));
                }

                {
                    //
                    // Type-safe exception.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    b1.opBatch();
                    b1.ice_getConnection().close(false);
                    FlushExCallback cb = new FlushExCallback();
                    Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests();
                    r.whenCompleted(cb.exception);
                    r.whenSent(cb.sent);
                    cb.check();
                    test(!r.isSent());
                    test(r.IsCompleted);
                    test(p.opBatchCount() == 0);
                }
            }
            WriteLine("ok");
        }

        if(p.ice_getConnection() != null)
        {
            Write("testing batch requests with connection and lambda... ");
            Flush();
            {
                Cookie cookie = new Cookie(5);

                {
                    //
                    // AsyncResult.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    b1.opBatch();
                    b1.opBatch();
                    FlushCallback cb = new FlushCallback(cookie);
                    Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests(
                        (Ice.AsyncResult result) =>
                        {
                            cb.completedAsync(result);
                        }, cookie);
                    r.whenSent(
                        (Ice.AsyncResult result) =>
                        {
                            cb.sentAsync(result);
                        });
                    cb.check();
                    test(r.isSent());
                    test(r.IsCompleted);
                    test(p.waitForBatch(2));
                }

                {
                    //
                    // AsyncResult exception.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    b1.opBatch();
                    b1.ice_getConnection().close(false);
                    FlushExCallback cb = new FlushExCallback(cookie);
                    Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests(
                        (Ice.AsyncResult result) =>
                        {
                            cb.completedAsync(result);
                        }, cookie);
                    r.whenSent(
                        (Ice.AsyncResult result) =>
                        {
                            cb.sentAsync(result);
                        });
                    cb.check();
                    test(!r.isSent());
                    test(r.IsCompleted);
                    test(p.opBatchCount() == 0);
                }

                {
                    //
                    // Type-safe.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    b1.opBatch();
                    b1.opBatch();
                    FlushCallback cb = new FlushCallback();
                    Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests();
                    r.whenCompleted(
                        (Ice.Exception ex) =>
                        {
                            cb.exception(ex);
                        });
                    r.whenSent(
                        (bool sentSynchronously) =>
                        {
                            cb.sent(sentSynchronously);
                        });
                    cb.check();
                    test(r.isSent());
                    test(r.IsCompleted);
                    test(p.waitForBatch(2));
                }

                {
                    //
                    // Type-safe exception.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    b1.opBatch();
                    b1.ice_getConnection().close(false);
                    FlushExCallback cb = new FlushExCallback();
                    Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests();
                    r.whenCompleted(
                        (Ice.Exception ex) =>
                        {
                            cb.exception(ex);
                        });
                    r.whenSent(
                        (bool sentSynchronously) =>
                        {
                            cb.sent(sentSynchronously);
                        });
                    cb.check();
                    test(!r.isSent());
                    test(r.IsCompleted);
                    test(p.opBatchCount() == 0);
                }
            }
            WriteLine("ok");

            Write("testing batch requests with communicator... ");
            Flush();
            {
                Cookie cookie = new Cookie(5);

                {
                    //
                    // AsyncResult - 1 connection.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    b1.opBatch();
                    b1.opBatch();
                    FlushCallback cb = new FlushCallback(cookie);
                    Ice.AsyncResult r = communicator.begin_flushBatchRequests(cb.completedAsync, cookie);
                    r.whenSent(cb.sentAsync);
                    cb.check();
                    test(r.isSent());
                    test(r.IsCompleted);
                    test(p.waitForBatch(2));
                }

                {
                    //
                    // AsyncResult exception - 1 connection.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    b1.opBatch();
                    b1.ice_getConnection().close(false);
                    FlushCallback cb = new FlushCallback(cookie);
                    Ice.AsyncResult r = communicator.begin_flushBatchRequests(cb.completedAsync, cookie);
                    r.whenSent(cb.sentAsync);
                    cb.check();
                    test(r.isSent()); // Exceptions are ignored!
                    test(r.IsCompleted);
                    test(p.opBatchCount() == 0);
                }

                {
                    //
                    // AsyncResult - 2 connections.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway();
                    b2.ice_getConnection(); // Ensure connection is established.
                    b1.opBatch();
                    b1.opBatch();
                    b2.opBatch();
                    b2.opBatch();
                    FlushCallback cb = new FlushCallback(cookie);
                    Ice.AsyncResult r = communicator.begin_flushBatchRequests(cb.completedAsync, cookie);
                    r.whenSent(cb.sentAsync);
                    cb.check();
                    test(r.isSent());
                    test(r.IsCompleted);
                    test(p.waitForBatch(4));
                }

                {
                    //
                    // AsyncResult exception - 2 connections - 1 failure.
                    //
                    // All connections should be flushed even if there are failures on some connections.
                    // Exceptions should not be reported.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway();
                    b2.ice_getConnection(); // Ensure connection is established.
                    b1.opBatch();
                    b2.opBatch();
                    b1.ice_getConnection().close(false);
                    FlushCallback cb = new FlushCallback(cookie);
                    Ice.AsyncResult r = communicator.begin_flushBatchRequests(cb.completedAsync, cookie);
                    r.whenSent(cb.sentAsync);
                    cb.check();
                    test(r.isSent()); // Exceptions are ignored!
                    test(r.IsCompleted);
                    test(p.waitForBatch(1));
                }

                {
                    //
                    // AsyncResult exception - 2 connections - 2 failures.
                    //
                    // The sent callback should be invoked even if all connections fail.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway();
                    b2.ice_getConnection(); // Ensure connection is established.
                    b1.opBatch();
                    b2.opBatch();
                    b1.ice_getConnection().close(false);
                    b2.ice_getConnection().close(false);
                    FlushCallback cb = new FlushCallback(cookie);
                    Ice.AsyncResult r = communicator.begin_flushBatchRequests(cb.completedAsync, cookie);
                    r.whenSent(cb.sentAsync);
                    cb.check();
                    test(r.isSent()); // Exceptions are ignored!
                    test(r.IsCompleted);
                    test(p.opBatchCount() == 0);
                }

                {
                    //
                    // Type-safe - 1 connection.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    b1.opBatch();
                    b1.opBatch();
                    FlushCallback cb = new FlushCallback();
                    Ice.AsyncResult r = communicator.begin_flushBatchRequests();
                    r.whenCompleted(cb.exception);
                    r.whenSent(cb.sent);
                    cb.check();
                    test(r.isSent());
                    test(r.IsCompleted);
                    test(p.waitForBatch(2));
                }

                {
                    //
                    // Type-safe exception - 1 connection.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    b1.opBatch();
                    b1.ice_getConnection().close(false);
                    FlushCallback cb = new FlushCallback();
                    Ice.AsyncResult r = communicator.begin_flushBatchRequests();
                    r.whenCompleted(cb.exception);
                    r.whenSent(cb.sent);
                    cb.check();
                    test(r.isSent()); // Exceptions are ignored!
                    test(r.IsCompleted);
                    test(p.opBatchCount() == 0);
                }

                {
                    //
                    // 2 connections.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway();
                    b2.ice_getConnection(); // Ensure connection is established.
                    b1.opBatch();
                    b1.opBatch();
                    b2.opBatch();
                    b2.opBatch();
                    FlushCallback cb = new FlushCallback();
                    Ice.AsyncResult r = communicator.begin_flushBatchRequests();
                    r.whenCompleted(cb.exception);
                    r.whenSent(cb.sent);
                    cb.check();
                    test(r.isSent());
                    test(r.IsCompleted);
                    test(p.waitForBatch(4));
                }

                {
                    //
                    // Exception - 2 connections - 1 failure.
                    //
                    // All connections should be flushed even if there are failures on some connections.
                    // Exceptions should not be reported.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway();
                    b2.ice_getConnection(); // Ensure connection is established.
                    b1.opBatch();
                    b2.opBatch();
                    b1.ice_getConnection().close(false);
                    FlushCallback cb = new FlushCallback();
                    Ice.AsyncResult r = communicator.begin_flushBatchRequests();
                    r.whenCompleted(cb.exception);
                    r.whenSent(cb.sent);
                    cb.check();
                    test(r.isSent()); // Exceptions are ignored!
                    test(r.IsCompleted);
                    test(p.waitForBatch(1));
                }

                {
                    //
                    // Exception - 2 connections - 2 failures.
                    //
                    // The sent callback should be invoked even if all connections fail.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway();
                    b2.ice_getConnection(); // Ensure connection is established.
                    b1.opBatch();
                    b2.opBatch();
                    b1.ice_getConnection().close(false);
                    b2.ice_getConnection().close(false);
                    FlushCallback cb = new FlushCallback();
                    Ice.AsyncResult r = communicator.begin_flushBatchRequests();
                    r.whenCompleted(cb.exception);
                    r.whenSent(cb.sent);
                    cb.check();
                    test(r.isSent()); // Exceptions are ignored!
                    test(r.IsCompleted);
                    test(p.opBatchCount() == 0);
                }
            }
            WriteLine("ok");

            Write("testing batch requests with communicator with lambda... ");
            Flush();
            {
                Cookie cookie = new Cookie(5);

                {
                    //
                    // AsyncResult - 1 connection.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    b1.opBatch();
                    b1.opBatch();
                    FlushCallback cb = new FlushCallback(cookie);
                    Ice.AsyncResult r = communicator.begin_flushBatchRequests(
                        (Ice.AsyncResult result) =>
                        {
                            cb.completedAsync(result);
                        }, cookie);
                    r.whenSent(
                        (Ice.AsyncResult result) =>
                        {
                            cb.sentAsync(result);
                        });
                    cb.check();
                    test(r.isSent());
                    test(r.IsCompleted);
                    test(p.waitForBatch(2));
                }

                {
                    //
                    // AsyncResult exception - 1 connection.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    b1.opBatch();
                    b1.ice_getConnection().close(false);
                    FlushCallback cb = new FlushCallback(cookie);
                    Ice.AsyncResult r = communicator.begin_flushBatchRequests(
                        (Ice.AsyncResult result) =>
                        {
                            cb.completedAsync(result);
                        }, cookie);
                    r.whenSent(
                        (Ice.AsyncResult result) =>
                        {
                            cb.sentAsync(result);
                        });
                    cb.check();
                    test(r.isSent()); // Exceptions are ignored!
                    test(r.IsCompleted);
                    test(p.opBatchCount() == 0);
                }

                {
                    //
                    // AsyncResult - 2 connections.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway();
                    b2.ice_getConnection(); // Ensure connection is established.
                    b1.opBatch();
                    b1.opBatch();
                    b2.opBatch();
                    b2.opBatch();
                    FlushCallback cb = new FlushCallback(cookie);
                    Ice.AsyncResult r = communicator.begin_flushBatchRequests(
                        (Ice.AsyncResult result) =>
                        {
                            cb.completedAsync(result);
                        }, cookie);
                    r.whenSent(
                        (Ice.AsyncResult result) =>
                        {
                            cb.sentAsync(result);
                        });
                    cb.check();
                    test(r.isSent());
                    test(r.IsCompleted);
                    test(p.waitForBatch(4));
                }

                {
                    //
                    // AsyncResult exception - 2 connections - 1 failure.
                    //
                    // All connections should be flushed even if there are failures on some connections.
                    // Exceptions should not be reported.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway();
                    b2.ice_getConnection(); // Ensure connection is established.
                    b1.opBatch();
                    b2.opBatch();
                    b1.ice_getConnection().close(false);
                    FlushCallback cb = new FlushCallback(cookie);
                    Ice.AsyncResult r = communicator.begin_flushBatchRequests(
                        (Ice.AsyncResult result) =>
                        {
                            cb.completedAsync(result);
                        }, cookie);
                    r.whenSent(
                        (Ice.AsyncResult result) =>
                        {
                            cb.sentAsync(result);
                        });
                    cb.check();
                    test(r.isSent()); // Exceptions are ignored!
                    test(r.IsCompleted);
                    test(p.waitForBatch(1));
                }

                {
                    //
                    // AsyncResult exception - 2 connections - 2 failures.
                    //
                    // The sent callback should be invoked even if all connections fail.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway();
                    b2.ice_getConnection(); // Ensure connection is established.
                    b1.opBatch();
                    b2.opBatch();
                    b1.ice_getConnection().close(false);
                    b2.ice_getConnection().close(false);
                    FlushCallback cb = new FlushCallback(cookie);
                    Ice.AsyncResult r = communicator.begin_flushBatchRequests(
                        (Ice.AsyncResult result) =>
                        {
                            cb.completedAsync(result);
                        }, cookie);
                    r.whenSent(
                        (Ice.AsyncResult result) =>
                        {
                            cb.sentAsync(result);
                        });
                    cb.check();
                    test(r.isSent()); // Exceptions are ignored!
                    test(r.IsCompleted);
                    test(p.opBatchCount() == 0);
                }

                {
                    //
                    // Type-safe - 1 connection.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    b1.opBatch();
                    b1.opBatch();
                    FlushCallback cb = new FlushCallback();
                    Ice.AsyncResult r = communicator.begin_flushBatchRequests();
                    r.whenCompleted(
                        (Ice.Exception ex) =>
                        {
                            cb.exception(ex);
                        });
                    r.whenSent(
                        (bool sentSynchronously) =>
                        {
                            cb.sent(sentSynchronously);
                        });
                    cb.check();
                    test(r.isSent());
                    test(r.IsCompleted);
                    test(p.waitForBatch(2));
                }

                {
                    //
                    // Type-safe exception - 1 connection.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    b1.opBatch();
                    b1.ice_getConnection().close(false);
                    FlushCallback cb = new FlushCallback();
                    Ice.AsyncResult r = communicator.begin_flushBatchRequests();
                    r.whenCompleted(
                        (Ice.Exception ex) =>
                        {
                            cb.exception(ex);
                        });
                    r.whenSent(
                        (bool sentSynchronously) =>
                        {
                            cb.sent(sentSynchronously);
                        });
                    cb.check();
                    test(r.isSent()); // Exceptions are ignored!
                    test(r.IsCompleted);
                    test(p.opBatchCount() == 0);
                }

                {
                    //
                    // 2 connections.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway();
                    b2.ice_getConnection(); // Ensure connection is established.
                    b1.opBatch();
                    b1.opBatch();
                    b2.opBatch();
                    b2.opBatch();
                    FlushCallback cb = new FlushCallback();
                    Ice.AsyncResult r = communicator.begin_flushBatchRequests();
                    r.whenCompleted(
                        (Ice.Exception ex) =>
                        {
                            cb.exception(ex);
                        });
                    r.whenSent(
                        (bool sentSynchronously) =>
                        {
                            cb.sent(sentSynchronously);
                        });
                    cb.check();
                    test(r.isSent());
                    test(r.IsCompleted);
                    test(p.waitForBatch(4));
                }

                {
                    //
                    // Exception - 2 connections - 1 failure.
                    //
                    // All connections should be flushed even if there are failures on some connections.
                    // Exceptions should not be reported.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway();
                    b2.ice_getConnection(); // Ensure connection is established.
                    b1.opBatch();
                    b2.opBatch();
                    b1.ice_getConnection().close(false);
                    FlushCallback cb = new FlushCallback();
                    Ice.AsyncResult r = communicator.begin_flushBatchRequests();
                    r.whenCompleted(
                        (Ice.Exception ex) =>
                        {
                            cb.exception(ex);
                        });
                    r.whenSent(
                        (bool sentSynchronously) =>
                        {
                            cb.sent(sentSynchronously);
                        });
                    cb.check();
                    test(r.isSent()); // Exceptions are ignored!
                    test(r.IsCompleted);
                    test(p.waitForBatch(1));
                }

                {
                    //
                    // Exception - 2 connections - 2 failures.
                    //
                    // The sent callback should be invoked even if all connections fail.
                    //
                    test(p.opBatchCount() == 0);
                    TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway();
                    TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway();
                    b2.ice_getConnection(); // Ensure connection is established.
                    b1.opBatch();
                    b2.opBatch();
                    b1.ice_getConnection().close(false);
                    b2.ice_getConnection().close(false);
                    FlushCallback cb = new FlushCallback();
                    Ice.AsyncResult r = communicator.begin_flushBatchRequests();
                    r.whenCompleted(
                        (Ice.Exception ex) =>
                        {
                            cb.exception(ex);
                        });
                    r.whenSent(
                        (bool sentSynchronously) =>
                        {
                            cb.sent(sentSynchronously);
                        });
                    cb.check();
                    test(r.isSent()); // Exceptions are ignored!
                    test(r.IsCompleted);
                    test(p.opBatchCount() == 0);
                }
            }
            WriteLine("ok");
        }

        Write("testing AsyncResult operations... ");
        Flush();
        {
            {
                testController.holdAdapter();
                Ice.AsyncResult r1;
                Ice.AsyncResult r2;
                try
                {
                    r1 = p.begin_op();
                    byte[] seq = new byte[10024];
                    (new System.Random()).NextBytes(seq);
                    while((r2 = p.begin_opWithPayload(seq)).sentSynchronously());

                    if(p.ice_getConnection() != null)
                    {
                        test(r1.sentSynchronously() && r1.isSent() && !r1.isCompleted_() ||
                             !r1.sentSynchronously() && !r1.isCompleted_());

                        test(!r2.sentSynchronously() && !r2.isCompleted_());

                        test(!r1.IsCompleted && !r1.CompletedSynchronously);
                        test(!r2.IsCompleted && !r2.CompletedSynchronously);
                    }
                }
                finally
                {
                    testController.resumeAdapter();
                }

                WaitHandle w1 = r1.AsyncWaitHandle;
                WaitHandle w2 = r2.AsyncWaitHandle;

                r1.waitForSent();
                test(r1.isSent());

                r2.waitForSent();
                test(r2.isSent());

                r1.waitForCompleted();
                test(r1.isCompleted_());
                w1.WaitOne();

                r2.waitForCompleted();
                test(r2.isCompleted_());
                w2.WaitOne();

                test(r1.getOperation().Equals("op"));
                test(r2.getOperation().Equals("opWithPayload"));
            }

            {
                Ice.AsyncResult r;

                //
                // Twoway
                //
                r = p.begin_ice_ping();
                test(r.getOperation().Equals("ice_ping"));
                test(r.getConnection() == null); // Expected
                test(r.getCommunicator() == communicator);
                test(r.getProxy() == p);
                p.end_ice_ping(r);

                Test.TestIntfPrx p2;

                //
                // Oneway
                //
                p2 = p.ice_oneway() as Test.TestIntfPrx;
                r = p2.begin_ice_ping();
                test(r.getOperation().Equals("ice_ping"));
                test(r.getConnection() == null); // Expected
                test(r.getCommunicator() == communicator);
                test(r.getProxy() == p2);

                //
                // Batch request via proxy
                //
                p2 = p.ice_batchOneway() as Test.TestIntfPrx;
                p2.ice_ping();
                r = p2.begin_ice_flushBatchRequests();
                test(r.getConnection() == null); // Expected
                test(r.getCommunicator() == communicator);
                test(r.getProxy() == p2);
                p2.end_ice_flushBatchRequests(r);

                if(p.ice_getConnection() != null)
                {
                    //
                    // Batch request via connection
                    //
                    Ice.Connection con = p.ice_getConnection();
                    p2 = p.ice_batchOneway() as Test.TestIntfPrx;
                    p2.ice_ping();
                    r = con.begin_flushBatchRequests();
                    test(r.getConnection() == con);
                    test(r.getCommunicator() == communicator);
                    test(r.getProxy() == null); // Expected
                    con.end_flushBatchRequests(r);

                    //
                    // Batch request via communicator
                    //
                    p2 = p.ice_batchOneway() as Test.TestIntfPrx;
                    p2.ice_ping();
                    r = communicator.begin_flushBatchRequests();
                    test(r.getConnection() == null); // Expected
                    test(r.getCommunicator() == communicator);
                    test(r.getProxy() == null); // Expected
                    communicator.end_flushBatchRequests(r);
                }
            }

            if(p.ice_getConnection() != null)
            {
                Ice.AsyncResult r1 = null;
                Ice.AsyncResult r2 = null;
                testController.holdAdapter();
                try
                {
                    Ice.AsyncResult r = null;
                    byte[] seq = new byte[10024];
                    for(int i = 0; i < 200; ++i) // 2MB
                    {
                        r = p.begin_opWithPayload(seq);
                    }

                    test(!r.isSent());

                    r1 = p.begin_ice_ping();
                    r2 = p.begin_ice_id();
                    r1.cancel();
                    r2.cancel();
                    try
                    {
                        p.end_ice_ping(r1);
                        test(false);
                    }
                    catch(Ice.InvocationCanceledException)
                    {
                    }
                    try
                    {
                        p.end_ice_id(r2);
                        test(false);
                    }
                    catch(Ice.InvocationCanceledException)
                    {
                    }

                }
                finally
                {
                    testController.resumeAdapter();
                    p.ice_ping();
                    test(!r1.isSent() && r1.isCompleted_());
                    test(!r2.isSent() && r2.isCompleted_());
                }


                testController.holdAdapter();
                try
                {
                    r1 = p.begin_op();
                    r2 = p.begin_ice_id();
                    r1.waitForSent();
                    r2.waitForSent();
                    r1.cancel();
                    r2.cancel();
                    try
                    {
                        p.end_op(r1);
                        test(false);
                    }
                    catch(Ice.InvocationCanceledException)
                    {
                    }
                    try
                    {
                        p.end_ice_id(r2);
                        test(false);
                    }
                    catch(Ice.InvocationCanceledException)
                    {
                    }
                }
                finally
                {
                    testController.resumeAdapter();
                }
            }
        }
        WriteLine("ok");

        if(p.ice_getConnection() != null)
        {
            Write("testing close connection with sending queue... ");
            Flush();
            {
                byte[] seq = new byte[1024 * 10];

                //
                // Send multiple opWithPayload, followed by a close and followed by multiple opWithPaylod.
                // The goal is to make sure that none of the opWithPayload fail even if the server closes
                // the connection gracefully in between.
                //
                int maxQueue = 2;
                bool done = false;
                while(!done && maxQueue < 50)
                {
                    done = true;
                    p.ice_ping();
                    List<Ice.AsyncResult> results = new List<Ice.AsyncResult>();
                    for(int i = 0; i < maxQueue; ++i)
                    {
                        results.Add(p.begin_opWithPayload(seq));
                    }
                    if(!p.begin_close(false).isSent())
                    {
                        for(int i = 0; i < maxQueue; i++)
                        {
                            Ice.AsyncResult r = p.begin_opWithPayload(seq);
                            results.Add(r);
                            if(r.isSent())
                            {
                                done = false;
                                maxQueue *= 2;
                                break;
                            }
                        }
                    }
                    else
                    {
                        maxQueue *= 2;
                        done = false;
                    }
                    foreach(Ice.AsyncResult q in results)
                    {
                        q.waitForCompleted();
                        try
                        {
                            q.throwLocalException();
                        }
                        catch(Ice.LocalException)
                        {
                            test(false);
                        }
                    }
                }
            }
            WriteLine("ok");
        }

        p.shutdown();
    }
 public void Request(byte requestByte, ResponseCallback responseCallback)
 {
     Request(requestByte, responseCallback, 0, 0);
 }
Beispiel #49
0
	public void Unenroll(string courseId, ResponseCallback cb = null) {
		if (cb != null) {
			mUnenroll_CBList.Add (cb);
		} else {
			ResponseCallback tempCB = ResponseCallback_Stub;
			mUnenroll_CBList.Add (tempCB);
		}
		
		GlasslabSDK_UnEnroll (mInst, courseId);
	}
Beispiel #50
0
	public void AuthStatus(ResponseCallback cb = null) {
		if (cb != null) {
			mAuthStatus_CBList.Add (cb);
		} else {
			ResponseCallback tempCB = ResponseCallback_Stub;
			mAuthStatus_CBList.Add (tempCB);
		}
		
		GlasslabSDK_AuthStatus (mInst);
	}
Beispiel #51
0
	public void GetCourses(ResponseCallback cb = null) {
		if (cb != null) {
			mGetCourses_CBList.Add (cb);
		} else {
			ResponseCallback tempCB = ResponseCallback_Stub;
			mGetCourses_CBList.Add (tempCB);
		}
		
		GlasslabSDK_GetCourses (mInst);
	}
Beispiel #52
0
	public void RegisterStudent(string username, string password, string firstName, string lastInitial, ResponseCallback cb = null) {
		if (cb != null) {
			mRegister_CBList.Add (cb);
		} else {
			ResponseCallback tempCB = ResponseCallback_Stub;
			mRegister_CBList.Add (tempCB);
		}
		
		GlasslabSDK_RegisterStudent (mInst, username, password, firstName, lastInitial);
	}
Beispiel #53
0
	public void SaveGame( string gameData, ResponseCallback cb = null ) {
		if (cb != null) {
			m_GameSave_CBList.Add (cb);
		} else {
			ResponseCallback tempCB = ResponseCallback_Stub;
			m_GameSave_CBList.Add (tempCB);
		}
		
		GlasslabSDK_SaveGame( mInst, gameData );
	}
Beispiel #54
0
	public void RegisterInstructor(string name, string email, string password, bool newsletter, ResponseCallback cb = null) {
		if (cb != null) {
			mRegister_CBList.Add (cb);
		} else {
			ResponseCallback tempCB = ResponseCallback_Stub;
			mRegister_CBList.Add (tempCB);
		}
		
		GlasslabSDK_RegisterInstructor (mInst, name, email, password, newsletter);
	}
Beispiel #55
0
	public void GetUserInfo(ResponseCallback cb = null) {
		if (cb != null) {
			m_GetUserInfo_CBList.Add (cb);
		} else {
			ResponseCallback tempCB = ResponseCallback_Stub;
			m_GetUserInfo_CBList.Add (tempCB);
		}
		
		GlasslabSDK_GetUserInfo( mInst );
	}
Beispiel #56
0
	public void Login(string username, string password, string type = null, ResponseCallback cb = null) {
		if (cb != null) {
			mLogin_CBList.Add (cb);
		} else {
			ResponseCallback tempCB = ResponseCallback_Stub;
			mLogin_CBList.Add (tempCB);
		}
		
		GlasslabSDK_Login (mInst, username, password, type);
	}
Beispiel #57
0
 internal void GetResponse(string method, Dictionary<string, string> parameters, ResponseCallback callback)
 {
     GetResponse(method, parameters, true, callback);
 }
Beispiel #58
0
	public void Login(string username, string password, ResponseCallback cb) {
		this.Login (username, password, null, cb);
	}
Beispiel #59
0
        internal void GetResponse(string method, Dictionary<string, string> parameters, bool throwOnError, ResponseCallback callback)
        {
            if (!Syncing)
                throw new InvalidOperationException("This instance of RTM is not syncing and as such, no web requests should be sent.");

            if (PreviewGotResponse != null)
                PreviewGotResponse(this, EventArgs.Empty);

            Client.GetResponse(method, parameters, throwOnError, (response) =>
            {
                if (GotResponse != null)
                    GotResponse(this, EventArgs.Empty);

                callback(response);
            });
        }
 public void GetResponse(string method, Dictionary<string, string> parameters, bool throwOnError, ResponseCallback callback)
 {
     throw new InvalidOperationException();
 }