| Quintiq file version 2.0 | 
| #parent: #root | 
| Method MessageReceive (NamedValueTree nvt_i) | 
| { | 
|   TextBody: | 
|   [* | 
|     sourceKind  := LibInt_MessageAccessor::GetHeaderPropertyAsString( nvt_i, LibDMF_CommunicationChannel::HEADER_SOURCEKIND()  ); | 
|     sourceName  := LibInt_MessageAccessor::GetHeaderPropertyAsString( nvt_i, LibDMF_CommunicationChannel::HEADER_SOURCENAME()  ); | 
|     messageType := LibInt_MessageAccessor::GetHeaderPropertyAsString( nvt_i, LibDMF_CommunicationChannel::HEADER_MESSAGETYPE() ); | 
|     messageID   := LibInt_MessageAccessor::GetHeaderPropertyAsString( nvt_i, LibDMF_CommunicationChannel::HEADER_MESSAGEID()   ); | 
|     sourceName  := LibInt_MessageAccessor::GetHeaderPropertyAsString( nvt_i, LibDMF_CommunicationChannel::HEADER_SOURCENAME()  ); | 
|      | 
|     // See if it is an error message. | 
|     isError := LibInt_MessageAccessor::HasHeaderProperty( nvt_i, LibDMF_CommunicationChannel::HEADER_IS_ERROR() ) and | 
|                LibInt_MessageAccessor::GetHeaderPropertyAsBoolean( nvt_i, LibDMF_CommunicationChannel::HEADER_IS_ERROR() ); | 
|      | 
|     // The message might have been sent in response to a Request; in that case the header contains a RequestID. | 
|     requestID   := ifexpr( LibInt_MessageAccessor::HasHeaderProperty( nvt_i, LibDMF_CommunicationChannel::HEADER_REQUESTID() ), | 
|                            LibInt_MessageAccessor::GetHeaderPropertyAsString( nvt_i, LibDMF_CommunicationChannel::HEADER_REQUESTID() ), | 
|                            LibDMF_CommunicationChannel::REQUEST_NO_ID() ); | 
|      | 
|     requestInfo := ifexpr( requestID <> LibDMF_CommunicationChannel::REQUEST_NO_ID(), ", RequestID = " + requestID, "" ); | 
|      | 
|     root := this.CommunicationChannelRoot(); | 
|      | 
|     // Retrieve IntegrationEvent | 
|     event := root.EventGetLast( sourceKind, sourceName ); | 
|      | 
|     // Log this action for tracing and update the IntegrationEvent | 
|     LibDMF_Util::Trace( sourceName, messageID, messageType, "", false, true ); | 
|     root.EventUpdateTraceInfo( event, messageID, requestID, messageType, "" ); | 
|      | 
|     errorText := ifexpr( isError, "error ", "" ); | 
|      | 
|     root.EventLogActivity( event, | 
|                            "Received " + errorText + "message '" + messageType + "' for CommunicationChannel = '" + this.Name() + "'; MessageID = " + messageID + requestInfo ); | 
|      | 
|     if( isError ) | 
|     { | 
|       this.MessageReceiveError( nvt_i ); | 
|     } | 
|     else | 
|     { | 
|       // SetUpdate and HierarchyUpdated are treated in the same way. | 
|       if( messageType = LibDMF_CommunicationChannel::MESSAGETYPE_SETUPDATED() or | 
|           messageType = LibDMF_CommunicationChannel::MESSAGETYPE_HIERARCHYUPDATED() ) | 
|       { | 
|         this.MessageReceiveSetUpdated( messageType, nvt_i ); | 
|       } | 
|       else if( messageType = LibDMF_CommunicationChannel::MESSAGETYPE_SETCREATED() ) | 
|       { | 
|         this.MessageReceiveSetCreated( nvt_i ); | 
|       } | 
|       else if( messageType = LibDMF_CommunicationChannel::MESSAGETYPE_SETREMOVED() ) | 
|       { | 
|         this.MessageReceiveSetRemoved( nvt_i ); | 
|       } | 
|       else if( messageType = LibDMF_CommunicationChannel::MESSAGETYPE_SETLISTUPDATED() ) | 
|       { | 
|         this.MessageReceiveSetListUpdated( nvt_i ); | 
|       } | 
|       else | 
|       { | 
|         root.EventLogActivityError( event, | 
|                                     "Received unknown message '" + messageType + "' for CommunicationChannel = '" + this.Name() + "'", | 
|                                     "Received unknown message '" + messageType + "' for CommunicationChannel = '" + this.Name() + "'; MessageID = " + messageID + requestInfo ); | 
|       } | 
|     } | 
|   *] | 
| } |