delphi - How to recreate exceptions of recurring appointment in the proper order? -
i have following issue:
- assume recurring event on 15, 19, 23, 27... february
- in exchange '19' occurrence moved 21
- next, '15' occurrence moved 20. moves past original start date (19) of 2nd occurrence
now if want recreate recurring event in exchange first create master event, i.e. automatically regular occurrences, , must modify of these create exceptions in same order. if don't , first create '15->20' occurrence, fail, because modified date past regular '19' occurrence.
exchange give me modified occurrence crossing or overlapping adjacent occurrence error.
but how determine order? in simple test case getitem call master event not give me modifiedoccurrences
in order in 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 getitem 2 exceptions see no appointment property can use determine order in created:
lastmodifiedtime
not anything, exceptions may have been modified repeatedly.originalstart
orrecurrenceid
(a date equaloriginalstart
) don't work, because process goes in both directions (the exceptions can back in time).- i see no other properties in calenderitem documentation seem usable.
i tried create master with exceptions in 1 step, inserting same modifiedoccurrences
block in createitem
call gives schema validation error because have supply itemids (but exchange creates those.)
so how can determine in order must recreate these exceptions (or did overlook , is possible create master event exceptions in 1 step)?
found answer. crucial remark in question was:
originalstart or recurrenceid (a date equal originalstart) don't work, because process goes in both directions (the exceptions can in time).
if split forward , backward occurrence moves , handle them in 2 blocks, works. actually, 3 blocks:
remove deleted occurrences
create occurrences moved forward (start > originalstart) last date first date
create occurrences moved backward (start < originalstart) first date last date
essential parts of (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; : integer; ldatelist : tobjectlist; liddate : tiddate; leventlist : tcxschedulereventlist; begin { main insertexchangemasterevent } [snip] leventlist := amasterevent.getrecurrencechain; // devex code // 1. deleted occurrences := 0 leventlist.count-1 begin lexchoccurrence := leventlist.items[i]; if lexchoccurrence.eventtype = etexception deleteexchangeitem(loccuritemid); // own code elsewhere end; // 2. occurrences moved forward (start > originalstart) last date first date ldatelist := tobjectlist.create(true); := 0 leventlist.count-1 begin lexchoccurrence := leventlist.items[i]; if lexchoccurrence.eventtype = etcustom begin liddate := tiddate.create(lexchoccurrence.getoriginaldate,lexchoccurrence.start,i); ldatelist.add(liddate); end; end; ldatelist.sortlist(function (item1, item2: pointer): integer var ldt1,ldt2: tdatetime; begin ldt1 := tiddate(item1).forgstart; ldt2 := tiddate(item2).forgstart; if ldt1 > ldt2 result := 1 else if ldt1 < ldt2 result := -1 else result := 0; end); := ldatelist.count-1 downto 0 tiddate(ldatelist[i]) if fstart > forgstart createoccurrence(findex,loccurchangekey); // own code elsewhere // 3. occurrences moved backward (start < originalstart) first date last date := 0 ldatelist.count-1 tiddate(ldatelist[i]) if fstart < forgstart createoccurrence(findex,loccurchangekey); // own code elsewhere ldatelist.free;
Comments
Post a Comment