/// <summary> /// Starts the output process by sending the according request to the storage system. /// </summary> void IOutputProcess.Start() { lock (_syncLock) { if (_currentState != OutputProcessState.Created) { return; } } var request = new OutputRequestEnvelope() { OutputRequest = this }; var outputMessageInterceptor = new MessageInterceptor(this.Id, typeof(OutputMessage)); _messageDispatcher.AddInterceptor(outputMessageInterceptor); var response = (OutputResponse)_messageDispatcher.SendAndWaitForResponse(request, this.Id, typeof(OutputResponse)); if (response == null) { _messageDispatcher.RemoveInterceptor(outputMessageInterceptor); outputMessageInterceptor.Dispose(); throw new ArgumentException("Waiting for the message 'OutputResponse' failed."); } if ((response.Details == null) || (Enum.TryParse <OutputProcessState>(response.Details.Status, out _currentState) == false)) { _currentState = OutputProcessState.Unknown; } if (_currentState != OutputProcessState.Queued) { if (_finished != null) { this.Trace("Raising event 'Finished'."); _finished(this, new EventArgs()); } } else { // wait for completion if (ThreadPool.QueueUserWorkItem(new WaitCallback(WaitForOutputMessage), outputMessageInterceptor) == false) { throw new ApplicationException("Starting observation thread failed."); } } }
/// <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."); } } }