/// <summary> /// Asynchronous thread which waits for the completion of the specified initiated input message interceptor. /// </summary> /// <param name="messageInterceptor">The message interceptor to wait for.</param> private void WaitForInitiateInputMessage(object messageInterceptor) { try { using (var interceptor = messageInterceptor as MessageInterceptor) { interceptor.Wait(); _messageDispatcher.RemoveInterceptor(interceptor); var inputMessage = (InitiateInputMessage)interceptor.Message; if (inputMessage != null) { lock (_syncLock) { if (inputMessage.Article != null) { _inputArticles = inputMessage.Article; } if (Enum.TryParse <InitiateInputRequestState>(inputMessage.Details.Status, out _currentState) == false) { _currentState = InitiateInputRequestState.Unknown; } } } else { this.Error("Waiting for the message 'InitiateInputMessage' failed."); lock (_syncLock) { _currentState = InitiateInputRequestState.Unknown; } } if (this.Finished != null) { this.Trace("Raising event 'Finished'."); this.Finished(this, new EventArgs()); } } } catch (Exception ex) { this.Error("Receiving and processing 'InitiateInputMessage' failed!", ex); } }
/// <summary> /// Initiates the input process by sending the according request to the storage system. /// </summary> void IInitiateInputRequest.Start() { lock (_syncLock) { if (_currentState != InitiateInputRequestState.Created) { return; } } var request = new InitiateInputRequestEnvelope() { InitiateInputRequest = this }; var initiateInputMessageInterceptor = new MessageInterceptor(this.Id, typeof(InitiateInputMessage)); _messageDispatcher.AddInterceptor(initiateInputMessageInterceptor); var response = (InitiateInputResponse)_messageDispatcher.SendAndWaitForResponse(request, this.Id, typeof(InitiateInputResponse)); if (response == null) { _messageDispatcher.RemoveInterceptor(initiateInputMessageInterceptor); initiateInputMessageInterceptor.Dispose(); throw new ArgumentException("Waiting for the message 'InitiateInputResponse' failed."); } if ((response.Details == null) || (Enum.TryParse <InitiateInputRequestState>(response.Details.Status, out _currentState) == false)) { _currentState = InitiateInputRequestState.Unknown; } if (_currentState != InitiateInputRequestState.Accepted) { if (this.Finished != null) { this.Trace("Raising event 'Finished'."); this.Finished(this, new EventArgs()); } } else { this.Details.InputPoint = (response.Details != null) ? response.Details.InputPoint : "0"; if (response.Article != null) { lock (_syncLock) { _inputArticles.AddRange(response.Article); } } // wait for completion if (ThreadPool.QueueUserWorkItem(new WaitCallback(WaitForInitiateInputMessage), initiateInputMessageInterceptor) == false) { throw new ApplicationException("Starting observation thread failed."); } } }