-
Notifications
You must be signed in to change notification settings - Fork 414
Expand file tree
/
Copy pathDependency.cs
More file actions
218 lines (184 loc) · 8.16 KB
/
Dependency.cs
File metadata and controls
218 lines (184 loc) · 8.16 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
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information.
using Microsoft.VisualStudio.Buffers.PooledObjects;
using Microsoft.VisualStudio.Imaging;
using Microsoft.VisualStudio.Imaging.Interop;
using Microsoft.VisualStudio.ProjectSystem.Tree.Dependencies.Models;
using Microsoft.VisualStudio.ProjectSystem.VS.Tree.Dependencies;
namespace Microsoft.VisualStudio.ProjectSystem.Tree.Dependencies.Snapshot
{
internal sealed class Dependency : IDependency
{
public Dependency(IDependencyModel dependencyModel)
{
Requires.NotNull(dependencyModel, nameof(dependencyModel));
Requires.NotNullOrEmpty(dependencyModel.ProviderType, nameof(dependencyModel.ProviderType));
Requires.NotNullOrEmpty(dependencyModel.Id, nameof(dependencyModel.Id));
Id = dependencyModel.Id;
ProviderType = dependencyModel.ProviderType;
Caption = dependencyModel.Caption ?? string.Empty;
OriginalItemSpec = dependencyModel.OriginalItemSpec;
FilePath = dependencyModel.Path;
SchemaName = dependencyModel.SchemaName ?? Folder.SchemaName;
SchemaItemType = dependencyModel.SchemaItemType ?? Folder.PrimaryDataSourceItemType;
Resolved = dependencyModel.Resolved;
Implicit = dependencyModel.Implicit;
Visible = dependencyModel.Visible;
Flags = dependencyModel.Flags;
// Just in case custom providers don't do it, add corresponding flags for Resolved state.
// This is needed for tree update logic to track if tree node changing state from unresolved
// to resolved or vice-versa (it helps to decide if we need to remove it or update in-place
// in the tree to avoid flicks).
if (Resolved)
{
if (!Flags.Contains(ProjectTreeFlags.ResolvedReference))
{
Flags += ProjectTreeFlags.ResolvedReference;
}
}
else
{
if (!Flags.Contains(ProjectTreeFlags.BrokenReference))
{
Flags += ProjectTreeFlags.BrokenReference;
}
}
// If this is one of our implementations of IDependencyModel then we can just reuse the icon
// set rather than creating a new one.
if (dependencyModel is DependencyModel model)
{
IconSet = model.IconSet;
DiagnosticLevel = model.DiagnosticLevel;
}
else
{
IconSet = DependencyIconSetCache.Instance.GetOrAddIconSet(dependencyModel.Icon, dependencyModel.ExpandedIcon, dependencyModel.UnresolvedIcon, dependencyModel.UnresolvedExpandedIcon, dependencyModel.Icon, dependencyModel.ExpandedIcon);
DiagnosticLevel = dependencyModel.Resolved ? DiagnosticLevel.None : DiagnosticLevel.Warning;
}
BrowseObjectProperties = dependencyModel.Properties
?? ImmutableStringDictionary<string>.EmptyOrdinal
.Add(Folder.IdentityProperty, Caption)
.Add(Folder.FullPathProperty, FilePath ?? string.Empty);
}
/// <summary>
/// Private constructor used to clone Dependency
/// </summary>
private Dependency(
Dependency dependency,
string? caption)
{
// Copy values as necessary to create a clone with any properties overridden
Id = dependency.Id;
ProviderType = dependency.ProviderType;
OriginalItemSpec = dependency.OriginalItemSpec;
FilePath = dependency.FilePath;
SchemaItemType = dependency.SchemaItemType;
Visible = dependency.Visible;
BrowseObjectProperties = dependency.BrowseObjectProperties; // NOTE we explicitly do not update Identity in these properties if caption changes
Caption = caption ?? dependency.Caption; // TODO if Properties contains "Folder.IdentityProperty" should we update it? (see public ctor)
Resolved = dependency.Resolved;
Flags = dependency.Flags;
SchemaName = dependency.SchemaName;
IconSet =dependency.IconSet;
Implicit = dependency.Implicit;
DiagnosticLevel = dependency.DiagnosticLevel;
}
public DiagnosticLevel DiagnosticLevel { get; }
#region IDependency
public string Id { get; }
public string ProviderType { get; }
public string? OriginalItemSpec { get; }
public string SchemaName { get; }
public string SchemaItemType { get; }
public string Caption { get; }
public bool Resolved { get; }
public bool Implicit { get; }
public bool Visible { get; }
public DependencyIconSet IconSet { get; }
public ProjectTreeFlags Flags { get; }
public IImmutableDictionary<string, string> BrowseObjectProperties { get; }
#endregion
#region IDependencyViewModel
public string? FilePath { get; }
public ImageMoniker Icon
{
get
{
if (DiagnosticLevel == DiagnosticLevel.None)
{
if (Implicit)
{
return IconSet.ImplicitIcon;
}
return IconSet.Icon;
}
switch (DiagnosticLevel)
{
case DiagnosticLevel.UpgradeAvailable:
return KnownMonikers.OfficeWord2013;
case DiagnosticLevel.Warning:
return IconSet.UnresolvedIcon;
case DiagnosticLevel.Deprecation:
return KnownMonikers.OfficeSharePoint2013;
case DiagnosticLevel.Error:
return IconSet.UnresolvedIcon;
case DiagnosticLevel.Vulnerability:
return KnownMonikers.OfficeExcel2013;
default:
throw new ArgumentOutOfRangeException();
}
}
}
public ImageMoniker ExpandedIcon
{
get
{
if (DiagnosticLevel == DiagnosticLevel.None)
{
if (Implicit)
{
return IconSet.ImplicitExpandedIcon;
}
return IconSet.ExpandedIcon;
}
// TODO update upgradeavailable/deprecation/vulnerability icons
switch (DiagnosticLevel)
{
case DiagnosticLevel.UpgradeAvailable:
return KnownMonikers.OfficeWord2013;
case DiagnosticLevel.Warning:
return IconSet.UnresolvedIcon;
case DiagnosticLevel.Deprecation:
return KnownMonikers.OfficeSharePoint2013;
case DiagnosticLevel.Error:
return IconSet.UnresolvedExpandedIcon;
case DiagnosticLevel.Vulnerability:
return KnownMonikers.OfficeExcel2013;
default:
throw new ArgumentOutOfRangeException();
}
}
}
#endregion
public IDependency WithCaption(string caption)
{
return new Dependency(this, caption);
}
public override string ToString()
{
// Used for debugging only
var sb = PooledStringBuilder.GetInstance();
sb.Append("Provider=\"");
sb.Append(ProviderType);
sb.Append("\" ModelId=\"");
sb.Append(Id);
sb.Append('"');
if (Resolved)
sb.Append(" Resolved");
if (Implicit)
sb.Append(" Implicit");
if (Visible)
sb.Append(" Visible");
return sb.ToStringAndFree();
}
}
}