Special cases for UpdateCollection events

There are special cases when an IDO UpdateCollection request might not process all items in the update. For example, this might happen when a caller is saving hierarchical data, which is represented as an UpdateCollection request with nested UpdateCollection child requests. The framework first processes only the deleted items in the child requests, then all items in the parent, followed by the inserted or updated items in the child requests. This example shows how an event handler can determine if the framework is processing inserted, update and/or deleted items.

private void HandlePostUpdateCollection(object sender, IDOEventArgs args) 
{ 

   // Get the original request: 
   UpdateCollectionRequestData updateRequest; 
   UpdateCollectionResponseData updateResponse; 
   IDOUpdateEventArgs updateArgs; 

   updateArgs = (IDOUpdateEventArgs)args; 
   updateRequest = (UpdateCollectionRequestData)args.RequestPayload; 
   updateResponse = (UpdateCollectionResponseData)args.ResponsePayload; 

   if ((updateArgs.ActionMask & UpdateAction.Delete) == UpdateAction.Delete) 
   { 
 // ...Only perform this logic if processing deleted items: 
   } 

   if ((updateArgs.ActionMask & UpdateAction.Insert) == UpdateAction.Insert) 
   { 
 // ...Only perform this logic if processing inserted items: 
   } 

   if ((updateArgs.ActionMask & UpdateAction.Update) == UpdateAction.Update) 
   { 
 // ...Only perform this logic if processing updated items: 
   } 
 // ...Additional logic based on loadRequest or loadResponse. 
} 

Using the ActionMask property

In the example above, the IDOUpdateEventArgs class inherits from IDOEventArgs, but has one additional property: ActionMask. The ActionMask property is declared as an UpdateAction, which is an enum, as shown here.

public enum UpdateAction : ushort 
{ 
   None = (ushort)0x0000, 
   Insert = (ushort)0x0001, 
   Update = (ushort)0x0002, 
   Delete = (ushort)0x0004, 
   All = (ushort)0xffff 
} 

The ActionMask property is usually a combination of Insert, Update, and Delete (All), meaning the UpdateCollection that was just performed executed all types of actions. However, there are certain circumstances when this can be a subset of Insert, Update and Delete, which means only the items that match the mask were actually saved. There are times when the IDO runtime service must save items in a particular order (with nested updates), and it might first process only deleted items. Then, in another pass, it executes all inserts and updates.

ActionMask is valid for both PreUpdateCollection and PostUpdateCollection. The PreUpdateCollection parameters are the same as the PostUpdateCollection parameters, but the action indicates which items are about to be saved, rather than which items were just saved.