Exemple #1
0
 private void LoadFolderHierarchy(StoreObjectId rootFolderId, NativeStorePropertyDefinition[] propertiesToLoad, List <FolderRec> result)
 {
     using (CoreFolder coreFolder = CoreFolder.Bind(this.StoreSession, rootFolderId))
     {
         FolderRec folderRec = this.GetFolderRec(coreFolder, propertiesToLoad);
         if (base.Flags.HasFlag(LocalMailboxFlags.ParallelPublicFolderMigration))
         {
             folderRec.FolderName = "Public Root";
         }
         result.Add(folderRec);
         using (QueryResult queryResult = coreFolder.QueryExecutor.FolderQuery(FolderQueryFlags.DeepTraversal, null, null, propertiesToLoad))
         {
             object[][] rows;
             do
             {
                 using (base.RHTracker.Start())
                 {
                     rows = queryResult.GetRows(1000);
                 }
                 foreach (object[] values in rows)
                 {
                     FolderRec folderRec2 = FolderRec.Create(this.StoreSession, propertiesToLoad, values);
                     if (folderRec2 != null)
                     {
                         result.Add(folderRec2);
                     }
                 }
             }while (rows.Length != 0);
         }
     }
 }
Exemple #2
0
        public T GetFolder <T>(byte[] folderId) where T : StorageFolder, new()
        {
            base.VerifyMailboxConnection(VerifyMailboxConnectionFlags.None);
            T result;

            using (base.RHTracker.Start())
            {
                StoreObjectId folderId2 = this.GetFolderId(folderId);
                CoreFolder    coreFolder;
                try
                {
                    coreFolder = CoreFolder.Bind(this.StoreSession, folderId2);
                }
                catch (ObjectNotFoundException)
                {
                    return(default(T));
                }
                if (MrsTracer.Provider.IsEnabled(TraceType.DebugTrace))
                {
                    coreFolder.PropertyBag.Load(new PropertyDefinition[]
                    {
                        FolderSchema.DisplayName
                    });
                    object obj = coreFolder.PropertyBag.TryGetProperty(FolderSchema.DisplayName);
                    MrsTracer.Provider.Debug("Opened folder '{0}'", new object[]
                    {
                        obj
                    });
                }
                StorageFolder storageFolder = Activator.CreateInstance <T>();
                storageFolder.Config(folderId, coreFolder, this);
                result = (T)((object)storageFolder);
            }
            return(result);
        }
Exemple #3
0
 void IDestinationMailbox.DeleteFolder(FolderRec folderRec)
 {
     MrsTracer.Provider.Function("StorageDestinationMailbox.DeleteFolder(\"{0}\")", new object[]
     {
         folderRec.FolderName
     });
     base.VerifyMailboxConnection(VerifyMailboxConnectionFlags.None);
     using (base.RHTracker.Start())
     {
         using (CoreFolder coreFolder = CoreFolder.Bind(base.StoreSession, base.GetFolderId(folderRec.ParentId)))
         {
             GroupOperationResult groupOperationResult = coreFolder.DeleteFolder(DeleteFolderFlags.DeleteMessages | DeleteFolderFlags.DeleteSubFolders, StoreObjectId.FromProviderSpecificId(folderRec.EntryId));
             if (groupOperationResult.OperationResult != OperationResult.Succeeded)
             {
                 MrsTracer.Provider.Error("StorageDestinationMailbox.DeleteFolder failed with '{0}'. Folder name: '{1}', type: '{2}', entry id: '{3}'.", new object[]
                 {
                     groupOperationResult.Exception.ToString(),
                     folderRec.FolderName,
                     folderRec.FolderType,
                     TraceUtils.DumpEntryId(folderRec.EntryId)
                 });
                 groupOperationResult.Exception.PreserveExceptionStack();
                 throw groupOperationResult.Exception;
             }
         }
     }
 }
Exemple #4
0
        private FolderRec GetFolderRec(StoreObjectId folderId, NativeStorePropertyDefinition[] propertiesToLoad)
        {
            FolderRec folderRec;

            using (CoreFolder coreFolder = CoreFolder.Bind(this.StoreSession, folderId))
            {
                folderRec = this.GetFolderRec(coreFolder, propertiesToLoad);
            }
            return(folderRec);
        }
Exemple #5
0
 private void ExecuteSyncStateOperation(Action <StoreSession, CoreFolder> operation)
 {
     using (base.RHTracker.Start())
     {
         if (base.IsPublicFolderMove || base.IsPublicFolderMailboxRestore)
         {
             PublicFolderSession publicFolderSession = this.GetPublicFolderSession();
             using (CoreFolder coreFolder = CoreFolder.Bind(publicFolderSession, publicFolderSession.GetTombstonesRootFolderId()))
             {
                 operation(publicFolderSession, coreFolder);
                 goto IL_A9;
             }
         }
         MailboxSession mailboxSession = null;
         bool           flag           = false;
         try
         {
             if (base.UseHomeMDB)
             {
                 mailboxSession = this.GetMailboxSession();
             }
             else
             {
                 mailboxSession = this.OpenSystemMailbox();
                 flag           = true;
             }
             using (CoreFolder coreFolder2 = CoreFolder.Create(mailboxSession, mailboxSession.GetDefaultFolderId(DefaultFolderType.Configuration), false, "MailboxReplicationService SyncStates", CreateMode.OpenIfExists))
             {
                 coreFolder2.Save(SaveMode.FailOnAnyConflict);
                 operation(mailboxSession, coreFolder2);
             }
         }
         finally
         {
             if (flag && mailboxSession != null)
             {
                 mailboxSession.Dispose();
             }
         }
         IL_A9 :;
     }
 }
Exemple #6
0
 internal static void SyncPublicFolder(IConfigurationSession configurationSession, StoreObjectId folderId)
 {
     using (PublicFolderDataProvider publicFolderDataProvider = new PublicFolderDataProvider(configurationSession, "*-PublicFolderClientPermission", Guid.Empty))
     {
         PublicFolderSession publicFolderSession = publicFolderDataProvider.PublicFolderSession;
         using (CoreFolder coreFolder = CoreFolder.Bind(publicFolderSession, folderId, new PropertyDefinition[]
         {
             CoreFolderSchema.AclTableAndSecurityDescriptor
         }))
         {
             PublicFolderContentMailboxInfo contentMailboxInfo = coreFolder.GetContentMailboxInfo();
             Guid guid = contentMailboxInfo.IsValid ? contentMailboxInfo.MailboxGuid : Guid.Empty;
             ExchangePrincipal contentMailboxPrincipal;
             if (guid != Guid.Empty && guid != publicFolderSession.MailboxGuid && PublicFolderSession.TryGetPublicFolderMailboxPrincipal(publicFolderSession.OrganizationId, guid, true, out contentMailboxPrincipal))
             {
                 PublicFolderSyncJobRpc.SyncFolder(contentMailboxPrincipal, folderId.ProviderLevelItemId);
             }
         }
     }
 }
Exemple #7
0
        public void ItemOperation(COWSettings settings, IDumpsterItemOperations dumpster, COWTriggerAction operation, COWTriggerActionState state, StoreSession session, StoreObjectId itemId, CoreItem item, CoreFolder folder, bool onBeforeNotification, OperationResult result, CallbackContext callbackContext)
        {
            Util.ThrowOnNullArgument(session, "session");
            EnumValidator.ThrowIfInvalid <COWTriggerAction>(operation, "operation");
            EnumValidator.ThrowIfInvalid <COWTriggerActionState>(state, "state");
            EnumValidator.ThrowIfInvalid <OperationResult>(result, "result");
            Util.ThrowOnNullArgument(item, "item");
            MailboxSession mailboxSession = session as MailboxSession;
            ExDateTime     now            = ExDateTime.Now;

            try
            {
                item.PropertyBag.Load(COWSiteMailboxMessageDedup.PropsForMessageRemoval);
                if (item.Id != null && item.Id.ObjectId != null)
                {
                    StoreObjectId storeObjectId = item.PropertyBag.TryGetProperty(StoreObjectSchema.ParentItemId) as StoreObjectId;
                    if (storeObjectId != null)
                    {
                        using (CoreFolder coreFolder = CoreFolder.Bind(session, storeObjectId))
                        {
                            DeleteItemFlags deleteItemFlags = DeleteItemFlags.HardDelete | DeleteItemFlags.SuppressReadReceipt;
                            coreFolder.DeleteItems(deleteItemFlags, new StoreObjectId[]
                            {
                                item.Id.ObjectId
                            });
                        }
                        COWSiteMailboxMessageDedup.Tracer.TraceDebug <StoreObjectId, string, double>((long)this.GetHashCode(), "COWSiteMailboxMessageDedup.ItemOperation: deleting message {0} from site mailbox {1} used {2} milliseconds", itemId, mailboxSession.DisplayName, (ExDateTime.Now - now).TotalMilliseconds);
                    }
                }
            }
            catch (StoragePermanentException arg)
            {
                COWSiteMailboxMessageDedup.Tracer.TraceError <StoragePermanentException>((long)this.GetHashCode(), "COWSiteMailboxMessageDedup.ItemOperation: got store permanent exception: {0}", arg);
            }
            catch (StorageTransientException arg2)
            {
                COWSiteMailboxMessageDedup.Tracer.TraceError <StorageTransientException>((long)this.GetHashCode(), "COWSiteMailboxMessageDedup.ItemOperation: got store transient exception: {0}", arg2);
            }
            callbackContext.SiteMailboxMessageDedupState = COWProcessorState.Processed;
        }
 protected override void InternalProcessRecord()
 {
     try
     {
         if (this.Path != null)
         {
             PublicFolder publicFolder = (PublicFolder)base.GetDataObject <PublicFolder>(this.Path, base.DataSession, null, new LocalizedString?(Strings.ErrorPublicFolderNotFound(this.Path.ToString())), new LocalizedString?(Strings.ErrorPublicFolderNotUnique(this.Path.ToString())));
             using (this.publicFolderDataProvider.PublicFolderSession.GetRestrictedOperationToken())
             {
                 using (CoreFolder coreFolder = CoreFolder.Bind(this.publicFolderDataProvider.PublicFolderSession, publicFolder.InternalFolderIdentity.ObjectId))
                 {
                     coreFolder.MoveFolder(coreFolder, this.DataObject.InternalFolderIdentity.ObjectId);
                     this.folderUpdated = true;
                 }
             }
         }
         if (this.OverrideContentMailbox != null && (this.Force || base.ShouldContinue(Strings.ConfirmationMessageOverrideContentMailbox)))
         {
             PublicFolder publicFolder2 = (PublicFolder)base.GetDataObject <PublicFolder>(this.Identity, base.DataSession, null, new LocalizedString?(Strings.ErrorPublicFolderNotFound(this.Identity.ToString())), new LocalizedString?(Strings.ErrorPublicFolderNotUnique(this.Identity.ToString())));
             using (this.publicFolderDataProvider.PublicFolderSession.GetRestrictedOperationToken())
             {
                 using (CoreFolder coreFolder2 = CoreFolder.Bind(this.publicFolderDataProvider.PublicFolderSession, publicFolder2.InternalFolderIdentity.ObjectId))
                 {
                     coreFolder2.PropertyBag.SetProperty(CoreFolderSchema.ReplicaList, new string[]
                     {
                         this.contentMailboxGuid.ToString()
                     });
                     coreFolder2.PropertyBag.SetProperty(CoreFolderSchema.LastMovedTimeStamp, ExDateTime.UtcNow);
                     coreFolder2.Save(SaveMode.NoConflictResolution);
                     this.folderUpdated = true;
                 }
             }
         }
         base.InternalProcessRecord();
     }
     catch (NotSupportedException exception)
     {
         base.WriteError(exception, ErrorCategory.InvalidType, this.Identity);
     }
 }
Exemple #9
0
 void IDestinationMailbox.MoveFolder(byte[] folderId, byte[] oldParentId, byte[] newParentId)
 {
     MrsTracer.Provider.Function("StorageDestinationMailbox.MoveFolder", new object[0]);
     base.VerifyMailboxConnection(VerifyMailboxConnectionFlags.None);
     using (base.RHTracker.Start())
     {
         using (CoreFolder coreFolder = CoreFolder.Bind(base.StoreSession, base.GetFolderId(oldParentId)))
         {
             using (CoreFolder coreFolder2 = CoreFolder.Bind(base.StoreSession, base.GetFolderId(newParentId)))
             {
                 GroupOperationResult groupOperationResult = coreFolder.MoveFolder(coreFolder2, StoreObjectId.FromProviderSpecificId(folderId));
                 if (groupOperationResult.OperationResult != OperationResult.Succeeded)
                 {
                     MrsTracer.Provider.Error("StorageDestinationMailbox.MoveFolder failed with {0}", new object[]
                     {
                         groupOperationResult.Exception.ToString()
                     });
                     groupOperationResult.Exception.PreserveExceptionStack();
                     throw groupOperationResult.Exception;
                 }
             }
         }
     }
 }
Exemple #10
0
        public void UpdateHistory(CallbackContext callbackContext)
        {
            if (this.ShouldSkipAudit)
            {
                return;
            }
            MailboxSession mailboxSession = (MailboxSession)this.currentFolder.Session;
            CoreFolder     coreFolder     = null;
            StoreObjectId  objectId       = this.currentFolder.Id.ObjectId;

            if (mailboxSession.LogonType == LogonType.Delegated || mailboxSession.LogonType == LogonType.DelegatedAdmin)
            {
                Exception ex = null;
                try
                {
                    coreFolder         = CoreFolder.Bind(callbackContext.SessionWithBestAccess, objectId);
                    this.currentFolder = coreFolder;
                }
                catch (StoragePermanentException ex2)
                {
                    ex = ex2;
                }
                catch (StorageTransientException ex3)
                {
                    ex = ex3;
                }
                if (ex != null)
                {
                    ExTraceGlobals.SessionTracer.TraceWarning <StoreObjectId, Exception>((long)this.currentFolder.Session.GetHashCode(), "Failed to rebind folder {0} with Admin logon. The cached RecentBindingHistory data will not be updated. Error: {1}", objectId, ex);
                    ProcessInfoEventLogger.Log(StorageEventLogConstants.Tuple_ErrorBindingFolderForFolderBindHistory, objectId.ToString(), new object[]
                    {
                        objectId,
                        mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString(),
                        mailboxSession.MailboxGuid,
                        mailboxSession.LogonType,
                        IdentityHelper.SidFromLogonIdentity(mailboxSession.Identity),
                        COWTriggerAction.FolderBind,
                        ex
                    });
                    this.currentFolder = null;
                }
            }
            if (this.currentFolder != null)
            {
                try
                {
                    this.currentFolder.PropertyBag.SetProperty(FolderSchema.RecentBindingHistory, this.bindingHistory.ToArray());
                    FolderSaveResult folderSaveResult = this.currentFolder.Save(SaveMode.NoConflictResolutionForceSave);
                    if (coreFolder == null)
                    {
                        this.currentFolder.PropertyBag.Load(null);
                    }
                    if (folderSaveResult.OperationResult != OperationResult.Succeeded)
                    {
                        ExTraceGlobals.SessionTracer.TraceWarning <StoreObjectId, LocalizedException>((long)this.currentFolder.Session.GetHashCode(), "Failed to save RecentBindingHistory on folder {0}. Error: {1}.", objectId, folderSaveResult.Exception);
                        ProcessInfoEventLogger.Log(StorageEventLogConstants.Tuple_ErrorSavingFolderBindHistory, objectId.ToString(), new object[]
                        {
                            objectId,
                            mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString(),
                            mailboxSession.MailboxGuid,
                            mailboxSession.LogonType,
                            IdentityHelper.SidFromLogonIdentity(mailboxSession.Identity),
                            COWTriggerAction.FolderBind,
                            folderSaveResult.Exception
                        });
                    }
                }
                finally
                {
                    if (coreFolder != null)
                    {
                        coreFolder.Dispose();
                    }
                }
            }
        }
Exemple #11
0
        MailboxInformation IMailbox.GetMailboxInformation()
        {
            MrsTracer.Provider.Function("StorageMailbox.GetMailboxInformation", new object[0]);
            MailboxInformation mailboxInformation = new MailboxInformation();
            MailboxDatabase    mailboxDatabase    = base.FindDatabaseByGuid <MailboxDatabase>(base.MdbGuid);

            mailboxInformation.ProviderName               = "StorageProvider";
            mailboxInformation.MailboxGuid                = base.MailboxGuid;
            mailboxInformation.MdbGuid                    = base.MdbGuid;
            mailboxInformation.MdbName                    = mailboxDatabase.Identity.ToString();
            mailboxInformation.MdbLegDN                   = mailboxDatabase.ExchangeLegacyDN;
            mailboxInformation.MdbQuota                   = (mailboxDatabase.ProhibitSendReceiveQuota.IsUnlimited ? null : new ulong?(mailboxDatabase.ProhibitSendReceiveQuota.Value.ToBytes()));
            mailboxInformation.MdbDumpsterQuota           = (mailboxDatabase.RecoverableItemsQuota.IsUnlimited ? null : new ulong?(mailboxDatabase.RecoverableItemsQuota.Value.ToBytes()));
            mailboxInformation.ServerVersion              = this.ServerVersion;
            mailboxInformation.ServerMailboxRelease       = base.ServerMailboxRelease.ToString();
            mailboxInformation.RecipientType              = this.recipientType;
            mailboxInformation.RecipientDisplayType       = this.recipientDisplayType;
            mailboxInformation.RecipientTypeDetailsLong   = this.recipientTypeDetails;
            mailboxInformation.MailboxHomeMdbGuid         = (base.IsArchiveMailbox ? base.MbxArchiveMdbGuid : base.MbxHomeMdbGuid);
            mailboxInformation.ArchiveGuid                = this.archiveGuid;
            mailboxInformation.AlternateMailboxes         = this.alternateMailboxes;
            mailboxInformation.UseMdbQuotaDefaults        = this.useMdbQuotaDefaults;
            mailboxInformation.MailboxQuota               = this.mbxQuota;
            mailboxInformation.MailboxDumpsterQuota       = this.mbxDumpsterQuota;
            mailboxInformation.MailboxArchiveQuota        = this.mbxArchiveQuota;
            mailboxInformation.MailboxIdentity            = ((base.MailboxId != null) ? base.MailboxId.ToString() : null);
            mailboxInformation.MailboxItemCount           = 0UL;
            mailboxInformation.MailboxSize                = 0UL;
            mailboxInformation.RegularItemCount           = 0UL;
            mailboxInformation.RegularDeletedItemCount    = 0UL;
            mailboxInformation.AssociatedItemCount        = 0UL;
            mailboxInformation.AssociatedDeletedItemCount = 0UL;
            mailboxInformation.RegularItemsSize           = 0UL;
            mailboxInformation.RegularDeletedItemsSize    = 0UL;
            mailboxInformation.AssociatedItemsSize        = 0UL;
            mailboxInformation.AssociatedDeletedItemsSize = 0UL;
            mailboxInformation.RulesSize                  = 0;
            mailboxInformation.MrsVersion                 = CommonUtils.GetEffectiveMrsVersion();
            int intValueAndDecrement = base.TestIntegration.GetIntValueAndDecrement("SimulatePushMove", 0, 0, int.MaxValue);

            if (intValueAndDecrement > 0)
            {
                if (intValueAndDecrement % 2 == 0)
                {
                    mailboxInformation.MrsVersion = 99.9f;
                }
                else
                {
                    mailboxInformation.MrsVersion = 99.8f;
                }
            }
            if (this.StoreSession != null)
            {
                object[] properties;
                using (base.RHTracker.Start())
                {
                    NativeStorePropertyDefinition[] array = this.ConvertPropTagsToDefinitions(MailboxProviderBase.MailboxInformationPropertyTags);
                    this.StoreSession.Mailbox.Load(array);
                    properties = this.StoreSession.Mailbox.GetProperties(array);
                }
                for (int i = 0; i < properties.Length; i++)
                {
                    object obj = properties[i];
                    if (obj != null && !(obj is PropertyError))
                    {
                        MailboxProviderBase.PopulateMailboxInformation(mailboxInformation, MailboxProviderBase.MailboxInformationPropertyTags[i], obj);
                    }
                }
                if (!base.IsPublicFolderMailbox)
                {
                    using (base.RHTracker.Start())
                    {
                        try
                        {
                            MailboxSession mailboxSession = this.GetMailboxSession();
                            using (CoreFolder coreFolder = CoreFolder.Bind(mailboxSession, mailboxSession.GetDefaultFolderId(DefaultFolderType.Inbox)))
                            {
                                coreFolder.PropertyBag.Load(StorageMailbox.InboxProperties);
                                object obj2 = coreFolder.PropertyBag.TryGetProperty(FolderSchema.FolderRulesSize);
                                if (obj2 is int)
                                {
                                    mailboxInformation.RulesSize = (int)obj2;
                                }
                                object obj3 = coreFolder.PropertyBag.TryGetProperty(FolderSchema.ContentAggregationFlags);
                                if (obj3 is int)
                                {
                                    mailboxInformation.ContentAggregationFlags = (int)obj3;
                                }
                                else
                                {
                                    mailboxInformation.ContentAggregationFlags = 0;
                                }
                            }
                        }
                        catch (ObjectNotFoundException)
                        {
                            MrsTracer.Provider.Debug("Inbox not found for mailbox '{0}'", new object[]
                            {
                                base.MdbGuid
                            });
                        }
                    }
                }
            }
            using (ExRpcAdmin rpcAdmin = base.GetRpcAdmin())
            {
                using (base.RHTracker.Start())
                {
                    mailboxInformation.MailboxTableFlags = (int)MapiUtils.GetMailboxTableFlags(rpcAdmin, base.MdbGuid, base.MailboxGuid);
                }
            }
            return(mailboxInformation);
        }
Exemple #12
0
        public IEnumerable <T> FindPaged <T>(QueryFilter filter, ObjectId rootId, bool deepSearch, SortBy sortBy, int pageSize) where T : IConfigurable, new()
        {
            base.CheckDisposed();
            if (!typeof(PublicFolderStatistics).GetTypeInfo().IsAssignableFrom(typeof(T).GetTypeInfo()))
            {
                throw new NotSupportedException("FindPaged: " + typeof(T).FullName);
            }
            IEnumerable <PublicFolder> publicFolders = this.publicFolderDataProvider.FindPaged <PublicFolder>(filter, rootId, deepSearch, sortBy, pageSize);

            foreach (PublicFolder publicFolder in publicFolders)
            {
                PublicFolderSession contentSession = null;
                if (this.mailboxGuid == Guid.Empty)
                {
                    contentSession = this.PublicFolderDataProvider.PublicFolderSessionCache.GetPublicFolderSession(publicFolder.InternalFolderIdentity.ObjectId);
                }
                else
                {
                    contentSession = this.PublicFolderDataProvider.PublicFolderSessionCache.GetPublicFolderSession(this.mailboxGuid);
                }
                using (Folder contentFolder = Folder.Bind(contentSession, publicFolder.InternalFolderIdentity, PublicFolderStatisticsDataProvider.contentFolderProperties))
                {
                    PublicFolderStatistics publicFolderStatistics = new PublicFolderStatistics();
                    publicFolderStatistics.LoadDataFromXso(contentSession.MailboxPrincipal.ObjectId, contentFolder);
                    uint          ownerCount          = 0U;
                    uint          contactCount        = 0U;
                    PermissionSet folderPermissionSet = contentFolder.GetPermissionSet();
                    foreach (Permission permission in folderPermissionSet)
                    {
                        if (permission.IsFolderContact)
                        {
                            contactCount += 1U;
                        }
                        if (permission.IsFolderOwner)
                        {
                            ownerCount += 1U;
                        }
                    }
                    publicFolderStatistics.OwnerCount   = ownerCount;
                    publicFolderStatistics.ContactCount = contactCount;
                    StoreObjectId dumpsterId = PublicFolderCOWSession.GetRecoverableItemsDeletionsFolderId((CoreFolder)contentFolder.CoreObject);
                    checked
                    {
                        if (dumpsterId != null)
                        {
                            try
                            {
                                using (CoreFolder coreFolder = CoreFolder.Bind(contentSession, dumpsterId, PublicFolderStatisticsDataProvider.dumpsterProperties))
                                {
                                    publicFolderStatistics.DeletedItemCount     = (uint)((int)coreFolder.PropertyBag[FolderSchema.ItemCount]);
                                    publicFolderStatistics.TotalDeletedItemSize = ByteQuantifiedSize.FromBytes((ulong)((long)coreFolder.PropertyBag[FolderSchema.ExtendedSize]));
                                }
                            }
                            catch (ObjectNotFoundException)
                            {
                            }
                        }
                        yield return((T)((object)publicFolderStatistics));
                    }
                }
            }
            yield break;
        }