-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathBaseReference.cs
225 lines (196 loc) · 6.19 KB
/
BaseReference.cs
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using System.Xml.Serialization;
#nullable disable
namespace Microsoft.Build.Tasks.Deployment.ManifestUtilities
{
/// <summary>
/// Describes base functionality common to both file and assembly references.
/// </summary>
/// <remarks>Note derived classes are serialization formats. Do not rename or remove private members.</remarks>
[ComVisible(false)]
public abstract class BaseReference
{
private bool _includeHash = true;
private string _group;
private string _hash;
private string _hashAlgorithm;
private string _isOptional;
private string _resolvedPath;
private string _size;
private string _sourcePath;
private string _targetPath;
protected internal BaseReference() // only internal classes can extend this class
{
}
protected internal BaseReference(string path) // only internal classes can extend this class
{
_sourcePath = path;
_targetPath = GetDefaultTargetPath(path);
}
internal static string GetDefaultTargetPath(string path)
{
if (String.IsNullOrEmpty(path))
{
return path;
}
if (path.EndsWith(Constants.DeployFileExtension, StringComparison.OrdinalIgnoreCase))
{
path = path.Substring(0, path.Length - Constants.DeployFileExtension.Length);
}
if (!Path.IsPathRooted(path))
{
return path;
}
return Path.GetFileName(path);
}
internal bool IncludeHash
{
get => _includeHash;
set => _includeHash = value;
}
/// <summary>
/// Specifies the group for on-demand download functionality. A blank string indicates a primary file.
/// </summary>
[XmlIgnore]
public string Group
{
get => _group;
set => _group = value;
}
/// <summary>
/// Specifies the SHA1 hash of the file.
/// </summary>
[XmlIgnore]
public string Hash
{
get
{
if (!IncludeHash)
{
return string.Empty;
}
return _hash;
}
set => _hash = value;
}
/// <summary>
/// Specifies whether the file is optional for on-deman download functionality.
/// </summary>
[XmlIgnore]
public bool IsOptional
{
get => ConvertUtil.ToBoolean(_isOptional);
set => _isOptional = value ? "true" : null;
// NOTE: optional=false is implied, and Fusion prefers them to be unspecified
}
/// <summary>
/// Specifies the resolved path to the file. This path is determined by the Resolve method, and is used to compute the file information by the UpdateFileInfo method.
/// </summary>
[XmlIgnore]
public string ResolvedPath
{
get => _resolvedPath;
set => _resolvedPath = value;
}
/// <summary>
/// Specifies the file size in bytes.
/// </summary>
[XmlIgnore]
public long Size
{
get => Convert.ToInt64(_size, CultureInfo.InvariantCulture);
set => _size = Convert.ToString(value, CultureInfo.InvariantCulture);
}
protected internal abstract string SortName { get; }
/// <summary>
/// Specifies the source path of the file.
/// </summary>
[XmlIgnore]
public string SourcePath
{
get => _sourcePath;
set => _sourcePath = value;
}
/// <summary>
/// Specifies the target path of the file. This is the path that is used for specification in the generated manifest.
/// </summary>
[XmlIgnore]
public string TargetPath
{
get => _targetPath;
set => _targetPath = value;
}
public override string ToString()
{
if (!String.IsNullOrEmpty(_sourcePath))
{
return _sourcePath;
}
if (!String.IsNullOrEmpty(_resolvedPath))
{
return _resolvedPath;
}
if (!String.IsNullOrEmpty(_targetPath))
{
return _targetPath;
}
return String.Empty;
}
#region " XmlSerializer "
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XmlAttribute("Group")]
public string XmlGroup
{
get => _group;
set => _group = value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XmlAttribute("Hash")]
public string XmlHash
{
get => Hash;
set => _hash = value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XmlAttribute("HashAlg")]
public string XmlHashAlgorithm
{
get => _hashAlgorithm;
set => _hashAlgorithm = value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XmlAttribute("IsOptional")]
public string XmlIsOptional
{
get => _isOptional?.ToLower(CultureInfo.InvariantCulture);
set => _isOptional = value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XmlAttribute("Path")]
public string XmlPath
{
get => _targetPath;
set => _targetPath = value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XmlAttribute("Size")]
public string XmlSize
{
get => _size;
set => _size = value;
}
#endregion
}
}