public override void EnforceLevelOfDetails(MailboxSession mailboxSession, StoreId itemId, LevelOfDetails levelOfDetails) { using (CalendarItem calendarItem = CalendarItem.Bind(mailboxSession, itemId)) { this.EnforceLevelOfDetailsOnItem(calendarItem, levelOfDetails); if (calendarItem.Recurrence != null) { IList <OccurrenceInfo> modifiedOccurrences = calendarItem.Recurrence.GetModifiedOccurrences(); ItemSynchronizer.Tracer.TraceDebug <CalendarItemSynchronizer, int, StoreId>((long)this.GetHashCode(), "{0}: Found {1} modified occurrences for item {2}.", this, modifiedOccurrences.Count, itemId); foreach (OccurrenceInfo occurrenceInfo in modifiedOccurrences) { ExDateTime originalStartTime = occurrenceInfo.OriginalStartTime; if (!calendarItem.Recurrence.IsOccurrenceDeleted(originalStartTime) && calendarItem.Recurrence.IsValidOccurrenceId(originalStartTime)) { using (CalendarItemOccurrence calendarItemOccurrence = calendarItem.OpenOccurrenceByOriginalStartTime(originalStartTime, new PropertyDefinition[0])) { this.EnforceLevelOfDetailsOnItem(calendarItemOccurrence, levelOfDetails); calendarItemOccurrence.Save(SaveMode.NoConflictResolution); continue; } } ItemSynchronizer.Tracer.TraceDebug <CalendarItemSynchronizer, ExDateTime>((long)this.GetHashCode(), "{0}: Exception {1} is deleted or invalid. Skipping enforcement of level of details.", this, originalStartTime); } } calendarItem.Save(SaveMode.NoConflictResolution); } }
private void CopyExceptions(ExchangeService exchangeService, CalendarItem localItem, CalendarItemType remoteItem) { bool flag = false; if (remoteItem.DeletedOccurrences != null) { foreach (DeletedOccurrenceInfoType deletedOccurrenceInfoType in remoteItem.DeletedOccurrences) { ExDateTime exDateTime = (ExDateTime)this.NormalizeDateToUtc(deletedOccurrenceInfoType.Start); ExDateTime date = localItem.Recurrence.CreatedExTimeZone.ConvertDateTime(exDateTime).Date; if (!localItem.Recurrence.IsOccurrenceDeleted(date) && localItem.Recurrence.IsValidOccurrenceId(date)) { AppointmentTranslator.Tracer.TraceDebug <AppointmentTranslator, DateTime>((long)this.GetHashCode(), "{0}: Copying deleted exception: {1}", this, deletedOccurrenceInfoType.Start); localItem.DeleteOccurrenceByOriginalStartTime(exDateTime); flag = true; } else { AppointmentTranslator.Tracer.TraceDebug <AppointmentTranslator, DateTime>((long)this.GetHashCode(), "{0}: Exception {1} is already deleted on the local copy or is invalid. Skipping delete.", this, deletedOccurrenceInfoType.Start); } } } new Dictionary <string, OccurrenceInfoType>(); if (remoteItem.ModifiedOccurrences != null) { List <ItemIdType> list = new List <ItemIdType>(128); Dictionary <string, OccurrenceInfoType> dictionary = new Dictionary <string, OccurrenceInfoType>(); foreach (OccurrenceInfoType occurrenceInfoType in remoteItem.ModifiedOccurrences) { AppointmentTranslator.Tracer.TraceDebug <AppointmentTranslator, string>((long)this.GetHashCode(), "{0}: Fetching modified exception: {1}", this, occurrenceInfoType.ItemId.Id); dictionary.Add(occurrenceInfoType.ItemId.Id, occurrenceInfoType); list.Add(occurrenceInfoType.ItemId); if (list.Count >= 128) { flag |= this.HandleModifiedExceptions(exchangeService, list.ToArray(), dictionary, localItem); list.Clear(); dictionary.Clear(); } } if (list.Count > 0) { flag |= this.HandleModifiedExceptions(exchangeService, list.ToArray(), dictionary, localItem); } } if (flag) { AppointmentTranslator.Tracer.TraceDebug <AppointmentTranslator>((long)this.GetHashCode(), "{0}: Saving exceptions to master", this); localItem.Save(SaveMode.NoConflictResolution); } }
protected internal override CalendarItemOccurrence RecoverDeletedOccurrence() { if (this.possibleDeletedOccurrenceId != null) { MailboxSession calendarMailboxSession = MeetingMessage.GetCalendarMailboxSession(this); for (int i = 0; i < 2; i++) { CalendarItem calendarItem = CalendarItem.Bind(calendarMailboxSession, StoreObjectId.FromProviderSpecificId(this.possibleDeletedOccurrenceId.ProviderLevelItemId, StoreObjectType.CalendarItem)); try { calendarItem.OpenAsReadWrite(); if (calendarItem.Recurrence != null) { InternalRecurrence internalRecurrence = (InternalRecurrence)calendarItem.Recurrence; ExDateTime occurrenceId = ((OccurrenceStoreObjectId)this.possibleDeletedOccurrenceId).OccurrenceId; if (internalRecurrence.IsValidOccurrenceId(occurrenceId)) { if (internalRecurrence.IsOccurrenceDeleted(occurrenceId)) { base.LocationIdentifierHelperInstance.SetLocationIdentifier(39541U, LastChangeAction.RecoverDeletedOccurance); calendarItem.RecoverDeletedOccurrence(this.possibleDeletedOccurrenceId); if (calendarItem.Save(SaveMode.ResolveConflicts).SaveStatus == SaveResult.IrresolvableConflict) { goto IL_136; } } CalendarItemOccurrence calendarItemOccurrence = CalendarItemOccurrence.Bind(calendarMailboxSession, this.possibleDeletedOccurrenceId, MeetingMessageSchema.Instance.AutoloadProperties); calendarItemOccurrence.OpenAsReadWrite(); ExTraceGlobals.MeetingMessageTracer.Information <GlobalObjectId>((long)this.GetHashCode(), "Storage.MeetingMessage.RecoverDeletedOccurrence: GOID={0}; occurrence recovered.", this.GlobalObjectId); return(calendarItemOccurrence); } ExTraceGlobals.MeetingMessageTracer.Information <GlobalObjectId>((long)this.GetHashCode(), "Storage.MeetingMessage.RecoverDeletedOccurrence: GOID={0}; occurrence id is invalid.", this.GlobalObjectId); return(null); } } catch (OccurrenceNotFoundException) { ExTraceGlobals.MeetingMessageTracer.Information <GlobalObjectId>((long)this.GetHashCode(), "Storage.MeetingMessage.RecoverDeletedOccurrence: GOID={0}; occurrence not found.", this.GlobalObjectId); return(null); } finally { calendarItem.Dispose(); } IL_136 :; } } ExTraceGlobals.MeetingMessageTracer.Information <GlobalObjectId>((long)this.GetHashCode(), "Storage.MeetingMessage.RecoverDeletedOccurrence: GOID={0}; occurrence not recovered.", this.GlobalObjectId); return(null); }
public void UpdateAppointment(ExchangeService exchangeService, MailboxSession session, CalendarItemType remoteItem, CalendarItem localItem) { AppointmentTranslator.Tracer.TraceDebug <AppointmentTranslator, string>((long)this.GetHashCode(), "{0}: Updating appointment {1}", this, remoteItem.ItemId.Id); this.CopyCalendarProperties(localItem, remoteItem); localItem.Recurrence = null; if (remoteItem.Recurrence != null) { localItem.ExTimeZone = localItem.StartTimeZone; localItem.Recurrence = this.ConvertRecurrence(localItem.StartTimeZone, localItem.EndTimeZone, remoteItem.Recurrence); } AppointmentTranslator.Tracer.TraceDebug <AppointmentTranslator, string>((long)this.GetHashCode(), "{0}: Saving local item {1}", this, remoteItem.ItemId.Id); localItem.Save(SaveMode.NoConflictResolution); localItem.Load(); if (remoteItem.Recurrence != null) { this.CopyExceptions(exchangeService, localItem, remoteItem); } }
private MeetingInquiryAction TryReviveMeeting(CalendarItemBase deletedVersion) { bool flag = false; if (this.GlobalObjectId.IsCleanGlobalObjectId) { using (CalendarItemBase calendarItemBase = (CalendarItemBase)Microsoft.Exchange.Data.Storage.Item.CloneItem(base.Session, this.MailboxSession.GetDefaultFolderId(DefaultFolderType.Calendar), deletedVersion, false, true, null)) { calendarItemBase.LocationIdentifierHelperInstance.SetLocationIdentifier(43287U, LastChangeAction.Resurrect); calendarItemBase.Save(SaveMode.NoConflictResolution); flag = true; goto IL_207; } } using (CalendarFolder calendarFolder = CalendarFolder.Bind(this.MailboxSession, DefaultFolderType.Calendar)) { StoreId calendarItemId = calendarFolder.GetCalendarItemId(this.GlobalObjectId.CleanGlobalObjectIdBytes); if (calendarItemId != null) { using (CalendarItem calendarItem = CalendarItem.Bind(this.MailboxSession, calendarItemId)) { if (calendarItem.CalendarItemType == CalendarItemType.RecurringMaster) { try { calendarItem.RecoverDeletedOccurrenceByDateId(this.GlobalObjectId.Date); calendarItem.LocationIdentifierHelperInstance.SetLocationIdentifier(59671U, LastChangeAction.Resurrect); ConflictResolutionResult conflictResolutionResult = calendarItem.Save(SaveMode.ResolveConflicts); if (conflictResolutionResult.SaveStatus == SaveResult.IrresolvableConflict) { ExTraceGlobals.MeetingMessageTracer.TraceError <string, GlobalObjectId>((long)this.GetHashCode(), "Storage.MeetingInquiryMessage::ReviveDeletedVersionIfNoCancellation for Mailbox {0} and GOID {1} hit a save conflict.", this.MailboxSession.DisplayName, this.GlobalObjectId); throw new SaveConflictException(ServerStrings.ExSaveFailedBecauseOfConflicts(base.InternalObjectId), conflictResolutionResult); } flag = true; } catch (OccurrenceNotFoundException) { ExTraceGlobals.MeetingMessageTracer.TraceError <string, GlobalObjectId, ExDateTime>((long)this.GetHashCode(), "Storage.MeetingInquiryMessage::ReviveDeletedVersionIfNoCancellation for Mailbox {0} and GOID {1}. There's no occurrence on {2}", this.MailboxSession.DisplayName, this.GlobalObjectId, this.GlobalObjectId.Date); } catch (ObjectValidationException ex) { if (ex.Errors.Count != 1 || (!(ex.Errors[0].Constraint is OrganizerPropertiesConstraint) && !(ex.Errors[0].Constraint is CalendarOriginatorIdConstraint))) { throw; } ExTraceGlobals.MeetingMessageTracer.TraceError <string, GlobalObjectId, string>((long)this.GetHashCode(), "Storage.MeetingInquiryMessage::ReviveDeletedVersionIfNoCancellation for Mailbox {0} and GOID {1}. Object validation failed : {2}", this.MailboxSession.DisplayName, this.GlobalObjectId, ex.Message); } } goto IL_1FB; } } ExTraceGlobals.MeetingMessageTracer.TraceError <string, byte[]>((long)this.GetHashCode(), "Storage.MeetingInquiryMessage::ReviveDeletedVersionIfNoCancellation for Mailbox {0}. Couldn't find calendar item with CGOID {1}", this.MailboxSession.DisplayName, this.GlobalObjectId.CleanGlobalObjectIdBytes); IL_1FB :; } IL_207 : if (!flag) { return(MeetingInquiryAction.FailedToRevive); } return(MeetingInquiryAction.ReviveMeeting); }
protected override void InternalCopyFromModified(IProperty srcProperty) { CalendarItem calendarItem = base.XsoItem as CalendarItem; IExceptionsProperty exceptionsProperty = srcProperty as IExceptionsProperty; XsoDataObject xsoDataObject = null; foreach (ExceptionInstance exceptionInstance in exceptionsProperty) { ExDateTime exDateTime = ExTimeZone.UtcTimeZone.ConvertDateTime(exceptionInstance.ExceptionStartTime); ExDateTime exDateTime2 = calendarItem.ExTimeZone.ConvertDateTime(exDateTime); if (exceptionInstance.Deleted == 1) { if (calendarItem.Id == null) { calendarItem.Save(SaveMode.ResolveConflicts); calendarItem.Load(); } try { this.ValidateCalendarItem(calendarItem); calendarItem.DeleteOccurrenceByOriginalStartTime(exDateTime2); continue; } catch (OccurrenceNotFoundException) { AirSyncDiagnostics.TraceDebug <ExDateTime>(ExTraceGlobals.XsoTracer, this, "Exception with OriginalStartTime: {0} already deleted.", exDateTime2); continue; } } if (xsoDataObject == null) { xsoDataObject = this.schemaState.GetInnerXsoDataObject(); } CalendarItemOccurrence calendarItemOccurrence = null; try { if (calendarItem.Id != null) { this.ValidateCalendarItem(calendarItem); calendarItemOccurrence = calendarItem.OpenOccurrenceByOriginalStartTime(exDateTime2, xsoDataObject.GetPrefetchProperties()); } else { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.XsoTracer, this, "New calendar recurrence item added with exceptions. Extra save (RPC to store) needed for this"); calendarItem.Save(SaveMode.ResolveConflicts); calendarItem.Load(); this.ValidateCalendarItem(calendarItem); calendarItemOccurrence = calendarItem.OpenOccurrenceByOriginalStartTime(exDateTime2, xsoDataObject.GetPrefetchProperties()); } if (calendarItemOccurrence == null) { throw new ConversionException("Could not open the Calendar Occurrence using the Original StartTime"); } calendarItemOccurrence.OpenAsReadWrite(); try { xsoDataObject.Bind(calendarItemOccurrence); xsoDataObject.CopyFrom(exceptionInstance.ModifiedException); } finally { xsoDataObject.Unbind(); } calendarItemOccurrence.Save(SaveMode.NoConflictResolution); } finally { if (calendarItemOccurrence != null) { calendarItemOccurrence.Dispose(); } } } }