コード例 #1
0
 protected override void InternalValidate()
 {
     TaskLogger.LogEnter();
     base.InternalValidate();
     MapiTaskHelper.VerifyDatabaseAndItsOwningServerInScope(base.SessionSettings, this.DataObject, new Task.ErrorLoggerDelegate(base.ThrowTerminatingError));
     TaskLogger.LogExit();
 }
コード例 #2
0
        protected override void InternalValidate()
        {
            TaskLogger.LogEnter();
            base.InternalValidate();
            if (this.OwnerServer == null)
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorDBOwningServerNotFound(this.DataObject.Identity.ToString())), ErrorCategory.InvalidOperation, this.DataObject.Identity);
            }
            base.VerifyIsWithinScopes((IConfigurationSession)base.DataSession, this.OwnerServer, true, new DataAccessTask <Database> .ADObjectOutOfScopeString(Strings.ErrorServerOutOfScope));
            if (this.DataObject != null)
            {
                MapiTaskHelper.VerifyDatabaseAndItsOwningServerInScope(base.SessionSettings, this.DataObject, new Task.ErrorLoggerDelegate(base.WriteError));
            }
            ADObjectId adobjectId = new ADObjectId(this.OwnerServer.Guid);

            if (null == this.EdbFilePath && (base.Fields.IsModified("EdbFilePath") || base.Fields.IsChanged("EdbFilePath")))
            {
                base.WriteError(new ArgumentException(Strings.ErrorInvalidParameterValue("EdbFilePath", "null"), "EdbFilePath"), ErrorCategory.InvalidArgument, this.Identity);
            }
            if (!this.IsEdbFilePathChanged && !this.isLogFolderPathChanged)
            {
                this.WriteWarning(Strings.FileLocationNotChanged);
                TaskLogger.LogExit();
                return;
            }
            this.needReportProgress = !base.ConfigurationOnly;
            this.shouldContinueToDoConfigurationOnly = true;
            try
            {
                QueryFilter            filter     = new ComparisonFilter(ComparisonOperator.NotEqual, ADObjectSchema.Guid, this.DataObject.Guid);
                ADObjectId             rootId     = this.DataObject.IsExchange2009OrLater ? this.DataObject.AdministrativeGroup.GetChildId("Databases") : this.DataObject.Server;
                IEnumerable <Database> collection = base.DataSession.FindPaged <Database>(filter, rootId, true, null, 0);
                List <Database>        databases  = new List <Database>(collection);
                if (this.IsEdbFilePathChanged)
                {
                    if (this.DataObject.IsExchange2009OrLater)
                    {
                        base.WriteVerbose(Strings.VerboseEdbFileLocationUniqueUnderDAGCondition(this.EdbFilePath.PathName));
                        ADObjectId[] serversId;
                        if (this.DataObject.Servers != null && this.DataObject.Servers.Length != 0)
                        {
                            serversId = this.DataObject.Servers;
                        }
                        else
                        {
                            serversId = new ADObjectId[]
                            {
                                this.DataObject.Server
                            };
                        }
                        if (!new EdbFileLocationUniqueUnderDAGCondition(this.EdbFilePath.PathName, adobjectId, serversId, databases).Verify())
                        {
                            base.WriteError(new ArgumentException(Strings.ErrorEdbFileLocationNotUniqueUnderSameDAG(this.EdbFilePath.PathName), "EdbFilePath"), ErrorCategory.InvalidArgument, this.Identity);
                        }
                    }
                    else
                    {
                        base.WriteVerbose(Strings.VerboseEdbFileLocationUniqueUnderServerCondition(base.OwnerServerName, this.EdbFilePath.PathName));
                        if (!new EdbFileLocationUniqueUnderServerCondition(this.EdbFilePath.PathName, adobjectId, databases).Verify())
                        {
                            base.WriteError(new ArgumentException(Strings.ErrorEdbFileLocationNotUniqueUnderSameNode(this.EdbFilePath.PathName, base.OwnerServerName), "EdbFilePath"), ErrorCategory.InvalidArgument, this.Identity);
                        }
                    }
                }
                if (this.isLogFolderPathChanged)
                {
                    if (this.DataObject.IsExchange2009OrLater)
                    {
                        ADObjectId[] serversId2;
                        if (this.DataObject.Servers != null && this.DataObject.Servers.Length != 0)
                        {
                            serversId2 = this.DataObject.Servers;
                        }
                        else
                        {
                            serversId2 = new ADObjectId[]
                            {
                                this.DataObject.Server
                            };
                        }
                        if (!new DbLogLocationUniqueUnderDAGCondition(this.LogFolderPath.PathName, adobjectId, serversId2, databases).Verify())
                        {
                            base.WriteError(new ArgumentException(Strings.ErrorLogFolderPathNotUniqueUnderSameDAG(this.LogFolderPath.PathName), "LogFolderPath"), ErrorCategory.InvalidArgument, this.DataObject.Identity);
                        }
                    }
                    else if (!new DbLogLocationUniqueUnderServerCondition(this.LogFolderPath.PathName, adobjectId, databases).Verify())
                    {
                        base.WriteError(new ArgumentException(Strings.ErrorLogFolderPathNotUniqueUnderTheSameNode(this.LogFolderPath.PathName, base.OwnerServerName), "LogFolderPath"), ErrorCategory.InvalidArgument, this.DataObject.Identity);
                    }
                }
                if (base.ConfigurationOnly)
                {
                    this.moveCatalogs = false;
                    if (!this.Force && !(this.shouldContinueToDoConfigurationOnly = base.ShouldContinue(Strings.WarningUseConfigurationOnly)))
                    {
                        TaskLogger.LogExit();
                        return;
                    }
                    if (this.IsEdbFilePathChanged)
                    {
                        base.WriteVerbose(Strings.VerboseCheckFileExistenceCondition(base.OwnerServerName, this.TargetEdbFilePath.PathName));
                        if (new FileNotExistCondition(this.OwnerServer.Fqdn, this.TargetEdbFilePath.PathName).Verify())
                        {
                            this.WriteWarning(Strings.WarningEdbFileLocationNotExists(this.EdbFilePath.PathName));
                        }
                    }
                    TaskLogger.LogExit();
                    return;
                }
                else
                {
                    if (this.needReportProgress)
                    {
                        base.WriteProgress(Strings.ProgressValidatingFileLocations, Strings.ProgressMoveDatabasePath(this.Identity.ToString()), 5);
                    }
                    if (this.IsEdbFilePathChanged)
                    {
                        if (this.OriginalEdbFilePath == null)
                        {
                            base.WriteError(new InvalidOperationException(Strings.ErrorOriginalEdbFilePathMissed(this.Identity.ToString())), ErrorCategory.InvalidOperation, this.Identity);
                        }
                        if (this.IsDatabaseFilesCreated)
                        {
                            base.WriteVerbose(Strings.VerboseCheckFileExistenceCondition(base.OwnerServerName, this.OriginalEdbFilePath.PathName));
                            if (new FileNotExistCondition(this.OwnerServer.Fqdn, this.OriginalEdbFilePath.PathName).Verify())
                            {
                                base.WriteError(new InvalidOperationException(Strings.ErrorSourceFileNotFound(base.OwnerServerName, this.OriginalEdbFilePath.PathName)), ErrorCategory.InvalidOperation, this.Identity);
                            }
                        }
                        base.WriteVerbose(Strings.VerbosePathOnFixedOrNetworkDriveCondition(base.OwnerServerName, this.EdbFilePath.PathName));
                        if (!new PathOnFixedOrNetworkDriveCondition(this.OwnerServer.Fqdn, this.EdbFilePath.PathName).Verify())
                        {
                            base.WriteError(new ArgumentException(Strings.ErrorEdbFileLocationNotOnFixedDrive(this.EdbFilePath.PathName), "EdbFilePath"), ErrorCategory.InvalidArgument, this.Identity);
                        }
                        base.WriteVerbose(Strings.VerboseCheckFileExistenceCondition(base.OwnerServerName, this.EdbFilePath.PathName));
                        if (!new FileNotExistCondition(this.OwnerServer.Fqdn, this.EdbFilePath.PathName).Verify())
                        {
                            base.WriteError(new ArgumentException(Strings.ErrorEdbFilePathOccupiedByFile(this.EdbFilePath.PathName, base.OwnerServerName), "EdbFilePath"), ErrorCategory.InvalidArgument, this.Identity);
                        }
                        base.WriteVerbose(Strings.VerboseCheckDirectoryExistenceCondition(base.OwnerServerName, this.EdbFilePath.PathName));
                        if (!new DirectoryNotExistCondition(this.OwnerServer.Fqdn, this.EdbFilePath.PathName).Verify())
                        {
                            base.WriteError(new ArgumentException(Strings.ErrorEdbFilePathOccupiedByDirectory(this.EdbFilePath.PathName, base.OwnerServerName), "EdbFilePath"), ErrorCategory.InvalidArgument, this.Identity);
                        }
                        string directoryName = Path.GetDirectoryName(this.EdbFilePath.PathName);
                        if (this.IsDatabaseFilesCreated && !SystemConfigurationTasksHelper.TryCreateDirectory(this.OwnerServer.Fqdn, directoryName, Database_Directory.GetDomainWidePermissions(), new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.TaskWarningLoggingDelegate(this.WriteWarning)))
                        {
                            base.WriteError(new ArgumentException(Strings.ErrorEdbFileDirectoryNotExist(directoryName, base.OwnerServerName), "EdbFilePath"), ErrorCategory.InvalidOperation, this.Identity);
                        }
                        if (this.moveCatalogs)
                        {
                            this.moveCatalogs = this.DataObject.ObjectClass.Contains("msExchPrivateMDB");
                            if (this.moveCatalogs)
                            {
                                string directoryName2 = Path.GetDirectoryName(this.OriginalEdbFilePath.PathName);
                                this.originalCatalogsPath = this.GenerateCatalogPath(directoryName2, this.DataObject.Guid);
                                base.WriteVerbose(Strings.VerboseCheckDirectoryExistenceCondition(base.OwnerServerName, this.originalCatalogsPath));
                                this.moveCatalogs = WmiWrapper.IsDirectoryExisting(this.OwnerServer.Fqdn, this.originalCatalogsPath);
                                if (this.moveCatalogs)
                                {
                                    string directoryName3 = Path.GetDirectoryName(this.EdbFilePath.PathName);
                                    this.targetCatalogsPath = this.GenerateCatalogPath(directoryName3, this.DataObject.Guid);
                                    this.moveCatalogs       = (this.originalCatalogsPath != this.targetCatalogsPath);
                                }
                            }
                        }
                    }
                    else
                    {
                        this.moveCatalogs = false;
                    }
                    if (base.ConfigurationOnly)
                    {
                        TaskLogger.LogExit();
                        return;
                    }
                    if (this.isLogFolderPathChanged)
                    {
                        if (this.OldLogFolderPath == null)
                        {
                            base.WriteError(new InvalidOperationException(Strings.ErrorOriginalLogFolderPathIsMissed(this.Identity.ToString())), ErrorCategory.InvalidOperation, this.DataObject.Identity);
                        }
                        base.WriteVerbose(Strings.VerbosePathOnFixedOrNetworkDriveCondition(this.OwnerServer.Fqdn, this.LogFolderPath.PathName));
                        if (!new PathOnFixedOrNetworkDriveCondition(this.OwnerServer.Fqdn, this.LogFolderPath.PathName).Verify())
                        {
                            base.WriteError(new ArgumentException(Strings.ErrorPathIsNotOnFixedDrive("LogFolderPath")), ErrorCategory.InvalidArgument, this.DataObject.Identity);
                        }
                        base.WriteVerbose(Strings.VerboseLogLocationAvailableCondition(this.OwnerServer.Fqdn, this.LogFolderPath.PathName));
                        if (!new LogLocationAvailableCondition(this.OwnerServer.Fqdn, this.LogFolderPath.PathName, this.DataObject.LogFilePrefix).Verify())
                        {
                            base.WriteError(new ArgumentException(Strings.ErrorLogFolderPathNotAvailable, "LogFolderPath"), ErrorCategory.InvalidArgument, this.DataObject.Identity);
                        }
                        base.WriteVerbose(Strings.VerboseCheckLogFileExistingInPath(this.OwnerServer.Fqdn, this.oldLogFolderPath.PathName));
                        if (!WmiWrapper.IsFileExistingInPath(this.OwnerServer.Fqdn, this.oldLogFolderPath.PathName, new WmiWrapper.FileFilter(this.LogFileFilter)))
                        {
                            base.WriteError(new InvalidOperationException(Strings.ErrorMoveDatabasePathAsSourceFileNotExist(this.oldLogFolderPath.PathName)), ErrorCategory.InvalidOperation, this.DataObject.Identity);
                        }
                    }
                }
            }
            catch (WmiException ex)
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorFailedToConnectToServer(base.OwnerServerName, ex.Message)), ErrorCategory.InvalidOperation, this.Identity);
            }
            catch (UnauthorizedAccessException ex2)
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorFailedToConnectToServer(base.OwnerServerName, ex2.Message)), ErrorCategory.InvalidOperation, this.Identity);
            }
            if (this.DataObject.ReplicationType == ReplicationType.Remote && !this.DataObject.Recovery)
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorMoveDatabasePathInvalidOnReplicated), ErrorCategory.InvalidOperation, this.DataObject.Identity);
            }
            TaskLogger.LogExit();
        }
コード例 #3
0
        protected override void InternalValidate()
        {
            bool flag = false;

            try
            {
                ADRecipient            adrecipient = null;
                List <MailboxDatabase> list        = new List <MailboxDatabase>();
                bool          flag2 = false;
                ActiveManager activeManagerInstance = ActiveManager.GetActiveManagerInstance();
                base.TenantGlobalCatalogSession.ServerTimeout = new TimeSpan?(TimeSpan.FromSeconds((double)this.ActiveDirectoryTimeout));
                this.ConfigurationSession.ServerTimeout       = new TimeSpan?(TimeSpan.FromSeconds((double)this.ActiveDirectoryTimeout));
                this.transactionTargets = new List <MapiTransaction>();
                if (this.Identity != null)
                {
                    if (this.EnableSoftDeletedRecipientLogon)
                    {
                        IDirectorySession directorySession = base.DataSession as IDirectorySession;
                        directorySession.SessionSettings.IncludeSoftDeletedObjects = true;
                    }
                    ADUser aduser = (ADUser)RecipientTaskHelper.ResolveDataObject <ADUser>(base.DataSession, base.TenantGlobalCatalogSession, base.ServerSettings, this.Identity, null, base.OptionalIdentityData, base.DomainController, new DataAccessHelper.CategorizedGetDataObjectDelegate(base.GetDataObject <ADUser>), new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.ErrorLoggerDelegate(base.WriteError));
                    if (this.Archive)
                    {
                        if (aduser.ArchiveDatabase == null)
                        {
                            base.WriteError(new MdbAdminTaskException(Strings.ErrorArchiveNotEnabled(aduser.ToString())), ErrorCategory.InvalidArgument, this.Identity);
                        }
                        else
                        {
                            this.Database = new DatabaseIdParameter(aduser.ArchiveDatabase);
                        }
                    }
                    else
                    {
                        this.Database = new DatabaseIdParameter(aduser.Database);
                    }
                    flag        = true;
                    adrecipient = aduser;
                }
                if (this.Database != null)
                {
                    MailboxDatabase mailboxDatabase  = null;
                    MailboxDatabase mailboxDatabase2 = (MailboxDatabase)base.GetDataObject <MailboxDatabase>(this.Database, base.GlobalConfigSession, null, new LocalizedString?(Strings.ErrorDatabaseNotFound(this.Database.ToString())), new LocalizedString?(Strings.ErrorDatabaseNotUnique(this.Database.ToString())));
                    if (mailboxDatabase2.Recovery)
                    {
                        string name = mailboxDatabase2.Name;
                        RecoveryMailboxDatabaseNotMonitoredException exception = new RecoveryMailboxDatabaseNotMonitoredException(name);
                        this.WriteErrorAndMonitoringEvent(exception, ErrorCategory.InvalidOperation, null, 1006, "MSExchange Monitoring MAPIConnectivity");
                        return;
                    }
                    mailboxDatabase = mailboxDatabase2;
                    if (!flag)
                    {
                        try
                        {
                            MapiTaskHelper.VerifyDatabaseAndItsOwningServerInScope(base.SessionSettings, mailboxDatabase, new Task.ErrorLoggerDelegate(base.ThrowTerminatingError));
                            flag = true;
                        }
                        catch (InvalidOperationException exception2)
                        {
                            this.WriteErrorAndMonitoringEvent(exception2, ErrorCategory.InvalidOperation, null, 1005, "MSExchange Monitoring MAPIConnectivity");
                            return;
                        }
                    }
                    list.Add(mailboxDatabase);
                    if (this.CopyOnServer != null)
                    {
                        this.Server = this.CopyOnServer;
                    }
                    else
                    {
                        DatabaseLocationInfo serverForDatabase = this.GetServerForDatabase(activeManagerInstance, mailboxDatabase.Guid);
                        if (serverForDatabase != null)
                        {
                            this.Server = ServerIdParameter.Parse(serverForDatabase.ServerFqdn);
                        }
                        else
                        {
                            this.Server = ServerIdParameter.Parse(mailboxDatabase.Server.DistinguishedName);
                        }
                    }
                }
                if (this.Server == null)
                {
                    string machineName = Environment.MachineName;
                    this.Server = ServerIdParameter.Parse(machineName);
                }
                this.targetServer = (Server)base.GetDataObject <Server>(this.Server, base.GlobalConfigSession, null, new LocalizedString?(Strings.ErrorServerNotFound(this.Server.ToString())), new LocalizedString?(Strings.ErrorServerNotUnique(this.Server.ToString())));
                LocalizedException ex = null;
                if (!this.targetServer.IsExchange2007OrLater)
                {
                    ex = new OperationOnOldServerException(this.targetServer.Name);
                }
                else if (!this.targetServer.IsMailboxServer)
                {
                    ex = new OperationOnlyOnMailboxServerException(this.targetServer.Name);
                }
                if (ex != null)
                {
                    this.WriteErrorAndMonitoringEvent(ex, ErrorCategory.InvalidArgument, null, 1005, "MSExchange Monitoring MAPIConnectivity");
                }
                else
                {
                    if (!flag)
                    {
                        try
                        {
                            MapiTaskHelper.VerifyIsWithinConfigWriteScope(base.SessionSettings, this.targetServer, new Task.ErrorLoggerDelegate(base.ThrowTerminatingError));
                        }
                        catch (InvalidOperationException exception3)
                        {
                            this.WriteErrorAndMonitoringEvent(exception3, ErrorCategory.InvalidOperation, null, 1005, "MSExchange Monitoring MAPIConnectivity");
                            return;
                        }
                    }
                    if (list.Count == 0)
                    {
                        MailboxDatabase[] mailboxDatabases = this.targetServer.GetMailboxDatabases();
                        if (mailboxDatabases.Length > 0)
                        {
                            flag2 = true;
                        }
                        foreach (MailboxDatabase mailboxDatabase3 in mailboxDatabases)
                        {
                            if (!mailboxDatabase3.AutoDagExcludeFromMonitoring)
                            {
                                if (this.IncludePassive)
                                {
                                    list.Add(mailboxDatabase3);
                                }
                                else
                                {
                                    DatabaseLocationInfo serverForDatabase = this.GetServerForDatabase(activeManagerInstance, mailboxDatabase3.Guid);
                                    if ((serverForDatabase != null && serverForDatabase.ServerGuid == this.targetServer.Guid) || (serverForDatabase == null && mailboxDatabase3.Server.ObjectGuid == this.targetServer.Guid))
                                    {
                                        list.Add(mailboxDatabase3);
                                    }
                                }
                            }
                        }
                    }
                    if (adrecipient != null)
                    {
                        this.wasTargetMailboxSpecified = true;
                        this.transactionTargets.Add(new MapiTransaction(this.targetServer, list[0], adrecipient, this.Archive, list[0].Server.ObjectGuid == this.targetServer.Guid));
                    }
                    else
                    {
                        foreach (MailboxDatabase mailboxDatabase4 in list)
                        {
                            if (!mailboxDatabase4.Recovery)
                            {
                                GeneralMailboxIdParameter id = GeneralMailboxIdParameter.Parse(string.Format(CultureInfo.InvariantCulture, "SystemMailbox{{{0}}}", new object[]
                                {
                                    mailboxDatabase4.Guid.ToString()
                                }));
                                IEnumerable <ADSystemMailbox> dataObjects = base.GetDataObjects <ADSystemMailbox>(id, base.RootOrgGlobalCatalogSession, null);
                                using (IEnumerator <ADSystemMailbox> enumerator2 = dataObjects.GetEnumerator())
                                {
                                    adrecipient = (enumerator2.MoveNext() ? enumerator2.Current : null);
                                    this.transactionTargets.Add(new MapiTransaction(this.targetServer, mailboxDatabase4, adrecipient, false, mailboxDatabase4.Server.ObjectGuid == this.targetServer.Guid));
                                }
                            }
                        }
                    }
                    this.transactionTargets.Sort();
                    if (this.transactionTargets.Count < 1)
                    {
                        if (flag2)
                        {
                            this.WriteWarning(Strings.MapiTransactionServerWithoutMdbs(this.targetServer.Name));
                            this.onlyPassives = true;
                        }
                        else
                        {
                            this.WriteErrorAndMonitoringEvent(new NoMdbForOperationException(this.targetServer.Name), ErrorCategory.ReadError, null, 1010, "MSExchange Monitoring MAPIConnectivity");
                        }
                    }
                }
            }
            finally
            {
                if (base.HasErrors && this.MonitoringContext)
                {
                    base.WriteObject(this.monitoringData);
                }
                TaskLogger.LogExit();
            }
        }