private bool SendMessage(bool enqueue, MessageType type, int resID, string userID, params object[] msgParams) { bool success = true; IBookingService stub; if (_clients.TryGetValue(userID, out stub)) { try { IAsyncResult result = null; //Apparently there is a problem of sending two async messages very close //to each other //Wait until previous call was completed before sending next message if (_previousCall.TryGetValue(userID, out result) && !result.IsCompleted) { Log.Debug(_userName, "Previous call was not completed, waiting 10ms before sending next message."); result.AsyncWaitHandle.WaitOne(10); } switch (type) { case MessageType.INIT_RESERVATION: InitReservationDelegate initRes = new InitReservationDelegate(stub.InitReservation); result = initRes.BeginInvoke((ReservationRequest)msgParams[0], resID, (string)msgParams[1], (string)msgParams[2], (int)msgParams[3], null, null); _initResCount++; break; case MessageType.BOOK_SLOT: ParticipantDelegate bookSlot = new ParticipantDelegate(stub.BookSlot); result = bookSlot.BeginInvoke(resID, (int)msgParams[0], null, null); _bookSlotCount++; break; case MessageType.PRE_COMMIT: ParticipantDelegate preCommit = new ParticipantDelegate(stub.PrepareCommit); result = preCommit.BeginInvoke(resID, (int)msgParams[0], null, null); _preCommitCount++; break; case MessageType.DO_COMMIT: ParticipantDelegate doCommit = new ParticipantDelegate(stub.DoCommit); result = doCommit.BeginInvoke(resID, (int)msgParams[0], null, null); _doCommitCount++; break; } //total counter for reservation messages between clients _messageCount++; Log.Debug(_userName, "Sucessfully sent " + type + " message to participant " + userID + " of reservation " + resID); _previousCall[userID] = result; } catch (Exception) { ClientDisconnected(resID, userID); success = false; } } else { success = false; } if (!success && enqueue) { EnqueueMessage(type, resID, userID, msgParams); } return(success); }
private bool SendMessage(bool enqueue, MessageType type, int resID, string userID, params object[] msgParams) { bool success = true; IBookingService stub; if (_clients.TryGetValue(userID, out stub)) { try { IAsyncResult result = null; //Apparently there is a problem of sending two async messages very close //to each other //Wait until previous call was completed before sending next message if (_previousCall.TryGetValue(userID, out result) && !result.IsCompleted) { Log.Debug(_userName, "Previous call was not completed, waiting 10ms before sending next message."); result.AsyncWaitHandle.WaitOne(10); } switch (type) { case MessageType.INIT_RESERVATION: InitReservationDelegate initRes = new InitReservationDelegate(stub.InitReservation); result = initRes.BeginInvoke((ReservationRequest)msgParams[0], resID, (string)msgParams[1], (string)msgParams[2], (int)msgParams[3], null, null); _initResCount++; break; case MessageType.BOOK_SLOT: ParticipantDelegate bookSlot = new ParticipantDelegate(stub.BookSlot); result = bookSlot.BeginInvoke(resID, (int)msgParams[0], null, null); _bookSlotCount++; break; case MessageType.PRE_COMMIT: ParticipantDelegate preCommit = new ParticipantDelegate(stub.PrepareCommit); result = preCommit.BeginInvoke(resID, (int)msgParams[0], null, null); _preCommitCount++; break; case MessageType.DO_COMMIT: ParticipantDelegate doCommit = new ParticipantDelegate(stub.DoCommit); result = doCommit.BeginInvoke(resID, (int)msgParams[0], null, null); _doCommitCount++; break; } //total counter for reservation messages between clients _messageCount++; Log.Debug(_userName, "Sucessfully sent " + type + " message to participant " + userID + " of reservation " + resID); _previousCall[userID] = result; } catch (Exception) { ClientDisconnected(resID, userID); success = false; } } else { success = false; } if (!success && enqueue) { EnqueueMessage(type, resID, userID, msgParams); } return success; }