forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSoftwareIdentityRequestObject.cs
More file actions
273 lines (223 loc) · 9.63 KB
/
Copy pathSoftwareIdentityRequestObject.cs
File metadata and controls
273 lines (223 loc) · 9.63 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
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
//
// 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.
//
namespace Microsoft.PackageManagement.Internal.Implementation {
using System;
using System.Globalization;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Api;
using PackageManagement.Implementation;
using PackageManagement.Packaging;
using PackageManagement.Internal.Packaging;
using PackageManagement.Internal.Utility.Plugin;
internal class SoftwareIdentityRequestObject : EnumerableRequestObject<SoftwareIdentity> {
private SoftwareIdentity _currentItem;
private readonly string _status;
public SoftwareIdentityRequestObject(ProviderBase provider, IHostApi request, Action<RequestObject> action, string status)
: base(provider, request, action) {
_status = status;
InvokeImpl();
}
private void CommitCurrentItem() {
if (_currentItem != null) {
Results.Add(_currentItem);
}
_currentItem = null;
}
public override string YieldSoftwareIdentity(string fastPath, string name, string version, string versionScheme, string summary, string source, string searchKey, string fullPath, string packageFileName) {
Activity();
CommitCurrentItem();
_currentItem = new SoftwareIdentity {
FastPackageReference = fastPath,
Name = name,
Version = version,
VersionScheme = versionScheme,
Summary = summary,
Provider = (PackageProvider)Provider,
Source = source,
Status = _status,
SearchKey = searchKey,
FullPath = fullPath,
PackageFilename = packageFileName
};
return fastPath;
}
public override string YieldSoftwareIdentityXml(string xmlSwidTag, bool commitImmediately=false)
{
Activity();
CommitCurrentItem();
if (string.IsNullOrWhiteSpace(xmlSwidTag))
{
return null;
}
try
{
XDocument xdoc = XDocument.Parse(xmlSwidTag);
if (xdoc != null && xdoc.Root != null && Swidtag.IsSwidtag(xdoc.Root))
{
_currentItem = new SoftwareIdentity(xdoc);
if (Provider != null) {
_currentItem.Provider = (PackageProvider)Provider;
}
}
else
{
Verbose(string.Format(CultureInfo.CurrentCulture, Resources.Messages.SwidTagXmlInvalidNameSpace, xmlSwidTag, Iso19770_2.Namespace.Iso19770_2));
}
}
catch (Exception e)
{
Verbose(e.Message);
Verbose(e.StackTrace);
}
if (_currentItem == null)
{
Warning(string.Format(CultureInfo.CurrentCulture, Resources.Messages.SwidTagXmlNotValid));
return null;
}
string result = _currentItem.FastPackageReference;
// provider author wants us to commit at once
if (commitImmediately)
{
CommitCurrentItem();
}
return result;
}
/// <summary>
/// Adds a metadata key/value pair to the Swidtag.
/// </summary>
/// <param name="name"></param>
/// <param name="value"></param>
/// <returns></returns>
public override string AddMetadata(string name, string value) {
Activity();
var swid = _currentItem;
return swid != null ? swid.AddMetadataValue(swid.FastPackageReference, name, value) : null;
}
/// <summary>
/// Adds a tagID to the swidtag
/// </summary>
/// <param name="tagId"></param>
/// <returns></returns>
public override string AddTagId(string tagId)
{
Activity();
var swid = _currentItem;
if (swid == null)
{
return null;
}
// we can't modify it once add so check that there is no swidtag
if (string.IsNullOrWhiteSpace(swid.TagId))
{
swid.TagId = tagId;
}
return swid.TagId;
}
public override string AddCulture(string xmlLang)
{
Activity();
var swid = _currentItem;
if (swid == null)
{
return null;
}
// we can't modify it once add, so check that there is no swidtag
if (string.IsNullOrWhiteSpace(swid.Culture))
{
swid.Culture = xmlLang;
}
return swid.Culture;
}
/// <summary>
/// Adds an attribute to a 'Meta' object. If called for a Swidtag or Entity, it implicitly adds a child Meta object.
/// Any other elementPath is an error and will be ignored.
/// </summary>
/// <param name="elementPath">
/// the string that represents one of :
/// a Swidtag (the fastPackageReference) (passing null as the elementPath will default to the swidtag)
/// an Entity (the result gained from an YieldEntity(...) call )
/// a Meta object (the result from previously calling AddMetadataValue(...) )
/// </param>
/// <param name="name">the name of the attribute to add</param>
/// <param name="value">the value of the attribute to add</param>
/// <returns></returns>
public override string AddMetadata(string elementPath, string name, string value) {
Activity();
var swid = _currentItem;
return swid != null ? swid.AddMetadataValue(elementPath, name, value) : null;
}
public override string AddMetadata(string elementPath, Uri @namespace, string name, string value) {
Activity();
var swid = _currentItem;
if (swid == null || string.IsNullOrWhiteSpace(elementPath)) {
return null;
}
return swid.AddMetadataValue(elementPath, @namespace, name, value);
}
public override string AddMeta(string elementPath) {
Activity();
var swid = _currentItem;
return swid != null ? swid.AddMeta(elementPath) : null;
}
public override string AddPayload() {
var swid = _currentItem;
return swid != null ? swid.AddPayload().ElementUniqueId : null;
}
public override string AddEvidence(DateTime date, string deviceId) {
var swid = _currentItem;
return swid != null ? swid.AddEvidence(date, deviceId).ElementUniqueId : null;
}
public override string AddDirectory(string elementPath, string directoryName, string location, string root, bool isKey) {
Activity();
var swid = _currentItem;
return swid != null ? swid.AddDirectory(elementPath, directoryName, location, root, isKey) : null;
}
public override string AddFile(string elementPath, string fileName, string location, string root, bool isKey, long size, string version) {
Activity();
var swid = _currentItem;
return swid != null ? swid.AddFile(elementPath, fileName, location, root, isKey, size, version) : null;
}
public override string AddProcess(string elementPath, string processName, int pid) {
Activity();
var swid = _currentItem;
return swid != null ? swid.AddProcess(elementPath, processName, pid) : null;
}
public override string AddResource(string elementPath, string type) {
Activity();
var swid = _currentItem;
return swid != null ? swid.AddResource(elementPath, type) : null;
}
public override string AddEntity(string name, string regid, string role, string thumbprint) {
Activity();
var swid = _currentItem;
return swid != null ? swid.AddEntity(name, regid, role, thumbprint) : null;
}
public override string AddLink(Uri referenceUri, string relationship, string mediaType, string ownership, string use, string appliesToMedia, string artifact) {
Activity();
var swid = _currentItem;
return swid != null ? swid.AddLink(referenceUri, relationship, mediaType, ownership, use, appliesToMedia, artifact) : null;
}
public override string AddDependency(string providerName, string packageName, string version, string source, string appliesTo) {
Activity();
var swid = _currentItem;
return swid != null ? swid.AddDependency(providerName, packageName, version, source, appliesTo) : null;
}
protected override void Complete() {
CommitCurrentItem();
base.Complete();
}
}
}