/// <summary> /// Asynchronous thread which waits for the completion of the specified output message interceptor. /// </summary> /// <param name="messageInterceptor">The message interceptor to wait for.</param> private void WaitForOutputMessage(object messageInterceptor) { try { using (var interceptor = messageInterceptor as MessageInterceptor) { bool orderNotFinished = true; while (orderNotFinished) { interceptor.Wait(); var outputMessage = (OutputMessage)interceptor.Message; if (outputMessage != null) { lock (_syncLock) { if (outputMessage.Article != null) { foreach (var article in outputMessage.Article) { if (article.Pack != null) { foreach (var pack in article.Pack) { pack.ArticleId = TextConverter.UnescapeInvalidXmlChars(article.Id); } _dispensedPackList.AddRange(article.Pack); } } } if (outputMessage.Box != null) { foreach (var box in outputMessage.Box) { _boxList.Add(box.Number); } } if (Enum.TryParse <OutputProcessState>(outputMessage.Details.Status, out _currentState) == false) { _currentState = OutputProcessState.Unknown; } } } else { this.Error("Waiting for the message 'OutputMessage' failed."); lock (_syncLock) { _currentState = OutputProcessState.Unknown; } } if (_currentState.Equals(OutputProcessState.BoxReleased)) { if (_boxReleased != null) { lock (_syncLock) { this.Trace("Raising event 'Box Released'."); _boxReleased(this, new EventArgs()); _dispensedPackList.Clear(); } } } else { orderNotFinished = false; _messageDispatcher.RemoveInterceptor(interceptor); if (_finished != null) { this.Trace("Raising event 'Finished'."); _finished(this, new EventArgs()); } } } } } catch (Exception ex) { this.Error("Receiving and processing 'OutputMessage' failed!", ex); } }
/// <summary> /// Asynchronous thread which waits for the completion of the specified output message interceptor. /// </summary> /// <param name="messageInterceptor">The message interceptor to wait for.</param> private void WaitForOutputMessage(object messageInterceptor) { try { using (var interceptor = messageInterceptor as MessageInterceptor) { bool orderNotFinished = true; while (orderNotFinished) { interceptor.Wait(); var outputMessage = interceptor.Message as OutputMessage; if (outputMessage != null) { lock (_syncLock) { this._boxList.Clear(); this._dispensedPackList.Clear(); this._dispensedPackList.AddRange(outputMessage.GetPacks()); if (outputMessage.Box != null) { foreach (var box in outputMessage.Box) { _boxList.Add(box.Number); } } if (Enum.TryParse <OutputProcessState>(outputMessage.Details.Status, out _currentState) == false) { _currentState = OutputProcessState.Unknown; } } } else { this.Error("Waiting for the message 'OutputMessage' failed."); lock (_syncLock) { _currentState = OutputProcessState.Unknown; } } if (_currentState.Equals(OutputProcessState.BoxReleased)) { if (_boxReleased != null) { lock (_syncLock) { this.Trace("Raising event 'Box Released'."); _boxReleased(this, new EventArgs()); } } } else if (_currentState.Equals(OutputProcessState.Completed) || _currentState.Equals(OutputProcessState.Incomplete) || _currentState.Equals(OutputProcessState.Aborted)) { orderNotFinished = false; _messageDispatcher.RemoveInterceptor(interceptor); if (_finished != null) { this.Trace("Raising event 'Finished'."); _finished(this, new EventArgs()); } } else { continue; } } } } catch (Exception ex) { this.Error("Receiving and processing 'OutputMessage' failed!", ex); } }