Common/Result/Result.psm1
class RMError { [string] $ErrorCode [string] $Message [string] $Resolution RMError() {} RMError ([string] $Message) { $this.ErrorCode = $null $this.Message = $Message $this.Resolution = $null } RMError ([string] $ErrorCode, [string] $Message) { $this.ErrorCode = $ErrorCode $this.Message = $Message $this.Resolution = $null } RMError ([string] $ErrorCode, [string] $Message, [string] $Resolution) { $this.ErrorCode = $ErrorCode $this.Message = $Message $this.Resolution = $Resolution } } class RMWarning { [string] $ErrorCode [string] $Message [string] $Resolution RMWarning() {} RMWarning ([string] $Message) { $this.ErrorCode = $null $this.Message = $Message $this.Resolution = $null } RMWarning ([string] $ErrorCode, [string] $Message) { $this.ErrorCode = $ErrorCode $this.Message = $Message $this.Resolution = $null } RMWarning ([string] $ErrorCode, [string] $Message, [string] $Resolution) { $this.ErrorCode = $ErrorCode $this.Message = $Message $this.Resolution = $Resolution } } class RMPreflightCheck { [string] $Name [string] $DisplayName [string] $Description [string] $Status [RMError[]] $RMError [RMWarning[]] $RMWarning RMPreflightCheck() {} RMPreflightCheck ([string] $Name, [string] $DisplayName, [string] $Description, [string] $Status) { $this.Name = $Name $this.DisplayName = $DisplayName $this.Description = $Description $this.Status = $Status $this.RMError = $null $this.RMWarning = $null } [void] AddError([string] $ErrorCode, [string] $ErrorMessage) { if ($null -eq $this.RMError) { $this.RMError = @() } $this.RMError += [RMError]::new($ErrorCode, $ErrorMessage) } [void] AddWarning([string] $ErrorCode, [string] $WarningMessage) { if ($null -eq $this.RMWarning) { $this.RMWarning = @() } $this.RMWarning += [RMWarning]::new($ErrorCode, $WarningMessage) } [void] SetName([string] $Name) { $this.Name = $Name } [void] SetDisplayName([string] $DisplayName) { $this.DisplayName = $DisplayName } [void] SetDiscription([string] $Discription) { $this.Description = $Discription } [void] SetStatus([string] $Status) { $this.Status = $Status } } class RMReturn { static [int] $SUCCESS = 0 static [int] $ERROR = 1 [int] $ReturnCode [RMError[]] $RMError [RMWarning[]] $RMWarning [hashtable] $OutputData RMReturn () {} RMReturn ([int] $ReturnCode, [RMError[]] $RMError, [RMWarning[]] $RMWarning, [hashtable] $OutputData) { $this.ReturnCode = $ReturnCode $this.RMError = $RMError $this.RMWarning = $RMWarning $this.OutputData = $OutputData } RMReturn ([int] $ReturnCode, [hashtable] $OutputData) { $this.ReturnCode = $ReturnCode $this.RMError = $null $this.RMWarning = $null $this.OutputData = $OutputData } [void] AddRMError([RMError] $RMError) { if ($null -eq $this.RMError) { $this.RMError = @() } $this.RMError += $RMError } [void] AddRMWarning([RMWarning] $RMWarning) { if ($null -eq $this.RMWarning) { $this.RMWarning = @() } $this.RMWarning += $RMWarning } [void] SetOutputData([hashtable] $OutputData) { $this.OutputData = $OutputData } [void] SetReturnCode([int] $ReturnCode) { $this.ReturnCode = $ReturnCode } } class RMMigrationReturn : RMReturn { [string] $MigrationId [RMPreflightCheck[]] $RMPreflightCheck RMMigrationReturn () {} RMMigrationReturn ([string] $MigrationId, [int] $ReturnCode) { $this.MigrationId = $MigrationId $this.ReturnCode = $ReturnCode $this.RMPreflightCheck = $null } RMMigrationReturn ([RMReturn] $RMReturn) : base($RMReturn.ReturnCode, $RMReturn.RMError, $RMReturn.RMWarning, $RMReturn.OutputData){ } [void] SetMigrationId([string] $MigrationId) { $this.MigrationId = $MigrationId } [void] SetRMReturn([RMReturn] $RMReturn) { $this.ReturnCode = $RMReturn.ReturnCode foreach ($ErrorObj in $RMReturn.RMError) { if ($null -eq $this.RMError) { $this.RMError = @() } $this.RMError += $ErrorObj } foreach ($WarningObj in $RMReturn.RMWarning) { if ($null -eq $this.RMWarning) { $this.RMWarning = @() } $this.RMWarning += $WarningObj } } [void] AddPreflightCheck([RMPreflightCheck] $PreflightCheck) { if ($null -eq $this.RMPreflightCheck) { $this.RMPreflightCheck = @() } $this.RMPreflightCheck += $PreflightCheck } } |