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);
            }
        }
Exemplo n.º 2
0
        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();
                    }
                }
            }
        }