diff --git a/.gitignore b/.gitignore
index aa4c089..a1db876 100644
--- a/.gitignore
+++ b/.gitignore
@@ -98,3 +98,6 @@ policheck*
*.orig.sln
*pingme*
*.GhostDoc.xml
+**/.vs/ChocolateyProvider
+/paket-files/
+/.paket/
diff --git a/.nuget/NuGet.Config b/.nuget/NuGet.Config
deleted file mode 100644
index 67f8ea0..0000000
--- a/.nuget/NuGet.Config
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.nuget/NuGet.exe b/.nuget/NuGet.exe
deleted file mode 100644
index c296edf..0000000
Binary files a/.nuget/NuGet.exe and /dev/null differ
diff --git a/.nuget/NuGet.targets b/.nuget/NuGet.targets
deleted file mode 100644
index 3f8c37b..0000000
--- a/.nuget/NuGet.targets
+++ /dev/null
@@ -1,144 +0,0 @@
-
-
-
- $(MSBuildProjectDirectory)\..\
-
-
- false
-
-
- false
-
-
- true
-
-
- false
-
-
-
-
-
-
-
-
-
-
- $([System.IO.Path]::Combine($(SolutionDir), ".nuget"))
-
-
-
-
- $(SolutionDir).nuget
-
-
-
- $(MSBuildProjectDirectory)\packages.$(MSBuildProjectName.Replace(' ', '_')).config
- $(MSBuildProjectDirectory)\packages.$(MSBuildProjectName).config
-
-
-
- $(MSBuildProjectDirectory)\packages.config
- $(PackagesProjectConfig)
-
-
-
-
- $(NuGetToolsPath)\NuGet.exe
- @(PackageSource)
-
- "$(NuGetExePath)"
- mono --runtime=v4.0.30319 "$(NuGetExePath)"
-
- $(TargetDir.Trim('\\'))
-
- -RequireConsent
- -NonInteractive
-
- "$(SolutionDir) "
- "$(SolutionDir)"
-
-
- $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)
- $(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols
-
-
-
- RestorePackages;
- $(BuildDependsOn);
-
-
-
-
- $(BuildDependsOn);
- BuildPackage;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 0000000..6c9fae7
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,29 @@
+{
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "type": "PowerShell",
+ "request": "launch",
+ "name": "Build",
+ "script": "Invoke-Psake",
+ "args": ["Build"],
+ "cwd": "${workspaceRoot}\\Build"
+ },
+ {
+ "type": "PowerShell",
+ "request": "launch",
+ "name": "Build and Test",
+ "script": "Invoke-Psake",
+ "args": [],
+ "cwd": "${workspaceRoot}\\Build"
+ },
+ {
+ "type": "PowerShell",
+ "request": "launch",
+ "name": "Test",
+ "script": "Invoke-Psake",
+ "args": ["Test"],
+ "cwd": "${workspaceRoot}\\Build"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..a0672fb
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,3 @@
+{
+ "powershell.scriptAnalysis.settingsPath": "PSScriptAnalyzerSettings.psd1"
+}
\ No newline at end of file
diff --git a/Build/build.ps1 b/Build/build.ps1
new file mode 100644
index 0000000..66bdf43
Binary files /dev/null and b/Build/build.ps1 differ
diff --git a/Build/prepareEnvironment.ps1 b/Build/prepareEnvironment.ps1
new file mode 100644
index 0000000..bf1e921
--- /dev/null
+++ b/Build/prepareEnvironment.ps1
@@ -0,0 +1,13 @@
+$InstallDir='C:\ProgramData\chocoportable'
+$env:ChocolateyInstall="$InstallDir"
+
+Set-ExecutionPolicy Bypass -Scope Process
+Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
+
+# Testing framework
+Install-Module -Name Pester -Force -SkipPublisherCheck -Scope "CurrentUser" -RequiredVersion 4.3.1
+Import-Module -Name Pester
+Install-Module -Name psake -Force -Scope "CurrentUser" -RequiredVersion 4.7.0
+Import-Module -Name psake
+
+choco install paket -y -version 5.133.0
\ No newline at end of file
diff --git a/Build/psakefile.ps1 b/Build/psakefile.ps1
new file mode 100644
index 0000000..35c2dbf
--- /dev/null
+++ b/Build/psakefile.ps1
@@ -0,0 +1,106 @@
+$targetFolder = Join-Path $PSScriptRoot "Output"
+$moduleName = "Chocolatey-OneGet"
+$moduleFolder = Join-Path $targetFolder $moduleName
+$outputRepository = "$moduleName-OutputRepository"
+$installedModule = "$home\Documents\WindowsPowerShell\Modules\$moduleName"
+$moduleVersion = "0.10.9"
+$testsFilter = "*" # all by default
+#$testsFilter = "Uninstall package"
+
+Task Default -Depends `
+ Build,`
+ Test
+
+Task Build -Depends `
+ Clean-OutputRepository,`
+ Clean,`
+ Restore-Packages,`
+ Register-OutputRepository, `
+ Compile, `
+ PublishTo-OutputRepository, `
+ Compile-TestPackage
+
+Task Restore-Packages {
+ Exec {
+ paket restore
+ }
+}
+
+Task Clean {
+ Remove-Item $targetFolder -Force -Recurse -ErrorAction SilentlyContinue
+ # This needs to kill the Visual Studio code powershell instance, otherwise the chocolatey.dll is locked.
+ Remove-Item $installedModule -Force -Recurse -ErrorAction SilentlyContinue
+}
+
+Task Compile {
+ Copy-ToTargetFolder $moduleFolder
+}
+
+Task Clean-OutputRepository {
+ Unregister-PSRepository $outputRepository -ErrorAction SilentlyContinue
+}
+
+Task Register-OutputRepository {
+ mkdir "$targetFolder\$moduleName" | Out-Null
+
+ if((Get-PSRepository | Where-Object { $_.Name -eq $outputRepository}) -eq $null){
+ Register-PSRepository -Name $outputRepository -SourceLocation $targetFolder -PublishLocation $targetFolder -InstallationPolicy Trusted | Out-Null
+ }
+}
+
+Task Compile-TestPackage {
+ $testPackages = Join-Path $targetFolder "TestPackages"
+
+ if(-Not (Test-Path $testPackages)){
+ mkdir $testPackages | Out-Null
+ }
+
+ Exec {
+ choco pack ..\TestPackage\TestPackage.nuspec --outputdirectory $testPackages --version=1.0.1
+ choco pack ..\TestPackage\TestPackage.nuspec --outputdirectory $testPackages --version=1.0.2
+ choco pack ..\TestPackage\TestPackage.nuspec --outputdirectory $testPackages --version=1.0.3
+ choco pack ..\TestPackage\TestPackage.nuspec --outputdirectory $testPackages --version=1.1.0-beta1
+ }
+}
+
+Task Import-CompiledModule {
+ if((Get-Module -Name $moduleName) -eq $null){
+ # equivalent to: Install-Module $moduleName -Repository $outputRepository -Force -AllowClobber -Scope "CurrentUser"
+ $targetFolder = Join-Path $installedModule $moduleVersion
+ Copy-ToTargetFolder $targetFolder
+
+ Import-Module $moduleName -Force -Scope Local
+ }
+}
+
+Task Test -Depends Import-CompiledModule {
+ # Run Pester tests
+ $testResults = Invoke-Pester ../Tests/* -PassThru -TestName $testsFilter
+
+ if ($testResults.FailedCount -gt 0) {
+ Write-Error -Message 'One or more Pester tests failed!'
+ }
+}
+
+Task PublishTo-OutputRepository {
+ Publish-Module -Path $moduleFolder -Repository $outputRepository -Force
+}
+
+Task Publish {
+ # nugetApi key needs to be provided by chocolatey owners
+ Publish-Module -Path $moduleFolder -NuGetApiKey ""
+}
+
+function Copy-ToTargetFolder(){
+ param([String]$targetFolder)
+
+ if(-Not (Test-Path $targetFolder)){
+ mkdir $targetFolder | Out-Null
+ }
+
+ Copy-Item -Path "..\$moduleName.psd1" -Destination "$targetFolder\$moduleName.psd1" -Force
+ Copy-Item -Path "..\$moduleName.psm1" -Destination "$targetFolder\$moduleName.psm1" -Force
+ Copy-Item -Path "..\Chocolatey-Helpers.psm1" -Destination "$targetFolder\Chocolatey-Helpers.psm1" -Force
+ Copy-Item -Path "..\packages\chocolatey.lib\lib\chocolatey.dll" -Destination "$targetFolder\chocolatey.dll" -Force
+ Copy-Item -Path "..\packages\log4net\lib\net40-client\log4net.dll" -Destination "$targetFolder\log4net.dll" -Force
+}
\ No newline at end of file
diff --git a/Chocolatey-Helpers.psm1 b/Chocolatey-Helpers.psm1
new file mode 100644
index 0000000..c3ad23c
--- /dev/null
+++ b/Chocolatey-Helpers.psm1
@@ -0,0 +1,19 @@
+function IsChocolateyInstalled() {
+ $script:chocolateyDir = $null
+ if ($null -ne $env:ChocolateyInstall) {
+ $script:chocolateyDir = $env:ChocolateyInstall;
+ }
+ elseif (Test-Path (Join-Path $env:SYSTEMDRIVE Chocolatey)) {
+ $script:chocolateyDir = Join-Path $env:SYSTEMDRIVE Chocolatey;
+ }
+ elseif (Test-Path (Join-Path ([Environment]::GetFolderPath("CommonApplicationData")) Chocolatey)) {
+ $script:chocolateyDir = Join-Path ([Environment]::GetFolderPath("CommonApplicationData")) Chocolatey;
+ }
+
+ Test-Path -Path $script:chocolateyDir;
+}
+
+function Register-ChocoDefaultSource(){
+ # choco source add -n=choco -s=https://chocolatey.org/api/v2/
+ Register-PackageSource -ProviderName chocolatey-oneget -Name choco -Location https://chocolatey.org/api/v2/
+}
\ No newline at end of file
diff --git a/Chocolatey-OneGet.psd1 b/Chocolatey-OneGet.psd1
new file mode 100644
index 0000000..8885c5f
Binary files /dev/null and b/Chocolatey-OneGet.psd1 differ
diff --git a/Chocolatey-OneGet.psm1 b/Chocolatey-OneGet.psm1
new file mode 100644
index 0000000..08e1ae6
--- /dev/null
+++ b/Chocolatey-OneGet.psm1
@@ -0,0 +1,573 @@
+$sourceCommandName = "source"
+$optionPriority = "Priority"
+$optionBypassProxy = "BypassProxy"
+$optionAllowSelfService = "AllowSelfService"
+$optionVisibleToAdminsOnly = "VisibleToAdminsOnly"
+$optionCertificate = "Certificate"
+$optionCertificatePassword = "CertificatePassword"
+$optionTags = "Tag"
+$optionAllVersions = "AllVersions"
+$optionPreRelease = "PrereleaseVersions"
+$optionAllowMultiple = "AllowMultipleVersions"
+$optionForceDependencies = "ForceDependencies"
+$optionPackageParameters = "PackageParameters"
+$optionUpgrade = "Upgrade"
+
+$script:wildcardOptions = [System.Management.Automation.WildcardOptions]::CultureInvariant -bor `
+ [System.Management.Automation.WildcardOptions]::IgnoreCase
+
+function Get-PackageProviderName {
+ return "Chocolatey-OneGet"
+}
+
+function Initialize-Provider {
+ $chocoBinary = Join-Path $PSScriptRoot "\\chocolatey.dll"
+ Add-Type -Path $chocoBinary
+}
+
+function Get-Feature {
+ # New-Feature commes from PackageProvider functions
+ Write-Output -InputObject (New-Feature -name "file-extensions" -values @(".nupkg"))
+ Write-Output -InputObject (New-Feature -name "uri-schemes" -values @("http", "https", "file"))
+}
+
+function Get-DynamicOptions{
+ param(
+ [Microsoft.PackageManagement.MetaProvider.PowerShell.OptionCategory]
+ $category
+ )
+
+ Write-Debug ("Get-DynamicOptions")
+ switch($category){
+ Source {
+ Write-Output -InputObject (New-DynamicOption -Category $category -Name $optionPriority -ExpectedType int -IsRequired $false)
+ Write-Output -InputObject (New-DynamicOption -Category $category -Name $optionBypassProxy -ExpectedType switch -IsRequired $false)
+ Write-Output -InputObject (New-DynamicOption -Category $category -Name $optionAllowSelfService -ExpectedType switch -IsRequired $false)
+ Write-Output -InputObject (New-DynamicOption -Category $category -Name $optionVisibleToAdminsOnly -ExpectedType switch -IsRequired $false)
+ Write-Output -InputObject (New-DynamicOption -Category $category -Name $optionCertificate -ExpectedType string -IsRequired $false)
+ Write-Output -InputObject (New-DynamicOption -Category $category -Name $optionCertificatePassword -ExpectedType string -IsRequired $false)
+ }
+
+ Package {
+ Write-Output -InputObject (New-DynamicOption -Category $category -Name $optionTags -ExpectedType StringArray -IsRequired $false)
+ Write-Output -InputObject (New-DynamicOption -Category $category -Name $optionAllVersions -ExpectedType switch -IsRequired $false)
+ Write-Output -InputObject (New-DynamicOption -Category $category -Name $optionPreRelease -ExpectedType switch -IsRequired $false)
+ }
+
+ Install {
+ Write-Output -InputObject (New-DynamicOption -Category $category -Name $optionAllowMultiple -ExpectedType switch -IsRequired $false)
+ Write-Output -InputObject (New-DynamicOption -Category $category -Name $optionForceDependencies -ExpectedType switch -IsRequired $false)
+ Write-Output -InputObject (New-DynamicOption -Category $category -Name $optionPreRelease -ExpectedType switch -IsRequired $false)
+ Write-Output -InputObject (New-DynamicOption -Category $category -Name $optionPackageParameters -ExpectedType string -IsRequired $false)
+ Write-Output -InputObject (New-DynamicOption -Category $category -Name $optionUpgrade -ExpectedType switch -IsRequired $false)
+ }
+ }
+}
+
+function Resolve-PackageSource {
+ $SourceNames = $request.PackageSources
+
+ if($SourceNames.Count -eq 0) {
+ $SourceNames += "*"
+ }
+
+ $choco = Get-Chocolatey
+ # fluent API of Set method returns it self,
+ # without assignment it is written as output object and break Find-Package
+ $choco = $choco.Set({
+ param($config)
+
+ $config.CommandName = $sourceCommandName
+ $config.SourceCommand.Command = [chocolatey.infrastructure.app.domain.SourceCommandType]::list
+ $config.QuietOutput = $True
+ });
+
+ $method = $choco.GetType().GetMethod("List")
+ $gMethod = $method.MakeGenericMethod([chocolatey.infrastructure.app.configuration.ChocolateySource])
+ $registered = $gMethod.Invoke($choco, $Null)
+
+ foreach($pattern in $SourceNames){
+ if($request.IsCanceled) {
+ return;
+ }
+
+ $wildcardPattern = New-Object System.Management.Automation.WildcardPattern $pattern, $script:wildcardOptions
+ $filtered = $registered | Where-Object { $wildcardPattern.IsMatch($_.Id) -or $wildcardPattern.IsMatch($_.Value) }
+
+ forEach($source in $filtered){
+ $packageSource = New-PackageSource -Name $source.Id -Location $source.Value -Trusted $False -Registered $True
+ Write-Output -InputObject $packageSource
+ }
+
+ if($iltered.Count -eq 0) {
+ # if the path is valid isnt really not our responsibility, only for Url values
+ $parsedUri = $null
+
+ if([System.Uri]::TryCreate($pattern, [System.UriKind]::Absolute, [ref]$parsedUri)){
+ $packageSource = New-PackageSource -Name $pattern -Location $pattern -Trusted $False -Registered $False
+ Write-Output -InputObject $packageSource
+ }
+ }
+ }
+}
+
+function Add-PackageSource {
+ [CmdletBinding()]
+ param(
+ [string]
+ $Name,
+
+ [string]
+ $Location,
+
+ [bool]
+ $Trusted
+ )
+
+ if([string]::IsNullOrEmpty($Name)) {
+ ThrowError "System.ArgumentException" "Source Name is required"
+ return
+ }
+
+ if([string]::IsNullOrEmpty($Location)) {
+ ThrowError "System.ArgumentException" "Source Location is required"
+ return
+ }
+
+ $priority = ParseDynamicOption $optionPriority 0
+ $bypassProxy = ParseDynamicOption $optionBypassProxy $False
+ $allowSelfService = ParseDynamicOption $optionAllowSelfService $False
+ $visibleToAdminsOnly = ParseDynamicOption $optionVisibleToAdminsOnly $False
+ $certificate = ParseDynamicOption $optionCertificate ""
+ $certificatePassword = ParseDynamicOption $optionCertificatePassword ""
+
+ $choco = Get-Chocolatey
+ $choco = $choco.Set({
+ param($config)
+
+ $config.CommandName = $sourceCommandName
+ $config.SourceCommand.Command = [chocolatey.infrastructure.app.domain.SourceCommandType]::add
+ $config.SourceCommand.Name = $Name
+ $config.Sources = $Location
+ $config.SourceCommand.Priority = $priority
+ $config.SourceCommand.BypassProxy = $bypassProxy
+ $config.SourceCommand.AllowSelfService = $allowSelfService
+ $config.SourceCommand.VisibleToAdminsOnly = $visibleToAdminsOnly
+ $config.SourceCommand.Certificate = $certificate
+ $config.SourceCommand.CertificatePassword = $certificatePassword
+
+ $credential = $request.Credential
+
+ if ($Null -ne $credential){
+ $config.SourceCommand.Username = $credential.UserName
+ $config.SourceCommand.Password = $credential.GetNetworkCredential().Password
+ }
+ })
+
+ $choco.Run()
+
+ $created = New-Object PSCustomObject -Property (@{
+ Name = $Name
+ Location = $Location
+ Trusted = $False
+ Registered = $True
+ })
+
+ $created = New-PackageSource -Name $Name -Location $Location -Trusted $False -Registered $True
+ Write-Output -InputObject $created
+}
+
+function Remove-PackageSource {
+ [CmdletBinding()]
+ param
+ (
+ [string]
+ $Name
+ )
+
+ if([string]::IsNullOrEmpty($Name)) {
+ ThrowError "System.ArgumentException" "Source Name is required"
+ return
+ }
+
+ $choco = Get-Chocolatey
+ $choco = $choco.Set({
+ param($config)
+
+ $config.CommandName = $sourceCommandName
+ $config.SourceCommand.Command = [chocolatey.infrastructure.app.domain.SourceCommandType]::remove
+ $config.SourceCommand.Name = $Name
+ });
+
+ $choco.Run()
+}
+
+function Find-Package {
+ [CmdletBinding()]
+ param(
+ [string]
+ $Name,
+
+ [string]
+ $RequiredVersion,
+
+ [string]
+ $MinimumVersion,
+
+ [string]
+ $MaximumVersion
+ )
+
+ Find-ChocoPackage $Name $RequiredVersion $MinimumVersion $MaximumVersion | Write-Output
+}
+function Find-ChocoPackage {
+ [CmdletBinding()]
+ param(
+ [string]
+ $Name,
+
+ [string]
+ $RequiredVersion,
+
+ [string]
+ $MinimumVersion,
+
+ [string]
+ $MaximumVersion,
+
+ [switch]
+ $localScope
+ )
+
+ $sourceNames = $Request.PackageSources
+ $tags = ParseDynamicOption $optionTags @()
+ $allVersions = ParseDynamicOption $optionAllVersions $false
+ $preRelease = ParseDynamicOption $optionPreRelease $false
+ $queryVersions = Parse-Version $RequiredVersion $MinimumVersion $MaximumVersion
+ $allVersions = ($allVersions -or $queryVersions.defined)
+ $byIdOnly = -not [string]::IsNullOrEmpty($Name) -or $queryVersions.defined
+
+ if($sourceNames.Count -eq 0){
+ Resolve-PackageSource | ForEach-Object{
+ $sourceNames += $_.Name
+ }
+ }
+
+ $source = [String]::Join(";", $sourceNames)
+
+ $choco = Get-Chocolatey
+ $choco = $choco.Set({
+ param($config)
+
+ $config.CommandName = [chocolatey.infrastructure.app.domain.CommandNameType]::list
+
+ $config.Input = $Name
+ $config.Sources = $source
+ $config.ListCommand.ByIdOnly = $byIdOnly
+ $config.ListCommand.LocalOnly = $localScope
+
+ if($queryVersions.min -eq $queryVersions.max){
+ $config.Version = $RequiredVersion
+ }
+
+ $config.AllVersions = $allVersions
+ $config.Prerelease = $preRelease
+ })
+
+ $method = $choco.GetType().GetMethod("List")
+ $gMethod = $method.MakeGenericMethod([chocolatey.infrastructure.results.PackageResult])
+ $packages = $gMethod.Invoke($choco, $Null)
+
+ foreach($found in $packages){
+ if($request.IsCanceled) {
+ return
+ }
+
+ # Choco has different usage for the tag filtering option
+ $package = $found.Package
+ $packageTags = $package.Tags
+ $tagFound = $tags.Count -eq 0
+
+ foreach($tag in $tags){
+ $tagFound = $tagFound -or $packageTags.Contains($tag)
+ }
+
+ if(-Not $tagFound){
+ continue
+ }
+
+ [NuGet.SemanticVersion]$actual = $null;
+ if ([NuGet.SemanticVersion]::TryParse($package.Version,[ref] $actual) `
+ -and ($actual -lt $queryVersions.min -or $actual -gt $queryVersions.max)){
+ continue
+ }
+
+ $packageName = $found.Name
+ $packageVersion = $found.Version
+ $fileName = "$packageName.$packageVersion.nupkg"
+ $packageReference = Build-FastPackageReference $found
+
+ # web server sends Uri, but local and Unc paths fill only source with full directory path
+ $fullPath = $found.SourceUri
+ if($Null -eq $fullPath) {
+ $parsedUri = $null
+
+ if([System.Uri]::TryCreate($found.Source, [System.UriKind]::Absolute, [ref]$parsedUri) -and $parsedUri.IsFile) {
+ $fullPath = Join-Path $parsedUri.AbsolutePath $fileName
+ } else {
+ ThrowError "System.FormatException" "Unable to parse local file path from '$fullPath'"
+ }
+ }
+
+ $identity = New-SoftwareIdentity $packageReference $packageName $packageVersion "semver" `
+ $source $found.Description $Name $fullPath $fileName
+ Write-Output $identity
+ }
+}
+
+function Get-InstalledPackage {
+ [CmdletBinding()]
+ param(
+ [Parameter()]
+ [string]
+ $Name,
+
+ [Parameter()]
+ [string]
+ $RequiredVersion,
+
+ [Parameter()]
+ [string]
+ $MinimumVersion,
+
+ [Parameter()]
+ [string]
+ $MaximumVersion
+ )
+
+ Find-ChocoPackage $Name $RequiredVersion $MinimumVersion $MaximumVersion -localScope | Write-Output
+}
+
+function Install-Package {
+ [CmdletBinding()]
+ param(
+ [Parameter(Mandatory=$true)]
+ [ValidateNotNullOrEmpty()]
+ [string]
+ $FastPackageReference
+ )
+
+ $packageReference = Parse-FastPackageReference $FastPackageReference
+ $multipleVersions = ParseDynamicOption $optionAllowMultiple $false
+ $packageArgs = ParseDynamicOption $optionPackageParameters ""
+ $upgrade = ParseDynamicOption $optionUpgrade $false
+ $installCommand = [chocolatey.infrastructure.app.domain.CommandNameType]::install
+
+ if ($upgrade) {
+ $installCommand = [chocolatey.infrastructure.app.domain.CommandNameType]::upgrade
+ }
+
+ #TODO needs to solve the source as trusted, otherwise automatic test is not able to execute
+
+ $choco = Get-Chocolatey
+ $choco = $choco.Set({
+ param($config)
+
+ $config.CommandName = $installCommand
+ $config.PackageNames = $packageReference.Name
+ $config.Version = $packageReference.Version
+ $config.Sources = $packageReference.Source
+ $config.PromptForConfirmation = $False
+ $config.AllowMultipleVersions = $multipleVersions
+ $config.PackageParameters = $packageArgs
+ $config.Features.UsePackageExitCodes = $false
+ });
+
+ $choco.Run()
+
+ $identity = New-SoftwareIdentity $FastPackageReference $packageReference.Name `
+ $packageReference.Version "semver" $packageReference.source
+ Write-Output $identity
+ }
+
+function UnInstall-Package {
+ [CmdletBinding()]
+ param(
+ [Parameter(Mandatory=$true)]
+ [ValidateNotNullOrEmpty()]
+ [string]
+ $FastPackageReference
+ )
+
+ $packageReference = Parse-FastPackageReference $FastPackageReference
+
+ $choco = Get-Chocolatey
+ $choco = $choco.Set({
+ param($config)
+
+ $config.CommandName = [chocolatey.infrastructure.app.domain.CommandNameType]::uninstall
+ $config.PackageNames = $packageReference.Name
+ $config.Features.UsePackageExitCodes = $false
+ $config.Version = $packageReference.Version
+ });
+
+ $choco.Run()
+
+ $identity = New-SoftwareIdentity $FastPackageReference $packageReference.Name `
+ $packageReference.Version "semver" $packageReference.source
+ Write-Output $identity
+}
+
+function Download-Package {
+ [CmdletBinding()]
+ param(
+ [Parameter(Mandatory=$true)]
+ [ValidateNotNullOrEmpty()]
+ [string]
+ $FastPackageReference,
+
+ [Parameter(Mandatory=$true)]
+ [ValidateNotNullOrEmpty()]
+ [string]
+ $Location
+ )
+
+ if(-not $Location -or -not (Test-Path $Location)){
+ ThrowError "System.ArgumentException" "Target location is required"
+ }
+
+ $force = ParseDynamicOption "Force" $false
+ $packageReference = Parse-FastPackageReference $FastPackageReference
+ $found = Find-ChocoPackage $packageReference.Name $packageReference.Version
+ $downloadUrl = $found.FullPath
+ $fileName = $found.PackageFilename
+ $output = Join-Path $outputDirectory $fileName
+
+ if (!(Test-Path $outputDirectory)) {
+ New-Item -ItemType Directory $outputDirectory
+ }
+
+ $parsedUri = $null
+
+ if([System.Uri]::TryCreate($downloadUrl, [System.UriKind]::Absolute, [ref]$parsedUri)) {
+ if($parsedUri.IsFile){
+ Copy-Item -Path $parsedUri.AbsolutePath -Destination $output -Force:$force
+ } else {
+ Invoke-WebRequest -Uri $downloadUrl -OutFile $output
+ }
+ } else {
+ ThrowError "System.FormatException" "Unable to parse download address from '$downloadUrl'"
+ }
+}
+
+#region Helper functions
+
+function Get-Chocolatey{
+ $choco = [chocolatey.Lets]::GetChocolatey()
+ return $choco
+}
+
+function ParseDynamicOption() {
+ param(
+ [string]
+ $optionName,
+
+ $defaultValue
+ )
+
+ $options = $request.Options
+
+ if($options.ContainsKey($optionName)){
+ return $options[$optionName]
+ }
+
+ return $defaultValue
+}
+
+function ThrowError(){
+ [CmdletBinding()]
+ param(
+ [Parameter(Mandatory=$true)]
+ [ValidateNotNullOrEmpty()]
+ [string]
+ $exceptionType,
+
+ [Parameter(Mandatory=$true)]
+ [ValidateNotNullOrEmpty()]
+ [string]
+ $exceptionMessage
+ )
+
+ $exception = New-Object $exceptionType $exceptionMessage
+ $errorCategory = [System.Management.Automation.ErrorCategory]::InvalidOperation
+ $errorRecord = New-Object System.Management.Automation.ErrorRecord $exception, "Chocolatey", $errorCategory, $Null
+ $PSCmdlet.ThrowTerminatingError($errorRecord)
+}
+
+function Parse-Version(){
+ param([string]$requiredVersion,
+ [string]$minimumVersion,
+ [string]$maximumVersion
+ )
+
+ [NuGet.SemanticVersion]$min = $null
+ [NuGet.SemanticVersion]$max = $null
+ [NuGet.SemanticVersion]$actual = $null
+ $defined = $false
+
+ if (-Not [string]::IsNullOrEmpty($requiredVersion) -and [NuGet.SemanticVersion]::TryParse($requiredVersion, [ref] $actual)){
+ $min = $max = $actual
+ $defined = $true
+ } else {
+ if ([string]::IsNullOrEmpty($minimumVersion) -or -not [NuGet.SemanticVersion]::TryParse($minimumVersion, [ref] $min)){
+ $version = New-Object Version
+ $min = New-Object "NuGet.SemanticVersion" $version
+ } else {
+ $defined = $true
+ }
+
+ if ([string]::IsNullOrEmpty($maximumVersion) -or -not [NuGet.SemanticVersion]::TryParse($maximumVersion, [ref] $max)){
+ $max = New-Object "NuGet.SemanticVersion" @([int32]::MaxValue, [int32]::MaxValue, [int32]::MaxValue, [int32]::MaxValue)
+ } else {
+ $defined = $true
+ }
+ }
+
+ return @{ "min" = $min
+ "max" = $max
+ "defined" = $defined
+ }
+}
+
+function Build-FastPackageReference($package){
+ $name = $package.Name
+ $version = $package.Version
+ $source = $package.Source
+ $parsedUri = $null
+
+ if([System.Uri]::TryCreate($package.Source, [System.UriKind]::Absolute, [ref]$parsedUri) -and $parsedUri.IsFile){
+ $source = $parsedUri.AbsolutePath
+ }
+
+ return "$name|#|$version|#|$source"
+}
+
+function Parse-FastPackageReference($fastPackageReference){
+ $pattern = "(?.*)\|#\|(?.*)\|#\|(?