public SystemValidationsProcessor(IPowershellCommandRunner commandRunner, IList <ISystemValidation> validations, IList <IOutputWriter> outputWriters, IProgressReporter progressReporter) { this._commandRunner = commandRunner; this._validations = validations; this._outputWriters = outputWriters; this._progressReporter = progressReporter; }
protected override IValidationResult DoValidateUsing(IPowershellCommandRunner commandRunner) { if (!this._driveLetter.HasValue) { return(this.UnableToRunBecause( @"Unable to perform the File System validation. In order to run this validation, specify 'Path' parameter such that it includes the drive letter, e.g. C:\MyDataSet or \\contoso-server\d$\data")); } string filesystem; try { commandRunner.AddScript($"Get-Volume -DriveLetter {this._driveLetter.Value}"); PSObject volume = commandRunner.Invoke()[0]; filesystem = (string)volume.Members["FileSystem"].Value; } catch (Exception e) { return(this.UnableToRunBecause($"The File System validation was not able to run. Cause: {e.Message}")); } if (this.IsValid(filesystem)) { return(this.SuccessfulResult); } return(new ValidationResult { Description = $"The {filesystem} filesystem is not supported.", Level = ResultLevel.Error, Result = Result.Fail, Type = this.ValidationType, Kind = this.ValidationKind }); }
protected override IValidationResult DoValidateUsing(IPowershellCommandRunner commandRunner) { string osVersion; UInt32 sku; try { commandRunner.AddScript("Get-CimInstance Win32_OperatingSystem"); PSObject resultPSObject = commandRunner.Invoke().First(); osVersion = (string)resultPSObject.Members["Version"].Value; sku = (UInt32)resultPSObject.Members["OperatingSystemSKU"].Value; } catch (Exception e) { return(ValidationResult.UnavailableValidation( this.ValidationType, this.ValidationKind, $"The OS Version validation was not able to complete. Cause: {e.Message}")); } if (!IsValidVersion(osVersion)) { return(new ValidationResult() { Description = $"OS version {osVersion} is not supported. Supported versions are: {this._supportedVersionsString}", Level = ResultLevel.Error, Type = this.ValidationType, Kind = this.ValidationKind, Result = Result.Fail }); } if (!this.IsValidSKU(sku)) { string skuEdition = this._editions.ContainsKey(sku) ? this._editions[sku] : sku.ToString(); return(new ValidationResult() { Description = $"OS edition '{skuEdition}' is not supported. Supported editions are: {this._supportedEditionsStrings}", Level = ResultLevel.Error, Type = this.ValidationType, Kind = this.ValidationKind, Result = Result.Fail }); } return(this.SuccessfulResult); }
/// <summary> /// Does the validate using. /// </summary> /// <param name="commandRunner">The command runner.</param> /// <returns>IValidationResult.</returns> protected virtual IValidationResult DoValidateUsing(IPowershellCommandRunner commandRunner) { return(SuccessfulResult); }
/// <summary> /// Validates the using. /// </summary> /// <param name="commandRunner">The command runner.</param> /// <returns>IValidationResult.</returns> public IValidationResult ValidateUsing(IPowershellCommandRunner commandRunner) { return(DoValidateUsing(commandRunner)); }