Sometimes you need getting more out your scripts with Sifon and that is the time where script meta-syntax comes into a play. Notice these triple-hash ('###') lines at the top.
Let's look at the working solution below, followed by an explanation on how it works:
### Name: Install Horizon for Sitecore 10.0
### Description: Installs Sitecore JSS along with CLI
### Compatibility: Sifon 1.01
### $SelectedFile = new Sifon.Shared.Forms.LocalFilePickerDialog.LocalFilePicker::GetFile("Sitecore license selector","Select Sitecore license in order to install Horizon:","License files|*.xml","OK")
### Display: Local
### Execution: Local
param(
[string]$Webroot,
[string]$Website,
[string]$Prefix,
[string]$SelectedFile
)
If(!(Test-Path -Path $SelectedFile))
{
Write-Error "File $SelectedFile does not exist on your local machine"
exit
}
Please pay attention to the line number 4. Everything starting with #
is ignored by PowerShell as being a comment, so it is a good opportunity to tell Sifon some necessary additional information, mandatory for a plugin to function. We do that by starting such lines with ###
block and passing Sifon necessary instruction.
In the above example we pass a line that looks very similar to a PowerShell code:
### $SelectedFile = new Sifon.Shared.Forms.LocalFilePickerDialog.LocalFilePicker::GetFile("Sitecore license selector","Select Sitecore license in order to install Horizon:","License files|*.xml","OK")
What happens under the bonnet is Sifon finding such meta-syntax instructions executes them in a local context prior to running a script that could be run a remote context. In this example, it instantiates a LocalFilePicker form and calls its method GetFile()
passing all the required parameters. This is the same class as shown in a previous PowerShell GUI example, that draws you a file selector form.
Once file get selected, it is being assigned to an input parameter $SelectedFile
as declared. Please pay attention to the following:
$SelectedFile
is below accepted as an income parameter to a scriptTo sum up - you as a script developer need to do:
param(...)
block and use it in you locally and remotely running script.No need to mess up with establishing remote connection and copying the selected file there - Sifon will do it all for you and will assign your declared variable with a correct path!