| Quintiq file version 2.0 | 
| #parent: #root | 
| StaticMethod HandleIncomingMessage ( | 
|   MPSync mpsync, | 
|   NamedValueTree requestnvt, | 
|   NamedValue requestNV, | 
|   Type objectType, | 
|   MessageIntegrationLog messagelog | 
| ) | 
| { | 
|   Description: 'Process incoming message to create, update or delete IO object' | 
|   TextBody: | 
|   [* | 
|     sourcemessage := MPSyncUtility::ID_Source_Message(); | 
|      | 
|     body := LibInt_NvtAccessor::FirstChildNamed( requestnvt, requestNV, MPSyncUtility::NVT_NAME_BODY() ); | 
|      | 
|     traverse( body.Children(), Elements, nvtobjects ) | 
|     { | 
|        | 
|       // to process particular object type only | 
|       traverse( nvtobjects.Children(), Elements, nvtobject, nvtobject.Name() = objectType.ShortName() ) | 
|       { | 
|         importedobject := NamedValueTreeIO::ImportObject( requestnvt, nvtobject, objectType ).astype( IOBase ); | 
|          | 
|         if( not isnull( importedobject ) ) | 
|         { | 
|           // Find existing data | 
|           mode   := importedobject.Mode(); | 
|            | 
|           object := importedobject.MessageFindIOObject( mpsync, sourcemessage );  | 
|          | 
|           if( mode = MPSyncUtility::Message_Mode_InsertUpdate() ) | 
|           { | 
|             if( isnull( object ) ) | 
|             { | 
|               // Assign imported object to temp object and then set to actual object | 
|              importedobject.SetDataSource( MPSyncUtility::ID_Source_Message(), false, '' ); | 
|              temp := importedobject; | 
|              temp.MessageLinkImportedObject( &importedobject, mpsync );  | 
|             } | 
|             else | 
|             { | 
|               // Not to update record if its old message | 
|               if( importedobject.Timestamp() >= object.Timestamp() ) | 
|               { | 
|                 // Update data | 
|                 object.Update( importedobject, sourcemessage ); | 
|               } | 
|               else | 
|               { | 
|                 messagelog.AddWarning( Translations::MPSync_MessageBasedIntegration_IgnoreOldMessage( importedobject.DefinitionName(),  | 
|                                                                                                       importedobject.GetFunctionalKeyValues(), | 
|                                                                                                       importedobject.Timestamp(), | 
|                                                                                                       object.Timestamp() | 
|                                                                                                     ) ); | 
|               } | 
|             } | 
|           } | 
|           // Delete data | 
|           else if( mode = MPSyncUtility::Message_Mode_Delete() ) | 
|           { | 
|             if( isnull( object ) ) | 
|             { | 
|               messagelog.AddWarning( Translations::MPSync_MessageBasedIntegration_Delete_NotExists( importedobject.DefinitionName(),  | 
|                                                                                                     importedobject.GetFunctionalKeyValues() )  | 
|                                                                                                   ); | 
|             } | 
|             else | 
|             { | 
|               object.Delete(); | 
|             } | 
|           }     | 
|           else | 
|           { | 
|             messagelog.AddError( Translations::MPSync_MessageBasedIntegration_UnexpectedMode( importedobject.Mode(),  | 
|                                                                                               importedobject.DefinitionName(),  | 
|                                                                                               importedobject.GetFunctionalKeyValues() )  | 
|                                                                                             ); | 
|           } | 
|         } | 
|       } | 
|     } | 
|     mpsync.LastImportTime( DateTime::ActualTime() ); | 
|   *] | 
| } |