| Quintiq file version 2.0 | 
| #parent: #root | 
| Method MPSyncLane ( | 
|   Boolean isoverwritemanualconfig, | 
|   IOLanes iolanes | 
| ) | 
| { | 
|   Description: 'Synchronization of Lane for MPSync' | 
|   TextBody: | 
|   [* | 
|     // Select a set of existing Lane | 
|     existing := selectset( this, Unit.Lane, item, true ); | 
|     updates := construct( Lanes ); | 
|      | 
|     // Traverse the new set of valid Lane | 
|     traverse( iolanes , Elements, io, io.IsValid() ) | 
|     { | 
|       id := io.ID(); | 
|       // Find existing Lane | 
|       objectinstance := Lane::FindLaneTypeIndex( id ); | 
|       // Find existing Unit | 
|       unit := Unit::FindUnitTypeIndex( io.UnitID() ); | 
|        | 
|       // If no existing Lane is found, and there's valid Unit, create one | 
|       if( isnull( objectinstance ) ) | 
|       {  | 
|         if( not isnull( unit ) ) | 
|         { | 
|           objectinstance := Lane::Create( id, | 
|                                           unit, | 
|                                           io.Name(), | 
|                                           io.IsEnabled(), | 
|                                           io.Start(), | 
|                                           io.End(), | 
|                                           io.UserLeadTime(), | 
|                                           io.StandardDeviationLeadTimeLane(), | 
|                                           true ); | 
|         } | 
|       } | 
|       // Else if the Lane is not manually configured or the imported instance should overwrite manual configuration, | 
|       // update the existing Lane | 
|       else if( not objectinstance.IsManuallyConfigured() or isoverwritemanualconfig ) | 
|       { | 
|         // Update Lane | 
|         if( not isnull( unit ) ) | 
|         { | 
|           objectinstance.Update( unit , | 
|                                  io.ID(), | 
|                                  io.Name(), | 
|                                  io.IsEnabled(),  | 
|                                  io.Start(), | 
|                                  io.End(), | 
|                                  io.UserLeadTime(), | 
|                                  io.StandardDeviationLeadTimeLane(), | 
|                                  true ); | 
|           updates.Add( objectinstance ); | 
|         } | 
|       } | 
|        | 
|       // If Lane is created or found, synchronize LaneLeg and ProductInLane | 
|       if( not isnull( objectinstance ) ) | 
|       { | 
|         // CustomUpdate method is extended | 
|         objectinstance.CustomUpdate( io, isoverwritemanualconfig ); | 
|         this.MPSyncLaneLeg( isoverwritemanualconfig, io, objectinstance ); | 
|         this.MPSyncProductInLane( isoverwritemanualconfig, io, objectinstance ); | 
|       }   | 
|     } | 
|      | 
|     // Get the set of old Lane to be deleted | 
|     tobedeleteset := existing.Difference( updates ); | 
|      | 
|     // Traverse the set of Lane to be deleted | 
|     // Only delete Lane that is not manually configured or the imported instance should overwrite manual configuration | 
|     traverse( tobedeleteset, Elements, ele, | 
|               not ele.IsManuallyConfigured() or isoverwritemanualconfig ) | 
|     { | 
|       ele.Delete(); | 
|     } | 
|   *] | 
| } |