-
Notifications
You must be signed in to change notification settings - Fork 414
Expand file tree
/
Copy pathDependencyModel.cs
More file actions
128 lines (108 loc) · 5.21 KB
/
DependencyModel.cs
File metadata and controls
128 lines (108 loc) · 5.21 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
// 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.Imaging.Interop;
using Microsoft.VisualStudio.ProjectSystem.Properties;
using Microsoft.VisualStudio.ProjectSystem.Tree.Dependencies.Subscriptions;
using Microsoft.VisualStudio.ProjectSystem.VS.Tree.Dependencies;
namespace Microsoft.VisualStudio.ProjectSystem.Tree.Dependencies.Models
{
internal enum DiagnosticLevel
{
// These states are in precedence order, where later states override earlier ones.
None = 0,
UpgradeAvailable = 1,
Warning = 2,
Deprecation = 3,
Error = 4,
Vulnerability = 5
}
/// <summary>
/// Base class for dependency models that ship with the .NET Project System.
/// </summary>
internal abstract partial class DependencyModel : IDependencyModel
{
[Flags]
private enum DependencyFlags : byte
{
Resolved = 1 << 0,
Implicit = 1 << 1,
Visible = 1 << 2
}
protected DependencyModel(
string caption,
string? path,
string originalItemSpec,
ProjectTreeFlags flags,
bool isResolved,
bool isImplicit,
IImmutableDictionary<string, string>? properties,
bool isVisible = true)
{
Requires.NotNullOrEmpty(caption, nameof(caption));
// IDependencyModel allows original item spec to be null, but we can satisfy a
// more strict requirement for the dependency types produced internally.
// External providers may not have a meaningful value, but do not use this type.
Requires.NotNullOrEmpty(originalItemSpec, nameof(originalItemSpec));
Path = path;
OriginalItemSpec = originalItemSpec;
Properties = properties ?? ImmutableStringDictionary<string>.EmptyOrdinal;
Caption = caption;
Flags = flags;
if (Properties.TryGetBoolProperty(ProjectItemMetadata.Visible, out bool visibleProperty))
{
isVisible = visibleProperty;
}
DiagnosticLevel diagnosticLevel = DiagnosticLevel.None;
if (Properties.TryGetStringProperty(ProjectItemMetadata.DiagnosticLevel, out string? levelString))
{
diagnosticLevel = levelString switch
{
nameof(DiagnosticLevel.Warning) => DiagnosticLevel.Warning,
nameof(DiagnosticLevel.Error) => DiagnosticLevel.Error,
nameof(DiagnosticLevel.UpgradeAvailable) => DiagnosticLevel.UpgradeAvailable,
nameof(DiagnosticLevel.Deprecation) => DiagnosticLevel.Deprecation,
nameof(DiagnosticLevel.Vulnerability) => DiagnosticLevel.Vulnerability,
_ => DiagnosticLevel.None
};
}
if (diagnosticLevel == DiagnosticLevel.None && !isResolved)
{
// Treat unresolved state as a warning diagnostic
diagnosticLevel = DiagnosticLevel.Warning;
}
DependencyFlags depFlags = 0;
if (isResolved)
depFlags |= DependencyFlags.Resolved;
if (isVisible)
depFlags |= DependencyFlags.Visible;
if (isImplicit)
depFlags |= DependencyFlags.Implicit;
_flags = depFlags;
DiagnosticLevel = diagnosticLevel;
}
private readonly DependencyFlags _flags;
public abstract string ProviderType { get; }
public string Id => OriginalItemSpec;
string IDependencyModel.Name => throw new NotImplementedException();
public string Caption { get; }
public string OriginalItemSpec { get; }
public string? Path { get; }
public virtual string? SchemaName => null;
public virtual string? SchemaItemType => null;
string IDependencyModel.Version => throw new NotImplementedException();
public bool Resolved => (_flags & DependencyFlags.Resolved) != 0;
bool IDependencyModel.TopLevel => true;
public bool Implicit => (_flags & DependencyFlags.Implicit) != 0;
public bool Visible => (_flags & DependencyFlags.Visible) != 0;
int IDependencyModel.Priority => throw new NotImplementedException();
public ImageMoniker Icon => Implicit ? IconSet.ImplicitIcon : IconSet.Icon;
public ImageMoniker ExpandedIcon => Implicit ? IconSet.ImplicitExpandedIcon : IconSet.ExpandedIcon;
public ImageMoniker UnresolvedIcon => IconSet.UnresolvedIcon;
public ImageMoniker UnresolvedExpandedIcon => IconSet.UnresolvedExpandedIcon;
public IImmutableDictionary<string, string> Properties { get; }
IImmutableList<string> IDependencyModel.DependencyIDs => throw new NotImplementedException();
public ProjectTreeFlags Flags { get; }
public DiagnosticLevel DiagnosticLevel { get; }
public abstract DependencyIconSet IconSet { get; }
public override string ToString() => $"{ProviderType}-{Id}";
}
}