# demo-options
#using module h:\psec\flows\run-gael\setup-run-gael.psm1;
#using module h:\psec\lib\lib-setup-run-gael.psm1;
set-strictmode -version 2.0
function defineFlowTask([Flow]$flow,[Task]$task) {
#--- define
$def = new-module -asCustomObject -scriptBlock {
function getTaskDesc([Task]$task) {
[string]$desc = @"
This illustrates how to manage the global workflow context for subsequent tasks.
"@
return $desc;
}
<#.md
.example set context with `cycleNo` and `month`
.exkeys context
.desc
prime the script when initially loaded. As a convenience the brief file is parsed and passed in.
the existance of this method signals this is a context task. The method is called when the
task is initally loaded.
This runs after the *params* function
#>
function primeContextTask([Task]$task, [hashtable]$brief) {
$tfs = $task.tfs;
$tfs.globMap.demoGlobs.cycleNo = 0;
if (exists $brief cycleNo) {
$tfs.globMap.demoGlobs.cycleNo = $brief.cycleNo / 1;
}
if (exists $brief month) {
$tfs.globMap.demoGlobs.month = $brief.month;
}
hlogBoth("Running primeContextTask $($task.name) $($tfs.globMap.demoGlobs.month) $($tfs.globMap.demoGlobs.cycleNo) $($brief.cycleNo)")
[void]($task.find("opt-cycleNo").setText("$($tfs.globMap.demoGlobs.cycleNo)"));
}
<#.md
.example set parameters with current date
.exkeys context
.desc
The $htOpts parms has the processed options. It can be modified or used to do
other changes to the setup.
The *brief* variable is set so that the *primeContextTask* has access to it.
#>
function params {
param([Object]$task,[hashtable]$htOpts)
$tfs = $task.tfs;
$date = Get-Date
[string]$dateStr = $date.ToString("yyyyMMdd")
$htOpts.datestr = $dateStr;
$htOpts.brief = "$($task.statlocn)"
return $htOpts
}
<#.md
.example set options with `month` and starting `cycleNo`
.exkeys context
.desc
The $htOpts is preloaded with prior values. This is used to
change and save them.
This runs before the *params* function and the values set here are passed to it.
#>
function options {
param([Object]$task)
$opts = @();
$tfs = $task.tfs;
$opts += @{type='input'; parm="cycleNo"; label='CycleNo'; place='cycloNo'; readonly=$true}
$opts += @{type='combo'; parm='month'; label='Month'; valset='jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec'}
hlogBoth("fetch.options $($tfs.globMap.demoGlobs.month) $($tfs.globMap.demoGlobs.cycleNo)")
return ,$opts
}
<#.md
.example run context script
.exkeys context
.desc
This function runs when the *Run Task* button is activated.
Since the *Brief* file is created it serves to persist them if the Workflow is restarted.
This example increases the `cycleNo` whenever the *runScript* function is run.
#>
function runScript([Task]$task, [hashtable]$parms, [hashtable]$status) {
$tfs = $task.tfs;
$status.month = $tfs.globMap.demoGlobs.month = $parms.month;
$status.cycleNo = $tfs.globMap.demoGlobs.cycleNo = $tfs.globMap.demoGlobs.cycleNo + 1;
hlogBoth("Running script $($task.name) $($tfs.globMap.demoGlobs.month) $($tfs.globMap.demoGlobs.cycleNo)")
[void]($task.find("opt-cycleNo").setText("$($tfs.globMap.demoGlobs.cycleNo)"));
}
Export-ModuleMember -Variable * -Function *
}
hlog("defineFlowTask $flow $task")
return $def;
}
PSEC is an extensive set of Powershell enhancements that, along with other acknowledged works, is deployed into the public domain subject to the limitations detailed below.
Ackowledgements
Pandoc, the system used to produce this documentation.
More detailed information is found by clicking on the link that triggered this popup