예제 #1
0
        FolderChangesManifest ISourceFolder.EnumerateChanges(EnumerateContentChangesFlags flags, int maxChanges)
        {
            if (!base.Folder.IsContentAvailable)
            {
                return(new FolderChangesManifest(base.FolderId));
            }
            SyncContentsManifestState syncState = ((MapiSourceMailbox)base.Mailbox).SyncState[base.FolderId];
            bool flag = maxChanges != 0;

            if (!flag || flags.HasFlag(EnumerateContentChangesFlags.FirstPage))
            {
                MapiStore mapiStore = base.Mailbox.MapiStore;
                int[]     array     = new int[4];
                array[0] = 8;
                if (mapiStore.IsVersionGreaterOrEqualThan(array))
                {
                    this.contentChangesFetcher = new ManifestContentChangesFetcher(this, base.Folder, base.Mailbox, flag);
                }
                else
                {
                    this.contentChangesFetcher = new TitaniumContentChangesFetcher(this, base.Folder, base.Mailbox);
                }
            }
            return(this.contentChangesFetcher.EnumerateContentChanges(syncState, flags, maxChanges));
        }
예제 #2
0
        private byte[] GetDestinationSpecificEntryId(MapiStore hierarchyStore, StoreId folderId)
        {
            StoreSession storeSession = null;
            object       thisObject   = null;
            bool         flag         = false;

            byte[] result;
            try
            {
                if (storeSession != null)
                {
                    storeSession.BeginMapiCall();
                    storeSession.BeginServerHealthCall();
                    flag = true;
                }
                if (StorageGlobals.MapiTestHookBeforeCall != null)
                {
                    StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                }
                result = hierarchyStore.CreateEntryId(hierarchyStore.GetFidFromEntryId(StoreId.GetStoreObjectId(folderId).ProviderLevelItemId));
            }
            catch (MapiPermanentException ex)
            {
                throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotCreateEntryIdFromShortTermId, ex, storeSession, thisObject, "{0}. MapiException = {1}.", new object[]
                {
                    string.Format("RPCPrimaryHierarchyProvider.GetDestinationSpecificEntryId : folderId = {0}", folderId),
                    ex
                });
            }
            catch (MapiRetryableException ex2)
            {
                throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotCreateEntryIdFromShortTermId, ex2, storeSession, thisObject, "{0}. MapiException = {1}.", new object[]
                {
                    string.Format("RPCPrimaryHierarchyProvider.GetDestinationSpecificEntryId : folderId = {0}", folderId),
                    ex2
                });
            }
            finally
            {
                try
                {
                    if (storeSession != null)
                    {
                        storeSession.EndMapiCall();
                        if (flag)
                        {
                            storeSession.EndServerHealthCall();
                        }
                    }
                }
                finally
                {
                    if (StorageGlobals.MapiTestHookAfterCall != null)
                    {
                        StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                    }
                }
            }
            return(result);
        }
예제 #3
0
 public RequestJobProvider(Guid mdbGuid, MapiStore mdbSession)
 {
     this.MdbGuid       = mdbGuid;
     this.store         = mdbSession;
     this.ownsStore     = (mdbSession == null);
     this.IndexProvider = new RequestIndexEntryProvider();
 }
예제 #4
0
 public LightJobBase(Guid requestGuid, Guid requestQueueGuid, MapiStore systemMailbox, byte[] messageId)
 {
     this.RequestGuid      = requestGuid;
     this.RequestQueueGuid = requestQueueGuid;
     this.SystemMailbox    = systemMailbox;
     this.MessageId        = messageId;
 }
예제 #5
0
 internal static MapiFolder GetFolderByPath(MapiStore mapiStore, MapiFolder parentFolder, MapiFolderPath folderPath)
 {
     if (null == folderPath)
     {
         throw new ArgumentNullException("folderPath");
     }
     if (folderPath.IsSubtreeRoot)
     {
         if (mapiStore == null)
         {
             throw new ArgumentNullException("mapiStore");
         }
         if (!folderPath.IsIpmPath)
         {
             return(mapiStore.GetNonIpmSubtreeFolder());
         }
         return(mapiStore.GetIpmSubtreeFolder());
     }
     else
     {
         if (parentFolder == null)
         {
             throw new ArgumentNullException("parentFolder");
         }
         return(parentFolder.OpenSubFolderByName(folderPath[folderPath.Depth - 1]));
     }
 }
예제 #6
0
        internal void SaveToMailbox(MapiStore mailbox, int maxMoveHistoryLength)
        {
            MrsTracer.Common.Function("MoveHistoryEntryInternal.SaveToMailbox(maxHistoryLength={0})", new object[]
            {
                maxMoveHistoryLength
            });
            List <byte[]> list = new List <byte[]>();

            using (MapiFolder folder = MapiUtils.OpenFolderUnderRoot(mailbox, MoveHistoryEntryInternal.MHEFolderName, true))
            {
                using (MapiTable contentsTable = folder.GetContentsTable(ContentsTableFlags.DeferredErrors))
                {
                    contentsTable.SortTable(new SortOrder(PropTag.LastModificationTime, SortFlags.Ascend), SortTableFlags.None);
                    PropValue[][] array = MapiUtils.QueryAllRows(contentsTable, null, new PropTag[]
                    {
                        PropTag.EntryId
                    });
                    foreach (PropValue[] array3 in array)
                    {
                        list.Add(array3[0].GetBytes());
                    }
                }
                MrsTracer.Common.Debug("Move history contains {0} items.", new object[]
                {
                    list.Count
                });
                List <byte[]> list2 = new List <byte[]>();
                while (list.Count >= maxMoveHistoryLength && list.Count > 0)
                {
                    list2.Add(list[0]);
                    list.RemoveAt(0);
                }
                if (list2.Count > 0)
                {
                    MrsTracer.Common.Debug("Clearing {0} entries from move history", new object[]
                    {
                        list2.Count
                    });
                    MapiUtils.ProcessMapiCallInBatches <byte[]>(list2.ToArray(), delegate(byte[][] batch)
                    {
                        folder.DeleteMessages(DeleteMessagesFlags.ForceHardDelete, batch);
                    });
                }
            }
            if (maxMoveHistoryLength <= 0)
            {
                MrsTracer.Common.Debug("Move history saving is disabled.", new object[0]);
                return;
            }
            DateTime dateTime = this.TimeTracker.GetTimestamp(RequestJobTimestamp.Creation) ?? DateTime.MinValue;
            string   subject  = string.Format("MoveHistoryEntry {0}", dateTime.ToString());

            byte[] bytes = BitConverter.GetBytes(dateTime.ToBinary());
            MoveObjectInfo <MoveHistoryEntryInternal> moveObjectInfo = new MoveObjectInfo <MoveHistoryEntryInternal>(Guid.Empty, mailbox, null, MoveHistoryEntryInternal.MHEFolderName, MoveHistoryEntryInternal.MHEMessageClass, subject, bytes);

            using (moveObjectInfo)
            {
                moveObjectInfo.SaveObject(this);
            }
        }
예제 #7
0
        internal override void Read(bool keepUnmanagedResources)
        {
            if (base.ObjectState != ObjectState.New)
            {
                throw new MapiInvalidOperationException(Strings.ExceptionObjectStateInvalid(base.ObjectState.ToString()));
            }
            Folder.CheckRequirementsToContinue(this.Identity, base.MapiSession);
            bool flag = false;

            ExTraceGlobals.FolderTracer.TraceDebug <FolderId, string>((long)this.GetHashCode(), "To Read Folder '{0}' from server '{1}'.", this.Identity, base.MapiSession.ServerName);
            base.EnableDisposeTracking();
            using (MapiStore messageStore = this.GetMessageStore())
            {
                using (MapiFolder mapiFolder = this.GetMapiFolder(messageStore))
                {
                    try
                    {
                        base.Instantiate(mapiFolder.GetProps(base.GetPropertyTagsToRead()));
                        this.UpdateIdentity(this.UpdateIdentityFlagsForReading);
                        flag = true;
                    }
                    finally
                    {
                        if (!keepUnmanagedResources || !flag)
                        {
                            base.Dispose();
                        }
                    }
                }
            }
            base.ResetChangeTrackingAndObjectState();
        }
예제 #8
0
        private bool TryOpenHistoryFolder()
        {
            bool result;

            try
            {
                MapiStore mapiStore = this.context.StoreSession.Mailbox.MapiStore;
                using (MapiFolder nonIpmSubtreeFolder = mapiStore.GetNonIpmSubtreeFolder())
                {
                    this.oofHistoryFolder = nonIpmSubtreeFolder.OpenSubFolderByName("Freebusy Data");
                }
                this.Trace("OOF history folder opened.");
                result = true;
            }
            catch (MapiExceptionNotFound mapiExceptionNotFound)
            {
                this.context.TraceError <string>("Unable to open the OOF history folder {0}, OOF history operation skipped.", "Freebusy Data");
                this.context.LogEvent(this.context.OofHistoryFolderMissing, mapiExceptionNotFound.GetType().ToString(), new object[]
                {
                    ((MailboxSession)this.context.StoreSession).MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString()
                });
                result = false;
            }
            return(result);
        }
 internal override void InternalProcessRecord()
 {
     base.InternalProcessRecord();
     if (!this.sourceServerHasMdb)
     {
         base.AddSuccessMonitoringEvent(1000, Strings.TestMailflowSucceededNoDatabaseOnSourceServer(base.SourceMailboxServer.Name));
         base.Task.WriteWarning(Strings.TestMailflowServerWithoutMdbs(base.SourceMailboxServer.Name));
         return;
     }
     if (!this.targetServerHasMdb)
     {
         base.AddSuccessMonitoringEvent(1000, Strings.TestMailflowSucceededNoDatabaseOnTargetServer(base.Task.TargetMailboxServer.ToString()));
         base.Task.WriteWarning(Strings.TestMailflowServerWithoutMdbs(base.Task.TargetMailboxServer.ToString()));
         return;
     }
     using (MapiStore mapiStore = MapiStore.OpenMailbox(base.SourceMailboxServer.Fqdn, base.SourceSystemMailbox.LegacyExchangeDN, base.SourceSystemMailbox.ExchangeGuid, base.SourceSystemMailbox.Database.ObjectGuid, base.SourceSystemMailbox.Name, null, null, ConnectFlag.UseAdminPrivilege | ConnectFlag.UseSeparateConnection, OpenStoreFlag.UseAdminPrivilege | OpenStoreFlag.TakeOwnership | OpenStoreFlag.MailboxGuid, CultureInfo.InvariantCulture, null, "Client=Management;Action=LegacyTestMailFlow", null))
     {
         using (MapiFolder outboxFolder = mapiStore.GetOutboxFolder())
         {
             using (MapiFolder inboxFolder = mapiStore.GetInboxFolder())
             {
                 LegacyTestMailFlowHelper.CleanUpInbox(inboxFolder);
                 string subject = string.Format("Test-Mailflow {0} {1}", Guid.NewGuid(), "66c7004a-6860-44b2-983a-327aa3c9cfec");
                 TestMailFlowHelper.CreateAndSubmitMessage(outboxFolder, base.SourceSystemMailbox.Name, this.targetMailboxAddress, subject, true);
                 this.WaitAndProcessDeliveryReceipt(inboxFolder, subject, this.friendlySourceAddress, this.friendlyTargetAddress, this.GetPerfInstanceName());
             }
         }
     }
 }
예제 #10
0
        private MapiStore GetHierarchyStore()
        {
            StoreSession storeSession = null;
            object       thisObject   = null;
            bool         flag         = false;
            MapiStore    result;

            try
            {
                if (storeSession != null)
                {
                    storeSession.BeginMapiCall();
                    storeSession.BeginServerHealthCall();
                    flag = true;
                }
                if (StorageGlobals.MapiTestHookBeforeCall != null)
                {
                    StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                }
                result = MapiStore.OpenPublicStore(this.getLegacyDN(this.PrimaryHierarchyMailboxPrincipal).ToString(), this.userDn, null, null, null, string.Format("{0}:{1}", this.PrimaryHierarchyMailboxPrincipal.MailboxInfo.Location.ServerFqdn, 81), ConnectFlag.UseDelegatedAuthPrivilege | ConnectFlag.UseNTLM | ConnectFlag.ConnectToExchangeRpcServerOnly, OpenStoreFlag.Public, CultureInfo.CurrentCulture, PublicFolderSession.FromClientSecurityContext(this.organizationId, this.clientSecurityContext), "Client=MSExchangeRPC");
            }
            catch (MapiPermanentException ex)
            {
                throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenMailbox(this.PrimaryHierarchyMailboxPrincipal.LegacyDn), ex, storeSession, thisObject, "{0}. MapiException = {1}.", new object[]
                {
                    string.Format("PublicFolderRPCHierarchyProvider.GetHierarchyStore : ServerFullyQualifiedDomainName = {0}, UserLegacyDN = {1}.", this.PrimaryHierarchyMailboxPrincipal.MailboxInfo.Location.ServerFqdn, this.userDn),
                    ex
                });
            }
            catch (MapiRetryableException ex2)
            {
                throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenMailbox(this.PrimaryHierarchyMailboxPrincipal.LegacyDn), ex2, storeSession, thisObject, "{0}. MapiException = {1}.", new object[]
                {
                    string.Format("PublicFolderRPCHierarchyProvider.GetHierarchyStore : ServerFullyQualifiedDomainName = {0}, UserLegacyDN = {1}.", this.PrimaryHierarchyMailboxPrincipal.MailboxInfo.Location.ServerFqdn, this.userDn),
                    ex2
                });
            }
            finally
            {
                try
                {
                    if (storeSession != null)
                    {
                        storeSession.EndMapiCall();
                        if (flag)
                        {
                            storeSession.EndServerHealthCall();
                        }
                    }
                }
                finally
                {
                    if (StorageGlobals.MapiTestHookAfterCall != null)
                    {
                        StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                    }
                }
            }
            return(result);
        }
예제 #11
0
        internal static bool IsMessageTypeSupported(MapiMessage message, MapiStore store)
        {
            RequestJobNamedPropertySet requestJobNamedPropertySet = RequestJobNamedPropertySet.Get(store);
            PropValue  prop  = message.GetProp(requestJobNamedPropertySet.PropTags[9]);
            MRSJobType value = MapiUtils.GetValue <MRSJobType>(prop, MRSJobType.RequestJobE14R3);

            return(RequestJobXML.IsKnownJobType(value));
        }
        public SyncContentsManifestState()
        {
            uint idsGivenPropTag = FastTransferIcsState.IdsetGiven;

            this.folderId   = null;
            this.data       = null;
            this.idSetGiven = new Lazy <IdSet>(() => MapiStore.GetIdSetFromMapiManifestBlob((PropTag)idsGivenPropTag, this.Data));
        }
예제 #13
0
 public static byte[] GetSignatureBytes(MapiStore systemMailbox)
 {
     byte[] result = null;
     using (MapiFolder rootFolder = systemMailbox.GetRootFolder())
     {
         result = (rootFolder.GetProp(PropTag.MappingSignature).Value as byte[]);
     }
     return(result);
 }
        protected override void ProcessJobs(MapiStore systemMbx, MapiTable contentsTable, RequestJobNamedPropertySet nps)
        {
            SortOrder sortOrder = new SortOrder(nps.PropTags[17], SortFlags.Descend);

            sortOrder.Add(nps.PropTags[7], SortFlags.Ascend);
            MrsTracer.Service.Debug("Searching for MRs to Rehome...", new object[0]);
            Restriction restriction = Restriction.And(new Restriction[]
            {
                Restriction.EQ(nps.PropTags[4], false),
                Restriction.EQ(nps.PropTags[20], true)
            });

            MrsTracer.Service.Debug("Searching for MRs to Suspend...", new object[0]);
            base.ProcessJobsInBatches(restriction, false, sortOrder, contentsTable, systemMbx, null);
            Restriction restriction2 = Restriction.And(new Restriction[]
            {
                Restriction.BitMaskNonZero(nps.PropTags[10], 256),
                Restriction.EQ(nps.PropTags[4], false),
                Restriction.EQ(nps.PropTags[20], false),
                Restriction.NE(nps.PropTags[0], RequestStatus.Failed),
                Restriction.NE(nps.PropTags[0], RequestStatus.Suspended),
                Restriction.NE(nps.PropTags[0], RequestStatus.AutoSuspended),
                Restriction.NE(nps.PropTags[0], RequestStatus.Completed),
                Restriction.NE(nps.PropTags[0], RequestStatus.CompletedWithWarning)
            });

            base.ProcessJobsInBatches(restriction2, false, sortOrder, contentsTable, systemMbx, null);
            MrsTracer.Service.Debug("Searching for MRs to Resume...", new object[0]);
            Restriction restriction3 = Restriction.And(new Restriction[]
            {
                Restriction.BitMaskZero(nps.PropTags[10], 256),
                Restriction.EQ(nps.PropTags[4], false),
                Restriction.EQ(nps.PropTags[20], false),
                Restriction.Or(new Restriction[]
                {
                    Restriction.EQ(nps.PropTags[0], RequestStatus.Failed),
                    Restriction.EQ(nps.PropTags[0], RequestStatus.Suspended),
                    Restriction.EQ(nps.PropTags[0], RequestStatus.AutoSuspended)
                })
            });

            base.ProcessJobsInBatches(restriction3, false, sortOrder, contentsTable, systemMbx, null);
            SortOrder sort   = new SortOrder(nps.PropTags[13], SortFlags.Ascend);
            DateTime  utcNow = DateTime.UtcNow;

            MrsTracer.Service.Debug("Searching for Completed MRs to clean up...", new object[0]);
            Restriction restriction4 = Restriction.And(new Restriction[]
            {
                Restriction.EQ(nps.PropTags[20], false),
                Restriction.EQ(nps.PropTags[4], false),
                Restriction.EQ(nps.PropTags[0], RequestStatus.Completed),
                Restriction.NE(nps.PropTags[13], SystemMailboxLightJobs.defaultDoNotPickUntil)
            });

            base.ProcessJobsInBatches(restriction4, false, sort, contentsTable, systemMbx, (MoveJob moveJob) => moveJob.DoNotPickUntilTimestamp > utcNow);
        }
예제 #15
0
        internal static List <MoveHistoryEntryInternal> LoadMoveHistory(MapiStore mailbox)
        {
            MrsTracer.Common.Function("MoveHistoryEntryInternal.LoadMoveHistory", new object[0]);
            List <MoveHistoryEntryInternal> list = new List <MoveHistoryEntryInternal>();

            using (MapiFolder mapiFolder = MapiUtils.OpenFolderUnderRoot(mailbox, MoveHistoryEntryInternal.MHEFolderName, false))
            {
                if (mapiFolder == null)
                {
                    return(list);
                }
                using (MapiTable contentsTable = mapiFolder.GetContentsTable(ContentsTableFlags.DeferredErrors))
                {
                    PropValue[][] array = MapiUtils.QueryAllRows(contentsTable, null, new PropTag[]
                    {
                        PropTag.EntryId
                    });
                    foreach (PropValue[] array3 in array)
                    {
                        byte[] bytes   = array3[0].GetBytes();
                        string subject = string.Format("MoveHistoryEntry {0}", TraceUtils.DumpEntryId(bytes));
                        MoveObjectInfo <MoveHistoryEntryInternal> moveObjectInfo = new MoveObjectInfo <MoveHistoryEntryInternal>(Guid.Empty, mailbox, bytes, MoveHistoryEntryInternal.MHEFolderName, MoveHistoryEntryInternal.MHEMessageClass, subject, null);
                        using (moveObjectInfo)
                        {
                            MoveHistoryEntryInternal moveHistoryEntryInternal = null;
                            try
                            {
                                moveHistoryEntryInternal = moveObjectInfo.ReadObject(ReadObjectFlags.DontThrowOnCorruptData);
                            }
                            catch (MailboxReplicationPermanentException ex)
                            {
                                MrsTracer.Common.Warning("Failed to read move history entry: {0}", new object[]
                                {
                                    ex.ToString()
                                });
                            }
                            if (moveHistoryEntryInternal != null)
                            {
                                list.Add(moveHistoryEntryInternal);
                            }
                            else if (moveObjectInfo.CreationTimestamp < DateTime.UtcNow - TimeSpan.FromDays(365.0))
                            {
                                MrsTracer.Common.Warning("Removing old corrupt MHEI entry {0}", new object[]
                                {
                                    TraceUtils.DumpEntryId(bytes)
                                });
                                moveObjectInfo.DeleteMessage();
                            }
                        }
                    }
                }
            }
            list.Sort();
            return(list);
        }
        internal override void InternalProcessRecord()
        {
            base.InternalProcessRecord();
            if (base.Task.MonitoringContext && !this.IsFirstActiveMdbLocallyMounted())
            {
                base.AddInformationMonitoringEvent(2004, Strings.CrossPremiseServerNotSelected(base.SourceMailboxServer.Name));
                return;
            }
            List <SmtpAddress> siteEgressTargets = this.GetSiteEgressTargets();

            if (siteEgressTargets.Count <SmtpAddress>() == 0)
            {
                base.AddWarningMonitoringEvent(2003, Strings.CrossPremiseNoEgressTargets(base.SourceMailboxServer.Name));
                base.Task.WriteWarning(Strings.CrossPremiseNoEgressTargets(base.SourceMailboxServer.Name));
                return;
            }
            ADSystemMailbox adsystemMailbox = this.localSystemMailbox as ADSystemMailbox;

            using (MapiStore mapiStore = MapiStore.OpenMailbox(base.SourceMailboxServer.Fqdn, this.localSystemMailbox.LegacyExchangeDN, adsystemMailbox.ExchangeGuid, adsystemMailbox.Database.ObjectGuid, this.localSystemMailbox.Name, null, null, ConnectFlag.UseAdminPrivilege | ConnectFlag.UseSeparateConnection, OpenStoreFlag.UseAdminPrivilege | OpenStoreFlag.TakeOwnership | OpenStoreFlag.MailboxGuid, CultureInfo.InvariantCulture, null, "Client=Management;Action=CrossPremiseTestMailFlow", null))
            {
                using (MapiFolder rootFolder = mapiStore.GetRootFolder())
                {
                    using (MapiFolder inboxFolder = mapiStore.GetInboxFolder())
                    {
                        using (MapiFolder mapiFolder = rootFolder.CreateFolder("Cross Premise", "The folder for cross premise mailflow monitoring.", true))
                        {
                            if (base.Task.MonitoringContext)
                            {
                                this.MatchCrossPremiseMessages(inboxFolder, mapiFolder, this.localSystemMailbox.WindowsEmailAddress, siteEgressTargets);
                                using (List <SmtpAddress> .Enumerator enumerator = siteEgressTargets.GetEnumerator())
                                {
                                    while (enumerator.MoveNext())
                                    {
                                        SmtpAddress smtpAddress = enumerator.Current;
                                        string      subject     = string.Format("{0}{{{1}}}", "CrossPremiseMailFlowMonitoring-", Guid.NewGuid());
                                        TestMailFlowHelper.CreateAndSubmitMessage(mapiFolder, this.localSystemMailbox.Name, smtpAddress.ToString(), subject, false);
                                    }
                                    goto IL_238;
                                }
                            }
                            Dictionary <string, string> dictionary = new Dictionary <string, string>();
                            ExDateTime utcNow = ExDateTime.UtcNow;
                            foreach (SmtpAddress smtpAddress2 in siteEgressTargets)
                            {
                                string text = string.Format("{0}{{{1}}}", "CrossPremiseMailFlowMonitoring-", Guid.NewGuid());
                                TestMailFlowHelper.CreateAndSubmitMessage(mapiFolder, this.localSystemMailbox.Name, smtpAddress2.ToString(), text, true);
                                dictionary[text] = smtpAddress2.ToString();
                            }
                            this.WaitAndProcessProbeResponses(inboxFolder, this.localSystemMailbox.Name, dictionary, utcNow);
                            IL_238 :;
                        }
                    }
                }
            }
        }
예제 #17
0
        private MessageSearcher CreateMessageSearcher(SearchTestResult result)
        {
            if (result == null)
            {
                throw new ArgumentNullException("result");
            }
            Exception       ex      = null;
            MessageSearcher result2 = null;

            try
            {
                this.monitor.AddMonitoringEvent(result, Strings.TestSearchGetMapiStore(result.Mailbox));
                MapiStore mapiStore = MapiStore.OpenMailbox(result.Server, result.UserLegacyExchangeDN, result.MailboxGuid, result.DatabaseGuid, null, null, null, ConnectFlag.UseAdminPrivilege | ConnectFlag.UseSeparateConnection, OpenStoreFlag.UseAdminPrivilege | OpenStoreFlag.TakeOwnership | OpenStoreFlag.MailboxGuid, CultureInfo.InvariantCulture, null, "Client=Management;Action=Test-Search", null);
                if (mapiStore != null)
                {
                    result2 = new MessageSearcher(mapiStore, result, this.monitor, this.threadExit);
                }
                else
                {
                    result.SetErrorTestResult(EventId.MapiStoreError, Strings.TestSearchMapiStoreError(result.Mailbox, result.Database));
                }
            }
            catch (ADTransientException ex2)
            {
                ex = ex2;
            }
            catch (ADExternalException ex3)
            {
                ex = ex3;
            }
            catch (MapiExceptionNotFound mapiExceptionNotFound)
            {
                ex = mapiExceptionNotFound;
            }
            catch (MapiPermanentException ex4)
            {
                ex = ex4;
            }
            catch (MapiRetryableException ex5)
            {
                ex = ex5;
            }
            finally
            {
                if (ex is ADTransientException || ex is ADExternalException)
                {
                    result.SetErrorTestResult(EventId.ADError, Strings.TestSearchADError(ex.Message));
                }
                if (ex is MapiExceptionNotFound || ex is MapiPermanentException || ex is MapiRetryableException)
                {
                    this.HandleExceptionInTestThread(result.DatabaseGuid, EventId.MapiError, result, ex);
                }
            }
            return(result2);
        }
예제 #18
0
 public MoveObjectInfo(Guid mdbGuid, MapiStore store, byte[] messageId, string folderName, string messageClass, string subject, byte[] searchKey)
 {
     this.store        = store;
     this.MessageId    = messageId;
     this.FolderId     = null;
     this.message      = null;
     this.folderName   = folderName;
     this.messageClass = messageClass;
     this.searchKey    = searchKey;
     this.subject      = subject;
 }
예제 #19
0
 private static void PerformLightJobAction(MapiStore systemMailbox, RequestStatisticsBase requestJobStats)
 {
     CommonUtils.CatchKnownExceptions(delegate
     {
         bool flag = false;
         LightJobBase lightJobBase;
         if (QuarantinedJobs.Contains(requestJobStats.IdentifyingGuid))
         {
             lightJobBase = new QuarantineJob(requestJobStats.IdentifyingGuid, requestJobStats.WorkItemQueueMdb.ObjectGuid, systemMailbox, requestJobStats.MessageId);
         }
         else if (requestJobStats.ShouldRehomeRequest)
         {
             lightJobBase = new RehomeJob(requestJobStats.IdentifyingGuid, requestJobStats.RequestQueue, requestJobStats.OptimalRequestQueue, systemMailbox, requestJobStats.MessageId);
         }
         else if (requestJobStats.ShouldClearRehomeRequest)
         {
             lightJobBase = new ClearRehomeJob(requestJobStats.IdentifyingGuid, requestJobStats.WorkItemQueueMdb.ObjectGuid, systemMailbox, requestJobStats.MessageId);
         }
         else if (requestJobStats.ShouldSuspendRequest)
         {
             lightJobBase = new SuspendJob(requestJobStats.IdentifyingGuid, requestJobStats.WorkItemQueueMdb.ObjectGuid, systemMailbox, requestJobStats.MessageId);
         }
         else
         {
             lightJobBase = new ResumeJob(requestJobStats.IdentifyingGuid, requestJobStats.WorkItemQueueMdb.ObjectGuid, systemMailbox, requestJobStats.MessageId);
             flag         = true;
         }
         using (lightJobBase)
         {
             lightJobBase.Run();
             if (flag)
             {
                 MRSService.Tickle(requestJobStats.IdentifyingGuid, requestJobStats.WorkItemQueueMdb.ObjectGuid, MoveRequestNotification.Created);
             }
         }
     }, delegate(Exception failure)
     {
         LocalizedString localizedString = CommonUtils.FullExceptionMessage(failure);
         MrsTracer.Service.Debug("Unexpected failure occurred trying to perform a light pipe action on MoveJob '{0}' from queue '{1}', skipping it. {2}", new object[]
         {
             requestJobStats.RequestGuid,
             requestJobStats.RequestQueue,
             localizedString
         });
         MailboxReplicationService.LogEvent(MRSEventLogConstants.Tuple_UnableToProcessRequest, new object[]
         {
             requestJobStats.RequestGuid.ToString(),
             requestJobStats.WorkItemQueueMdb.ObjectGuid.ToString(),
             localizedString
         });
     });
 }
예제 #20
0
 void IReportHelper.Load(ReportData report, MapiStore storeToUse)
 {
     using (MoveObjectInfo <T> moveObjectInfo = new MoveObjectInfo <T>(Guid.Empty, storeToUse, report.MessageId, this.reportFolderName, this.reportMessageClass, this.CreateMessageSubject(report), this.CreateMessageSearchKey(report)))
     {
         if (!moveObjectInfo.OpenMessage())
         {
             report.Entries = null;
         }
         else
         {
             report.MessageId = moveObjectInfo.MessageId;
             report.Entries   = this.DeserializeEntries(moveObjectInfo, false);
         }
     }
 }
예제 #21
0
 void IReportHelper.Delete(ReportData report, MapiStore storeToUse)
 {
     MapiUtils.RetryOnObjectChanged(delegate
     {
         using (MoveObjectInfo <T> moveObjectInfo = new MoveObjectInfo <T>(Guid.Empty, storeToUse, report.MessageId, this.reportFolderName, this.reportMessageClass, this.CreateMessageSubject(report), this.CreateMessageSearchKey(report)))
         {
             moveObjectInfo.OpenMessage();
             if (moveObjectInfo.MessageFound)
             {
                 moveObjectInfo.DeleteMessage();
             }
         }
     });
     report.MessageId = null;
 }
예제 #22
0
        protected override ICollection <ServiceIssue> RunFullIssueScan()
        {
            ICollection <ServiceIssue> collection = new List <ServiceIssue>();

            foreach (Guid mdbGuid in MapiUtils.GetDatabasesOnThisServer())
            {
                using (new DatabaseSettingsContext(mdbGuid, null).Activate())
                {
                    try
                    {
                        DatabaseInformation databaseInformation = MapiUtils.FindServerForMdb(mdbGuid, null, null, FindServerFlags.None);
                        string databaseName = databaseInformation.DatabaseName;
                        if (!databaseInformation.IsOnThisServer)
                        {
                            return(null);
                        }
                        using (MapiStore systemMailbox = MapiUtils.GetSystemMailbox(mdbGuid, false))
                        {
                            using (MapiFolder requestJobsFolder = RequestJobXML.GetRequestJobsFolder(systemMailbox))
                            {
                                using (MapiTable contentsTable = requestJobsFolder.GetContentsTable(ContentsTableFlags.DeferredErrors))
                                {
                                    if (contentsTable.GetRowCount() > 0)
                                    {
                                        RequestJobNamedPropertySet requestJobNamedPropertySet = RequestJobNamedPropertySet.Get(systemMailbox);
                                        contentsTable.SetColumns(requestJobNamedPropertySet.PropTags);
                                        Restriction    restriction = Restriction.GT(requestJobNamedPropertySet.PropTags[23], ConfigBase <MRSConfigSchema> .GetConfig <int>("PoisonLimit"));
                                        List <MoveJob> allMoveJobs = SystemMailboxJobs.GetAllMoveJobs(restriction, null, contentsTable, mdbGuid, null);
                                        if (allMoveJobs != null)
                                        {
                                            foreach (MoveJob job in allMoveJobs)
                                            {
                                                collection.Add(new MRSPoisonedJobIssue(job));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (LocalizedException lastScanError)
                    {
                        base.LastScanError = lastScanError;
                    }
                }
            }
            return(collection);
        }
예제 #23
0
 internal override void Delete()
 {
     if (ObjectState.Deleted == base.ObjectState)
     {
         throw new MapiInvalidOperationException(Strings.ExceptionObjectStateInvalid(base.ObjectState.ToString()));
     }
     if (base.ObjectState == ObjectState.New)
     {
         base.MarkAsDeleted();
         return;
     }
     Folder.CheckRequirementsToContinue(this.Identity, base.MapiSession);
     ExTraceGlobals.FolderTracer.TraceDebug <FolderId, string>((long)this.GetHashCode(), "To Delete Folder '{0}' on server '{1}'.", this.Identity, base.MapiSession.ServerName);
     base.EnableDisposeTracking();
     using (MapiStore messageStore = this.GetMessageStore())
     {
         using (MapiFolder mapiFolder = this.GetMapiFolder(messageStore))
         {
             try
             {
                 this.DetectDisallowedModification(messageStore);
                 bool flag = false;
                 this.TryTestHasSubFolders(mapiFolder, out flag);
                 try
                 {
                     using (MapiFolder parentFolder = this.GetParentFolder(messageStore))
                     {
                         parentFolder.DeleteFolder((byte[])this.Identity.MapiEntryId);
                     }
                 }
                 catch (MapiExceptionPartialCompletion innerException)
                 {
                     if (flag)
                     {
                         throw new MapiPartialCompletionException(Strings.ErrorRemovalPartialCompleted(this.Identity.ToString()), innerException);
                     }
                     throw;
                 }
             }
             finally
             {
                 base.Dispose();
             }
         }
     }
     base.ResetChangeTracking();
     base.MarkAsDeleted();
 }
예제 #24
0
        public static FolderHierarchyChangeDetector.MailboxChangesManifest RunICSManifestSync(bool catchup, FolderHierarchyChangeDetector.SyncHierarchyManifestState hierState, MailboxSession mailboxSession, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            syncLogger.TraceDebug <SmtpAddress, bool>(ExTraceGlobals.SyncProcessTracer, 0L, "[FolderHierarchyChangeDetector.RunICSManifestSync] Checking for folder hierarhcy changes for Mailbox: {0}.  Catchup? {1}", mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress, catchup);
            MapiStore _ContainedMapiStore = mailboxSession.__ContainedMapiStore;

            FolderHierarchyChangeDetector.MailboxChangesManifest    mailboxChangesManifest = new FolderHierarchyChangeDetector.MailboxChangesManifest();
            FolderHierarchyChangeDetector.ManifestHierarchyCallback iMapiManifestCallback  = new FolderHierarchyChangeDetector.ManifestHierarchyCallback(catchup, mailboxChangesManifest);
            try
            {
                using (MapiFolder ipmSubtreeFolder = _ContainedMapiStore.GetIpmSubtreeFolder())
                {
                    SyncConfigFlags syncConfigFlags = SyncConfigFlags.ManifestHierReturnDeletedEntryIds;
                    int             serverVersion   = mailboxSession.MailboxOwner.MailboxInfo.Location.ServerVersion;
                    if ((serverVersion >= Server.E14MinVersion && serverVersion < Server.E15MinVersion) || (long)serverVersion >= FolderHierarchyChangeDetector.E15MinVersionSupportsOnlySpecifiedPropsForHierarchy)
                    {
                        syncConfigFlags |= SyncConfigFlags.OnlySpecifiedProps;
                    }
                    using (MapiHierarchyManifestEx mapiHierarchyManifestEx = ipmSubtreeFolder.CreateExportHierarchyManifestEx(syncConfigFlags, hierState.IdsetGiven, hierState.CnsetSeen, iMapiManifestCallback, FolderHierarchyChangeDetector.PropsToFetch, null))
                    {
                        while (mapiHierarchyManifestEx.Synchronize() != ManifestStatus.Done)
                        {
                        }
                        byte[] idSetGiven;
                        byte[] cnetSeen;
                        mapiHierarchyManifestEx.GetState(out idSetGiven, out cnetSeen);
                        syncLogger.TraceDebug <SmtpAddress, int, int>(ExTraceGlobals.SyncProcessTracer, 0L, "[FolderHierarchyChangeDetector.RunICSManifestSync] Updating ICS state for mailbox: '{0}'.  Change Count: {1}, Delete Count: {2}", mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress, mailboxChangesManifest.ChangedFolders.Count, mailboxChangesManifest.DeletedFolders.Count);
                        hierState.Update(idSetGiven, cnetSeen);
                    }
                }
            }
            catch (MapiPermanentException arg)
            {
                syncLogger.TraceDebug <SmtpAddress, MapiPermanentException>(ExTraceGlobals.SyncProcessTracer, 0L, "[FolderHierarchyChangeDetector.RunICSManifestSync] Caught MapiPermanentException when determining folder ICS changes for mailbox: {0}.  Exception: {1}", mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress, arg);
                return(null);
            }
            catch (MapiRetryableException arg2)
            {
                syncLogger.TraceDebug <SmtpAddress, MapiRetryableException>(ExTraceGlobals.SyncProcessTracer, 0L, "[FolderHierarchyChangeDetector.RunICSManifestSync] Caught MapiRetryableException when determining folder ICS changes for mailbox: {0}.  Exception: {1}", mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress, arg2);
                return(null);
            }
            return(mailboxChangesManifest);
        }
예제 #25
0
        internal static List <MoveHistoryEntryInternal> LoadMoveHistory(Guid mailboxGuid, Guid mdbGuid, UserMailboxFlags flags)
        {
            List <MoveHistoryEntryInternal> result;

            using (MapiStore userMailbox = MapiUtils.GetUserMailbox(mailboxGuid, mdbGuid, flags))
            {
                if (userMailbox == null)
                {
                    result = null;
                }
                else
                {
                    result = MoveHistoryEntryInternal.LoadMoveHistory(userMailbox);
                }
            }
            return(result);
        }
예제 #26
0
        public static MapiFolder OpenFolderUnderRoot(MapiStore mailbox, string folderName, bool createIfMissing)
        {
            MapiFolder result;

            using (MapiFolder nonIpmSubtreeFolder = mailbox.GetNonIpmSubtreeFolder())
            {
                MapiFolder mapiFolder = null;
                try
                {
                    mapiFolder = nonIpmSubtreeFolder.OpenSubFolderByName(folderName);
                }
                catch (MapiExceptionNotFound)
                {
                }
                if (mapiFolder == null && createIfMissing)
                {
                    MrsTracer.Common.Debug("Folder '{0}' does not exist, creating it.", new object[]
                    {
                        folderName
                    });
                    try
                    {
                        mapiFolder = nonIpmSubtreeFolder.CreateFolder(folderName, null, false);
                        MrsTracer.Common.Debug("Created '{0}' folder.", new object[]
                        {
                            folderName
                        });
                    }
                    catch (MapiExceptionCollision)
                    {
                        MrsTracer.Common.Debug("Somebody beat us to creating the folder. Will attempt to open it.", new object[0]);
                    }
                    if (mapiFolder == null)
                    {
                        mapiFolder = nonIpmSubtreeFolder.OpenSubFolderByName(folderName);
                        MrsTracer.Common.Debug("Opened '{0}' folder.", new object[]
                        {
                            folderName
                        });
                    }
                }
                result = mapiFolder;
            }
            return(result);
        }
예제 #27
0
        internal static MapiFolder GetFolderByPath(MapiStore mapiStore, MapiFolderPath folderPath)
        {
            MapiFolder mapiFolder = null;
            MapiFolder folderByPath;

            try
            {
                folderByPath = Folder.GetFolderByPath(mapiStore, folderPath, out mapiFolder);
            }
            finally
            {
                if (mapiFolder != null)
                {
                    mapiFolder.Dispose();
                }
            }
            return(folderByPath);
        }
예제 #28
0
 internal MessageSearcher(MapiStore store, SearchTestResult searchResult, MonitorHelper monitor, StopClass threadExit)
 {
     if (store == null)
     {
         throw new ArgumentNullException("store");
     }
     if (searchResult == null)
     {
         throw new ArgumentNullException("searchResult");
     }
     this.store        = store;
     this.searchResult = searchResult;
     this.databaseGuid = searchResult.DatabaseGuid;
     this.searchString = DateTime.UtcNow.Ticks.ToString();
     this.monitor      = monitor;
     this.threadExit   = threadExit;
     this.ReadSleepTestHook();
 }
예제 #29
0
        internal static MapiFolder RetrieveMapiFolder(MapiStore store, FolderId identity)
        {
            MapiFolder mapiFolder = null;
            MapiFolder result;

            try
            {
                FolderId folderId = null;
                result = Folder.RetrieveMapiFolder(store, identity, ref mapiFolder, null, out folderId);
            }
            finally
            {
                if (mapiFolder != null)
                {
                    mapiFolder.Dispose();
                }
            }
            return(result);
        }
예제 #30
0
 public static void StartMapiDeadSessionChecking(MapiStore store, string mailboxId)
 {
     if (store == null)
     {
         return;
     }
     CommonUtils.ProcessKnownExceptions(delegate
     {
         store.Advise(null, AdviseFlags.Extended, new MapiNotificationHandler(MapiUtils.OnDroppedMapiSessionNotify), NotificationCallbackMode.Async, MapiNotificationClientFlags.AutoDisposeNotificationHandles);
         store.Advise(null, AdviseFlags.ConnectionDropped, new MapiNotificationHandler(MapiUtils.OnDroppedMapiSessionNotify), NotificationCallbackMode.Async, MapiNotificationClientFlags.AutoDisposeNotificationHandles);
     }, delegate(Exception ex)
     {
         MrsTracer.Provider.Warning("Failed to subscribe to Store session dead notification for {0}. Failure: {1}.", new object[]
         {
             mailboxId,
             CommonUtils.FullExceptionMessage(ex)
         });
         return(true);
     });
 }