Exemple #1
0
        private bool CopyLocalModifications()
        {
            bool flag = false;

            foreach (OccurrenceInfo occurrenceInfo in this.OriginalRecurrence.GetModifiedOccurrences())
            {
                ExceptionInfo exceptionInfo = occurrenceInfo as ExceptionInfo;
                if (exceptionInfo != null)
                {
                    if (this.NewRecurrence.IsValidOccurrenceId(exceptionInfo.OccurrenceDateId))
                    {
                        if (!this.NewRecurrence.IsOccurrenceDeleted(exceptionInfo.OccurrenceDateId) && !(this.NewRecurrence.GetOccurrenceInfoByDateId(exceptionInfo.OccurrenceDateId) is ExceptionInfo))
                        {
                            this.NewRecurrence.ModifyOccurrence(exceptionInfo);
                            flag = true;
                            ExTraceGlobals.RecurrenceTracer.Information <string, ExDateTime>((long)this.GetHashCode(), "Storage.RecurrenceBlobMerger.CopyLocalModifications: GOID={0} has revived a local exception with id={1}", this.GlobalObjectId, exceptionInfo.OccurrenceDateId);
                        }
                    }
                    else if (this.CalendarItem != null)
                    {
                        ExTraceGlobals.RecurrenceTracer.Information <string>((long)this.GetHashCode(), "Storage.RecurrenceBlobMerger.CopyLocalModifications: GOID={0} will remove the attachment for an invalid occurrence", this.GlobalObjectId);
                        RecurrenceManager.DeleteAttachment(this.CalendarItem, this.NewRecurrence.CreatedExTimeZone, exceptionInfo.StartTime, exceptionInfo.EndTime);
                    }
                }
            }
            ExTraceGlobals.RecurrenceTracer.Information <string, bool>((long)this.GetHashCode(), "Storage.RecurrenceBlobMerger.CopyLocalModifications: GOID={0}; will return {1}", this.GlobalObjectId, flag);
            return(flag);
        }
Exemple #2
0
 private static void ValidateAdditionalProperties(ICollection <PropertyDefinition> additionalProperties)
 {
     if (additionalProperties == null || additionalProperties.Count == 0)
     {
         return;
     }
     foreach (PropertyDefinition propertyDefinition in additionalProperties)
     {
         if (!RecurrenceManager.CanPropertyBeInExceptionData(propertyDefinition) && !RecurrenceManager.MasterOnlyProperties.Contains(propertyDefinition))
         {
             throw new ArgumentException(string.Format("[CalendarCorrelationMatch.ValidateAdditionalProperties] Property '{0}' cannot be requested because it is not in the O11 blob properties nor master property list", propertyDefinition.Name));
         }
     }
 }
        internal static void DeleteAttachment(Item message, ExTimeZone organizerTimeZone, ExDateTime startTime, ExDateTime endTime)
        {
            bool valueOrDefault = message.GetValueOrDefault <bool>(InternalSchema.MapiHasAttachment, true);

            if (!valueOrDefault)
            {
                ExTraceGlobals.RecurrenceTracer.TraceDebug((long)message.GetHashCode(), "RecurrenceManager::DeleteAttachment: There are no attachments on this message");
                return;
            }
            ItemAttachment itemAttachment = null;
            AttachmentId   attachmentId   = null;

            AttachmentId[] array;
            using (RecurrenceManager.InternalOpenEmbeddedMessageAndAttachment(message.AttachmentCollection, organizerTimeZone, startTime, endTime, out itemAttachment, true, out array, null))
            {
                if (itemAttachment != null)
                {
                    using (itemAttachment)
                    {
                        if (itemAttachment.IsCalendarException)
                        {
                            CalendarItem calendarItem = message as CalendarItem;
                            if (calendarItem != null)
                            {
                                calendarItem.ClearExceptionSummaryList();
                            }
                        }
                        attachmentId = itemAttachment.Id;
                    }
                }
            }
            if (attachmentId != null)
            {
                message.AttachmentCollection.Remove(attachmentId);
                foreach (AttachmentId attachmentId2 in array)
                {
                    message.AttachmentCollection.Remove(attachmentId2);
                }
                return;
            }
            ExTraceGlobals.RecurrenceTracer.TraceDebug <ExDateTime, ExDateTime>((long)message.GetHashCode(), "RecurrenceManager::DeleteAttachment, Couldn't find attachment for startTime: {0} endTime: {1}", startTime, endTime);
        }
        private static Item InternalOpenEmbeddedMessageAndAttachment(AttachmentCollection attachments, ExTimeZone organizerTimeZone, ExDateTime userStartTime, ExDateTime userEndTime, out ItemAttachment itemAttachment, bool detectDuplicatedAttachment, out AttachmentId[] duplicatedAttachmentIds, ICollection <PropertyDefinition> properties)
        {
            itemAttachment          = null;
            duplicatedAttachmentIds = null;
            Item           item            = null;
            ItemAttachment itemAttachment2 = null;
            List <KeyValuePair <long, AttachmentHandle> > list = new List <KeyValuePair <long, AttachmentHandle> >();
            List <AttachmentId> list2       = null;
            ExDateTime          exDateTime  = ExTimeZone.UtcTimeZone.ConvertDateTime(userStartTime);
            ExDateTime          exDateTime2 = ExTimeZone.UtcTimeZone.ConvertDateTime(userEndTime);
            ExDateTime          exDateTime3 = organizerTimeZone.ConvertDateTime(exDateTime);
            ExDateTime          exDateTime4 = organizerTimeZone.ConvertDateTime(exDateTime2);

            exDateTime3 = new ExDateTime(ExTimeZone.UtcTimeZone, (DateTime)exDateTime3);
            exDateTime4 = new ExDateTime(ExTimeZone.UtcTimeZone, (DateTime)exDateTime4);
            if (properties == null)
            {
                properties = new PropertyDefinition[]
                {
                    InternalSchema.StartTime,
                    InternalSchema.EndTime
                };
            }
            else
            {
                properties = InternalSchema.Combine <PropertyDefinition>(properties, new PropertyDefinition[]
                {
                    InternalSchema.StartTime,
                    InternalSchema.EndTime
                });
            }
            CalendarItem calendarItem = attachments.ContainerItem as CalendarItem;
            List <RecurrenceManager.ExceptionSummary> list3;

            if (calendarItem != null)
            {
                if (calendarItem.ExceptionSummaryList == null)
                {
                    ExTraceGlobals.RecurrenceTracer.TraceDebug((long)calendarItem.GetHashCode(), "For calendar item, retrieve exception summary information by walking through all hidden attachements");
                    calendarItem.ExceptionSummaryList = RecurrenceManager.GetExceptionSumaryList(attachments);
                }
                list3 = calendarItem.ExceptionSummaryList;
            }
            else
            {
                ExTraceGlobals.RecurrenceTracer.TraceDebug((long)attachments.GetHashCode(), "No calendar item exists, retrieve exception summary information by walking through all hidden attachements");
                list3 = RecurrenceManager.GetExceptionSumaryList(attachments);
            }
            foreach (RecurrenceManager.ExceptionSummary exceptionSummary in list3)
            {
                ExDateTime utcStartTime = exceptionSummary.UtcStartTime;
                ExDateTime utcEndTime   = exceptionSummary.UtcEndTime;
                TimeSpan   timeSpan     = utcStartTime - exDateTime;
                utcEndTime - exDateTime2;
                if (Math.Abs((exDateTime3 - exDateTime4 - (utcStartTime - utcEndTime)).Ticks) < 1200000000L && Math.Abs(timeSpan.Ticks) <= 504000000000L)
                {
                    list.Add(new KeyValuePair <long, AttachmentHandle>(Math.Abs((utcStartTime - exDateTime3).Ticks), exceptionSummary.Handle));
                }
            }
            list.Sort(delegate(KeyValuePair <long, AttachmentHandle> left, KeyValuePair <long, AttachmentHandle> right)
            {
                if (left.Key == right.Key)
                {
                    return(0);
                }
                if (left.Key <= right.Key)
                {
                    return(-1);
                }
                return(1);
            });
            bool flag = false;

            try
            {
                foreach (KeyValuePair <long, AttachmentHandle> keyValuePair in list)
                {
                    ItemAttachment itemAttachment3 = (ItemAttachment)attachments.Open(keyValuePair.Value, new AttachmentType?(AttachmentType.EmbeddedMessage), null);
                    ExTraceGlobals.RecurrenceTracer.TraceDebug <ExDateTime, int>((long)keyValuePair.Value.GetHashCode(), "Open embedded message for StartTime: {0}, Probables queue length: {1}", userStartTime, list.Count);
                    if (itemAttachment3 != null)
                    {
                        Item item2 = null;
                        bool flag2 = true;
                        try
                        {
                            if (itemAttachment3.IsItemOpen)
                            {
                                ExTraceGlobals.RecurrenceTracer.TraceError((long)keyValuePair.Value.GetHashCode(), "Embedded message is in erroneous open state, which should be guaranteed by master");
                            }
                            else
                            {
                                item2 = itemAttachment3.GetItem(InternalSchema.Combine <PropertyDefinition>(MessageItemSchema.Instance.AutoloadProperties, properties));
                                TimeSpan timeSpan2 = item2.GetValueOrDefault <ExDateTime>(InternalSchema.MapiStartTime, ExDateTime.MinValue) - userStartTime;
                                TimeSpan timeSpan3 = item2.GetValueOrDefault <ExDateTime>(InternalSchema.MapiEndTime, ExDateTime.MinValue) - userEndTime;
                                if (timeSpan2.TotalMinutes < 1.0 && timeSpan2.TotalMinutes > -1.0 && timeSpan3.TotalMinutes < 1.0 && timeSpan3.TotalMinutes > -1.0)
                                {
                                    if (item == null)
                                    {
                                        flag2           = false;
                                        itemAttachment2 = itemAttachment3;
                                        item            = item2;
                                        if (!detectDuplicatedAttachment)
                                        {
                                            break;
                                        }
                                        list2 = new List <AttachmentId>();
                                    }
                                    else
                                    {
                                        ExTraceGlobals.RecurrenceTracer.TraceDebug <AttachmentId, ExDateTime>((long)keyValuePair.Value.GetHashCode(), "Detected duplicated attachment {0} for StartTime: {1}", itemAttachment3.Id, userStartTime);
                                        list2.Add(itemAttachment3.Id);
                                    }
                                }
                            }
                        }
                        finally
                        {
                            if (flag2)
                            {
                                Util.DisposeIfPresent(item2);
                                Util.DisposeIfPresent(itemAttachment3);
                            }
                        }
                    }
                }
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    Util.DisposeIfPresent(item);
                    Util.DisposeIfPresent(itemAttachment2);
                }
            }
            itemAttachment          = itemAttachment2;
            duplicatedAttachmentIds = ((list2 == null) ? null : list2.ToArray());
            return(item);
        }
 internal static Item OpenEmbeddedMessageAndAttachment(AttachmentCollection attachments, ExTimeZone organizerTimeZone, ExDateTime userStartTime, ExDateTime userEndTime, out ItemAttachment itemAttachment, ICollection <PropertyDefinition> properties)
 {
     AttachmentId[] array;
     return(RecurrenceManager.InternalOpenEmbeddedMessageAndAttachment(attachments, organizerTimeZone, userStartTime, userEndTime, out itemAttachment, false, out array, properties));
 }
 private void PopulateExceptionOccurrence(object[] occurrence, PropertyDefinition[] columns, ExceptionInfo exception, ref AttachmentCollection attachments, ref Item master, VersionedId versionedId)
 {
     object[] array = null;
     for (int i = 0; i < columns.Length; i++)
     {
         if (!columns[i].Equals(InternalSchema.ItemId) && !columns[i].Equals(InternalSchema.IsRecurring) && !columns[i].Equals(InternalSchema.IsException) && !columns[i].Equals(InternalSchema.AppointmentRecurring) && !columns[i].Equals(InternalSchema.MapiStartTime) && !columns[i].Equals(InternalSchema.MapiPRStartDate) && !columns[i].Equals(InternalSchema.MapiEndTime) && !columns[i].Equals(InternalSchema.MapiPREndDate) && !columns[i].Equals(InternalSchema.CalendarItemType) && !columns[i].Equals(InternalSchema.GlobalObjectId) && !columns[i].Equals(InternalSchema.TimeZoneDefinitionStart) && !columns[i].Equals(InternalSchema.TimeZoneDefinitionEnd) && !columns[i].Equals(InternalSchema.Codepage) && !RecurrenceManager.MasterOnlyProperties.Contains(columns[i]))
         {
             if (RecurrenceManager.CanPropertyBeInExceptionData(columns[i]))
             {
                 object        obj           = exception.PropertyBag.TryGetProperty(columns[i]);
                 PropertyError propertyError = obj as PropertyError;
                 if (propertyError != null)
                 {
                     if (propertyError.PropertyErrorCode != PropertyErrorCode.NotFound)
                     {
                         throw PropertyError.ToException(new PropertyError[]
                         {
                             propertyError
                         });
                     }
                 }
                 else
                 {
                     occurrence[i] = obj;
                 }
             }
             else
             {
                 ExTraceGlobals.RecurrenceTracer.Information <PropertyDefinition>((long)this.recurrence.GetHashCode(), "RecurrenceManager::Expand, Opening embedded message for {0} property", columns[i]);
                 if (array == null)
                 {
                     if (attachments == null)
                     {
                         if (master == null)
                         {
                             ExTraceGlobals.RecurrenceTracer.Information((long)this.recurrence.GetHashCode(), "RecurrenceManager::Expand. Fetching master message when constructing view");
                             StoreObjectId masterId = versionedId.ObjectId;
                             bool          flag     = false;
                             try
                             {
                                 master = ItemBuilder.ConstructItem <Item>(this.storeSession, masterId, null, CalendarItemBaseSchema.Instance.AutoloadProperties, () => new StoreObjectPropertyBag(this.storeSession, this.storeSession.GetMapiProp(masterId), CalendarItemBaseSchema.Instance.AutoloadProperties), ItemCreateInfo.GenericItemInfo.Creator, Origin.Existing, ItemLevel.TopLevel);
                                 flag   = true;
                             }
                             finally
                             {
                                 if (!flag && master != null)
                                 {
                                     master.Dispose();
                                     master = null;
                                 }
                             }
                         }
                         attachments = master.AttachmentCollection;
                         ExTraceGlobals.RecurrenceTracer.Information((long)this.recurrence.GetHashCode(), "RecurrenceManager::Expand, Fetching attachments");
                     }
                     ItemAttachment itemAttachment = null;
                     using (Item item = RecurrenceManager.OpenEmbeddedMessageAndAttachment(attachments, TimeZoneHelper.GetRecurringTimeZoneFromPropertyBag(attachments.ContainerItem.PropertyBag), exception.StartTime, exception.EndTime, out itemAttachment, columns))
                     {
                         ExTraceGlobals.RecurrenceTracer.Information <ExDateTime>((long)this.recurrence.GetHashCode(), "RecurrenceManager::Expand, Fetching Embedded Message for exception occurence dateId: {0}", exception.OccurrenceDateId);
                         if (item != null)
                         {
                             array = item.GetProperties(columns);
                             itemAttachment.Dispose();
                         }
                         else
                         {
                             array = new object[columns.Length];
                         }
                     }
                 }
                 if (array[i] != null && !(array[i] is PropertyError))
                 {
                     occurrence[i] = array[i];
                 }
             }
         }
     }
 }