-
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathSet-PSFDynamicContentObject.ps1
More file actions
124 lines (97 loc) · 3.74 KB
/
Copy pathSet-PSFDynamicContentObject.ps1
File metadata and controls
124 lines (97 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
function Set-PSFDynamicContentObject
{
<#
.SYNOPSIS
Updates a value object that can easily be accessed on another runspace.
.DESCRIPTION
Updates a value object that can easily be accessed on another runspace.
The Dynamic Content Object system allows the user to easily have the content of a variable updated in the background.
The update is performed by this very function.
.PARAMETER Name
The name of the value to update.
Not case sensitive.
.PARAMETER Object
The value object to update
.PARAMETER Value
The value to apply
.PARAMETER Queue
Set the object to be a threadsafe queue.
Safe to use in multiple runspaces in parallel.
Will not apply changes if the current value is already such an object.
.PARAMETER Stack
Set the object to be a threadsafe stack.
Safe to use in multiple runspaces in parallel.
Will not apply changes if the current value is already such an object.
.PARAMETER List
Set the object to be a threadsafe list.
Safe to use in multiple runspaces in parallel.
Will not apply changes if the current value is already such an object.
.PARAMETER Dictionary
Set the object to be a threadsafe dictionary.
Safe to use in multiple runspaces in parallel.
Will not apply changes if the current value is already such an object.
.PARAMETER PassThru
Has the command returning the object just set.
.PARAMETER Reset
Clears the dynamic content object's collection objects.
Use this to ensure the collection is actually empty.
Only used in combination of either -Queue, -Stack, -List or -Dictionary.
.EXAMPLE
PS C:\> Set-PSFDynamicContentObject -Name Test -Value $Value
Sets the Dynamic Content Object named "test" to the value $Value.
.EXAMPLE
PS C:\> Set-PSFDynamicContentObject -Name MyModule.Value -Queue
Sets the Dynamic Content Object named "MyModule.Value" to contain a threadsafe queue.
This queue will be safe to enqueue and dequeue from, no matter the number of runspaces accessing it simultaneously.
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
[OutputType([PSFramework.Utility.DynamicContentObject])]
[CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Set-PSFDynamicContentObject')]
Param (
[string[]]
$Name,
[Parameter(ValueFromPipeline = $true)]
[PSFramework.Utility.DynamicContentObject[]]
$Object,
[Parameter(Mandatory = $true, ParameterSetName = 'Value')]
[AllowNull()]
$Value,
[Parameter(Mandatory = $true, ParameterSetName = 'Queue')]
[switch]
$Queue,
[Parameter(Mandatory = $true, ParameterSetName = 'Stack')]
[switch]
$Stack,
[Parameter(Mandatory = $true, ParameterSetName = 'List')]
[switch]
$List,
[Parameter(Mandatory = $true, ParameterSetName = 'Dictionary')]
[switch]
$Dictionary,
[switch]
$PassThru,
[switch]
$Reset
)
process
{
foreach ($item in $Name)
{
if ($Queue) { [PSFramework.Utility.DynamicContentObject]::Set($item, $Value, 'Queue') }
elseif ($Stack) { [PSFramework.Utility.DynamicContentObject]::Set($item, $Value, 'Stack') }
elseif ($List) { [PSFramework.Utility.DynamicContentObject]::Set($item, $Value, 'List') }
elseif ($Dictionary) { [PSFramework.Utility.DynamicContentObject]::Set($item, $Value, 'Dictionary') }
else { [PSFramework.Utility.DynamicContentObject]::Set($item, $Value, 'Common') }
if ($PassThru) { [PSFramework.Utility.DynamicContentObject]::Get($item) }
}
foreach ($item in $Object)
{
$item.Value = $Value
if ($Queue) { $item.ConcurrentQueue($Reset) }
if ($Stack) { $item.ConcurrentStack($Reset) }
if ($List) { $item.ConcurrentList($Reset) }
if ($Dictionary) { $item.ConcurrentDictionary($Reset) }
if ($PassThru) { $item }
}
}
}