-
Notifications
You must be signed in to change notification settings - Fork 414
Expand file tree
/
Copy pathPropertyPageDataProducer.cs
More file actions
139 lines (117 loc) · 6.4 KB
/
PropertyPageDataProducer.cs
File metadata and controls
139 lines (117 loc) · 6.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
// 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.Build.Framework.XamlTypes;
using Microsoft.VisualStudio.ProjectSystem.Properties;
using Microsoft.VisualStudio.ProjectSystem.Query;
using Microsoft.VisualStudio.ProjectSystem.Query.Execution;
using Microsoft.VisualStudio.ProjectSystem.Query.Framework;
namespace Microsoft.VisualStudio.ProjectSystem.VS.Query
{
/// <summary>
/// Handles the creation of <see cref="IPropertyPageSnapshot"/> instances and populating the requested members.
/// </summary>
internal static class PropertyPageDataProducer
{
public static IEntityValue CreatePropertyPageValue(IQueryExecutionContext queryExecutionContext, IEntityValue parent, IProjectState cache, QueryProjectPropertiesContext propertiesContext, Rule rule, IPropertyPagePropertiesAvailableStatus requestedProperties)
{
Requires.NotNull(parent);
Requires.NotNull(rule);
var identity = new EntityIdentity(
((IEntityWithId)parent).Id,
createKeys());
return CreatePropertyPageValue(queryExecutionContext, identity, cache, propertiesContext, rule, requestedProperties);
IEnumerable<KeyValuePair<string, string>> createKeys()
{
yield return new(ProjectModelIdentityKeys.PropertyPageName, rule.Name);
if (propertiesContext.ItemType is not null)
{
yield return new(ProjectModelIdentityKeys.SourceItemType, propertiesContext.ItemType);
}
if (propertiesContext.ItemName is not null)
{
yield return new(ProjectModelIdentityKeys.SourceItemName, propertiesContext.ItemName);
}
}
}
public static IEntityValue CreatePropertyPageValue(IQueryExecutionContext queryExecutionContext, EntityIdentity id, IProjectState cache, QueryProjectPropertiesContext propertiesContext, Rule rule, IPropertyPagePropertiesAvailableStatus requestedProperties)
{
Requires.NotNull(rule);
var newPropertyPage = new PropertyPageSnapshot(queryExecutionContext.EntityRuntime, id, new PropertyPagePropertiesAvailableStatus());
if (requestedProperties.Name)
{
newPropertyPage.Name = rule.Name;
}
if (requestedProperties.DisplayName)
{
newPropertyPage.DisplayName = rule.DisplayName;
}
if (requestedProperties.Order)
{
newPropertyPage.Order = rule.Order;
}
if (requestedProperties.Kind)
{
newPropertyPage.Kind = rule.PageTemplate;
}
((IEntityValueFromProvider)newPropertyPage).ProviderState = new ContextAndRuleProviderState(cache, propertiesContext, rule);
return newPropertyPage;
}
public static async Task<IEntityValue?> CreatePropertyPageValueAsync(
IQueryExecutionContext queryExecutionContext,
EntityIdentity id,
IProjectService2 projectService,
QueryProjectPropertiesContext propertiesContext,
string propertyPageName,
IPropertyPagePropertiesAvailableStatus requestedProperties)
{
if (projectService.GetLoadedProject(propertiesContext.File) is UnconfiguredProject project)
{
// TODO: Go through the IProjectState to get this
project.GetQueryDataVersion(out string versionKey, out long versionNumber);
queryExecutionContext.ReportInputDataVersion(versionKey, versionNumber);
if (await project.GetProjectLevelPropertyPagesCatalogAsync() is IPropertyPagesCatalog projectCatalog
&& projectCatalog.GetSchema(propertyPageName) is { PropertyPagesHidden: false } rule)
{
IProjectState projectState = new PropertyPageProjectState(project);
IEntityValue propertyPageValue = CreatePropertyPageValue(queryExecutionContext, id, projectState, propertiesContext, rule, requestedProperties);
return propertyPageValue;
}
}
return null;
}
public static async Task<IEnumerable<IEntityValue>> CreatePropertyPageValuesAsync(
IQueryExecutionContext queryExecutionContext,
IEntityValue parent,
UnconfiguredProject project,
IPropertyPagePropertiesAvailableStatus requestedProperties)
{
if (await project.GetProjectLevelPropertyPagesCatalogAsync() is IPropertyPagesCatalog projectCatalog)
{
return CreatePropertyPageValues();
}
return Enumerable.Empty<IEntityValue>();
IEnumerable<IEntityValue> CreatePropertyPageValues()
{
IProjectState projectState = new PropertyPageProjectState(project);
QueryProjectPropertiesContext propertiesContext = new QueryProjectPropertiesContext(isProjectFile: true, project.FullPath, itemType: null, itemName: null);
foreach (string schemaName in projectCatalog.GetProjectLevelPropertyPagesSchemas())
{
if (projectCatalog.GetSchema(schemaName) is { PropertyPagesHidden: false } rule)
{
if (rule.Name is "RazorGeneral" or "RazorExtension")
{
// Some versions of the .NET SDK include a Razor property page that appears
// in the UI. This page is not intended for display.
//
// We cannot remove this page from existing versions of the SDK, so have to
// explicitly exclude it from query results so that it doesn't appear in any
// UI.
continue;
}
IEntityValue propertyPageValue = CreatePropertyPageValue(queryExecutionContext, parent, projectState, propertiesContext, rule, requestedProperties: requestedProperties);
yield return propertyPageValue;
}
}
}
}
}
}