Esempio n. 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));
        }
        internal static void DoubleWrite <TDataObject>(ObjectId objectId, TDataObject scratchPad, string ownerServerName, Fqdn domainController, Task.TaskVerboseLoggingDelegate writeVerbose, Task.TaskWarningLoggingDelegate writeWarning) where TDataObject : ADConfigurationObject, new()
        {
            string configDC;

            try
            {
                writeVerbose(Strings.VerboseGetStoreConfigDCName(ownerServerName));
                configDC = ADSession.GetConfigDC(TopologyProvider.LocalForestFqdn, ownerServerName);
            }
            catch (ADTransientException ex)
            {
                writeWarning(Strings.VerboseFailedDoubleWriteOperation(ex.Message));
                TaskLogger.Trace("Failed to get the domain controller which store is using: {0}.", new object[]
                {
                    ex.Message
                });
                return;
            }
            if (domainController == null || !domainController.ToString().Equals(configDC, StringComparison.InvariantCultureIgnoreCase))
            {
                IConfigurationSession configurationSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(configDC, false, ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromRootOrgScopeSet(), 416, "DoubleWrite", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\common\\SystemConfigurationCommon.cs");
                writeVerbose(TaskVerboseStringHelper.GetReadObjectVerboseString(objectId, configurationSession, typeof(TDataObject)));
                try
                {
                    TDataObject tdataObject = configurationSession.Read <TDataObject>((ADObjectId)objectId);
                    writeVerbose(TaskVerboseStringHelper.GetSourceVerboseString(configurationSession));
                    if (tdataObject == null)
                    {
                        writeVerbose(Strings.VerboseFailedReadObjectFromDC(objectId.ToString(), typeof(TDataObject).Name, configDC));
                        TaskLogger.Trace("Failed to read the data object from config DC: \"{0}\"", new object[]
                        {
                            configDC
                        });
                        TaskLogger.LogExit();
                        return;
                    }
                    tdataObject.CopyChangesFrom(scratchPad);
                    writeVerbose(Strings.VerboseDoubleWriteADChangeOnDC(objectId.ToString(), configDC));
                    configurationSession.Save(tdataObject);
                }
                catch (DataValidationException ex2)
                {
                    writeWarning(Strings.VerboseFailedDoubleWriteOperation(ex2.Message));
                    TaskLogger.Trace("Double write failed on DC '{0}': {1}", new object[]
                    {
                        configDC,
                        ex2.ToString()
                    });
                }
                catch (ADOperationException ex3)
                {
                    writeWarning(Strings.VerboseFailedDoubleWriteOperation(ex3.Message));
                    TaskLogger.Trace("Double write failed on DC '{0}': {1}", new object[]
                    {
                        configDC,
                        ex3.ToString()
                    });
                }
                catch (DataSourceTransientException ex4)
                {
                    writeWarning(Strings.VerboseFailedDoubleWriteOperation(ex4.Message));
                    TaskLogger.Trace("Double write failed on DC '{0}': {1}", new object[]
                    {
                        configDC,
                        ex4.ToString()
                    });
                }
                finally
                {
                    writeVerbose(TaskVerboseStringHelper.GetSourceVerboseString(configurationSession));
                }
            }
            TaskLogger.LogExit();
        }