C# Class ChocoPM.Services.LocalChocolateyService

Inheritance: ObservableBase, ILocalChocolateyService
Show file Open project: RichiCoder1/ChocoPM

Private Properties

Property Type Description
RefreshPackages void
WriteError void
WriteOutput void

Public Methods

Method Description
ExecutePackageCommand ( string commandString, bool refreshPackages = true ) : Task

Executes a PowerShell command and returns whether or not there was a result. Optionally calls RefreshPackages.

GetPackages ( bool logOutput = false ) : Task>

Retrives all the local packages.

InstallPackageAsync ( string id, string version = null ) : Task

Install the specific package. Optionally installs a specific version of the package.

IsInstalled ( string id, string version ) : bool

Checks wether the specified package is installed.

This method will only return true if: A) We've already retrieved the local packages and cached them. B) The package is found in the cache. This is to ensure that we're not pulling the local package list until the App specifically request it.

LocalChocolateyService ( IRemoteChocolateyService remoteService ) : System.Collections.ObjectModel
RunPackageCommand ( string commandString, bool refreshPackages = true, bool logOutput = true, bool clearBuffer = true ) : Task>

Executes a PowerShell Command.

UninstallPackageAsync ( string id, string version ) : Task

Uninstall the specified package.

UpdatePackageAsync ( string id ) : Task

Updates the installed package.

Chocolatey does not currently support updating an installed package to a specific version. There's a way to do this (basically uninstall and install specific version), but it's complex and error prone enough that we're avoiding it for now.

Private Methods

Method Description
RefreshPackages ( bool logOutput = false ) : void

Invalidates and refreshes the cache.

WriteError ( string message ) : void

Helper function to write error messages to the faux PowerShell console.

WriteOutput ( string message ) : void

Helper function to write output messages to the faux PowerShell console.

Method Details

ExecutePackageCommand() public method

Executes a PowerShell command and returns whether or not there was a result. Optionally calls RefreshPackages.
public ExecutePackageCommand ( string commandString, bool refreshPackages = true ) : Task
commandString string The PowerShell command string.
refreshPackages bool Whether to call .
return Task

GetPackages() public method

Retrives all the local packages.
public GetPackages ( bool logOutput = false ) : Task>
logOutput bool If true, writes messages out to the faux PowerShell console.
return Task>

InstallPackageAsync() public method

Install the specific package. Optionally installs a specific version of the package.
public InstallPackageAsync ( string id, string version = null ) : Task
id string The Id of the package to be isntalled.
version string The specific Version string of the package to be installed.
return Task

IsInstalled() public method

Checks wether the specified package is installed.
This method will only return true if: A) We've already retrieved the local packages and cached them. B) The package is found in the cache. This is to ensure that we're not pulling the local package list until the App specifically request it.
public IsInstalled ( string id, string version ) : bool
id string The Id of the package.
version string The Version string of the package.
return bool

LocalChocolateyService() public method

public LocalChocolateyService ( IRemoteChocolateyService remoteService ) : System.Collections.ObjectModel
remoteService IRemoteChocolateyService
return System.Collections.ObjectModel

RunPackageCommand() public method

Executes a PowerShell Command.
public RunPackageCommand ( string commandString, bool refreshPackages = true, bool logOutput = true, bool clearBuffer = true ) : Task>
commandString string The PowerShell command string.
refreshPackages bool Whether to call .
logOutput bool Whether the output should be logged to the faux PowerShell console or returned as results.
clearBuffer bool Whether the faux PowerShell console should be cleared.
return Task>

UninstallPackageAsync() public method

Uninstall the specified package.
public UninstallPackageAsync ( string id, string version ) : Task
id string The Id of the package to be removed.
version string The Version string of the package to be removed.
return Task

UpdatePackageAsync() public method

Updates the installed package.
Chocolatey does not currently support updating an installed package to a specific version. There's a way to do this (basically uninstall and install specific version), but it's complex and error prone enough that we're avoiding it for now.
public UpdatePackageAsync ( string id ) : Task
id string The Id of the package.
return Task