protected override object InternalTryGetValue(PropertyBag.BasicPropertyStore propertyBag)
        {
            object value = propertyBag.GetValue(this.enclosedPropertyDefinition);

            if (value is byte[])
            {
                return(StoreObjectId.FromProviderSpecificId((byte[])value, StoreObjectType.Unknown));
            }
            return(new PropertyError(this, PropertyErrorCode.NotFound));
        }
        public static VersionedId Deserialize(byte[] providerSpecificId, byte[] byteArrayChangeKey, StoreObjectType objectType)
        {
            if (providerSpecificId == null || byteArrayChangeKey == null)
            {
                throw new ArgumentNullException();
            }
            StoreObjectId itemId = StoreObjectId.FromProviderSpecificId(providerSpecificId, objectType);

            return(new VersionedId(itemId, byteArrayChangeKey));
        }
 public override object GetValue(IStorePropertyBag contact)
 {
     Util.ThrowOnNullArgument(contact, "contact");
     byte[] valueOrDefault = contact.GetValueOrDefault <byte[]>(InternalSchema.EntryId, null);
     if (valueOrDefault == null)
     {
         return(null);
     }
     return(StoreObjectId.FromProviderSpecificId(valueOrDefault, StoreObjectType.Unknown));
 }
        protected override object InternalTryGetValue(PropertyBag.BasicPropertyStore propertyBag)
        {
            object value = propertyBag.GetValue(BirthdayContactIdProperty.EnclosedPropertyDefinition);

            if (value is byte[])
            {
                return(StoreObjectId.FromProviderSpecificId(value as byte[], StoreObjectType.Contact));
            }
            return(new PropertyError(this, PropertyErrorCode.NotFound));
        }
Exemple #5
0
        internal StoreObjectId ToUniqueItemId()
        {
            StoreObjectId result;

            using (ParticipantEntryId.Writer writer = new ParticipantEntryId.Writer())
            {
                writer.Write(this.ltEntryId);
                result = StoreObjectId.FromProviderSpecificId(writer.GetBytes(), (this.IsDL == true) ? StoreObjectType.DistributionList : StoreObjectType.Contact);
            }
            return(result);
        }
        public StoreObjectId ToStoreObjectId()
        {
            switch (this.IdProcessingInstruction)
            {
            case IdProcessingInstruction.Normal:
                return(StoreObjectId.FromProviderSpecificId(this.StoreIdBytes));

            case IdProcessingInstruction.Series:
                return(StoreObjectId.FromProviderSpecificId(this.StoreIdBytes, StoreObjectType.CalendarItemSeries));
            }
            return(StoreObjectId.Deserialize(this.StoreIdBytes));
        }
Exemple #7
0
 public static StoreObjectId GetRecoverableItemsDeletionsFolderId(CoreFolder folder)
 {
     byte[] valueOrDefault = folder.PropertyBag.GetValueOrDefault <byte[]>(CoreFolderSchema.DeletedItemsEntryId, Array <byte> .Empty);
     if (valueOrDefault.Length == 22)
     {
         return(folder.Session.IdConverter.CreateFolderId(folder.Session.IdConverter.GetIdFromLongTermId(valueOrDefault)));
     }
     if (valueOrDefault.Length == 46)
     {
         return(StoreObjectId.FromProviderSpecificId(valueOrDefault, StoreObjectType.Folder));
     }
     return(null);
 }
		protected override object InternalTryGetValue(PropertyBag.BasicPropertyStore propertyBag)
		{
			byte[][] array = propertyBag.GetValue(this.enclosedPropertyDefinition) as byte[][];
			if (array != null)
			{
				StoreObjectId[] array2 = new StoreObjectId[array.Length];
				for (int i = 0; i < array.Length; i++)
				{
					array2[i] = StoreObjectId.FromProviderSpecificId(array[i], StoreObjectType.Unknown);
				}
				return array2;
			}
			return new PropertyError(this, PropertyErrorCode.NotFound);
		}
Exemple #9
0
            ManifestCallbackStatus IMapiHierarchyManifestCallback.Delete(byte[] entryId)
            {
                if (this.catchup)
                {
                    return(ManifestCallbackStatus.Continue);
                }
                StoreObjectId item = StoreObjectId.FromProviderSpecificId(entryId);

                if (!this.changes.DeletedFolders.Contains(item))
                {
                    this.changes.DeletedFolders.Add(item);
                }
                return(ManifestCallbackStatus.Continue);
            }
 public WellKnownPublicFolders(PropValue[] propValues)
 {
     this.folderIdMappings   = new Dictionary <WellKnownPublicFolders.FolderType, byte[]>(propValues.Length);
     this.longTermIdMappings = new Dictionary <byte[], WellKnownPublicFolders.FolderType?>(propValues.Length, ArrayComparer <byte> .Comparer);
     foreach (PropValue propValue in propValues)
     {
         WellKnownPublicFolders.FolderType?folderType = WellKnownPublicFolders.GetFolderType(propValue.PropTag);
         if (folderType != null)
         {
             byte[] bytes = propValue.GetBytes();
             this.folderIdMappings.Add(folderType.Value, bytes);
             StoreObjectId storeObjectId = StoreObjectId.FromProviderSpecificId(bytes, StoreObjectType.Folder);
             this.longTermIdMappings.Add(storeObjectId.LongTermFolderId, new WellKnownPublicFolders.FolderType?(folderType.Value));
         }
     }
 }
Exemple #11
0
        public ManifestCallbackStatus ReadUnread(byte[] entryId, bool read)
        {
            ManifestCallbackStatus result     = ManifestCallbackStatus.Continue;
            StoreObjectId          id         = StoreObjectId.FromProviderSpecificId(entryId, StoreObjectType.Unknown);
            ISyncItemId            syncItemId = MailboxSyncItemId.CreateForExistingItem(this.mailboxSyncProvider.FolderSync, id);

            if (syncItemId == null)
            {
                return(result);
            }
            ServerManifestEntry serverManifestEntry = this.mailboxSyncProvider.CreateReadFlagChangeManifestEntry(syncItemId, read);

            if (serverManifestEntry != null)
            {
                this.lastServerManifestEntry = serverManifestEntry;
            }
            return(this.CheckYieldOrStop());
        }
Exemple #12
0
        internal static StoreObjectId GetStoreObjectId(MapiEvent mapiEvent, out string className)
        {
            className = string.Empty;
            switch (mapiEvent.ItemType)
            {
            case Microsoft.Mapi.ObjectType.MAPI_FOLDER:
            case Microsoft.Mapi.ObjectType.MAPI_MESSAGE:
                className = mapiEvent.ObjectClass;
                break;
            }
            StoreObjectType storeObjectType = ObjectClass.GetObjectType(className);
            StoreObjectId   result          = null;

            if (mapiEvent.ItemEntryId != null)
            {
                result = StoreObjectId.FromProviderSpecificId(mapiEvent.ItemEntryId, storeObjectType);
            }
            return(result);
        }
 public static byte[] GetFreeBusyMsgId(MailboxSession session, out FolderSaveResult result)
 {
     result = null;
     byte[] array = null;
     using (Folder folder = Folder.Bind(session, DefaultFolderType.Inbox, new PropertyDefinition[]
     {
         InternalSchema.FreeBusyEntryIds
     }))
     {
         byte[][] array2 = folder.TryGetProperty(InternalSchema.FreeBusyEntryIds) as byte[][];
         if (array2 != null)
         {
             if (array2.Length > 1)
             {
                 array = array2[1];
                 try
                 {
                     StoreObjectId storeObjectId = StoreObjectId.FromProviderSpecificId(array);
                     if (!IdConverter.IsMessageId(storeObjectId))
                     {
                         ExTraceGlobals.CalendarLoggingTracer.TraceError(0L, "FreeBusyUtil::GetFreeBusyMsgId. The extracted storeObjectId is not a valid MessageId");
                         array = null;
                     }
                 }
                 catch (CorruptDataException)
                 {
                     ExTraceGlobals.CalendarLoggingTracer.TraceError(0L, "FreeBusyUtil::GetFreeBusyMsgId. The localFreeBusyMsgId is not a valid entry id");
                     array = null;
                 }
             }
             if (array == null || array.Length == 0)
             {
                 array = FreeBusyUtil.FindFreeBusyMsgId(session);
                 if (array == null)
                 {
                     ExTraceGlobals.CalendarLoggingTracer.TraceDebug(0L, "FreeBusyUtil::GetFreeBusyMsgId. Couldn't find a free busy message. Attempting to create one.");
                     array = FreeBusyUtil.CreateFreeBusyMessage(session, out result);
                 }
             }
         }
     }
     return(array);
 }
        internal StoreId[] ReadEntryIdList()
        {
            this.ReadInt();
            int num = this.ReadInt();

            this.ReadInt();
            int[]           array  = new int[num];
            StoreObjectId[] array2 = new StoreObjectId[num];
            for (int i = 0; i < num; i++)
            {
                array[i] = this.ReadInt();
                this.ReadInt();
            }
            for (int j = 0; j < num; j++)
            {
                array2[j] = StoreObjectId.FromProviderSpecificId(this.reader.ReadBytes(array[j]));
            }
            return(array2);
        }
Exemple #15
0
            protected override bool TryAggregate(PropertyAggregationContext context, out object value)
            {
                List <StoreObjectId> list = new List <StoreObjectId>(context.Sources.Count);

                foreach (IStorePropertyBag storePropertyBag in context.Sources)
                {
                    byte[] valueOrDefault = storePropertyBag.GetValueOrDefault <byte[]>(InternalSchema.EntryId, null);
                    if (valueOrDefault != null)
                    {
                        StoreObjectId storeObjectId = StoreObjectId.FromProviderSpecificId(valueOrDefault, StoreObjectType.Unknown);
                        if (storeObjectId != null)
                        {
                            list.Add(storeObjectId);
                        }
                    }
                }
                value = list.ToArray();
                return(true);
            }
Exemple #16
0
        public ManifestCallbackStatus Delete(byte[] entryId, bool softDelete, bool expiry)
        {
            if (ExTraceGlobals.SyncTracer.IsTraceEnabled(TraceType.InfoTrace))
            {
                this.TraceDeleteCallbackProps(entryId, softDelete, expiry);
            }
            if (softDelete)
            {
                return(ManifestCallbackStatus.Continue);
            }
            StoreObjectId     id = StoreObjectId.FromProviderSpecificId(entryId, StoreObjectType.Unknown);
            MailboxSyncItemId mailboxSyncItemId = MailboxSyncItemId.CreateForExistingItem(this.mailboxSyncProvider.FolderSync, id);

            if (mailboxSyncItemId == null)
            {
                return(ManifestCallbackStatus.Continue);
            }
            this.lastServerManifestEntry = MailboxSyncProvider.CreateItemDeleteManifestEntry(mailboxSyncItemId);
            return(this.CheckYieldOrStop());
        }
Exemple #17
0
        public PersistablePropertyBag CreateStorePropertyBag(PropertyBag propertyBag, ICollection <PropertyDefinition> prefetchProperties)
        {
            byte[]                           entryId = propertyBag.TryGetProperty(InternalSchema.EntryId) as byte[];
            StoreObjectId                    id      = StoreObjectId.FromProviderSpecificId(entryId, StoreObjectType.Unknown);
            StoreObjectPropertyBag           storeObjectPropertyBag = propertyBag as StoreObjectPropertyBag;
            ICollection <PropertyDefinition> prefetchPropertyArray;

            if (storeObjectPropertyBag != null)
            {
                prefetchPropertyArray = ((prefetchProperties != null) ? prefetchProperties.Union(storeObjectPropertyBag.PrefetchPropertyArray) : storeObjectPropertyBag.PrefetchPropertyArray);
            }
            else
            {
                prefetchPropertyArray = prefetchProperties;
            }
            PersistablePropertyBag persistablePropertyBag = ItemBagFactory.CreatePropertyBag(this.storeSession, id, prefetchPropertyArray);

            persistablePropertyBag.ExTimeZone = this.exTimeZone;
            return(persistablePropertyBag);
        }
Exemple #18
0
        private DefaultFolderData InitializeFolderIdPrivate()
        {
            ExTraceGlobals.DefaultFoldersTracer.TraceDebug <DefaultFolder>((long)this.GetHashCode(), "DefaultFolder::InitializeFolderId. The default folder ID is about to be initialized. defaultFolder = {0}.", this);
            byte[] array = this.defaultFolderInfo.EntryIdStrategy.GetEntryId(this.context);
            if (!IdConverter.IsFolderId(array))
            {
                array = null;
                ExTraceGlobals.DefaultFoldersTracer.TraceError <DefaultFolder>((long)this.GetHashCode(), "DefaultFolder::InitializeFolderId. Invalid entry id found. defaultFolder = {0}.", this);
            }
            DefaultFolderData result;

            if (array != null)
            {
                result = new DefaultFolderData(StoreObjectId.FromProviderSpecificId(array, this.StoreObjectType), true, false);
            }
            else
            {
                result = new DefaultFolderData(null, true, false);
            }
            return(result);
        }
        public static StoreObjectId GetLinkedFolderIdForFilteredView(MailboxSession session, StoreId sourceFolderId, OwaViewFilter viewFilter)
        {
            StoreObjectId result = null;

            try
            {
                using (Folder folder = Folder.Bind(session, sourceFolderId))
                {
                    byte[] folderProperty = OwaFilterState.GetFolderProperty <byte[]>(folder, OwaFilterState.FilterToLinkPropertyDefinitionsMap[viewFilter], null);
                    if (folderProperty != null)
                    {
                        result = StoreObjectId.FromProviderSpecificId(folderProperty, StoreObjectType.Folder);
                    }
                }
            }
            catch (CorruptDataException arg)
            {
                ExTraceGlobals.StorageTracer.TraceError <OwaViewFilter, CorruptDataException>(0L, "[OwaFilterState::GetLinkedFolderIdForFilteredView] Caught a CorruptDataException for OwaViewFilter {0}: {1}", viewFilter, arg);
            }
            return(result);
        }
        public static DelegateRuleType GetDelegateRuleType(MailboxSession session)
        {
            DelegateRuleType result = DelegateRuleType.ForwardAndDelete;
            FolderSaveResult folderSaveResult;

            byte[] freeBusyMsgId = FreeBusyUtil.GetFreeBusyMsgId(session, out folderSaveResult);
            if (freeBusyMsgId != null && freeBusyMsgId.Length > 0)
            {
                try
                {
                    using (MessageItem messageItem = MessageItem.Bind(session, StoreObjectId.FromProviderSpecificId(freeBusyMsgId), FreeBusyUtil.FreeBusyMessageProperties))
                    {
                        result = FreeBusyUtil.GetDelegateRuleType(messageItem);
                    }
                }
                catch (ObjectNotFoundException)
                {
                    ExTraceGlobals.CalendarLoggingTracer.TraceDebug((long)session.GetHashCode(), "FreeBusyUtil::GetDelegateRuleType. No FreeBusyMessage");
                }
            }
            return(result);
        }
Exemple #21
0
        protected override object InternalTryGetValue(PropertyBag.BasicPropertyStore propertyStore)
        {
            StoreObjectId storeObjectId = null;
            ICoreObject   coreObject    = propertyStore.Context.CoreObject;

            if (coreObject != null)
            {
                storeObjectId = coreObject.InternalStoreObjectId;
            }
            if (storeObjectId == null)
            {
                byte[] array = propertyStore.GetValue(InternalSchema.EntryId) as byte[];
                if (array != null)
                {
                    storeObjectId = StoreObjectId.FromProviderSpecificId(array, this.GetStoreObjectType(propertyStore));
                }
                else
                {
                    QueryResultPropertyBag queryResultPropertyBag = ((PropertyBag)propertyStore) as QueryResultPropertyBag;
                    if (queryResultPropertyBag != null && (!((IDirectPropertyBag)queryResultPropertyBag).IsLoaded(InternalSchema.RowType) || object.Equals(queryResultPropertyBag.TryGetProperty(InternalSchema.RowType), 1)))
                    {
                        ExDiagnostics.FailFast(string.Format("EntryId: \"{0}\" in view", queryResultPropertyBag.TryGetProperty(InternalSchema.EntryId)), false);
                    }
                }
            }
            if (storeObjectId == null)
            {
                return(new PropertyError(this, PropertyErrorCode.NotFound));
            }
            VersionedId versionedId = new VersionedId(storeObjectId, this.GetChangeKey(propertyStore));

            if (!this.IsCompatibleId(versionedId, coreObject))
            {
                return(new PropertyError(this, PropertyErrorCode.NotSupported));
            }
            return(versionedId);
        }
        protected override object InternalTryGetValue(PropertyBag.BasicPropertyStore propertyBag)
        {
            StoreSession session = propertyBag.Context.Session;

            if (session == null)
            {
                ExTraceGlobals.StorageTracer.TraceDebug((long)propertyBag.GetHashCode(), "ReminderDueByProperty: StoreObject is not present and the property bag is not a QueryResultsPropertyBag. First should be present when accessing a property on an object, and the second one - when called from a view. All other cases are wrong.");
                return(propertyBag.GetValue(InternalSchema.ReminderDueByInternal));
            }
            PropertyError      result             = new PropertyError(InternalSchema.ReminderDueBy, PropertyErrorCode.GetCalculatedPropertyError);
            CalendarItem       calendarItem       = propertyBag.Context.StoreObject as CalendarItem;
            InternalRecurrence internalRecurrence = null;

            if (calendarItem != null)
            {
                try
                {
                    internalRecurrence = (InternalRecurrence)calendarItem.Recurrence;
                    goto IL_206;
                }
                catch (RecurrenceFormatException ex)
                {
                    ExTraceGlobals.StorageTracer.TraceDebug <string, StoreObjectId>((long)session.GetHashCode(), "Unable to parse recurrence info. Using the stored value for DueBy.\r\n\tError: {0}\r\n\tID:{1}", ex.Message, (calendarItem.Id != null) ? calendarItem.Id.ObjectId : null);
                    return(result);
                }
                catch (CorruptDataException ex2)
                {
                    ExTraceGlobals.StorageTracer.TraceDebug <string, StoreObjectId>((long)session.GetHashCode(), "Unable to parse the organizer timezone. Using the stored value for DueBy.\r\n\tError: {0}\r\n\tID:{1}", ex2.Message, (calendarItem.Id != null) ? calendarItem.Id.ObjectId : null);
                    return(result);
                }
            }
            byte[] entryId;
            if (Util.TryConvertTo <byte[]>(propertyBag.GetValue(InternalSchema.EntryId), out entryId))
            {
                VersionedId versionedId = new VersionedId(StoreObjectId.FromProviderSpecificId(entryId), Array <byte> .Empty);
                byte[]      array       = propertyBag.GetValue(InternalSchema.AppointmentRecurrenceBlob) as byte[];
                if (array != null)
                {
                    string     valueOrDefault         = propertyBag.GetValueOrDefault <string>(InternalSchema.TimeZone, string.Empty);
                    byte[]     valueOrDefault2        = propertyBag.GetValueOrDefault <byte[]>(InternalSchema.TimeZoneBlob);
                    byte[]     valueOrDefault3        = propertyBag.GetValueOrDefault <byte[]>(InternalSchema.TimeZoneDefinitionRecurring);
                    ExTimeZone timeZoneFromProperties = TimeZoneHelper.GetTimeZoneFromProperties(valueOrDefault, valueOrDefault2, valueOrDefault3);
                    if (timeZoneFromProperties == null)
                    {
                        ExTraceGlobals.StorageTracer.TraceDebug <string, StoreObjectId>((long)session.GetHashCode(), "Unable to parse the organizer timezone. Using the stored value for DueBy.\r\n\tError: {0}\r\n\tID:{1}", "organizerTimeZone is null", versionedId.ObjectId);
                        return(result);
                    }
                    try
                    {
                        internalRecurrence = InternalRecurrence.GetRecurrence(versionedId, session, array, timeZoneFromProperties, CalendarItem.DefaultCodePage);
                    }
                    catch (RecurrenceFormatException ex3)
                    {
                        ExTraceGlobals.StorageTracer.TraceDebug <string, StoreObjectId>((long)session.GetHashCode(), "Unable to parse recurrence info. Using the stored value for DueBy.\r\n\tError: {0}\r\n\tID:{1}", ex3.Message, versionedId.ObjectId);
                        return(result);
                    }
                    catch (CorruptDataException ex4)
                    {
                        ExTraceGlobals.StorageTracer.TraceDebug <string, StoreObjectId>((long)session.GetHashCode(), "Unable to parse the organizer timezone. Using the stored value for DueBy.\r\n\tError: {0}\r\n\tID:{1}", ex4.Message, versionedId.ObjectId);
                        return(result);
                    }
                }
            }
IL_206:
            bool defaultIsSet;
            int        defaultMinutesBeforeStart;
            ExDateTime value;

            if (internalRecurrence == null || !Util.TryConvertTo <bool>(propertyBag.GetValue(InternalSchema.ReminderIsSetInternal), out defaultIsSet) || !Util.TryConvertTo <int>(propertyBag.GetValue(InternalSchema.ReminderMinutesBeforeStartInternal), out defaultMinutesBeforeStart) || !Util.TryConvertTo <ExDateTime>(propertyBag.GetValue(InternalSchema.ReminderNextTime), out value))
            {
                return(propertyBag.GetValue(InternalSchema.ReminderDueByInternal));
            }
            ExDateTime     probeTime = Reminder.GetProbeTime(Reminder.GetTimeNow(session.ExTimeZone), new ExDateTime?(value));
            OccurrenceInfo mostRecentOccurrence;

            try
            {
                mostRecentOccurrence = CalendarItem.CustomReminder.GetMostRecentOccurrence(internalRecurrence, probeTime, defaultIsSet, defaultMinutesBeforeStart);
            }
            catch (CorruptDataException)
            {
                return(result);
            }
            if (mostRecentOccurrence == null)
            {
                return(new PropertyError(this, PropertyErrorCode.NotFound));
            }
            return(mostRecentOccurrence.StartTime);
        }
 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);
 }
        internal static StoreObjectId CreateVersion(StoreSession session, StoreObjectId itemId, StoreObjectId versionFolderId)
        {
            StoreObjectId result;

            using (CoreCalendarItemVersion coreCalendarItemVersion = new CoreCalendarItemVersion(session))
            {
                using (MapiProp mapiProp = session.GetMapiProp(itemId, OpenEntryFlags.DeferredErrors | OpenEntryFlags.ShowSoftDeletes))
                {
                    coreCalendarItemVersion.underlyingMessage = Folder.InternalCreateMapiMessage(session, versionFolderId, CreateMessageType.Normal);
                    coreCalendarItemVersion.CopyRequiredData((MapiMessage)mapiProp);
                    object thisObject = null;
                    bool   flag       = false;
                    try
                    {
                        if (session != null)
                        {
                            session.BeginMapiCall();
                            session.BeginServerHealthCall();
                            flag = true;
                        }
                        if (StorageGlobals.MapiTestHookBeforeCall != null)
                        {
                            StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                        }
                        coreCalendarItemVersion.underlyingMessage.SetReadFlag(SetReadFlags.ClearRnPending | SetReadFlags.CleanNrnPending);
                    }
                    catch (MapiPermanentException ex)
                    {
                        throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotSetReadFlags, ex, session, thisObject, "{0}. MapiException = {1}.", new object[]
                        {
                            string.Format("CoreCalendarItemVersion::CreateVersion. Failed to set read flag of underlying message.", new object[0]),
                            ex
                        });
                    }
                    catch (MapiRetryableException ex2)
                    {
                        throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotSetReadFlags, ex2, session, thisObject, "{0}. MapiException = {1}.", new object[]
                        {
                            string.Format("CoreCalendarItemVersion::CreateVersion. Failed to set read flag of underlying message.", new object[0]),
                            ex2
                        });
                    }
                    finally
                    {
                        try
                        {
                            if (session != null)
                            {
                                session.EndMapiCall();
                                if (flag)
                                {
                                    session.EndServerHealthCall();
                                }
                            }
                        }
                        finally
                        {
                            if (StorageGlobals.MapiTestHookAfterCall != null)
                            {
                                StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                            }
                        }
                    }
                }
                coreCalendarItemVersion.Save();
                StoreObjectId storeObjectId = StoreObjectId.FromProviderSpecificId(coreCalendarItemVersion.underlyingMessage.GetProp(PropTag.EntryId).GetBytes(), itemId.ObjectType);
                CoreCalendarItemVersion.perfCounters.DumpsterCalendarLogsRate.Increment();
                result = storeObjectId;
            }
            return(result);
        }
Exemple #25
0
        public StoreId CreateFolder(string folderName, string folderDescription, StoreId parentFolderId, CreateMode mode, out Guid contentMailboxGuid)
        {
            StoreId result;

            using (PublicFolderConnectionLimitsTracker.Instance.GetToken(this.PrimaryHierarchyMailboxPrincipal.MailboxInfo.Location.ServerFqdn))
            {
                StoreSession storeSession = null;
                object       thisObject   = null;
                bool         flag         = false;
                try
                {
                    if (storeSession != null)
                    {
                        storeSession.BeginMapiCall();
                        storeSession.BeginServerHealthCall();
                        flag = true;
                    }
                    if (StorageGlobals.MapiTestHookBeforeCall != null)
                    {
                        StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                    }
                    using (MapiStore hierarchyStore = this.GetHierarchyStore())
                    {
                        using (MapiFolder mapiFolder = (MapiFolder)hierarchyStore.OpenEntry(this.GetDestinationSpecificEntryId(hierarchyStore, parentFolderId)))
                        {
                            using (MapiFolder mapiFolder2 = mapiFolder.CreateFolder(folderName, folderDescription, mode == CreateMode.OpenIfExists))
                            {
                                contentMailboxGuid = RPCPrimaryHierarchyProvider.GetMailboxGuidFromPersonalizedLegacyDN(mapiFolder2.GetReplicaServers()[0]);
                                result             = StoreObjectId.FromProviderSpecificId(mapiFolder2.GetProp(PropTag.EntryId).GetBytes(), StoreObjectType.Folder);
                            }
                        }
                    }
                }
                catch (MapiPermanentException ex)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotCreateFolder(folderName), ex, storeSession, thisObject, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("RPCPrimaryHierarchyProvider.CreateFolder : folderName = {0}", folderName),
                        ex
                    });
                }
                catch (MapiRetryableException ex2)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotCreateFolder(folderName), ex2, storeSession, thisObject, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("RPCPrimaryHierarchyProvider.CreateFolder : folderName = {0}", folderName),
                        ex2
                    });
                }
                finally
                {
                    try
                    {
                        if (storeSession != null)
                        {
                            storeSession.EndMapiCall();
                            if (flag)
                            {
                                storeSession.EndServerHealthCall();
                            }
                        }
                    }
                    finally
                    {
                        if (StorageGlobals.MapiTestHookAfterCall != null)
                        {
                            StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                        }
                    }
                }
            }
            return(result);
        }
Exemple #26
0
 internal Event(Guid mdbGuid, MapiEvent mapiEvent)
 {
     this.mdbGuid   = mdbGuid;
     this.eventType = EventType.None;
     if ((mapiEvent.EventMask & MapiEventTypeFlags.NewMail) == MapiEventTypeFlags.NewMail)
     {
         this.eventType |= EventType.NewMail;
     }
     if ((mapiEvent.EventMask & MapiEventTypeFlags.ObjectCreated) == MapiEventTypeFlags.ObjectCreated)
     {
         this.eventType |= EventType.ObjectCreated;
     }
     if ((mapiEvent.EventMask & MapiEventTypeFlags.ObjectDeleted) == MapiEventTypeFlags.ObjectDeleted)
     {
         this.eventType |= EventType.ObjectDeleted;
     }
     if ((mapiEvent.EventMask & MapiEventTypeFlags.ObjectModified) == MapiEventTypeFlags.ObjectModified)
     {
         this.eventType |= EventType.ObjectModified;
     }
     if ((mapiEvent.EventMask & MapiEventTypeFlags.ObjectMoved) == MapiEventTypeFlags.ObjectMoved)
     {
         this.eventType |= EventType.ObjectMoved;
     }
     if ((mapiEvent.EventMask & MapiEventTypeFlags.ObjectCopied) == MapiEventTypeFlags.ObjectCopied)
     {
         this.eventType |= EventType.ObjectCopied;
     }
     if ((mapiEvent.EventMask & MapiEventTypeFlags.CriticalError) == MapiEventTypeFlags.CriticalError)
     {
         this.eventType |= EventType.CriticalError;
     }
     if ((mapiEvent.EventMask & MapiEventTypeFlags.MailboxDeleted) == MapiEventTypeFlags.MailboxDeleted)
     {
         this.eventType |= EventType.MailboxDeleted;
     }
     if ((mapiEvent.EventMask & MapiEventTypeFlags.MailboxDisconnected) == MapiEventTypeFlags.MailboxDisconnected)
     {
         this.eventType |= EventType.MailboxDisconnected;
     }
     if ((mapiEvent.EventMask & MapiEventTypeFlags.MailboxMoveFailed) == MapiEventTypeFlags.MailboxMoveFailed)
     {
         this.eventType |= EventType.MailboxMoveFailed;
     }
     if ((mapiEvent.EventMask & MapiEventTypeFlags.MailboxMoveStarted) == MapiEventTypeFlags.MailboxMoveStarted)
     {
         this.eventType |= EventType.MailboxMoveStarted;
     }
     if ((mapiEvent.EventMask & MapiEventTypeFlags.MailboxMoveSucceeded) == MapiEventTypeFlags.MailboxMoveSucceeded)
     {
         this.eventType |= EventType.MailboxMoveSucceeded;
     }
     if (mapiEvent.ObjectClass == "IPM.Appointment")
     {
         this.eventType |= Event.GetFreeBusyEventType(mapiEvent);
     }
     this.objectType = EventObjectType.None;
     if (mapiEvent.ItemType == Microsoft.Mapi.ObjectType.MAPI_FOLDER)
     {
         this.objectType |= EventObjectType.Folder;
     }
     if (mapiEvent.ItemType == Microsoft.Mapi.ObjectType.MAPI_MESSAGE)
     {
         this.objectType |= EventObjectType.Item;
     }
     this.objectId = Event.GetStoreObjectId(mapiEvent, out this.className);
     if (mapiEvent.ParentEntryId != null)
     {
         this.parentObjectId = StoreObjectId.FromProviderSpecificId(mapiEvent.ParentEntryId, StoreObjectType.Unknown);
     }
     if (mapiEvent.OldItemEntryId != null)
     {
         this.oldObjectId = StoreObjectId.FromProviderSpecificId(mapiEvent.OldItemEntryId, StoreObjectType.Unknown);
     }
     if (mapiEvent.OldParentEntryId != null)
     {
         this.oldParentObjectId = StoreObjectId.FromProviderSpecificId(mapiEvent.OldParentEntryId, StoreObjectType.Unknown);
     }
     this.mailboxGuid     = mapiEvent.MailboxGuid;
     this.timeStamp       = (ExDateTime)mapiEvent.CreateTime;
     this.itemCount       = mapiEvent.ItemCount;
     this.unreadItemCount = mapiEvent.UnreadItemCount;
     this.watermark       = mapiEvent.Watermark.EventCounter;
     this.eventFlags      = EventFlags.None;
     if ((mapiEvent.ExtendedEventFlags & MapiExtendedEventFlags.NoReminderPropertyModified) != MapiExtendedEventFlags.NoReminderPropertyModified)
     {
         this.eventFlags |= EventFlags.ReminderPropertiesModified;
     }
     if ((mapiEvent.ExtendedEventFlags & MapiExtendedEventFlags.TimerEventFired) == MapiExtendedEventFlags.TimerEventFired)
     {
         this.eventFlags |= EventFlags.TimerEventFired;
     }
     if ((mapiEvent.ExtendedEventFlags & MapiExtendedEventFlags.NonIPMFolder) == MapiExtendedEventFlags.NonIPMFolder)
     {
         this.eventFlags |= EventFlags.NonIPMChange;
     }
 }
        private static Notification CreateNotification(MapiNotification notification)
        {
            Notification result;

            if (notification.NotificationType == AdviseFlags.NewMail)
            {
                MapiNewMailNotification mapiNewMailNotification = notification as MapiNewMailNotification;
                result = new NewMailNotification(StoreObjectId.FromProviderSpecificId(mapiNewMailNotification.EntryId, ObjectClass.GetObjectType(mapiNewMailNotification.MessageClass)), StoreObjectId.FromProviderSpecificId(mapiNewMailNotification.ParentId, StoreObjectType.Folder), mapiNewMailNotification.MessageClass, (MessageFlags)mapiNewMailNotification.MessageFlags);
            }
            else if (notification.NotificationType == AdviseFlags.SearchComplete)
            {
                result = new ObjectNotification(null, null, null, null, (NotificationObjectType)0, null, NotificationType.SearchComplete);
            }
            else if (notification.NotificationType == AdviseFlags.ConnectionDropped)
            {
                MapiConnectionDroppedNotification mapiConnectionDroppedNotification = notification as MapiConnectionDroppedNotification;
                result = new ConnectionDroppedNotification(mapiConnectionDroppedNotification.ServerDN, mapiConnectionDroppedNotification.UserDN, mapiConnectionDroppedNotification.TickDeath);
            }
            else
            {
                MapiObjectNotification mapiObjectNotification = notification as MapiObjectNotification;
                if (mapiObjectNotification == null)
                {
                    throw new InvalidOperationException(ServerStrings.ExNotSupportedNotificationType((uint)notification.NotificationType));
                }
                AdviseFlags      notificationType = notification.NotificationType;
                NotificationType type;
                if (notificationType <= AdviseFlags.ObjectDeleted)
                {
                    if (notificationType == AdviseFlags.ObjectCreated)
                    {
                        type = NotificationType.Created;
                        goto IL_10A;
                    }
                    if (notificationType == AdviseFlags.ObjectDeleted)
                    {
                        type = NotificationType.Deleted;
                        goto IL_10A;
                    }
                }
                else
                {
                    if (notificationType == AdviseFlags.ObjectModified)
                    {
                        type = NotificationType.Modified;
                        goto IL_10A;
                    }
                    if (notificationType == AdviseFlags.ObjectMoved)
                    {
                        type = NotificationType.Moved;
                        goto IL_10A;
                    }
                    if (notificationType == AdviseFlags.ObjectCopied)
                    {
                        type = NotificationType.Copied;
                        goto IL_10A;
                    }
                }
                throw new InvalidOperationException(ServerStrings.ExNotSupportedNotificationType((uint)notification.NotificationType));
IL_10A:
                UnresolvedPropertyDefinition[] propertyDefinitions;
                if (mapiObjectNotification.Tags != null)
                {
                    propertyDefinitions = PropertyTagCache.UnresolvedPropertyDefinitionsFromPropTags(mapiObjectNotification.Tags);
                }
                else
                {
                    propertyDefinitions = Array <UnresolvedPropertyDefinition> .Empty;
                }
                result = new ObjectNotification((mapiObjectNotification.EntryId == null) ? null : StoreObjectId.FromProviderSpecificId(mapiObjectNotification.EntryId, StoreObjectType.Unknown), (mapiObjectNotification.ParentId == null) ? null : StoreObjectId.FromProviderSpecificId(mapiObjectNotification.ParentId, StoreObjectType.Folder), (mapiObjectNotification.OldId == null) ? null : StoreObjectId.FromProviderSpecificId(mapiObjectNotification.OldId, StoreObjectType.Unknown), (mapiObjectNotification.OldParentId == null) ? null : StoreObjectId.FromProviderSpecificId(mapiObjectNotification.OldParentId, StoreObjectType.Folder), (NotificationObjectType)mapiObjectNotification.ObjectType, propertyDefinitions, type);
            }
            return(result);
        }
Exemple #28
0
 private static StoreObjectId EntryIdToStoreObjectId(byte[] entryId, StoreObjectType storeObjectType)
 {
     return(StoreObjectId.FromProviderSpecificId(entryId, storeObjectType));
 }
Exemple #29
0
        private bool IsDuplicateMessageBySiteMailboxDrop(MailboxSession session, CoreItem item)
        {
            if (item.Origin != Origin.New)
            {
                return(false);
            }
            item.PropertyBag.Load(COWSiteMailboxMessageDedup.PropItemClass);
            if (item.ClassName() != "IPM.Note")
            {
                return(false);
            }
            byte[]     array      = item.PropertyBag.TryGetProperty(StoreObjectSchema.ParentEntryId) as byte[];
            string     text       = item.PropertyBag.TryGetProperty(ItemSchema.InternetMessageId) as string;
            string     text2      = item.PropertyBag.TryGetProperty(MessageItemSchema.SenderSmtpAddress) as string;
            ExDateTime?exDateTime = item.PropertyBag.TryGetProperty(ItemSchema.SentTime) as ExDateTime?;
            string     a          = item.PropertyBag.TryGetProperty(ItemSchema.Subject) as string;

            if (array == null || string.IsNullOrEmpty(text) || string.IsNullOrEmpty(text2) || exDateTime == null)
            {
                COWSiteMailboxMessageDedup.Tracer.TraceError((long)this.GetHashCode(), "COWSiteMailboxMessageDedup.IsDuplicateMessageBySiteMailboxDrop: required poperties are not complete, rawId: {0}, internetMessageId: {1}, senderSmtpAddress: {2}, sentTime: {3}", new object[]
                {
                    array,
                    text,
                    text2,
                    exDateTime
                });
                return(false);
            }
            int           hashValue = (int)AllItemsFolderHelper.GetHashValue(text);
            StoreObjectId folderId  = StoreObjectId.FromProviderSpecificId(array, StoreObjectType.Message);

            using (Folder folder = Folder.Bind(session, folderId))
            {
                using (QueryResult queryResult = folder.ItemQuery(ItemQueryType.None, null, COWSiteMailboxMessageDedup.DedupSortBy, COWSiteMailboxMessageDedup.DedupProperties))
                {
                    if (!queryResult.SeekToCondition(SeekReference.OriginBeginning, new ComparisonFilter(ComparisonOperator.Equal, ItemSchema.InternetMessageIdHash, hashValue)))
                    {
                        return(false);
                    }
                    IStorePropertyBag[] array2 = AllItemsFolderHelper.ProcessQueryResult(queryResult, text, hashValue);
                    if (array2 == null)
                    {
                        COWSiteMailboxMessageDedup.Tracer.TraceDebug((long)this.GetHashCode(), "COWSiteMailboxMessageDedup.IsDuplicateMessageBySiteMailboxDrop: propertyBags is null for ProcessQueryResult.");
                        return(false);
                    }
                    foreach (IStorePropertyBag storePropertyBag in array2)
                    {
                        string      text3       = storePropertyBag.TryGetProperty(ItemSchema.InternetMessageId) as string;
                        string      text4       = storePropertyBag.TryGetProperty(MessageItemSchema.SenderSmtpAddress) as string;
                        string      b           = storePropertyBag.TryGetProperty(ItemSchema.Subject) as string;
                        ExDateTime? exDateTime2 = storePropertyBag.TryGetProperty(ItemSchema.SentTime) as ExDateTime?;
                        VersionedId versionedId = storePropertyBag.TryGetProperty(ItemSchema.Id) as VersionedId;
                        if (!string.IsNullOrEmpty(text3) && string.Equals(text, text3, StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(text4) && string.Equals(text2, text4, StringComparison.OrdinalIgnoreCase) && string.Equals(a, b) && exDateTime2 != null && exDateTime2 == exDateTime)
                        {
                            if (item.Id == null || item.Id.ObjectId == null || versionedId == null || versionedId.ObjectId == null)
                            {
                                COWSiteMailboxMessageDedup.Tracer.TraceError((long)this.GetHashCode(), "COWSiteMailboxMessageDedup.IsDuplicateMessageBySiteMailboxDrop: some following values are unavailable: item.Id, item.Id.ObjectId, matchedId, matchedId.ObjectId");
                            }
                            else
                            {
                                COWSiteMailboxMessageDedup.Tracer.TraceDebug <StoreObjectId, StoreObjectId, string>((long)this.GetHashCode(), "COWSiteMailboxMessageDedup.IsDuplicateMessageBySiteMailboxDrop: found duplicate {0} of message {1} in site mailbox {2}.", versionedId.ObjectId, item.Id.ObjectId, session.DisplayName);
                            }
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
        internal static Folder BindToSubfolderByName(StoreSession session, StoreObjectId containerId, string folderName, params PropertyDefinition[] propsToReturn)
        {
            Folder result;

            using (Folder folder = Folder.Bind(session, containerId))
            {
                MapiFolder mapiFolder = null;
                Folder     folder2    = null;
                bool       flag       = false;
                try
                {
                    object thisObject = null;
                    bool   flag2      = false;
                    try
                    {
                        if (session != null)
                        {
                            session.BeginMapiCall();
                            session.BeginServerHealthCall();
                            flag2 = true;
                        }
                        if (StorageGlobals.MapiTestHookBeforeCall != null)
                        {
                            StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                        }
                        mapiFolder = folder.MapiFolder.OpenSubFolderByName(folderName);
                    }
                    catch (MapiPermanentException ex)
                    {
                        throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenFolder, ex, session, thisObject, "{0}. MapiException = {1}.", new object[]
                        {
                            string.Format("DefaultFolderCreator::BindToSubfolderByName. Unable to open folder by name.", new object[0]),
                            ex
                        });
                    }
                    catch (MapiRetryableException ex2)
                    {
                        throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenFolder, ex2, session, thisObject, "{0}. MapiException = {1}.", new object[]
                        {
                            string.Format("DefaultFolderCreator::BindToSubfolderByName. Unable to open folder by name.", new object[0]),
                            ex2
                        });
                    }
                    finally
                    {
                        try
                        {
                            if (session != null)
                            {
                                session.EndMapiCall();
                                if (flag2)
                                {
                                    session.EndServerHealthCall();
                                }
                            }
                        }
                        finally
                        {
                            if (StorageGlobals.MapiTestHookAfterCall != null)
                            {
                                StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                            }
                        }
                    }
                    using (MapiPropertyBag mapiPropertyBag = new MapiPropertyBag(session, mapiFolder))
                    {
                        byte[] entryId = (byte[])mapiPropertyBag.GetProperties(new NativeStorePropertyDefinition[]
                        {
                            InternalSchema.EntryId
                        })[0];
                        StoreObjectId folderObjectId = StoreObjectId.FromProviderSpecificId(entryId);
                        folder2 = Folder.InternalBind <Folder>(session, mapiFolder, folderObjectId, null, propsToReturn);
                        mapiPropertyBag.DetachMapiProp();
                    }
                    flag   = true;
                    result = folder2;
                }
                finally
                {
                    if (!flag)
                    {
                        Util.DisposeIfPresent(folder2);
                        Util.DisposeIfPresent(mapiFolder);
                    }
                }
            }
            return(result);
        }