protected override void WriteResult()
        {
            TaskLogger.LogEnter(new object[]
            {
                this.DataObject.Identity
            });
            this.nonAtomicTagObject = this.DataObject;
            base.WriteVerbose(TaskVerboseStringHelper.GetReadObjectVerboseString(this.DataObject.Identity, base.DataSession, typeof(RetentionPolicyTag)));
            RetentionPolicyTag retentionPolicyTag = null;

            try
            {
                IConfigurationSession configurationSession = base.DataSession as IConfigurationSession;
                configurationSession.SessionSettings.IsSharedConfigChecked = true;
                retentionPolicyTag = configurationSession.Read <RetentionPolicyTag>(this.DataObject.Id);
            }
            finally
            {
                base.WriteVerbose(TaskVerboseStringHelper.GetSourceVerboseString(base.DataSession));
            }
            if (retentionPolicyTag == null)
            {
                base.WriteError(new ManagementObjectNotFoundException(base.GetErrorMessageObjectNotFound(this.ResolveIdentityString(this.DataObject.Identity), typeof(RetentionPolicyTag).ToString(), (base.DataSession != null) ? base.DataSession.Source : null)), (ErrorCategory)1003, this.DataObject.Identity);
            }
            IConfigurationSession session = base.DataSession as IConfigurationSession;

            this.MakeContentSettingUniqueAndSave(session, this.DataObject, this.contentSettingsObject, this.contentSettingsObject.Name);
            this.nonAtomicTagObject = null;
            PresentationRetentionPolicyTag result = new PresentationRetentionPolicyTag(retentionPolicyTag, this.contentSettingsObject);

            this.WriteResult(result);
            TaskLogger.LogExit();
        }
Beispiel #2
0
        protected override void WriteResult()
        {
            TaskLogger.LogEnter(new object[]
            {
                this.DataObject.Identity
            });
            base.WriteVerbose(TaskVerboseStringHelper.GetReadObjectVerboseString(this.DataObject.Identity, base.DataSession, typeof(RoleGroup)));
            ADGroup adgroup = null;

            try
            {
                adgroup = (ADGroup)base.DataSession.Read <ADGroup>(this.DataObject.Identity);
            }
            finally
            {
                base.WriteVerbose(TaskVerboseStringHelper.GetSourceVerboseString(base.DataSession));
            }
            if (adgroup == null)
            {
                base.WriteError(new ManagementObjectNotFoundException(base.GetErrorMessageObjectNotFound(this.ResolveIdentityString(this.DataObject.Identity), typeof(RoleGroup).ToString(), (base.DataSession != null) ? base.DataSession.Source : null)), (ErrorCategory)1003, this.DataObject.Identity);
            }
            Result <ExchangeRoleAssignment>[] array = null;
            if (this.roleAssignments != null)
            {
                array = new Result <ExchangeRoleAssignment> [this.roleAssignments.Count];
                for (int i = 0; i < this.roleAssignments.Count; i++)
                {
                    array[i] = new Result <ExchangeRoleAssignment>(this.roleAssignments[i], null);
                }
            }
            if (null != adgroup.ForeignGroupSid)
            {
                adgroup.LinkedGroup = SecurityPrincipalIdParameter.GetFriendlyUserName(adgroup.ForeignGroupSid, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose));
                adgroup.ResetChangeTracking();
            }
            RoleGroup result = new RoleGroup(adgroup, array);

            base.WriteResult(result);
            TaskLogger.LogExit();
        }
Beispiel #3
0
        protected override void WriteResult()
        {
            TaskLogger.LogEnter(new object[]
            {
                this.DataObject.Identity
            });
            base.WriteVerbose(TaskVerboseStringHelper.GetReadObjectVerboseString(this.DataObject.Identity, base.DataSession, typeof(TransactionalRequestJob)));
            IConfigurable configurable = null;

            try
            {
                try
                {
                    configurable = base.DataSession.Read <TransactionalRequestJob>(this.DataObject.Identity);
                }
                finally
                {
                    base.WriteVerbose(TaskVerboseStringHelper.GetSourceVerboseString(base.DataSession));
                }
                if (configurable == null)
                {
                    base.WriteError(new ManagementObjectNotFoundException(base.GetErrorMessageObjectNotFound(this.DataObject.Identity.ToString(), typeof(TRequest).ToString(), (base.DataSession != null) ? base.DataSession.Source : null)), (ErrorCategory)1003, this.DataObject.Identity);
                }
                this.WriteResult(configurable);
            }
            finally
            {
                IDisposable disposable = configurable as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                    configurable = null;
                }
            }
            TaskLogger.LogExit();
        }
Beispiel #4
0
        protected override void InternalProcessRecord()
        {
            TaskLogger.LogEnter(new object[]
            {
                this.DataObject
            });
            bool       flag   = false;
            bool       flag2  = false;
            bool       flag3  = true;
            bool       flag4  = false;
            bool       flag5  = false;
            Server     server = this.OwnerServer;
            ADObjectId id     = new ADObjectId(this.OwnerServer.Guid);

            if (server == null)
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorDBOwningServerNotFound(this.DataObject.Identity.ToString())), ErrorCategory.InvalidOperation, this.DataObject.Identity);
            }
            try
            {
                if ((!this.IsEdbFilePathChanged && !this.isLogFolderPathChanged) || (base.ConfigurationOnly && !this.shouldContinueToDoConfigurationOnly))
                {
                    TaskLogger.LogExit();
                }
                else
                {
                    if (this.needReportProgress)
                    {
                        base.WriteProgress(Strings.ProgressMoveDatabasePath(this.Identity.ToString()), Strings.ProgressCheckingReplayState, 10);
                    }
                    base.WriteVerbose(Strings.VerboseConnectionAdminRpcInterface(this.OwnerServer.Fqdn));
                    MdbStatus mdbStatus = AmStoreHelper.GetMdbStatus(this.OwnerServer.Fqdn, this.DataObject.Guid);
                    if (mdbStatus == null)
                    {
                        base.WriteError(new InvalidOperationException(Strings.ErrorFailedToGetDatabaseStatus(this.Identity.ToString())), ErrorCategory.InvalidOperation, this.Identity);
                    }
                    if ((mdbStatus.Status & MdbStatusFlags.Backup) != MdbStatusFlags.Offline)
                    {
                        base.WriteError(new InvalidOperationException(Strings.ErrorBackupInProgress(this.Identity.ToString())), ErrorCategory.InvalidOperation, this.Identity);
                    }
                    else if ((mdbStatus.Status & MdbStatusFlags.Online) != MdbStatusFlags.Offline)
                    {
                        if (!this.Force && !base.ShouldContinue(base.ConfigurationOnly ? Strings.WarningDismountDatabaseToDoConfigurationOnly(this.Identity.ToString()) : Strings.WarningDismountDatabaseToContinue(this.Identity.ToString())))
                        {
                            TaskLogger.LogExit();
                            return;
                        }
                        if (this.needReportProgress)
                        {
                            base.WriteProgress(Strings.ProgressMoveDatabasePath(this.Identity.ToString()), Strings.ProgressDismountingDatabase(this.Identity.ToString()), 20);
                        }
                        base.WriteVerbose(TaskVerboseStringHelper.GetReadObjectVerboseString(id, base.DataSession, typeof(Server)));
                        try
                        {
                            base.WriteVerbose(Strings.VerboseUnmountDatabase(this.DataObject.Identity.ToString()));
                            AmRpcClientHelper.DismountDatabase(ADObjectWrapperFactory.CreateWrapper(this.DataObject), 0);
                        }
                        catch (AmServerException ex)
                        {
                            Exception ex2;
                            if (ex.TryGetInnerExceptionOfType(out ex2))
                            {
                                TaskLogger.Trace("MoveDatabasePath.InternalProcessRecord raises exception while unmounting database: {0}", new object[]
                                {
                                    ex2.Message
                                });
                            }
                            else if (ex.TryGetInnerExceptionOfType(out ex2))
                            {
                                TaskLogger.Trace("MoveDatabasePath.InternalProcessRecord raises exception while unmounting database: {0}", new object[]
                                {
                                    ex2.Message
                                });
                            }
                            else if (ex is AmDatabaseNeverMountedException)
                            {
                                TaskLogger.Trace("MoveDatabasePath.InternalProcessRecord raises exception while unmounting database: {0}", new object[]
                                {
                                    ex.Message
                                });
                            }
                            else
                            {
                                TaskLogger.Trace("MoveDatabasePath.InternalProcessRecord raises exception while unmounting database: {0}", new object[]
                                {
                                    ex.Message
                                });
                                base.WriteError(ex, ErrorCategory.InvalidOperation, this.DataObject.Identity);
                            }
                        }
                        catch (AmServerTransientException ex3)
                        {
                            TaskLogger.Trace("MoveDatabasePath.InternalProcessRecord raises exception while dismounting database: {0}", new object[]
                            {
                                ex3.Message
                            });
                            base.WriteError(ex3, ErrorCategory.InvalidOperation, this.DataObject.Identity);
                        }
                        flag = true;
                    }
                    if (!base.ConfigurationOnly)
                    {
                        if (this.IsDatabaseFilesCreated && this.IsEdbFilePathChanged)
                        {
                            if (this.needReportProgress)
                            {
                                base.WriteProgress(Strings.ProgressMoveDatabasePath(this.Identity.ToString()), Strings.ProgressCopyingEdbFile, 25);
                            }
                            if (!this.TryCopyFile(this.OriginalEdbFilePath.PathName, this.TargetEdbFilePath.PathName))
                            {
                                base.WriteError(new InvalidOperationException(Strings.ErrorFailedToMoveEdbFile(this.OriginalEdbFilePath.PathName, this.TargetEdbFilePath.PathName)), ErrorCategory.InvalidOperation, this.Identity);
                            }
                            flag2 = true;
                        }
                        if (this.isLogFolderPathChanged)
                        {
                            if (this.needReportProgress)
                            {
                                base.WriteProgress(Strings.ProgressMoveDatabasePath(this.Identity.ToString()), Strings.ProgressCopyingLogFiles, 45);
                            }
                            base.WriteVerbose(Strings.VerboseCopyDatabaseLogFiles(base.OwnerServerName, this.OldLogFolderPath.PathName, this.LogFolderPath.PathName));
                            if (!this.TryCopyPath(this.OldLogFolderPath.PathName, this.LogFolderPath.PathName, new WmiWrapper.FileFilter(this.LogFileFilter)))
                            {
                                base.WriteError(new InvalidOperationException(Strings.ErrorFailedToMoveDatabaseLogFiles(this.OldLogFolderPath.PathName, this.LogFolderPath.PathName)), ErrorCategory.InvalidOperation, this.DataObject.Identity);
                            }
                            flag4 = true;
                        }
                    }
                    if (this.needReportProgress)
                    {
                        base.WriteProgress(Strings.ProgressMoveDatabasePath(this.Identity.ToString()), Strings.ProgressSavingADObject, 69);
                    }
                    base.InternalProcessRecord();
                    flag3 = false;
                    if (flag2)
                    {
                        if (this.needReportProgress)
                        {
                            base.WriteProgress(Strings.ProgressMoveDatabasePath(this.Identity.ToString()), Strings.ProgressDeletingEdbFile, 72);
                        }
                        if (!this.TryDeleteFile(this.OriginalEdbFilePath.PathName))
                        {
                            this.WriteWarning(Strings.FailedToDeleteOldEdbFile(this.OriginalEdbFilePath.PathName));
                            TaskLogger.Trace("MoveDatabasePath: delete edb \"{0}\" file failed", new object[]
                            {
                                this.OriginalEdbFilePath.PathName
                            });
                        }
                    }
                    if (flag4)
                    {
                        if (this.needReportProgress)
                        {
                            base.WriteProgress(Strings.ProgressMoveDatabasePath(this.Identity.ToString()), Strings.ProgressDeletingLogFiles, 81);
                        }
                        base.WriteVerbose(Strings.VerboseDeleteDatabaseLogFiles(this.OwnerServer.Fqdn, this.OldLogFolderPath.PathName));
                        if (!WmiWrapper.DeleteFilesInDirectory(this.OwnerServer.Fqdn, this.OldLogFolderPath.PathName, new WmiWrapper.FileFilter(this.LogPathFilter)))
                        {
                            this.WriteWarning(Strings.FailedDeleteOldDatabaseLogFiles(this.OwnerServer.Fqdn, this.OldLogFolderPath.PathName));
                            TaskLogger.Trace("Failed to delete some of the orignal log files.", new object[0]);
                        }
                    }
                    if (this.moveCatalogs && SystemConfigurationTasksHelper.TryCreateDirectory(this.OwnerServer.Fqdn, this.targetCatalogsPath, null, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.TaskWarningLoggingDelegate(this.WriteWarning)))
                    {
                        if (this.needReportProgress)
                        {
                            base.WriteProgress(Strings.ProgressMoveDatabasePath(this.Identity.ToString()), Strings.ProgressCopyingCatalog, 87);
                        }
                        try
                        {
                            base.WriteVerbose(Strings.VerboseCopyDatabaseCatalogFiles(this.OwnerServer.Fqdn, this.originalCatalogsPath, this.targetCatalogsPath));
                            if (WmiWrapper.CopyFilesInDirectory(this.OwnerServer.Fqdn, this.originalCatalogsPath, this.targetCatalogsPath, new WmiWrapper.FileFilter(MoveDatabasePath.ReturnAllFiles)))
                            {
                                if (this.needReportProgress)
                                {
                                    base.WriteProgress(Strings.ProgressMoveDatabasePath(this.Identity.ToString()), Strings.ProgressDeletingCatalog, 92);
                                }
                                base.WriteVerbose(Strings.VerboseDeleteDatabaseCatalogFiles(this.OwnerServer.Fqdn, this.originalCatalogsPath));
                                WmiWrapper.DeleteFilesInDirectory(this.OwnerServer.Fqdn, this.originalCatalogsPath, new WmiWrapper.FileFilter(MoveDatabasePath.ReturnAllFiles));
                                base.WriteVerbose(Strings.VerboseDeleteDirectory(this.OwnerServer.Fqdn, this.originalCatalogsPath));
                                WmiWrapper.RemoveDirectory(this.OwnerServer.Fqdn, this.originalCatalogsPath);
                            }
                        }
                        catch (ManagementException ex4)
                        {
                            TaskLogger.Trace("MoveDatabasePath raised exception {0} while moving catalog files", new object[]
                            {
                                ex4.ToString()
                            });
                            this.WriteWarning(Strings.ErrorMovingCatalogs(this.Identity.ToString(), ex4.Message));
                        }
                        catch (ArgumentException ex5)
                        {
                            TaskLogger.Trace("MoveDatabasePath raised exception {0} while moving catalog files", new object[]
                            {
                                ex5.ToString()
                            });
                            this.WriteWarning(Strings.ErrorMovingCatalogs(this.Identity.ToString(), ex5.Message));
                        }
                    }
                    this.SendNotificationRpcToReplayService();
                    flag5 = true;
                }
            }
            catch (WmiException ex6)
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorFailedToConnectToServer(base.OwnerServerName, ex6.Message)), ErrorCategory.InvalidOperation, this.Identity);
            }
            catch (UnauthorizedAccessException ex7)
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorFailedToConnectToServer(base.OwnerServerName, ex7.Message)), ErrorCategory.InvalidOperation, this.Identity);
            }
            finally
            {
                if (flag3)
                {
                    if (flag2 && !this.TryDeleteFile(this.TargetEdbFilePath.PathName))
                    {
                        this.WriteWarning(Strings.FailedToDeleteTempEdbFile(this.TargetEdbFilePath.PathName));
                        TaskLogger.Trace("MoveDatabasePath: delete edb \"{0}\" file failed", new object[]
                        {
                            this.TargetEdbFilePath.PathName
                        });
                    }
                    if (flag4)
                    {
                        TaskLogger.Trace("Error occurs when Copying path. delete copied log files", new object[0]);
                        base.WriteVerbose(Strings.VerboseDeleteDatabaseLogFiles(this.OwnerServer.Fqdn, this.LogFolderPath.PathName));
                        if (!WmiWrapper.DeleteFilesInDirectory(this.OwnerServer.Fqdn, this.LogFolderPath.PathName, new WmiWrapper.FileFilter(this.LogFileFilter)))
                        {
                            this.WriteWarning(Strings.FailedDeleteTempDatabaseLogFiles(base.OwnerServerName, this.LogFolderPath.PathName));
                            TaskLogger.Trace("Failed to delete some of the copied log files.", new object[0]);
                        }
                    }
                }
                if (!base.ConfigurationOnly && flag)
                {
                    if (this.needReportProgress)
                    {
                        base.WriteProgress(Strings.ProgressMoveDatabasePath(this.Identity.ToString()), Strings.ProgressRestoringDatabaseStatus, 95);
                    }
                    base.WriteVerbose(TaskVerboseStringHelper.GetReadObjectVerboseString(id, base.DataSession, typeof(Server)));
                    try
                    {
                        if (!flag5)
                        {
                            this.SendNotificationRpcToReplayService();
                            flag5 = true;
                        }
                        base.WriteVerbose(Strings.VerboseMountDatabase(this.Identity.ToString()));
                        AmRpcClientHelper.MountDatabase(ADObjectWrapperFactory.CreateWrapper(this.DataObject), 0, 0, 0);
                    }
                    catch (AmServerException ex8)
                    {
                        string message = ex8.Message;
                        TaskLogger.Trace("MoveDatabasePath.InternalProcessRecord raises exception while re-mounting Mdb status: {0}", new object[]
                        {
                            message
                        });
                        this.WriteWarning(Strings.ErrorFailedToRestoreDatabaseStatus(this.Identity.ToString(), message));
                    }
                    catch (AmServerTransientException ex9)
                    {
                        string message2 = ex9.Message;
                        TaskLogger.Trace("MoveDatabasePath.InternalProcessRecord raises exception while re-mounting Mdb status: {0}", new object[]
                        {
                            message2
                        });
                        this.WriteWarning(Strings.ErrorFailedToRestoreDatabaseStatus(this.Identity.ToString(), message2));
                    }
                }
                TaskLogger.LogExit();
            }
        }
        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();
        }