Jan Doggen February 2016

How to recreate exceptions of recurring appointment in the proper order?

I have the following issue:

  • Assume a recurring event on 15, 19, 23, 27... February
  • In Exchange the '19' occurrence was moved to 21
  • Next, the '15' occurrence was moved to 20. So it moves past the original start date (19) of the 2nd occurrence

Now if I want to recreate this recurring event in Exchange I first create the master event, i.e. automatically with all its regular occurrences, and then I must modify some of these to create the exceptions in this same order. If I don't do that and first create the '15->20' occurrence, this will fail, because its modified date is past the regular '19' occurrence.
Exchange will give me the Modified occurrence is crossing or overlapping adjacent occurrence error.

But how do I determine the order? In a simple test case the GetItem call for the master event does not give me the ModifiedOccurrences in the order in which they were created:

 <t:ModifiedOccurrences>
    <t:Occurrence>
       <t:ItemId Id="AAMkA[snip]pQAAEA==" ChangeKey="DwA[snip]bix"/>
       <t:Start>2016-02-20T09:00:00Z</t:Start>
       <t:End>2016-02-20T10:30:00Z</t:End>
       <t:OriginalStart>2016-02-15T09:00:00Z</t:OriginalStart>
    </t:Occurrence>
    <t:Occurrence>
       <t:ItemId Id="AAMkA[snip]pQAAEA==" ChangeKey="DwA[snip]bix"/>
       <t:Start>2016-02-21T09:00:00Z</t:Start>
       <t:End>2016-02-21T10:30:00Z</t:End>
       <t:OriginalStart>2016-02-19T09:00:00Z</t:OriginalStart>
    </t:Occurrence>
 </t:ModifiedOccurrences>

If I do a GetItem for those two exceptions I see no appointment property that I can use to determine the order in which they were created:

  • LastModifiedTime does not say anything, the exceptions may have been modified repeatedly.

Answers


Jan Doggen February 2016

Found the answer. The crucial remark in my question was:

OriginalStart or RecurrenceId (a date equal to OriginalStart) don't work, because this process goes in both directions (the exceptions can also be back in time).

If you split forward and backward occurrence moves and handle them in two blocks, it works. Actually, three blocks:

  1. Remove deleted occurrences

  2. Create occurrences moved forward (Start > OriginalStart) from last date to first date

  3. Create occurrences moved backward (Start < OriginalStart) from first date to last date

Essential parts of the (Delphi XE2) code using Developer Express components:

type 
   TIDDate = class
                FOrgStart,
                FStart   : TDateTime;
                FIndex   : Integer;
                Constructor Create(AOrgStart,AStart: TDateTime; AIndex: Integer);
             end;

constructor TIDDate.Create(AOrgStart,AStart: TDateTime; AIndex: Integer);
begin
   FOrgStart := AOrgStart;
   FStart    := AStart;
   FIndex    := AIndex;
end;

function TDataModuleSyncExchange.InsertExchangeMasterEvent(AMasterEvent: TcxSchedulerEvent; var AMasterItemID, AMasterEntryID: String): Boolean;
var
   lExchOccurrence: TcxSchedulerEvent;
   i              : Integer;
   lDateList      : TObjectList;
   lIDDate        : TIDDate;
   lEventList     : TcxSchedulerEventList;

begin { Main InsertExchangeMasterEvent }
   [snip]
   lEventList := AMasterEvent.GetRecurrenceChain;  // DevEx code

   // 1. Deleted occurrences 
   for i := 0 to lEventList.Count-1 do
   begin
      lExchOccurrence := lEventList.Items[i];
      if lExchOccurrence.EventType = etException then
         DeleteExchangeItem(lOccurItemID);  // Own code elsewhere
   end;

   // 2. Occurrences moved forward (Start > OriginalStart) from last date to first date
   lDateList := TObjectList.Create(true);
   for i := 0 to lEventList.Count-1 do 

Post Status

Asked in February 2016
Viewed 3,705 times
Voted 4
Answered 1 times

Search




Leave an answer