Module/BusinessCentral/Invoke-BCSAlValidation.ps1

<#
.SYNOPSIS
    Validate your app against the app that is currently in use
.DESCRIPTION
    Validate your app against the app that is currently in use, validates agains Current, NextMinor and NextMajor. SaSToken must be provided.
 
.PARAMETER currentApp
  URL or filepath to the new version of the app
.PARAMETER previousApp
    URL or filepath to the app that is currently installed in BC
.PARAMETER sasToken
  Insider Token, can be found in Passwordstate
.PARAMETER supportedCountries
  listof countries where the app will be availible in App Source (se,dk,no)
.PARAMETER affixes
  list of mandatory affixes (BRC)
 
.NOTES
  Author: Mathias Stjernfelt
  Website: http://www.brightcom.se
 
.EXAMPLE
  Invoke-BCSAlValidation -currentApp "https://myUrl/myNewApp.app" -previousApp "https://myUrl/myPreviousApp.app" -sasToken "mySasToken"
 
  Invoke-BCSAlValidation -currentApp "https://myUrl/myNewApp.app" -previousApp "c:\myPreviousApp.app" -sasToken "mySasToken"
 
  Invoke-BCSAlValidation -currentApp "c:\myNewApp.app" -previousApp "https://myUrl/myPreviousApp.app" -sasToken "mySasToken"
 
  Invoke-BCSAlValidation -currentApp "c:\myNewApp.app" -previousApp "c:\myPreviousApp.app" -sasToken "mySasToken"
 
#>


function Invoke-BCSAlValidation {
    Param (
        [Parameter(ValueFromPipelineByPropertyName, Mandatory = $true)]
        [string]$currentApp,
        [Parameter(ValueFromPipelineByPropertyName, Mandatory = $false)]
        [string]$previousApp,
        [Parameter(ValueFromPipelineByPropertyName, Mandatory = $true)]
        [string]$sasToken,
        [Parameter(ValueFromPipelineByPropertyName, Mandatory = $false)]
        [string]$supportedCountries = "se,dk,no",
        [Parameter(ValueFromPipelineByPropertyName, Mandatory = $false)]
        [string]$affixes = "BRC"
    )
    begin {}

    process {
        if ($currentApp -like "http://*" -or $currentApp -like "https://*") {
            $currentAppFile = New-TemporaryFile;

            $fileName = Split-Path $currentApp -Leaf
            Write-Host "Downloading file $fileName to $currentAppFile"            
            
            (New-Object System.Net.WebClient).DownloadFile($currentApp, $currentAppFile)
        } else {
            $currentAppFile = $currentApp
        }

        if ($previousApp -like "http://*" -or $previousApp -like "https://*") {
            $previousAppFile = New-TemporaryFile;

            $fileName = Split-Path $previousApp -Leaf
            Write-Host "Downloading file $fileName to $previousAppFile"            

            (New-Object System.Net.WebClient).DownloadFile($previousApp, $previousAppFile)
        } else {
            $previousAppFile = $previousApp
        }

        Run-AlValidation -previousApps $previousApp `
            -apps $currentAppFile `
            -validateCurrent `
            -validateNextMajor `
            -validateNextMinor `
            -sasToken $sasToken `
            -countries $supportedCountries `
            -affixes $affixes `
            -supportedCountries $supportedCountries
    }
    end {
    }
}
            
Export-ModuleMember -Function Invoke-BCSAlValidation