コード例 #1
0
        protected override StoreSession CreateStoreConnection(MailboxConnectFlags mailboxConnectFlags)
        {
            StoreSession storeSession = null;
            StoreSession result;

            try
            {
                if (base.UseHomeMDB || base.IsPublicFolderMove || base.IsFolderMove || mailboxConnectFlags.HasFlag(MailboxConnectFlags.NonMrsLogon))
                {
                    storeSession = base.CreateStoreConnection(mailboxConnectFlags);
                    if (storeSession != null && base.Flags.HasFlag(LocalMailboxFlags.WordBreak))
                    {
                        bool invalidateAnnotations = base.Flags.HasFlag(LocalMailboxFlags.InvalidateContentIndexAnnotations);
                        storeSession.ContentIndexingSession = ContentIndexingSession.CreateSession(storeSession, invalidateAnnotations);
                    }
                }
                else
                {
                    storeSession = this.ConnectToTargetMailbox(false, mailboxConnectFlags);
                }
                StoreSession storeSession2 = storeSession;
                storeSession = null;
                result       = storeSession2;
            }
            finally
            {
                if (storeSession != null)
                {
                    storeSession.Dispose();
                }
            }
            return(result);
        }
コード例 #2
0
        private StoreSession ConnectToTargetMailbox(bool mailboxMustExist, MailboxConnectFlags mailboxConnectFlags)
        {
            MrsTracer.Provider.Function("StorageDestinationMailbox.ConnectToTargetMailbox", new object[0]);
            base.CheckDisposed();
            StoreSession result      = null;
            ConnectFlag  connectFlag = ConnectFlag.UseAdminPrivilege;

            connectFlag |= ConnectFlag.UseRpcContextPool;
            if (!mailboxMustExist)
            {
                bool flag = false;
                MrsTracer.Provider.Debug("Checking if destination mailbox exists...", new object[0]);
                using (ExRpcAdmin rpcAdmin = base.GetRpcAdmin())
                {
                    using (base.RHTracker.Start())
                    {
                        flag = MapiUtils.IsMailboxInDatabase(rpcAdmin, base.MdbGuid, base.MailboxGuid);
                    }
                }
                if (!flag)
                {
                    MrsTracer.Provider.Debug("Mailbox {0} does not exist in database {1}", new object[]
                    {
                        base.MailboxGuid,
                        base.MdbGuid
                    });
                    return(null);
                }
                MrsTracer.Provider.Debug("Mailbox {0} exists in database {1}", new object[]
                {
                    base.MailboxGuid,
                    base.MdbGuid
                });
            }
            StoreSession storeSession = null;

            try
            {
                using (base.RHTracker.Start())
                {
                    DefaultFolderType[] foldersToInit = (DefaultFolderType[])Enum.GetValues(typeof(DefaultFolderType));
                    MailboxSession.InitializationFlags initializationFlags = MailboxSession.InitializationFlags.DefaultFolders | MailboxSession.InitializationFlags.UserConfigurationManager | MailboxSession.InitializationFlags.DeadSessionChecking | MailboxSession.InitializationFlags.RequestLocalRpc | MailboxSession.InitializationFlags.OverrideHomeMdb | MailboxSession.InitializationFlags.SuppressFolderIdPrefetch | MailboxSession.InitializationFlags.UseNamedProperties | MailboxSession.InitializationFlags.DisconnectedMailbox | MailboxSession.InitializationFlags.MoveUser;
                    if (base.MbxType == MailboxType.DestMailboxCrossOrg)
                    {
                        initializationFlags |= MailboxSession.InitializationFlags.XForestMove;
                    }
                    MrsTracer.Provider.Debug("Opening Mailbox Session: mailbox='{0}', mailboxGuid={1}, dbGuid={2}, connectFlags=[{3}], initFlags=[{4}]", new object[]
                    {
                        base.TraceMailboxId,
                        base.MailboxGuid.ToString(),
                        base.MdbGuid.ToString(),
                        connectFlag,
                        initializationFlags
                    });
                    OrganizationId organizationId;
                    if (base.PartitionHint != null)
                    {
                        ADSessionSettings adsessionSettings = ADSessionSettings.FromTenantPartitionHint(base.PartitionHint);
                        organizationId = adsessionSettings.CurrentOrganizationId;
                    }
                    else
                    {
                        organizationId = OrganizationId.ForestWideOrgId;
                    }
                    ExchangePrincipal exchangePrincipal = ExchangePrincipal.FromMailboxData(base.MailboxGuid, base.MdbGuid, organizationId, StorageMailbox.CultureInfos);
                    string            clientInfoString  = "Client=MSExchangeMigration";
                    if ((mailboxConnectFlags & MailboxConnectFlags.PublicFolderHierarchyReplication) != MailboxConnectFlags.None)
                    {
                        clientInfoString = "Client=PublicFolderSystem;Action=PublicFolderHierarchyReplication";
                    }
                    if (base.IsPublicFolderMailbox)
                    {
                        storeSession = PublicFolderSession.OpenAsMRS(exchangePrincipal, clientInfoString, OpenMailboxSessionFlags.None);
                    }
                    else
                    {
                        MailboxAccessInfo accessInfo = new MailboxAccessInfo(new WindowsPrincipal(WindowsIdentity.GetCurrent()));
                        storeSession = MailboxSession.ConfigurableOpen(exchangePrincipal, accessInfo, CultureInfo.InvariantCulture, clientInfoString, LogonType.SystemService, null, initializationFlags, foldersToInit);
                    }
                    if (!base.TestIntegration.DisableFolderCreationBlockFeature)
                    {
                        storeSession.BlockFolderCreation = true;
                    }
                    if (storeSession != null && base.Flags.HasFlag(LocalMailboxFlags.WordBreak))
                    {
                        bool invalidateAnnotations = base.Flags.HasFlag(LocalMailboxFlags.InvalidateContentIndexAnnotations);
                        storeSession.ContentIndexingSession = ContentIndexingSession.CreateSession(storeSession, invalidateAnnotations);
                    }
                    result       = storeSession;
                    storeSession = null;
                }
            }
            catch (Exception ex)
            {
                if (CommonUtils.ExceptionIs(ex, new WellKnownException[]
                {
                    WellKnownException.MapiNotFound
                }))
                {
                    base.VerifyMdbIsOnline(ex);
                    if (mailboxMustExist)
                    {
                        throw;
                    }
                }
                else
                {
                    if (CommonUtils.ExceptionIs(ex, new WellKnownException[]
                    {
                        WellKnownException.MapiMailboxInTransit
                    }))
                    {
                        throw this.GetMailboxInTransitException(ex);
                    }
                    throw;
                }
            }
            finally
            {
                if (storeSession != null)
                {
                    storeSession.Dispose();
                }
            }
            return(result);
        }