/// <summary> /// Adds message to destination's send queue. /// </summary> /// <param name="senderApplication">Sender application/server</param> /// <param name="senderCommunicator">Sender communicator</param> /// <param name="destApplication">Destination application/server</param> /// <param name="message">Message</param> private static void EnqueueMessage(MDSRemoteApplication senderApplication, ICommunicator senderCommunicator, MDSPersistentRemoteApplicationBase destApplication, MDSDataTransferMessage message) { destApplication.EnqueueMessage(message); SendOperationResultMessage(senderApplication, senderCommunicator, message, true, "Success."); }
/// <summary> /// Sends message directly to application (not stores) and waits ACK. /// This method adds message to queue by MDSPersistentRemoteApplicationBase.AddMessageToHeadOfQueue method /// and waits a signal/pulse from RemoteApplication_MessageReceived method to get ACK/Reject. /// </summary> /// <param name="senderApplication">Sender application/server</param> /// <param name="senderCommunicator">Sender communicator</param> /// <param name="destApplication">Destination application/server</param> /// <param name="message">Message</param> private void SendMessageDirectly(MDSRemoteApplication senderApplication, ICommunicator senderCommunicator, MDSPersistentRemoteApplicationBase destApplication, MDSDataTransferMessage message) { //Create a WaitingMessage to wait and get ACK/Reject message and add it to waiting messages var waitingMessage = new WaitingMessage(); lock (_waitingMessages) { _waitingMessages[message.MessageId] = waitingMessage; } try { //Add message to head of queue of remote application destApplication.AddMessageToHeadOfQueue(message); //Wait until thread is signalled by another thread to get response (Signalled by RemoteApplication_MessageReceived method) waitingMessage.WaitEvent.WaitOne((int) (_settings.MessageResponseTimeout*1.2)); //Evaluate response if (waitingMessage.ResponseMessage.Success) { SendOperationResultMessage(senderApplication, senderCommunicator, message, true, "Success."); } else { SendOperationResultMessage(senderApplication, senderCommunicator, message, false, "Message is not acknowledged. Reason: " + waitingMessage.ResponseMessage.ResultText); } } finally { //Remove message from waiting messages lock (_waitingMessages) { _waitingMessages.Remove(message.MessageId); } } }
/// <summary> /// Sends message directly to application (not stores) and waits ACK. /// This method adds message to queue by MDSPersistentRemoteApplicationBase.AddMessageToHeadOfQueue method /// and waits a signal/pulse from RemoteApplication_MessageReceived method to get ACK/Reject. /// </summary> /// <param name="senderApplication">Sender application/server</param> /// <param name="senderCommunicator">Sender communicator</param> /// <param name="destApplication">Destination application/server</param> /// <param name="message">Message</param> private void SendMessageDirectly(MDSRemoteApplication senderApplication, ICommunicator senderCommunicator, MDSPersistentRemoteApplicationBase destApplication, MDSDataTransferMessage message) { //Create a WaitingMessage to wait and get ACK/Reject message and add it to waiting messages var waitingMessage = new WaitingMessage(); lock (_waitingMessages) { _waitingMessages[message.MessageId] = waitingMessage; } try { //Add message to head of queue of remote application destApplication.AddMessageToHeadOfQueue(message); //Wait until thread is signalled by another thread to get response (Signalled by RemoteApplication_MessageReceived method) waitingMessage.WaitEvent.WaitOne((int)(_settings.MessageResponseTimeout * 1.2)); //Evaluate response if (waitingMessage.ResponseMessage.Success) { SendOperationResultMessage(senderApplication, senderCommunicator, message, true, "Success."); } else { SendOperationResultMessage(senderApplication, senderCommunicator, message, false, "Message is not acknowledged. Reason: " + waitingMessage.ResponseMessage.ResultText); } } finally { //Remove message from waiting messages lock (_waitingMessages) { _waitingMessages.Remove(message.MessageId); } } }