Esempio n. 1
0
        public IEnumerator <ExceptionInstance> GetEnumerator()
        {
            CalendarItem calItem = base.XsoItem as CalendarItem;

            if (calItem.Recurrence == null)
            {
                base.State = PropertyState.SetToDefault;
            }
            else
            {
                ExDateTime[] deletedExceptions = calItem.Recurrence.GetDeletedOccurrences();
                for (int idx = 0; idx < deletedExceptions.Length; idx++)
                {
                    yield return(new ExceptionInstance(ExTimeZone.UtcTimeZone.ConvertDateTime(deletedExceptions[idx]), 1));
                }
                XsoDataObject    mailboxDataObject  = null;
                OccurrenceInfo[] modifiedExceptions = (OccurrenceInfo[])calItem.Recurrence.GetModifiedOccurrences();
                for (int idx2 = 0; idx2 < modifiedExceptions.Length; idx2++)
                {
                    if (mailboxDataObject == null)
                    {
                        mailboxDataObject = this.schemaState.GetInnerXsoDataObject();
                    }
                    ExceptionInstance instance = new ExceptionInstance(ExTimeZone.UtcTimeZone.ConvertDateTime(modifiedExceptions[idx2].OriginalStartTime), 0);
                    using (CalendarItemOccurrence mailboxOccurrence = calItem.OpenOccurrenceByOriginalStartTime(modifiedExceptions[idx2].OriginalStartTime, mailboxDataObject.GetPrefetchProperties()))
                    {
                        if (mailboxOccurrence == null)
                        {
                            throw new ConversionException("Could not look up the modified item by itemId");
                        }
                        mailboxDataObject.Bind(mailboxOccurrence);
                        instance.ModifiedException = mailboxDataObject;
                        yield return(instance);

                        mailboxDataObject.Unbind();
                    }
                }
            }
            yield break;
        }
Esempio 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();
                    }
                }
            }
        }