none
How to Identify Deleted Items locally? RRS feed

  • Question

  • I'm writing a Syncronization operation with Exchange WebServices... Currently, only concerned with Updates and Deletes.  I've got Updates running fine, but I'm having an issue with Deletes...
    I've got my local items tied to the Exchange items via an extended property that stores the id of my local item...
    When I detect a delete, it's not returning the item (or it's extended properties), the `ItemChange.Item` is `null`, I assume because it no longer exists, but how would I know what to delete locally?  I thought about using the ItemId, but apparently that is not consistent...
          Folder calendar = Folder.Bind(service, new FolderId(WellKnownFolderName.Calendar, testEmail));
          ExtendedPropertyDefinition mapAppointmentId = new ExtendedPropertyDefinition(new Guid(EBI.Map.Appointment.ExchIdGuid), "mapAppointmentId", MapiPropertyType.Integer);
          
          ChangeCollection<ItemChange> icc = service.SyncFolderItems(calendar.Id, new PropertySet(mapAppointmentId), null, 512, SyncFolderItemsScope.NormalItems, syncState);
    
          syncState = icc.SyncState;
    
          foreach (ItemChange ic in icc)
          {
            int apptId = 0;
            switch(ic.ChangeType)
            {
              case ChangeType.Update:
    
                if (ic.Item.TryGetProperty<int>(mapAppointmentId, out apptId))
                {
                  Microsoft.Exchange.WebServices.Data.Appointment exchAppt = Microsoft.Exchange.WebServices.Data.Appointment.Bind(service, ic.ItemId);
                  EBI.Map.Appointment mapAppt = EBI.Map.Appointment.GetByID(apptId);
    
                  mapAppt.StartDateTime = exchAppt.Start;
                  mapAppt.EndDateTime = exchAppt.End;
    
                  // pass false to disable exchange sync on save
                  mapAppt.Save(false);
                }
                break;
              case ChangeType.Delete:
                // FAILS HERE: ic.Item is null since it's been deleted... makes sense, except how am I suppose to know what to delete in my system???
                if (ic.Item.TryGetProperty<int>(mapAppointmentId, out apptId))
                {
                  EBI.Map.Appointment mapAppt = EBI.Map.Appointment.GetByID(apptId);
                  mapAppt.AppointmentStatusTypeID = EBI.Map.Appointment.AppointmentStatus.Cancelled_Faculty;
    
                  // pass false to disable exchange sync on save
                  mapAppt.Save(false);
                }
                break;
            }
    




    Tuesday, January 10, 2012 6:43 PM

Answers

  • The UID is kept stable for a given meeting by Exchange.
     Kind regards,
    Henning

    If you get your question answered, please come back and mark the reply as an answer.
    If you are helped by an answer to someone else's question, please mark it as helpful.

    • Marked as answer by jondavidjohn Wednesday, January 11, 2012 3:26 PM
    Wednesday, January 11, 2012 8:06 AM

All replies

  • The ItemId is stable with everything except meetings. In this case it's better to use the UID.

    That being said, you should still use the ItemId to identify items, because as you've noticed, that's all you get when an item is deleted. You should use the UID (or your own extended property) as an additional mean to identify an item during modify events. This way you would catch the change of an ItemId for a given instance of a meeting.
     Kind regards,
    Henning

    If you get your question answered, please come back and mark the reply as an answer.
    If you are helped by an answer to someone else's question, please mark it as helpful.

    Tuesday, January 10, 2012 9:30 PM
  • As you point out on the SO question i link to...

    " the situation is more complicated with calendar entries, as Exchange destroys and recreates an appointment under certain circumstances, thereby changing the unique id."

    So event the UID wouldn't be considered stable would it?


    Tuesday, January 10, 2012 9:31 PM
  • The UID is kept stable for a given meeting by Exchange.
     Kind regards,
    Henning

    If you get your question answered, please come back and mark the reply as an answer.
    If you are helped by an answer to someone else's question, please mark it as helpful.

    • Marked as answer by jondavidjohn Wednesday, January 11, 2012 3:26 PM
    Wednesday, January 11, 2012 8:06 AM