protected override void InternalProcessRecord()
 {
     try
     {
         using (PublicFolderDataProvider publicFolderDataProvider = new PublicFolderDataProvider(this.ConfigurationSession, "Disable-MailPublicFolder", Guid.Empty))
         {
             if (!string.IsNullOrWhiteSpace(base.DataObject.EntryId))
             {
                 StoreObjectId storeObjectId = StoreObjectId.FromHexEntryId(base.DataObject.EntryId);
                 PublicFolder  publicFolder  = (PublicFolder)publicFolderDataProvider.Read <PublicFolder>(new PublicFolderId(storeObjectId));
                 publicFolder.MailEnabled = false;
                 publicFolder.ProxyGuid   = Guid.Empty.ToByteArray();
                 publicFolderDataProvider.Save(publicFolder);
             }
         }
     }
     catch (AccessDeniedException exception)
     {
         base.WriteError(exception, ExchangeErrorCategory.Authorization, this.Identity);
     }
     catch (ObjectNotFoundException ex)
     {
         this.WriteWarning(Strings.FailedToLocatePublicFolder(this.Identity.ToString(), ex.ToString()));
     }
     base.InternalProcessRecord();
 }
Exemple #2
0
 internal static MailboxFolderIdParameter GetMailboxFolderIdParameterForPublicFolder(IConfigurationSession configurationSession, PublicFolderIdParameter publicFolderIdParameter, Guid publicFolderMailboxGuid, ADUser publicFolderMailboxUser, OrganizationId organizationId, Task.ErrorLoggerDelegate errorHandler)
 {
     if (publicFolderMailboxUser == null)
     {
         publicFolderMailboxUser = PublicFolderPermissionTaskHelper.GetPublicFolderHierarchyMailboxUser(configurationSession);
         if (publicFolderMailboxUser == null)
         {
             errorHandler(new LocalizedException(PublicFolderSession.GetNoPublicFoldersProvisionedError(configurationSession.SessionSettings.CurrentOrganizationId)), ExchangeErrorCategory.Client, publicFolderIdParameter);
         }
     }
     if (publicFolderIdParameter.PublicFolderId.StoreObjectId == null)
     {
         using (PublicFolderDataProvider publicFolderDataProvider = new PublicFolderDataProvider(configurationSession, "*-PublicFolderClientPermission", publicFolderMailboxGuid))
         {
             StoreObjectId storeObjectId = publicFolderDataProvider.ResolveStoreObjectIdFromFolderPath(publicFolderIdParameter.PublicFolderId.MapiFolderPath);
             if (storeObjectId == null)
             {
                 errorHandler(new LocalizedException(Strings.ErrorPublicFolderNotFound(publicFolderIdParameter.ToString())), ExchangeErrorCategory.Client, publicFolderIdParameter);
             }
             publicFolderIdParameter.PublicFolderId.StoreObjectId = storeObjectId;
         }
     }
     if (publicFolderIdParameter.Organization != null)
     {
         publicFolderIdParameter.PublicFolderId.OrganizationId = organizationId;
     }
     return(new MailboxFolderIdParameter(publicFolderIdParameter, publicFolderMailboxUser));
 }
        private Guid GetSourceMailboxGuid()
        {
            Guid guid = Guid.Empty;

            base.WriteVerbose(Strings.DetermineSourceMailbox);
            using (PublicFolderDataProvider publicFolderDataProvider = new PublicFolderDataProvider(this.ConfigurationSession, "New-PublicFolderMoveRequest", Guid.Empty))
            {
                foreach (PublicFolderIdParameter publicFolderIdParameter in this.Folders)
                {
                    PublicFolder publicFolder = (PublicFolder)base.GetDataObject <PublicFolder>(publicFolderIdParameter, publicFolderDataProvider, null, new LocalizedString?(Strings.ErrorPublicFolderNotFound(publicFolderIdParameter.ToString())), new LocalizedString?(Strings.ErrorPublicFolderNotUnique(publicFolderIdParameter.ToString())));
                    if (publicFolderDataProvider.PublicFolderSession.IsWellKnownFolder(publicFolder.InternalFolderIdentity.ObjectId))
                    {
                        base.WriteError(new RecipientTaskException(Strings.ErrorCannotMoveWellKnownPublicFolders), ErrorCategory.InvalidArgument, publicFolderIdParameter);
                    }
                    if (guid == Guid.Empty)
                    {
                        guid = publicFolder.ContentMailboxGuid;
                    }
                    else if (guid != publicFolder.ContentMailboxGuid)
                    {
                        base.WriteError(new RecipientTaskException(Strings.ErrorCannotMovePublicFoldersFromDifferentSourceMailbox), ErrorCategory.InvalidArgument, publicFolderIdParameter);
                    }
                    if (publicFolder.EntryId == null || publicFolder.DumpsterEntryId == null)
                    {
                        base.WriteError(new RecipientTaskException(Strings.ErrorCannotMovePublicFoldersWithNullEntryId), ErrorCategory.InvalidData, publicFolderIdParameter);
                    }
                    this.folderList.Add(new MoveFolderInfo(publicFolder.EntryId, false));
                    this.folderList.Add(new MoveFolderInfo(publicFolder.DumpsterEntryId, false));
                }
            }
            return(guid);
        }
        private bool IsValidToUpdateEntryId(string entryId, out ADObjectId contentMailbox)
        {
            contentMailbox = null;
            if (string.IsNullOrEmpty(entryId))
            {
                return(false);
            }
            if (StringComparer.OrdinalIgnoreCase.Equals(entryId, this.DataObject.EntryId))
            {
                return(false);
            }
            StoreObjectId storeObjectId = null;

            try
            {
                storeObjectId = StoreObjectId.FromHexEntryId(entryId);
            }
            catch (FormatException innerException)
            {
                base.WriteError(new RecipientTaskException(Strings.ErrorSetMailPublicFolderEntryIdWrongFormat(entryId), innerException), ExchangeErrorCategory.Client, this.DataObject.Identity);
            }
            using (PublicFolderDataProvider publicFolderDataProvider = new PublicFolderDataProvider(this.ConfigurationSession, "Set-MailPublicFolder", Guid.Empty))
            {
                Guid exchangeGuid = Guid.Empty;
                try
                {
                    PublicFolder publicFolder = (PublicFolder)publicFolderDataProvider.Read <PublicFolder>(new PublicFolderId(storeObjectId));
                    exchangeGuid = publicFolder.ContentMailboxGuid;
                }
                catch (ObjectNotFoundException innerException2)
                {
                    base.WriteError(new RecipientTaskException(Strings.ErrorSetMailPublicFolderEntryIdNotExist(entryId), innerException2), ExchangeErrorCategory.Client, this.DataObject.Identity);
                }
                ADRecipient adrecipient = base.TenantGlobalCatalogSession.FindByExchangeGuid(exchangeGuid);
                if (adrecipient != null)
                {
                    contentMailbox = adrecipient.Id;
                }
                if (string.IsNullOrEmpty(this.DataObject.EntryId))
                {
                    return(true);
                }
                StoreObjectId storeObjectId2 = StoreObjectId.FromHexEntryId(this.DataObject.EntryId);
                try
                {
                    PublicFolder publicFolder2 = (PublicFolder)publicFolderDataProvider.Read <PublicFolder>(new PublicFolderId(storeObjectId2));
                }
                catch (ObjectNotFoundException)
                {
                    return(true);
                }
                if (ArrayComparer <byte> .Comparer.Equals(storeObjectId2.LongTermFolderId, storeObjectId.LongTermFolderId))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #5
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 #6
0
        // Token: 0x06000D66 RID: 3430 RVA: 0x00028850 File Offset: 0x00026A50
        internal sealed override IEnumerable <T> GetObjects <T>(ADObjectId rootId, IDirectorySession session, IDirectorySession subTreeSession, OptionalIdentityData optionalData, out LocalizedString?notFoundReason)
        {
            notFoundReason = null;
            bool flag = false;

            if (base.InternalADObjectId == null && this.folderId != null)
            {
                IConfigurationSession tenantOrTopologyConfigurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(session.ConsistencyMode, session.SessionSettings, 205, "GetObjects", "f:\\15.00.1497\\sources\\dev\\Configuration\\src\\ObjectModel\\IdentityParameter\\RecipientParameters\\MailPublicFolderIdParameter.cs");
                using (PublicFolderDataProvider publicFolderDataProvider = new PublicFolderDataProvider(tenantOrTopologyConfigurationSession, "resolve-MailPublicFolderIdParameter", Guid.Empty))
                {
                    PublicFolder publicFolder = (PublicFolder)publicFolderDataProvider.Read <PublicFolder>(this.folderId);
                    if (publicFolder == null)
                    {
                        return(new List <T>());
                    }
                    flag = true;
                    if (!publicFolder.MailEnabled)
                    {
                        notFoundReason = new LocalizedString?(Strings.ErrorPublicFolderMailDisabled(this.folderId.ToString()));
                        return(new List <T>());
                    }
                    if (publicFolder.ProxyGuid == null)
                    {
                        notFoundReason = new LocalizedString?(Strings.ErrorPublicFolderGeneratingProxy(this.folderId.ToString()));
                        return(new List <T>());
                    }
                    this.Initialize(new ADObjectId(publicFolder.ProxyGuid));
                }
            }
            IEnumerable <T>       objects = base.GetObjects <T>(rootId, session, subTreeSession, optionalData, out notFoundReason);
            EnumerableWrapper <T> wrapper = EnumerableWrapper <T> .GetWrapper(objects);

            if (!wrapper.HasElements() && flag)
            {
                notFoundReason = new LocalizedString?(Strings.ErrorPublicFolderMailDisabled(this.folderId.ToString()));
            }
            return(wrapper);
        }
        protected override IConfigurable PrepareDataObject()
        {
            MailboxDiscoverySearch mailboxDiscoverySearch = (MailboxDiscoverySearch)base.PrepareDataObject();

            string[] paramNames = new string[]
            {
                "AllSourceMailboxes",
                "AllPublicFolderSources",
                "PublicFolderSources"
            };
            ScopeSet scopeSet = base.ScopeSet;
            bool     flag     = false;

            if (scopeSet == null)
            {
                scopeSet = ScopeSet.GetOrgWideDefaultScopeSet(base.CurrentOrganizationId);
            }
            if (scopeSet != null)
            {
                ADRawEntry executingUser = base.ExchangeRunspaceConfig.ExecutingUser;
                if (executingUser != null)
                {
                    flag = base.ExchangeRunspaceConfig.IsCmdletAllowedInScope("Set-MailboxSearch", paramNames, executingUser, ScopeLocation.RecipientWrite);
                }
                else
                {
                    flag = base.ExchangeRunspaceConfig.IsCmdletAllowedInScope("Set-MailboxSearch", paramNames, scopeSet);
                }
            }
            if (flag && mailboxDiscoverySearch.Version == SearchObjectVersion.Original && (mailboxDiscoverySearch.Sources == null || mailboxDiscoverySearch.Sources.Count == 0) && (mailboxDiscoverySearch.PublicFolderSources == null || mailboxDiscoverySearch.PublicFolderSources.Count == 0) && !mailboxDiscoverySearch.AllSourceMailboxes && !mailboxDiscoverySearch.AllPublicFolderSources)
            {
                this.AllSourceMailboxes = true;
            }
            if (flag)
            {
                mailboxDiscoverySearch.Version = SearchObjectVersion.SecondVersion;
            }
            if (base.Fields.IsModified(SearchObjectSchema.TargetMailbox.Name))
            {
                if (this.TargetMailbox != null)
                {
                    try
                    {
                        this.recipientSession.SessionSettings.IncludeInactiveMailbox = false;
                        ADUser aduser = (ADUser)base.GetDataObject <ADUser>(this.TargetMailbox, this.recipientSession, null, new LocalizedString?(Strings.ExceptionUserObjectNotFound(this.TargetMailbox.ToString())), new LocalizedString?(Strings.ExceptionUserObjectAmbiguous));
                        if (aduser.RecipientType != RecipientType.UserMailbox)
                        {
                            base.ThrowTerminatingError(new MailboxSearchTaskException(Strings.ErrorInvalidRecipientType(aduser.ToString(), aduser.RecipientType.ToString())), ErrorCategory.InvalidArgument, SearchObjectSchema.TargetMailbox.Name);
                        }
                        mailboxDiscoverySearch.Target = aduser.LegacyExchangeDN;
                        if (base.ScopeSet != null)
                        {
                            Utils.VerifyIsInScopes(aduser, base.ScopeSet, new Task.TaskErrorLoggingDelegate(base.WriteError));
                        }
                        Utils.VerifyMailboxVersion(aduser, new Task.TaskErrorLoggingDelegate(base.WriteError));
                        goto IL_20B;
                    }
                    finally
                    {
                        if (VariantConfiguration.InvariantNoFlightingSnapshot.Global.MultiTenancy.Enabled)
                        {
                            this.recipientSession.SessionSettings.IncludeInactiveMailbox = true;
                        }
                    }
                }
                mailboxDiscoverySearch.Target = null;
            }
IL_20B:
            if (flag)
            {
                if (base.Fields.IsModified(MailboxDiscoverySearchSchema.AllSourceMailboxes.Name))
                {
                    mailboxDiscoverySearch.AllSourceMailboxes = this.AllSourceMailboxes;
                }
                if (this.AllSourceMailboxes)
                {
                    if (this.SourceMailboxes != null || mailboxDiscoverySearch.Sources != null)
                    {
                        this.WriteWarning(Strings.AllSourceMailboxesParameterOverride("AllSourceMailboxes", "SourceMailboxes"));
                    }
                    this.SourceMailboxes           = null;
                    mailboxDiscoverySearch.Sources = null;
                }
            }
            bool flag2 = base.Fields.IsModified(SearchObjectSchema.SourceMailboxes.Name);

            if (!flag2)
            {
                if (!mailboxDiscoverySearch.IsChanged(MailboxDiscoverySearchSchema.InPlaceHoldEnabled) || !mailboxDiscoverySearch.InPlaceHoldEnabled)
                {
                    goto IL_442;
                }
            }
            try
            {
                if (mailboxDiscoverySearch.InPlaceHoldEnabled)
                {
                    this.recipientSession.SessionSettings.IncludeSoftDeletedObjects = true;
                }
                IEnumerable <RecipientIdParameter> enumerable;
                if (!flag2)
                {
                    if (mailboxDiscoverySearch.Sources != null)
                    {
                        enumerable = from legacyDn in mailboxDiscoverySearch.Sources
                                     select new RecipientIdParameter(legacyDn);
                    }
                    else
                    {
                        enumerable = null;
                    }
                }
                else
                {
                    enumerable = this.SourceMailboxes;
                }
                IEnumerable <RecipientIdParameter> recipientIds        = enumerable;
                MultiValuedProperty <string>       multiValuedProperty = Utils.ConvertSourceMailboxesCollection(recipientIds, mailboxDiscoverySearch.InPlaceHoldEnabled, (RecipientIdParameter recipientId) => base.GetDataObject <ADRecipient>(recipientId, this.recipientSession, null, new LocalizedString?(Strings.ExceptionUserObjectNotFound(recipientId.ToString())), new LocalizedString?(Strings.ExceptionUserObjectAmbiguous)) as ADRecipient, this.recipientSession, new Task.TaskErrorLoggingDelegate(base.WriteError), new Action <LocalizedString>(this.WriteWarning), (LocalizedString locString) => this.Force || base.ShouldContinue(locString)) ?? new MultiValuedProperty <string>();
                mailboxDiscoverySearch.Sources.CopyChangesFrom(multiValuedProperty);
                if (mailboxDiscoverySearch.Sources.Count != multiValuedProperty.Count)
                {
                    mailboxDiscoverySearch.Sources = multiValuedProperty;
                }
                if (base.ScopeSet != null)
                {
                    foreach (string legacyExchangeDN in mailboxDiscoverySearch.Sources)
                    {
                        ADRecipient adrecipient = this.recipientSession.FindByLegacyExchangeDN(legacyExchangeDN);
                        if (adrecipient == null)
                        {
                            base.WriteError(new ObjectNotFoundException(Strings.ExceptionSourceMailboxNotFound(mailboxDiscoverySearch.Target, mailboxDiscoverySearch.Name)), ErrorCategory.InvalidOperation, null);
                        }
                        Utils.VerifyIsInHoldScopes(mailboxDiscoverySearch.InPlaceHoldEnabled, base.ExchangeRunspaceConfig, adrecipient, "Set-MailboxSearch", new Task.TaskErrorLoggingDelegate(base.WriteError));
                        Utils.VerifyIsInScopes(adrecipient, base.ScopeSet, new Task.TaskErrorLoggingDelegate(base.WriteError));
                    }
                }
            }
            finally
            {
                this.recipientSession.SessionSettings.IncludeSoftDeletedObjects = false;
            }
IL_442:
            if (flag)
            {
                if (base.Fields.IsModified(MailboxDiscoverySearchSchema.AllPublicFolderSources.Name))
                {
                    mailboxDiscoverySearch.AllPublicFolderSources = this.AllPublicFolderSources;
                }
                if (this.AllPublicFolderSources)
                {
                    if (this.PublicFolderSources != null)
                    {
                        this.WriteWarning(Strings.AllSourceMailboxesParameterOverride("AllPublicFolderSources", "PublicFolderSources"));
                    }
                    this.PublicFolderSources = null;
                }
                if (base.Fields.IsModified(MailboxDiscoverySearchSchema.PublicFolderSources.Name))
                {
                    string[] array = null;
                    if (this.PublicFolderSources != null && this.PublicFolderSources.Length != 0)
                    {
                        array = new string[this.PublicFolderSources.Length];
                        string action = "Get-PublicFolder";
                        try
                        {
                            using (PublicFolderDataProvider publicFolderDataProvider = new PublicFolderDataProvider(this.ConfigurationSession, action, Guid.Empty))
                            {
                                for (int i = 0; i < this.PublicFolderSources.Length; i++)
                                {
                                    PublicFolder publicFolder = null;
                                    array[i] = this.PublicFolderSources[i].ToString();
                                    try
                                    {
                                        publicFolder = (PublicFolder)publicFolderDataProvider.Read <PublicFolder>(this.PublicFolderSources[i].PublicFolderId);
                                    }
                                    catch (FormatException exception)
                                    {
                                        base.WriteError(exception, ErrorCategory.WriteError, null);
                                    }
                                    if (publicFolder == null)
                                    {
                                        base.WriteError(new MailboxSearchTaskException(Strings.PublicFolderSourcesFolderDoesnotExist(array[i])), ErrorCategory.InvalidArgument, null);
                                    }
                                }
                            }
                        }
                        catch (AccessDeniedException exception2)
                        {
                            base.WriteError(exception2, ErrorCategory.PermissionDenied, mailboxDiscoverySearch.Name);
                        }
                    }
                    mailboxDiscoverySearch.PublicFolderSources = Utils.ConvertCollectionToMultiValedProperty <string, string>(array, (string value, object param) => value, null, new MultiValuedProperty <string>(), new Task.TaskErrorLoggingDelegate(base.WriteError), MailboxDiscoverySearchSchema.PublicFolderSources.Name);
                }
            }
            if (base.Fields.IsModified(SearchObjectSchema.Senders.Name))
            {
                MultiValuedProperty <string> senders = Utils.ConvertCollectionToMultiValedProperty <string, string>(this.Senders, (string value, object param) => value, null, new MultiValuedProperty <string>(), new Task.TaskErrorLoggingDelegate(base.WriteError), SearchObjectSchema.Senders.Name);
                mailboxDiscoverySearch.Senders = senders;
            }
            if (base.Fields.IsModified(SearchObjectSchema.Recipients.Name))
            {
                MultiValuedProperty <string> recipients = Utils.ConvertCollectionToMultiValedProperty <string, string>(this.Recipients, (string value, object param) => value, null, new MultiValuedProperty <string>(), new Task.TaskErrorLoggingDelegate(base.WriteError), SearchObjectSchema.Recipients.Name);
                mailboxDiscoverySearch.Recipients = recipients;
            }
            if (base.Fields.IsModified(SearchObjectSchema.StartDate.Name))
            {
                mailboxDiscoverySearch.StartDate = this.StartDate;
            }
            if (base.Fields.IsModified(SearchObjectSchema.EndDate.Name))
            {
                mailboxDiscoverySearch.EndDate = this.EndDate;
            }
            if (base.Fields.IsModified(SearchObjectSchema.MessageTypes.Name))
            {
                MultiValuedProperty <KindKeyword> messageTypes = Utils.ConvertCollectionToMultiValedProperty <KindKeyword, KindKeyword>(this.MessageTypes, (KindKeyword kind, object param) => kind, null, new MultiValuedProperty <KindKeyword>(), new Task.TaskErrorLoggingDelegate(base.WriteError), SearchObjectSchema.MessageTypes.Name);
                mailboxDiscoverySearch.MessageTypes = messageTypes;
            }
            if (base.Fields.IsModified(SearchObjectSchema.StatusMailRecipients.Name))
            {
                MultiValuedProperty <ADObjectId> multiValuedProperty2 = Utils.ConvertCollectionToMultiValedProperty <RecipientIdParameter, ADObjectId>(this.StatusMailRecipients, new Utils.IdentityToRawIdDelegate <RecipientIdParameter, ADObjectId>(this.ADObjectIdFromRecipientIdParameter), null, new MultiValuedProperty <ADObjectId>(), new Task.TaskErrorLoggingDelegate(base.WriteError), SearchObjectSchema.StatusMailRecipients.Name);
                mailboxDiscoverySearch.StatusMailRecipients.CopyChangesFrom(multiValuedProperty2);
                if (mailboxDiscoverySearch.StatusMailRecipients.Count != multiValuedProperty2.Count)
                {
                    mailboxDiscoverySearch.StatusMailRecipients = multiValuedProperty2;
                }
            }
            if (base.Fields.IsModified(SearchObjectSchema.ManagedBy.Name))
            {
                MultiValuedProperty <ADObjectId> multiValuedProperty3 = Utils.ConvertCollectionToMultiValedProperty <RecipientIdParameter, ADObjectId>(this.ManagedBy, new Utils.IdentityToRawIdDelegate <RecipientIdParameter, ADObjectId>(this.ADObjectIdFromRecipientIdParameter), null, new MultiValuedProperty <ADObjectId>(), new Task.TaskErrorLoggingDelegate(base.WriteError), SearchObjectSchema.ManagedBy.Name);
                mailboxDiscoverySearch.ManagedBy.CopyChangesFrom(multiValuedProperty3);
                if (mailboxDiscoverySearch.ManagedBy.Count != multiValuedProperty3.Count)
                {
                    mailboxDiscoverySearch.ManagedBy = multiValuedProperty3;
                }
            }
            if (base.Fields.IsModified("SearchQuery"))
            {
                mailboxDiscoverySearch.Query = this.SearchQuery;
            }
            if (base.Fields.IsModified(SearchObjectSchema.EstimateOnly.Name))
            {
                mailboxDiscoverySearch.StatisticsOnly = this.EstimateOnly;
                if (this.EstimateOnly)
                {
                    mailboxDiscoverySearch.LogLevel = LoggingLevel.Suppress;
                }
                else
                {
                    mailboxDiscoverySearch.IncludeKeywordStatistics = false;
                }
            }
            if (base.Fields.IsModified(SearchObjectSchema.IncludeKeywordStatistics.Name))
            {
                mailboxDiscoverySearch.IncludeKeywordStatistics = this.IncludeKeywordStatistics.ToBool();
            }
            if (base.Fields.IsModified(MailboxDiscoverySearchSchema.StatisticsStartIndex.Name))
            {
                mailboxDiscoverySearch.StatisticsStartIndex = this.StatisticsStartIndex;
            }
            if (flag && (mailboxDiscoverySearch.Sources == null || mailboxDiscoverySearch.Sources.Count == 0) && (mailboxDiscoverySearch.PublicFolderSources == null || mailboxDiscoverySearch.PublicFolderSources.Count == 0) && !mailboxDiscoverySearch.AllSourceMailboxes && !mailboxDiscoverySearch.AllPublicFolderSources)
            {
                base.WriteError(new MailboxSearchTaskException(Strings.NoSourceMailboxesAndNoPublicFolderSourcesSet), ErrorCategory.InvalidArgument, null);
            }
            bool flag3 = mailboxDiscoverySearch.InPlaceHoldEnabled && (mailboxDiscoverySearch.Sources == null || mailboxDiscoverySearch.Sources.Count == 0);
            bool flag4 = false;

            if (flag)
            {
                flag3 = (mailboxDiscoverySearch.InPlaceHoldEnabled && mailboxDiscoverySearch.AllSourceMailboxes);
                flag4 = (mailboxDiscoverySearch.InPlaceHoldEnabled && (mailboxDiscoverySearch.AllPublicFolderSources || (mailboxDiscoverySearch.PublicFolderSources != null && mailboxDiscoverySearch.PublicFolderSources.Count != 0)));
            }
            if (flag3)
            {
                base.WriteError(new MailboxSearchTaskException(Strings.InPlaceHoldNotAllowedForAllSourceMailboxes), ErrorCategory.InvalidArgument, null);
            }
            if (flag4)
            {
                base.WriteError(new MailboxSearchTaskException(Strings.InPlaceHoldNotAllowedForPublicFolders), ErrorCategory.InvalidArgument, null);
            }
            return(mailboxDiscoverySearch);
        }
        public IEnumerable <SearchSource> Convert(ISearchPolicy policy, IEnumerable <SearchSource> sources)
        {
            Recorder.Trace(5L, TraceType.InfoTrace, "PublicFolderSourceConverter.Convert Sources:", sources);
            IConfigurationSession configurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(ConsistencyMode.IgnoreInvalid, policy.RecipientSession.SessionSettings, 46, "Convert", "f:\\15.00.1497\\sources\\dev\\EDiscovery\\src\\MailboxSearch\\WebService\\External\\PublicFolderSourceConverter.cs");

            using (PublicFolderDataProvider provider = new PublicFolderDataProvider(configurationSession, "Get-PublicFolder", Guid.Empty))
            {
                foreach (SearchSource source in sources)
                {
                    if (source.SourceType == SourceType.PublicFolder)
                    {
                        Recorder.Trace(5L, TraceType.InfoTrace, new object[]
                        {
                            "PublicFolderSourceConverter.Convert Source:",
                            source.ReferenceId,
                            "PublicFolderSourceConverter.Type:",
                            source.SourceType
                        });
                        PublicFolder publicFolder = null;
                        try
                        {
                            PublicFolderId publicFolderId2;
                            if (this.IsPath(source.ReferenceId))
                            {
                                Recorder.Trace(5L, TraceType.InfoTrace, "PublicFolderSourceConverter.Convert From Path:", source.ReferenceId);
                                publicFolderId2 = new PublicFolderId(new MapiFolderPath(source.ReferenceId));
                            }
                            else
                            {
                                Recorder.Trace(5L, TraceType.InfoTrace, "PublicFolderSourceConverter.Convert From StoreId:", source.ReferenceId);
                                StoreObjectId storeObjectId = StoreObjectId.FromHexEntryId(source.ReferenceId);
                                publicFolderId2 = new PublicFolderId(storeObjectId);
                            }
                            if (publicFolderId2 != null)
                            {
                                Recorder.Trace(5L, TraceType.InfoTrace, "PublicFolderSourceConverter.Convert PublicFolderId:", publicFolderId2);
                                publicFolder = (PublicFolder)provider.Read <PublicFolder>(publicFolderId2);
                            }
                        }
                        catch (FormatException)
                        {
                            Recorder.Trace(5L, TraceType.InfoTrace, "PublicFolderSourceConverter.Convert FormatException, Source:", source);
                        }
                        if (publicFolder != null)
                        {
                            yield return(this.GetSource(source, publicFolder));
                        }
                        else
                        {
                            Recorder.Trace(5L, TraceType.InfoTrace, "PublicFolderSourceConverter.Convert Failed, Source:", source);
                            yield return(source);
                        }
                    }
                    else if (source.SourceType == SourceType.AllPublicFolders)
                    {
                        Recorder.Trace(5L, TraceType.InfoTrace, new object[]
                        {
                            "PublicFolderSourceConverter.Convert Source:",
                            source.ReferenceId,
                            "Type:",
                            source.SourceType
                        });
                        PublicFolderId             publicFolderId = new PublicFolderId(MapiFolderPath.IpmSubtreeRoot);
                        IEnumerable <PublicFolder> folders        = provider.FindPaged <PublicFolder>(null, publicFolderId, true, null, 50);
                        foreach (PublicFolder publicFolder2 in folders)
                        {
                            if (publicFolder2.FolderPath != MapiFolderPath.IpmSubtreeRoot)
                            {
                                yield return(this.GetSource(source, publicFolder2));
                            }
                        }
                    }
                }
            }
            yield break;
        }