示例#1
0
        internal static void DoMaintenanceTask(PublicFolderDatabase publicStore, string domainController, Task.TaskWarningLoggingDelegate warningHandler)
        {
            Server server = publicStore.GetServer();

            if (!server.IsExchange2007OrLater)
            {
                warningHandler(Strings.WarningSiteFolderCheckTaskNotAvailableOnTiServer(server.Name));
                return;
            }
            string a = domainController;

            try
            {
                a = SystemConfigurationTasksHelper.GetConfigurationDomainControllerFqdn(domainController);
            }
            catch (SocketException ex)
            {
                warningHandler(Strings.ErrorResolveFqdnForDomainController(domainController, ex.Message));
            }
            string configDC = ADSession.GetConfigDC(TopologyProvider.LocalForestFqdn, server.Name);

            if (string.Equals(a, configDC, StringComparison.InvariantCultureIgnoreCase))
            {
                try
                {
                    using (ExRpcAdmin exRpcAdmin = ExRpcAdmin.Create("Client=Management", server.Fqdn, null, null, null))
                    {
                        exRpcAdmin.DoMaintenanceTask(publicStore.Guid, MaintenanceTask.SiteFolderCheck);
                    }
                    return;
                }
                catch (MapiPermanentException ex2)
                {
                    TaskLogger.Trace("Set/New-OfflineAddressBook.InternalProcessRecord raises exception while running site folder check task: {0}", new object[]
                    {
                        ex2.Message
                    });
                    warningHandler(Strings.ErrorFailedToRunSiteFolderCheckTask(server.Name, ex2.Message));
                    return;
                }
                catch (MapiRetryableException ex3)
                {
                    TaskLogger.Trace("Set/New-OfflineAddressBook.InternalProcessRecord raises exception while running site folder check task: {0}", new object[]
                    {
                        ex3.Message
                    });
                    warningHandler(Strings.ErrorFailedToRunSiteFolderCheckTask(server.Name, ex3.Message));
                    return;
                }
            }
            warningHandler(Strings.WarningOabSiteFolderCheckNotRun(server.Name));
        }
示例#2
0
        internal static void UpdateRecipients(AddressBookBase abb, ADObjectId[] removedAbbTreeIds, string domainController, IRecipientSession globalCatalogSession, Task.TaskWarningLoggingDelegate writeWarning, WriteProgress writeProgress, Cmdlet cmdlet)
        {
            if (abb == null)
            {
                throw new ArgumentNullException("abb");
            }
            if (Guid.Empty == abb.Guid)
            {
                throw new ArgumentNullException("abb.Guid");
            }
            if (writeWarning == null)
            {
                throw new ArgumentNullException("writeWarning");
            }
            if (writeProgress == null)
            {
                throw new ArgumentNullException("writeProgress");
            }
            int num = 0;

            try
            {
                if (cmdlet != null && cmdlet.Stopping)
                {
                    return;
                }
                string domainControllerFqdn = null;
                if (!string.IsNullOrEmpty(domainController))
                {
                    try
                    {
                        domainControllerFqdn = SystemConfigurationTasksHelper.GetConfigurationDomainControllerFqdn(domainController);
                    }
                    catch (SocketException ex)
                    {
                        writeWarning(Strings.ErrorResolveFqdnForDomainController(domainController, ex.Message));
                        return;
                    }
                }
                if (string.IsNullOrEmpty(abb.LdapRecipientFilter) || removedAbbTreeIds != null)
                {
                    List <Guid> list = new List <Guid>();
                    if (removedAbbTreeIds != null)
                    {
                        foreach (ADObjectId adobjectId in removedAbbTreeIds)
                        {
                            list.Add(adobjectId.ObjectGuid);
                        }
                        list.Sort();
                    }
                    else
                    {
                        list.Add(abb.Guid);
                    }
                    QueryFilter[] array = null;
                    int           num2  = LdapFilterBuilder.MaxCustomFilterTreeSize - 1;
                    for (int j = 0; j < list.Count; j += num2)
                    {
                        int num3 = Math.Min(num2, list.Count - j);
                        if (array == null || array.Length != num3)
                        {
                            array = new QueryFilter[num3];
                        }
                        for (int k = 0; k < num3; k++)
                        {
                            array[k] = new ComparisonFilter(ComparisonOperator.Equal, ADRecipientSchema.AddressListMembership, new ADObjectId(list[k + j]));
                        }
                        QueryFilter queryFilter = new OrFilter(array);
                        ADPagedReader <ADRecipient> adpagedReader = globalCatalogSession.FindPaged(null, QueryScope.SubTree, queryFilter, null, 0);
                        using (IEnumerator <ADRecipient> enumerator = adpagedReader.GetEnumerator())
                        {
                            UpdateAddressBookBase <TIdParameter> .InternalUpdateRecipients(enumerator, null, queryFilter, list, domainControllerFqdn, globalCatalogSession, writeWarning, writeProgress, cmdlet, ref num);
                        }
                    }
                }
                else
                {
                    IEnumerator <ADRecipient> enumerator2 = abb.FindUpdatingRecipientsPaged(globalCatalogSession, null).GetEnumerator();
                    UpdateAddressBookBase <TIdParameter> .InternalUpdateRecipients(enumerator2, abb, null, null, domainControllerFqdn, globalCatalogSession, writeWarning, writeProgress, cmdlet, ref num);
                }
            }
            finally
            {
                if (cmdlet != null && cmdlet.Stopping)
                {
                    ExManagementApplicationLogger.LogEvent(ManagementEventLogConstants.Tuple_RecipientsUpdateForAddressBookCancelled, new string[]
                    {
                        string.Format("{0} (objectGUID=<{1}>)", abb.DistinguishedName ?? string.Empty, abb.Guid.ToString()),
                        abb.LdapRecipientFilter,
                        ADRecipientSchema.AddressListMembership.Name
                    });
                }
            }
            if (num != 0)
            {
                writeProgress(Strings.ProgressActivityUpdateRecipient, Strings.ProgressStatusFinished, 100);
            }
        }
示例#3
0
        private static void UpdateRecipients(EmailAddressPolicy eap, OrganizationId organizationId, string domainController, IRecipientSession globalCatalogSession, Task.TaskVerboseLoggingDelegate writeVerbose, Task.TaskWarningLoggingDelegate writeWarning, WriteProgress writeProgress, Task cmdlet, bool fixMissingAlias)
        {
            UpdateEmailAddressPolicy.AssertArgumentNotNull(eap, "eap");
            UpdateEmailAddressPolicy.AssertArgumentNotNull(writeVerbose, "writeVerbose");
            UpdateEmailAddressPolicy.AssertArgumentNotNull(writeWarning, "writeWarning");
            UpdateEmailAddressPolicy.AssertArgumentNotNull(writeProgress, "writeProgress");
            if (string.IsNullOrEmpty(eap.LdapRecipientFilter) && !fixMissingAlias)
            {
                return;
            }
            int num = 0;

            try
            {
                if (cmdlet != null && cmdlet.Stopping)
                {
                    return;
                }
                IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(false, ConsistencyMode.PartiallyConsistent, globalCatalogSession.SessionSettings, 409, "UpdateRecipients", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\RecipientPolicy\\UpdateEmailAddressPolicy.cs");
                tenantOrRootOrgRecipientSession.EnforceDefaultScope = false;
                IEnumerable <ADRecipient> enumerable = eap.FindMatchingRecipientsPaged(globalCatalogSession, organizationId, null, fixMissingAlias);
                string    text      = null;
                Hashtable hashtable = new Hashtable();
                foreach (ADRecipient adrecipient in enumerable)
                {
                    if (cmdlet != null && cmdlet.Stopping)
                    {
                        return;
                    }
                    if (!string.IsNullOrEmpty(domainController) && string.IsNullOrEmpty(text))
                    {
                        try
                        {
                            string configurationDomainControllerFqdn = SystemConfigurationTasksHelper.GetConfigurationDomainControllerFqdn(domainController);
                            int    num2 = configurationDomainControllerFqdn.IndexOf(".");
                            if (0 <= num2)
                            {
                                text = configurationDomainControllerFqdn.Substring(num2);
                            }
                        }
                        catch (SocketException ex)
                        {
                            writeWarning(Strings.ErrorResolveFqdnForDomainController(domainController, ex.Message));
                            return;
                        }
                    }
                    string text2 = adrecipient.Id.DomainId.DistinguishedName.ToLowerInvariant();
                    if (!hashtable.ContainsKey(text2))
                    {
                        SystemConfigurationTasksHelper.PrepareDomainControllerRecipientSessionForUpdate(tenantOrRootOrgRecipientSession, adrecipient.Id, domainController, text);
                        IEnumerable <ADRecipient> collection = eap.FindMatchingRecipientsPaged(tenantOrRootOrgRecipientSession, organizationId, adrecipient.Id, fixMissingAlias);
                        List <ADRecipient>        list       = new List <ADRecipient>();
                        Exception ex2 = null;
                        Exception ex3 = null;
                        try
                        {
                            list.AddRange(collection);
                        }
                        catch (DataSourceOperationException ex4)
                        {
                            TaskLogger.Trace("Exception caught when re-read recipient from DC : {0}", new object[]
                            {
                                ex4.ToString()
                            });
                            if (ex4.InnerException is ActiveDirectoryObjectNotFoundException || ex4.InnerException is AuthenticationException)
                            {
                                ex3 = ex4;
                            }
                            else
                            {
                                ex2 = ex4;
                            }
                        }
                        catch (DataSourceTransientException ex5)
                        {
                            TaskLogger.Trace("Exception caught when re-read recipient from DC : {0}", new object[]
                            {
                                ex5.ToString()
                            });
                            if (ex5.InnerException is ActiveDirectoryOperationException || ex5.InnerException is ActiveDirectoryServerDownException)
                            {
                                ex3 = ex5;
                            }
                            else
                            {
                                ex2 = ex5;
                            }
                        }
                        if (ex3 != null)
                        {
                            hashtable.Add(text2, null);
                            writeWarning(Strings.ErrorCannotUpdateRecipientOfDomain(DNConvertor.FqdnFromDomainDistinguishedName(text2), ex3.Message));
                        }
                        else if (ex2 != null)
                        {
                            writeWarning(Strings.ErrorFailedToReadRecipientForUpdate(adrecipient.Id.ToString(), ex2.Message));
                        }
                        else if (1 == list.Count)
                        {
                            ADRecipient adrecipient2 = list[0];
                            if (cmdlet != null && cmdlet.Stopping)
                            {
                                return;
                            }
                            num = num++ % 99 + 1;
                            writeProgress(Strings.ProgressActivityUpdateRecipient, Strings.ProgressStatusUpdateRecipient(adrecipient2.Id.ToString()), num);
                            writeVerbose(Strings.ProgressStatusUpdateRecipient(adrecipient2.Id.ToString()));
                            try
                            {
                                if (fixMissingAlias && string.IsNullOrEmpty(adrecipient2.Alias))
                                {
                                    if (adrecipient2 is ADMicrosoftExchangeRecipient)
                                    {
                                        adrecipient2.Alias = RecipientTaskHelper.GenerateUniqueAlias(globalCatalogSession, adrecipient2.OrganizationId, ADMicrosoftExchangeRecipient.DefaultName, writeVerbose);
                                    }
                                    else if (adrecipient2 is ADSystemAttendantMailbox)
                                    {
                                        adrecipient2.Alias = RecipientTaskHelper.GenerateUniqueAlias(globalCatalogSession, adrecipient2.OrganizationId, (adrecipient2 as ADSystemAttendantMailbox).ServerName + "-SA", writeVerbose);
                                    }
                                    else
                                    {
                                        adrecipient2.Alias = RecipientTaskHelper.GenerateUniqueAlias(globalCatalogSession, adrecipient2.OrganizationId, adrecipient2.Name, writeVerbose);
                                    }
                                    writeWarning(Strings.WarningGeneratingMissingAlias(adrecipient2.Identity.ToString(), adrecipient2.Alias));
                                }
                                if (!adrecipient2.IsReadOnly)
                                {
                                    ProvisioningLayer.UpdateAffectedIConfigurable(cmdlet, RecipientTaskHelper.ConvertRecipientToPresentationObject(adrecipient2), true);
                                }
                                if (!adrecipient2.IsValid || adrecipient2.IsReadOnly)
                                {
                                    writeWarning(Strings.ErrorCannotUpdateInvalidRecipient(adrecipient2.Id.ToString()));
                                }
                                else
                                {
                                    if (cmdlet.IsVerboseOn && adrecipient2.ObjectState != ObjectState.Unchanged)
                                    {
                                        writeVerbose(TaskVerboseStringHelper.GetConfigurableObjectChangedProperties(adrecipient2));
                                    }
                                    tenantOrRootOrgRecipientSession.Save(adrecipient2);
                                }
                            }
                            catch (DataSourceTransientException ex6)
                            {
                                writeWarning(Strings.ErrorUpdateRecipient(adrecipient2.Id.ToString(), ex6.Message));
                                TaskLogger.Trace("Exception is raised while updating recipient '{0}': {1}", new object[]
                                {
                                    adrecipient2.Id.ToString(),
                                    ex6.Message
                                });
                            }
                            catch (DataSourceOperationException ex7)
                            {
                                writeWarning(Strings.ErrorUpdateRecipient(adrecipient2.Id.ToString(), ex7.Message));
                                TaskLogger.Trace("Exception is raised while updating recipient '{0}': {1}", new object[]
                                {
                                    adrecipient2.Id.ToString(),
                                    ex7.Message
                                });
                            }
                            catch (DataValidationException ex8)
                            {
                                writeWarning(Strings.ErrorUpdateRecipient(adrecipient2.Id.ToString(), ex8.Message));
                                TaskLogger.Trace("Exception is raised while updating recipient '{0}': {1}", new object[]
                                {
                                    adrecipient2.Id.ToString(),
                                    ex8.Message
                                });
                            }
                        }
                    }
                }
            }
            finally
            {
                if (cmdlet != null && cmdlet.Stopping)
                {
                    ExManagementApplicationLogger.LogEvent(ManagementEventLogConstants.Tuple_RecipientsUpdateForEmailAddressPolicyCancelled, new string[]
                    {
                        eap.Identity.ToString(),
                        eap.LdapRecipientFilter,
                        ADRecipientSchema.EmailAddresses.Name
                    });
                }
            }
            if (num != 0)
            {
                writeVerbose(Strings.ProgressStatusFinished);
                writeProgress(Strings.ProgressActivityUpdateRecipient, Strings.ProgressStatusFinished, 100);
            }
        }
示例#4
0
        private static void InternalUpdateRecipients(IEnumerator <ADRecipient> pagedReaderGC, AddressBookBase abb, QueryFilter removeFilter, List <Guid> abbObjectGuidList, string domainControllerFqdn, IRecipientSession globalCatalogSession, Task.TaskWarningLoggingDelegate writeWarning, WriteProgress writeProgress, Cmdlet cmdlet, ref int currentPercent)
        {
            if (cmdlet != null && cmdlet.Stopping)
            {
                return;
            }
            string domainControllerDomainName = null;

            if (!string.IsNullOrEmpty(domainControllerFqdn))
            {
                int num = domainControllerFqdn.IndexOf(".");
                if (0 <= num)
                {
                    domainControllerDomainName = domainControllerFqdn.Substring(num + 1);
                }
            }
            IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(false, ConsistencyMode.PartiallyConsistent, globalCatalogSession.SessionSettings, 300, "InternalUpdateRecipients", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\AddressBook\\UpdateAddressBook.cs");

            tenantOrRootOrgRecipientSession.EnforceDefaultScope         = false;
            tenantOrRootOrgRecipientSession.EnforceContainerizedScoping = false;
            string text = null;

            while (pagedReaderGC.MoveNext())
            {
                ADRecipient adrecipient = pagedReaderGC.Current;
                if (cmdlet != null && cmdlet.Stopping)
                {
                    return;
                }
                ADRecipient adrecipient2 = adrecipient;
                try
                {
                    SystemConfigurationTasksHelper.PrepareDomainControllerRecipientSessionForUpdate(tenantOrRootOrgRecipientSession, adrecipient.Id, domainControllerFqdn, domainControllerDomainName);
                    tenantOrRootOrgRecipientSession.LinkResolutionServer = null;
                    IConfigurable configurable = null;
                    if (abb != null)
                    {
                        IEnumerator <ADRecipient> enumerator = abb.FindUpdatingRecipientsPaged(tenantOrRootOrgRecipientSession, adrecipient.Id).GetEnumerator();
                        if (enumerator.MoveNext())
                        {
                            configurable = enumerator.Current;
                        }
                    }
                    else
                    {
                        IConfigurable[] array = tenantOrRootOrgRecipientSession.Find(adrecipient.Id, QueryScope.Base, removeFilter, null, 1);
                        if (array.Length > 0)
                        {
                            configurable = array[0];
                        }
                    }
                    if (configurable != null)
                    {
                        adrecipient2 = (ADRecipient)configurable;
                        if (!adrecipient2.IsValid || adrecipient2.IsReadOnly)
                        {
                            writeWarning(Strings.ErrorCannotUpdateInvalidRecipient(adrecipient2.Id.ToString()));
                        }
                        else
                        {
                            if (cmdlet != null && cmdlet.Stopping)
                            {
                                break;
                            }
                            bool flag = false;
                            if (abb != null)
                            {
                                using (MultiValuedProperty <ADObjectId> .Enumerator enumerator2 = adrecipient2.AddressListMembership.GetEnumerator())
                                {
                                    while (enumerator2.MoveNext())
                                    {
                                        ADObjectId adobjectId = enumerator2.Current;
                                        if (ADObjectId.Equals(adobjectId, abb.Id))
                                        {
                                            flag = true;
                                            adrecipient2.AddressListMembership.Remove(adobjectId);
                                            break;
                                        }
                                    }
                                    goto IL_1E5;
                                }
                            }
                            int num2 = adrecipient2.AddressListMembership.Count - 1;
                            while (0 <= num2)
                            {
                                if (abbObjectGuidList.BinarySearch(adrecipient2.AddressListMembership[num2].ObjectGuid) >= 0)
                                {
                                    flag = true;
                                    adrecipient2.AddressListMembership.RemoveAt(num2);
                                }
                                num2--;
                            }
IL_1E5:
                            if (!flag && !adrecipient2.HiddenFromAddressListsEnabled)
                            {
                                if (string.IsNullOrEmpty(text))
                                {
                                    try
                                    {
                                        if (!string.IsNullOrEmpty(abb.OriginatingServer))
                                        {
                                            text = SystemConfigurationTasksHelper.GetConfigurationDomainControllerFqdn(abb.OriginatingServer);
                                        }
                                    }
                                    catch (SocketException ex)
                                    {
                                        writeWarning(Strings.ErrorResolveFqdnForDomainController(abb.OriginatingServer, ex.Message));
                                        continue;
                                    }
                                }
                                tenantOrRootOrgRecipientSession.LinkResolutionServer = text;
                                adrecipient2.AddressListMembership.Add(abb.Id);
                            }
                            currentPercent = currentPercent++ % 99 + 1;
                            writeProgress(Strings.ProgressActivityUpdateRecipient, Strings.ProgressStatusUpdateRecipient(adrecipient2.Id.ToString()), currentPercent);
                            tenantOrRootOrgRecipientSession.Save(adrecipient2);
                        }
                    }
                }
                catch (DataSourceTransientException ex2)
                {
                    writeWarning(Strings.ErrorUpdateRecipient(adrecipient2.Id.ToString(), ex2.Message));
                    TaskLogger.Trace("Exception is raised while updating recipient '{0}': {1}", new object[]
                    {
                        adrecipient2.Id.ToString(),
                        ex2.Message
                    });
                }
                catch (DataSourceOperationException ex3)
                {
                    writeWarning(Strings.ErrorUpdateRecipient(adrecipient2.Id.ToString(), ex3.Message));
                    TaskLogger.Trace("Exception is raised while updating recipient '{0}': {1}", new object[]
                    {
                        adrecipient2.Id.ToString(),
                        ex3.Message
                    });
                }
                catch (DataValidationException ex4)
                {
                    writeWarning(Strings.ErrorUpdateRecipient(adrecipient2.Id.ToString(), ex4.Message));
                    TaskLogger.Trace("Exception is raised while updating recipient '{0}': {1}", new object[]
                    {
                        adrecipient2.Id.ToString(),
                        ex4.Message
                    });
                }
            }
        }