-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathPackageProviderFunctions.ps1
390 lines (329 loc) · 11.2 KB
/
PackageProviderFunctions.ps1
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
###
# ==++==
#
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###
<#
Overrides the default Write-Debug so that the output gets routed back thru the
$request.Debug() function
#>
function Write-Debug {
param(
[Parameter(Mandatory=$true)][string] $message,
[parameter(ValueFromRemainingArguments=$true)]
[object[]]
$args= @()
)
if( -not $request ) {
if( -not $args ) {
Microsoft.PowerShell.Utility\write-verbose $message
return
}
$msg = [system.string]::format($message, $args)
Microsoft.PowerShell.Utility\write-verbose $msg
return
}
if( -not $args ) {
$null = $request.Debug($message);
return
}
$null = $request.Debug($message,$args);
}
function Write-Error {
param(
[Parameter(Mandatory=$true)][string] $Message,
[Parameter()][string] $Category,
[Parameter()][string] $ErrorId,
[Parameter()][string] $TargetObject
)
$null = $request.Warning($Message);
}
<#
Overrides the default Write-Verbose so that the output gets routed back thru the
$request.Verbose() function
#>
function Write-Progress {
param(
[CmdletBinding()]
[Parameter(Position=0)]
[string]
$Activity,
# This parameter is not supported by request object
[Parameter(Position=1)]
[ValidateNotNullOrEmpty()]
[string]
$Status,
[Parameter(Position=2)]
[ValidateRange(0,[int]::MaxValue)]
[int]
$Id,
[Parameter()]
[int]
$PercentComplete,
# This parameter is not supported by request object
[Parameter()]
[int]
$SecondsRemaining,
# This parameter is not supported by request object
[Parameter()]
[string]
$CurrentOperation,
[Parameter()]
[ValidateRange(-1,[int]::MaxValue)]
[int]
$ParentID,
[Parameter()]
[switch]
$Completed,
# This parameter is not supported by request object
[Parameter()]
[int]
$SourceID,
[object[]]
$args= @()
)
$params = @{}
if ($PSBoundParameters.ContainsKey("Activity")) {
$params.Add("Activity", $PSBoundParameters["Activity"])
}
if ($PSBoundParameters.ContainsKey("Status")) {
$params.Add("Status", $PSBoundParameters["Status"])
}
if ($PSBoundParameters.ContainsKey("PercentComplete")) {
$params.Add("PercentComplete", $PSBoundParameters["PercentComplete"])
}
if ($PSBoundParameters.ContainsKey("Id")) {
$params.Add("Id", $PSBoundParameters["Id"])
}
if ($PSBoundParameters.ContainsKey("ParentID")) {
$params.Add("ParentID", $PSBoundParameters["ParentID"])
}
if ($PSBoundParameters.ContainsKey("Completed")) {
$params.Add("Completed", $PSBoundParameters["Completed"])
}
if( -not $request ) {
if( -not $args ) {
Microsoft.PowerShell.Utility\Write-Progress @params
return
}
$params["Activity"] = [system.string]::format($Activity, $args)
Microsoft.PowerShell.Utility\Write-Progress @params
return
}
if( -not $args ) {
# Need to return int value for start progress
if ($PSBoundParameters.ContainsKey("ParentID")) {
return $request.StartProgress($ParentActivityID, $Activity, $args)
}
elseif ($PSBoundParameters.ContainsKey("Completed")) {
$iscompleted = $PSBoundParameters["Completed"] -eq [switch]::Present
$null = $request.CompleteProgress($Id, $iscompleted)
}
else {
$null = $request.Progress($Id, $PercentComplete, $Activity, $args)
}
}
}
function Write-Verbose{
param(
[Parameter(Mandatory=$true)][string] $message,
[parameter(ValueFromRemainingArguments=$true)]
[object[]]
$args= @()
)
if( -not $request ) {
if( -not $args ) {
Microsoft.PowerShell.Utility\write-verbose $message
return
}
$msg = [system.string]::format($message, $args)
Microsoft.PowerShell.Utility\write-verbose $msg
return
}
if( -not $args ) {
$null = $request.Verbose($message);
return
}
$null = $request.Verbose($message,$args);
}
<#
Overrides the default Write-Warning so that the output gets routed back thru the
$request.Warning() function
#>
function Write-Warning{
param(
[Parameter(Mandatory=$true)][string] $message,
[parameter(ValueFromRemainingArguments=$true)]
[object[]]
$args= @()
)
if( -not $request ) {
if( -not $args ) {
Microsoft.PowerShell.Utility\write-warning $message
return
}
$msg = [system.string]::format($message, $args)
Microsoft.PowerShell.Utility\write-warning $msg
return
}
if( -not $args ) {
$null = $request.Warning($message);
return
}
$null = $request.Warning($message,$args);
}
<#
Creates a new instance of a PackageSource object
#>
function New-PackageSource {
param(
[Parameter(Mandatory=$true)][string] $name,
[Parameter(Mandatory=$true)][string] $location,
[Parameter(Mandatory=$true)][bool] $trusted,
[Parameter(Mandatory=$true)][bool] $registered,
[bool] $valid = $false,
[System.Collections.Hashtable] $details = $null
)
return New-Object -TypeName Microsoft.PackageManagement.MetaProvider.PowerShell.PackageSource -ArgumentList $name,$location,$trusted,$registered,$valid,$details
}
<#
Creates a new instance of a SoftwareIdentity object
#>
function New-SoftwareIdentity {
param(
[Parameter(Mandatory=$true)][string] $fastPackageReference,
[Parameter(Mandatory=$true)][string] $name,
[Parameter(Mandatory=$true)][string] $version,
[Parameter(Mandatory=$true)][string] $versionScheme,
[Parameter(Mandatory=$true)][string] $source,
[string] $summary,
[string] $searchKey = $null,
[string] $fullPath = $null,
[string] $filename = $null,
[System.Collections.Hashtable] $details = $null,
[System.Collections.ArrayList] $entities = $null,
[System.Collections.ArrayList] $links = $null,
[bool] $fromTrustedSource = $false,
[System.Collections.ArrayList] $dependencies = $null,
[string] $tagId = $null
)
return New-Object -TypeName Microsoft.PackageManagement.MetaProvider.PowerShell.SoftwareIdentity -ArgumentList $fastPackageReference, $name, $version, $versionScheme, $source, $summary, $searchKey, $fullPath, $filename , $details , $entities, $links, $fromTrustedSource, $dependencies, $tagId
}
<#
Creates a new instance of a SoftwareIdentity object based on an xml string
#>
function New-SoftwareIdentityFromXml {
param(
[Parameter(Mandatory=$true)][string] $xmlSwidtag,
[bool] $commitImmediately = $false
)
return New-Object -TypeName Microsoft.PackageManagement.MetaProvider.PowerShell.SoftwareIdentity -ArgumentList $xmlSwidtag, $commitImmediately
}
<#
Creates a new instance of a DyamicOption object
#>
function New-DynamicOption {
param(
[Parameter(Mandatory=$true)][Microsoft.PackageManagement.MetaProvider.PowerShell.OptionCategory] $category,
[Parameter(Mandatory=$true)][string] $name,
[Parameter(Mandatory=$true)][Microsoft.PackageManagement.MetaProvider.PowerShell.OptionType] $expectedType,
[Parameter(Mandatory=$true)][bool] $isRequired,
[System.Collections.ArrayList] $permittedValues = $null
)
if( -not $permittedValues ) {
return New-Object -TypeName Microsoft.PackageManagement.MetaProvider.PowerShell.DynamicOption -ArgumentList $category,$name, $expectedType, $isRequired
}
return New-Object -TypeName Microsoft.PackageManagement.MetaProvider.PowerShell.DynamicOption -ArgumentList $category,$name, $expectedType, $isRequired, $permittedValues.ToArray()
}
<#
Creates a new instance of a Feature object
#>
function New-Feature {
param(
[Parameter(Mandatory=$true)][string] $name,
[System.Collections.ArrayList] $values = $null
)
if( -not $values ) {
return New-Object -TypeName Microsoft.PackageManagement.MetaProvider.PowerShell.Feature -ArgumentList $name
}
return New-Object -TypeName Microsoft.PackageManagement.MetaProvider.PowerShell.Feature -ArgumentList $name, $values.ToArray()
}
<#
Duplicates the $request object and overrides the client-supplied data with the specified values.
#>
function New-Request {
param(
[System.Collections.Hashtable] $options = $null,
[System.Collections.ArrayList] $sources = $null,
[PSCredential] $credential = $null
)
return $request.CloneRequest( $options, $sources, $credential )
}
function New-Entity {
param(
[Parameter(Mandatory=$true)][string] $name,
[Parameter(Mandatory=$true,ParameterSetName="role")][string] $role,
[Parameter(Mandatory=$true,ParameterSetName="roles")][System.Collections.ArrayList]$roles,
[string] $regId = $null,
[string] $thumbprint= $null
)
$o = New-Object -TypeName Microsoft.PackageManagement.MetaProvider.PowerShell.Entity
$o.Name = $name
# support role as a NMTOKENS string or an array of strings
if( $role ) {
$o.Role = $role
}
if( $roles ) {
$o.Roles = $roles
}
$o.regId = $regId
$o.thumbprint = $thumbprint
return $o
}
function New-Link {
param(
[Parameter(Mandatory=$true)][string] $HRef,
[Parameter(Mandatory=$true)][string] $relationship,
[string] $mediaType = $null,
[string] $ownership = $null,
[string] $use= $null,
[string] $appliesToMedia= $null,
[string] $artifact = $null
)
$o = New-Object -TypeName Microsoft.PackageManagement.MetaProvider.PowerShell.Link
$o.HRef = $HRef
$o.Relationship =$relationship
$o.MediaType =$mediaType
$o.Ownership =$ownership
$o.Use = $use
$o.AppliesToMedia = $appliesToMedia
$o.Artifact = $artifact
return $o
}
function New-Dependency {
param(
[Parameter(Mandatory=$true)][string] $providerName,
[Parameter(Mandatory=$true)][string] $packageName,
[string] $version= $null,
[string] $source = $null,
[string] $appliesTo = $null
)
$o = New-Object -TypeName Microsoft.PackageManagement.MetaProvider.PowerShell.Dependency
$o.ProviderName = $providerName
$o.PackageName =$packageName
$o.Version =$version
$o.Source =$source
$o.AppliesTo = $appliesTo
return $o
}