public override bool Verify() { bool flag = !WmiWrapper.IsDirectoryExisting(base.ComputerName, base.PathName); TaskLogger.Trace("DirectoryNotExistCondition.Verify() returns {0}: <Server '{1}', DirectoryName '{2}'>", new object[] { flag, base.ComputerName, base.PathName }); return(flag); }
private void SaveLocalPath() { DirectoryEntry directoryEntry; try { directoryEntry = IisUtility.FindWebObject(this.Parent, this.Name, "IIsWebVirtualDir"); } catch (WebObjectNotFoundException) { return; } this.serverName = IisUtility.GetHostName(this.parent); if (WmiWrapper.IsDirectoryExisting(this.serverName, (string)directoryEntry.Properties["Path"].Value)) { this.localPath = (string)directoryEntry.Properties["Path"].Value; } }
public static bool CheckSeedingPath(string machineFqdn, string logFolderPath, string edbFilePath, string logPrefix) { LocalLongFullPath.Parse(logFolderPath); LocalLongFullPath.Parse(edbFilePath); string directoryName = Path.GetDirectoryName(edbFilePath); string[] array = new string[] { logFolderPath, directoryName }; string[] array2 = new string[] { "LogFolderPath", "EdbFolderPath" }; for (int i = 0; i < array.Length; i++) { if (WmiWrapper.IsFileExisting(machineFqdn, array[i])) { throw new SeedingPathErrorException(Strings.SeedingErrorDirectoryIsFile(array2[i], array[i])); } } string text = Path.Combine(logFolderPath, logPrefix + ".log"); if (WmiWrapper.IsDirectoryExisting(machineFqdn, text)) { throw new SeedingPathErrorException(Strings.SeedingErrorFileIsDirectory("CopyLogFile", text)); } if (WmiWrapper.IsDirectoryExisting(machineFqdn, edbFilePath)) { throw new SeedingPathErrorException(Strings.SeedingErrorFileIsDirectory("CopyEdbFilePath", edbFilePath)); } if (WmiWrapper.IsFileExisting(machineFqdn, edbFilePath)) { throw new SeedingPathWarningException(Strings.SeedingEdbFileExists(edbFilePath)); } if (WmiWrapper.IsFileExisting(machineFqdn, text)) { throw new SeedingPathWarningException(Strings.SeedingLogFileExists(text)); } return(true); }
public override bool Verify() { string dirName = null; try { dirName = LocalLongFullPath.ParseFromPathNameAndFileName(base.PathName, this.logPrefix + ".log").PathName; } catch (ArgumentException ex) { TaskLogger.Trace("LogLocationAvailableCondition.Verify() caught exception '{0}': <Server '{1}', PathName '{2}'>", new object[] { ex.Message, base.ComputerName, base.PathName }); return(false); } bool flag = true; if (WmiWrapper.IsDirectoryExisting(base.ComputerName, dirName)) { flag = false; } else if (WmiWrapper.IsFileExistingInPath(base.ComputerName, base.PathName, new WmiWrapper.FileFilter(this.LogFileFilter))) { flag = false; } else if (WmiWrapper.IsFileExisting(base.ComputerName, base.PathName)) { flag = false; } TaskLogger.Trace("LogLocationAvailableCondition.Verify() returns {0}: <Server '{1}', PathName '{2}'>", new object[] { flag, base.ComputerName, base.PathName }); return(flag); }
public override bool Verify() { string text = null; try { text = LocalLongFullPath.ParseFromPathNameAndFileName(base.PathName, "tmp.edb").PathName; } catch (ArgumentException ex) { TaskLogger.Trace("SystemPathAvailableCondition.Verify() caught exception '{0}': <Server '{1}', PathName '{2}'>", new object[] { ex.Message, base.ComputerName, base.PathName }); return(false); } bool flag = true; if (WmiWrapper.IsDirectoryExisting(base.ComputerName, text)) { flag = false; } else if (WmiWrapper.IsFileExisting(base.ComputerName, text)) { flag = false; } else if (WmiWrapper.IsFileExisting(base.ComputerName, base.PathName)) { flag = false; } TaskLogger.Trace("SystemPathAvailableCondition.Verify() returns {0}: <Server '{1}', PathName '{2}'>", new object[] { flag, base.ComputerName, base.PathName }); return(flag); }
private bool TryCopyPath(string originalPath, string newPath, WmiWrapper.FileFilter filter) { bool result = true; try { if (SystemConfigurationTasksHelper.TryCreateDirectory(this.ownerServer.Fqdn, newPath, Database_Directory.GetDomainWidePermissions(), new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.TaskWarningLoggingDelegate(this.WriteWarning))) { base.WriteVerbose(Strings.VerboseCheckDirectoryExistenceCondition(this.OwnerServer.Fqdn, originalPath)); if (WmiWrapper.IsDirectoryExisting(this.OwnerServer.Fqdn, originalPath)) { base.WriteVerbose(Strings.VerboseCopyDirectory(this.OwnerServer.Fqdn, originalPath, newPath)); if (!WmiWrapper.CopyFilesInDirectory(this.OwnerServer.Fqdn, originalPath, newPath, filter)) { result = false; } } else { TaskLogger.Trace("Original directory does not exist, nothing to copy.", new object[0]); } } else { result = false; } } catch (ManagementException ex) { base.WriteVerbose(Strings.VerboseEatUpException(ex.Message)); TaskLogger.Trace("Error occurs when copying path: {0}", new object[] { ex.Message }); result = false; } return(result); }
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(); }
public static bool TryCreateDirectory(string serverFQDN, string directoryPath, FileSystemAccessRule[] directoryPermissions, Task.TaskVerboseLoggingDelegate verboseDelegate, Task.TaskWarningLoggingDelegate warningDelegate) { bool flag = false; if (string.Compare(serverFQDN, NativeHelpers.GetLocalComputerFqdn(false), StringComparison.InvariantCultureIgnoreCase) == 0) { try { verboseDelegate(Strings.VerboseCheckDirectoryExistenceCondition(serverFQDN, directoryPath)); if (Directory.Exists(directoryPath)) { if (directoryPermissions != null) { DirectorySecurity directorySecurity = SystemConfigurationTasksHelper.CreateDirectorySecurityHelper(directoryPermissions); directorySecurity.SetAccessRuleProtection(true, false); verboseDelegate(Strings.VerboseSetAccessControl(serverFQDN, directoryPath)); TaskLogger.Trace("Directory \"" + directoryPath + "\" already exists on the local machine, just set the access control.", new object[0]); Directory.SetAccessControl(directoryPath, directorySecurity); flag = true; } else { verboseDelegate(Strings.VerboseNoAccessControlSpecified(serverFQDN, directoryPath)); TaskLogger.Trace("No access control specified to be set on directory \"" + directoryPath + "\".", new object[0]); flag = true; } } else if (directoryPermissions != null) { DirectorySecurity directorySecurity = SystemConfigurationTasksHelper.CreateDirectorySecurityHelper(directoryPermissions); directorySecurity.SetAccessRuleProtection(true, false); verboseDelegate(Strings.VerboseCreateDirectory(serverFQDN, directoryPath)); TaskLogger.Trace("Directory \"" + directoryPath + "\" does not exist. Create the directory on the local machine and set the access control.", new object[0]); Directory.CreateDirectory(directoryPath, directorySecurity); flag = true; } else { verboseDelegate(Strings.VerboseCreateDirectory(serverFQDN, directoryPath)); verboseDelegate(Strings.VerboseNoAccessControlSpecified(serverFQDN, directoryPath)); TaskLogger.Trace("Directory \"" + directoryPath + "\" does not exist. Create the directory on the local machine. No access controls specified to set on the directory.", new object[0]); Directory.CreateDirectory(directoryPath); flag = true; } goto IL_43C; } catch (NotSupportedException ex) { verboseDelegate(Strings.VerboseFailedCreateDirectory(serverFQDN, directoryPath, ex.Message)); TaskLogger.Trace("this.TryCreateDirectory() raised exception: {0}", new object[] { ex.ToString() }); goto IL_43C; } catch (ArgumentNullException ex2) { verboseDelegate(Strings.VerboseFailedCreateDirectory(serverFQDN, directoryPath, ex2.Message)); TaskLogger.Trace("this.TryCreateDirectory() raised exception: {0}", new object[] { ex2.ToString() }); goto IL_43C; } catch (UnauthorizedAccessException ex3) { verboseDelegate(Strings.VerboseFailedCreateDirectory(serverFQDN, directoryPath, ex3.Message)); TaskLogger.Trace("this.TryCreateDirectory() raised exception: {0}", new object[] { ex3.ToString() }); goto IL_43C; } catch (ArgumentException ex4) { verboseDelegate(Strings.VerboseFailedCreateDirectory(serverFQDN, directoryPath, ex4.Message)); TaskLogger.Trace("this.TryCreateDirectory() raised exception: {0}", new object[] { ex4.ToString() }); goto IL_43C; } catch (IOException ex5) { verboseDelegate(Strings.VerboseFailedCreateDirectory(serverFQDN, directoryPath, ex5.Message)); TaskLogger.Trace("this.TryCreateDirectory() raised exception: {0}", new object[] { ex5.ToString() }); goto IL_43C; } } try { verboseDelegate(Strings.VerboseCheckDirectoryExistenceCondition(serverFQDN, directoryPath)); uint num; if (!WmiWrapper.IsDirectoryExisting(serverFQDN, directoryPath)) { verboseDelegate(Strings.VerboseCreateDirectory(serverFQDN, directoryPath)); TaskLogger.Trace(string.Concat(new string[] { "Create the directory \"", directoryPath, "\" on the remote machine \"", serverFQDN, "\"." }), new object[0]); num = WmiWrapper.CreateDirectory(serverFQDN, directoryPath); } else { num = 0U; } if (num == 0U) { if (directoryPermissions != null) { verboseDelegate(Strings.VerboseSetAccessControl(serverFQDN, directoryPath)); TaskLogger.Trace(string.Concat(new string[] { "Set the access control for directory \"", directoryPath, "\" on the remote machine \"", serverFQDN, "\"." }), new object[0]); num = WmiWrapper.ChangeSecurityPermissions(serverFQDN, directoryPath, directoryPermissions); if (num == 0U) { flag = true; } else { verboseDelegate(Strings.VerboseFailedSetAccessControl(serverFQDN, directoryPath, "WMI Status: " + num.ToString())); TaskLogger.Trace("this.TryCreateDirectory() failed to set the access control on the directory - WMI Status: {0}", new object[] { num.ToString() }); } } else { verboseDelegate(Strings.VerboseNoAccessControlSpecified(serverFQDN, directoryPath)); TaskLogger.Trace("No access control specified to be set on directory \"" + directoryPath + "\".", new object[0]); flag = true; } } else { verboseDelegate(Strings.VerboseFailedCreateDirectory(serverFQDN, directoryPath, "WMI Status: " + num.ToString())); TaskLogger.Trace("this.TryCreateDirectory() failed to create the directory - WMI Status: {0}", new object[] { num.ToString() }); } } catch (WmiException ex6) { verboseDelegate(Strings.VerboseFailedCreateDirectory(serverFQDN, directoryPath, ex6.Message)); TaskLogger.Trace("this.TryCreateDirectory() raised exception: {0}", new object[] { ex6.ToString() }); } catch (UnauthorizedAccessException ex7) { verboseDelegate(Strings.ErrorFailedToConnectToServer(serverFQDN, ex7.Message)); TaskLogger.Trace("this.TryCreateDirectory() raised exception: {0}", new object[] { ex7.ToString() }); } IL_43C: if (!flag) { warningDelegate(Strings.WarningFailedCreateDirectory(serverFQDN, directoryPath)); } return(flag); }
public override bool Verify() { return((this.Path.Length >= "\\\\.\\".Length && this.Path.StartsWith("\\\\.\\")) || WmiWrapper.IsDirectoryExisting(this.ServerName, this.Path)); }