forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequest.cs
More file actions
266 lines (192 loc) · 11.4 KB
/
Copy pathRequest.cs
File metadata and controls
266 lines (192 loc) · 11.4 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
//
// 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.Net;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Security;
using Internal.Api;
public abstract class Request : IRequest {
#region core-apis
public abstract IPackageManagementService PackageManagementService {get;}
public abstract IProviderServices ProviderServices {get;}
#endregion
#region copy host-apis
/* Synced/Generated code =================================================== */
public abstract bool IsCanceled { get; }
public abstract string GetMessageString(string messageText, string defaultText);
public abstract bool Warning(string messageText);
public abstract bool Error(string id, string category, string targetObjectValue, string messageText);
public abstract bool Message(string messageText);
public abstract bool Verbose(string messageText);
public abstract bool Debug(string messageText);
public abstract int StartProgress(int parentActivityId, string messageText);
public abstract bool Progress(int activityId, int progressPercentage, string messageText);
public abstract bool Progress(string activity, string messageText, int activityId, int progressPercentage, int secondsRemaining, string currentOperation, int parentActivityId, bool completed);
public abstract bool CompleteProgress(int activityId, bool isSuccessful);
/// <summary>
/// Used by a provider to request what metadata keys were passed from the user
/// </summary>
/// <returns></returns>
public abstract IEnumerable<string> OptionKeys {get;}
/// <summary>
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public abstract IEnumerable<string> GetOptionValues(string key);
public abstract IEnumerable<string> Sources {get;}
public abstract IWebProxy WebProxy { get; }
public abstract string CredentialUsername { get; }
public abstract SecureString CredentialPassword { get; }
public abstract bool ShouldBootstrapProvider(string requestor, string providerName, string providerVersion, string providerType, string location, string destination);
public abstract bool ShouldContinueWithUntrustedPackageSource(string package, string packageSource);
public abstract bool ShouldContinue(string query, string caption, ref bool yesToAll, ref bool noToAll);
public abstract bool ShouldContinue(string query, string caption);
public abstract bool AskPermission(string permission);
public abstract bool IsInteractive {get;}
public abstract int CallCount {get;}
#endregion
#region copy response-apis
/* Synced/Generated code =================================================== */
/// <summary>
/// Used by a provider to return fields for a SoftwareIdentity.
/// </summary>
/// <param name="fastPath"></param>
/// <param name="name"></param>
/// <param name="version"></param>
/// <param name="versionScheme"></param>
/// <param name="summary"></param>
/// <param name="source"></param>
/// <param name="searchKey"></param>
/// <param name="fullPath"></param>
/// <param name="packageFileName"></param>
/// <returns></returns>
public abstract string YieldSoftwareIdentity(string fastPath, string name, string version, string versionScheme, string summary, string source, string searchKey, string fullPath, string packageFileName);
public abstract string YieldSoftwareIdentityXml(string xmlSwidTag, bool commitImmediately);
public abstract bool IsSwidTagXml(string xmlSwidTag);
public abstract string AddTagId(string tagId);
public abstract string AddCulture(string xmlLang);
public abstract string AddMetadata(string name, string value);
public abstract string AddMetadata(string elementPath, string name, string value);
public abstract string AddMetadata(string elementPath, Uri @namespace, string name, string value);
public abstract string AddMeta(string elementPath);
public abstract string AddEntity(string name, string regid, string role, string thumbprint);
public abstract string AddLink(Uri referenceUri, string relationship, string mediaType, string ownership, string use, string appliesToMedia, string artifact);
public abstract string AddDependency(string providerName, string packageName, string version, string source, string appliesTo);
public abstract string AddPayload();
public abstract string AddEvidence(DateTime date, string deviceId);
public abstract string AddDirectory(string elementPath, string directoryName, string location, string root, bool isKey);
public abstract string AddFile(string elementPath, string fileName, string location, string root, bool isKey, long size, string version);
public abstract string AddProcess(string elementPath, string processName, int pid);
public abstract string AddResource(string elementPath, string type);
/// <summary>
/// Used by a provider to return fields for a package source (repository)
/// </summary>
/// <param name="name"></param>
/// <param name="location"></param>
/// <param name="isTrusted"></param>
/// <param name="isRegistered"></param>
/// <param name="isValidated"></param>
/// <returns></returns>
public abstract bool YieldPackageSource(string name, string location, bool isTrusted, bool isRegistered, bool isValidated);
/// <summary>
/// Used by a provider to return the fields for a Metadata Definition
/// The cmdlets can use this to supply tab-completion for metadata to the user.
/// </summary>
/// <param name="name">the provider-defined name of the option</param>
/// <param name="expectedType"> one of ['string','int','path','switch']</param>
/// <param name="isRequired">if the parameter is mandatory</param>
/// <returns></returns>
public abstract bool YieldDynamicOption(string name, string expectedType, bool isRequired);
public bool YieldDynamicOption(string name, string expectedType, bool isRequired, IEnumerable<string> permittedValues) {
return YieldDynamicOption(name, expectedType, isRequired) && (permittedValues ?? Enumerable.Empty<string>()).All(each => YieldKeyValuePair(name, each));
}
public abstract bool YieldKeyValuePair(string key, string value);
public abstract bool YieldValue(string value);
#endregion
#region declare Request-implementation
/// <summary>
/// Yield values in a dictionary as key/value pairs. (one pair for each value in each key)
/// </summary>
/// <param name="dictionary"></param>
/// <returns></returns>
public bool Yield(Dictionary<string, string[]> dictionary) {
if( dictionary != null ) {
return dictionary.All(Yield);
}
return true;
}
public bool Yield(KeyValuePair<string, string[]> pair) {
if (pair.Value.Length == 0) {
return YieldKeyValuePair(pair.Key, null);
}
return pair.Value.All(each => YieldKeyValuePair(pair.Key, each));
}
public bool Error(ErrorCategory category, string targetObjectValue, string messageText, params object[] args) {
return Error(messageText, category.ToString(), targetObjectValue, FormatMessageString(messageText, args));
}
public bool Warning(string messageText, params object[] args) {
return Warning(FormatMessageString(messageText, args));
}
public bool Message(string messageText, params object[] args) {
return Message(FormatMessageString(messageText, args));
}
public bool Verbose(string messageText, params object[] args) {
return Verbose(FormatMessageString(messageText, args));
}
public bool Debug(string messageText, params object[] args) {
return Debug(FormatMessageString(messageText, args));
}
public int StartProgress(int parentActivityId, string messageText, params object[] args) {
return StartProgress(parentActivityId, FormatMessageString(messageText, args));
}
public bool Progress(string activity, string messageText, int activityId, int progressPercentage, int secondsRemaining, string currentOperation, int parentActivityId, bool completed, params object[] args)
{
return Progress(activity, FormatMessageString(messageText, args), activityId, progressPercentage, secondsRemaining, currentOperation, parentActivityId, completed);
}
public bool Progress(int activityId, int progressPercentage, string messageText, params object[] args) {
return Progress(activityId, progressPercentage, FormatMessageString(messageText, args));
}
public string GetOptionValue(string name) {
// get the value from the request
return (GetOptionValues(name) ?? Enumerable.Empty<string>()).LastOrDefault();
}
private static string FixMeFormat(string formatString, object[] args) {
if (args == null || args.Length == 0) {
// not really any args, and not really expecting any
return formatString.Replace('{', '\u00ab').Replace('}', '\u00bb');
}
return args.Aggregate(formatString.Replace('{', '\u00ab').Replace('}', '\u00bb'), (current, arg) => current + string.Format(CultureInfo.CurrentCulture, " \u00ab{0}\u00bb", arg));
}
#endregion
protected string FormatMessageString(string messageText, params object[] args) {
if (string.IsNullOrWhiteSpace(messageText)) {
return string.Empty;
}
if (messageText.IndexOf(Constants.MSGPrefix, StringComparison.CurrentCultureIgnoreCase) == 0) {
// check with the caller first, then with the local resources, and fallback to using the messageText itself.
messageText = GetMessageString(messageText.Substring(Constants.MSGPrefix.Length),messageText) ?? messageText;
}
// if it doesn't look like we have the correct number of parameters
// let's return a fix-me-format string.
var c = messageText.ToCharArray().Where(each => each == '{').Count();
if (c < args.Length) {
return FixMeFormat(messageText, args);
}
return string.Format(CultureInfo.CurrentCulture, messageText, args);
}
}
}