public static async Task <IEnumerable <IEntityValue> > CreatePropertyPageValuesAsync(
            IQueryExecutionContext queryExecutionContext,
            IEntityValue parent,
            UnconfiguredProject project,
            IProjectStateProvider projectStateProvider,
            IPropertyPagePropertiesAvailableStatus requestedProperties)
        {
            if (await project.GetProjectLevelPropertyPagesCatalogAsync() is IPropertyPagesCatalog projectCatalog)
            {
                return(createPropertyPageValuesAsync());
            }

            return(Enumerable.Empty <IEntityValue>());

            IEnumerable <IEntityValue> createPropertyPageValuesAsync()
            {
                IProjectState projectState = projectStateProvider.CreateState(project);
                QueryProjectPropertiesContext propertiesContext = new QueryProjectPropertiesContext(isProjectFile: true, project.FullPath, itemType: null, itemName: null);

                foreach (string schemaName in projectCatalog.GetProjectLevelPropertyPagesSchemas())
                {
                    if (projectCatalog.GetSchema(schemaName) is Rule rule &&
                        !rule.PropertyPagesHidden)
                    {
                        IEntityValue propertyPageValue = CreatePropertyPageValue(queryExecutionContext, parent, projectState, propertiesContext, rule, requestedProperties: requestedProperties);
                        yield return(propertyPageValue);
                    }
                }
            }
        }
        public static async Task <IEntityValue?> CreatePropertyPageValueAsync(
            IQueryExecutionContext queryExecutionContext,
            EntityIdentity id,
            IProjectService2 projectService,
            IProjectStateProvider projectStateProvider,
            QueryProjectPropertiesContext propertiesContext,
            string propertyPageName,
            IPropertyPagePropertiesAvailableStatus requestedProperties)
        {
            if (projectService.GetLoadedProject(propertiesContext.File) is UnconfiguredProject project)
            {
                project.GetQueryDataVersion(out string versionKey, out long versionNumber);
                queryExecutionContext.ReportInputDataVersion(versionKey, versionNumber);

                if (await project.GetProjectLevelPropertyPagesCatalogAsync() is IPropertyPagesCatalog projectCatalog &&
                    projectCatalog.GetSchema(propertyPageName) is Rule rule &&
                    !rule.PropertyPagesHidden)
                {
                    IProjectState projectState      = projectStateProvider.CreateState(project);
                    IEntityValue  propertyPageValue = CreatePropertyPageValue(queryExecutionContext, id, projectState, propertiesContext, rule, requestedProperties);
                    return(propertyPageValue);
                }
            }

            return(null);
        }
 public PropertyProviderState(IProjectState projectState, Rule containingRule, QueryProjectPropertiesContext propertiesContext, string propertyName)
 {
     ProjectState      = projectState;
     ContainingRule    = containingRule;
     PropertiesContext = propertiesContext;
     PropertyName      = propertyName;
 }
Пример #4
0
        protected override Task <IEntityValue?> TryCreateEntityOrNullAsync(IQueryExecutionContext queryExecutionContext, EntityIdentity id)
        {
            if (QueryProjectPropertiesContext.TryCreateFromEntityId(id, out QueryProjectPropertiesContext? propertiesContext) &&
                StringComparers.ItemTypes.Equals(propertiesContext.ItemType, "LaunchProfile"))
            {
                return(CreateLaunchProfileValueAsync(queryExecutionContext, id, propertiesContext));
            }

            return(NullEntityValue);
        }
Пример #5
0
        public static async Task <IEnumerable <IEntityValue> > CreateUIPropertyValueValuesAsync(
            IQueryExecutionContext queryExecutionContext,
            IEntityValue parent,
            IProjectState cache,
            Rule schema,
            QueryProjectPropertiesContext propertiesContext,
            string propertyName,
            IUIPropertyValuePropertiesAvailableStatus requestedProperties)
        {
            BaseProperty?unboundProperty = schema.GetProperty(propertyName);

            if (unboundProperty is null)
            {
                return(ImmutableList <IEntityValue> .Empty);
            }

            ImmutableList <IEntityValue> .Builder builder = ImmutableList.CreateBuilder <IEntityValue>();

            IEnumerable <ProjectConfiguration> configurations;

            if (unboundProperty.IsConfigurationDependent())
            {
                // Return the values across all configurations.
                configurations = await cache.GetKnownConfigurationsAsync() ?? Enumerable.Empty <ProjectConfiguration>();
            }
            else
            {
                // Return the value from any one configuration.
                if (await cache.GetSuggestedConfigurationAsync() is ProjectConfiguration defaultConfiguration)
                {
                    configurations = CreateSingleItemEnumerable(defaultConfiguration);
                }
                else
                {
                    configurations = Enumerable.Empty <ProjectConfiguration>();
                }
            }

            foreach (ProjectConfiguration configuration in configurations)
            {
                if (await cache.GetDataVersionAsync(configuration) is (string versionKey, long versionNumber))
                {
                    queryExecutionContext.ReportInputDataVersion(versionKey, versionNumber);
                }

                if (await cache.BindToRuleAsync(configuration, schema.Name, propertiesContext) is IRule rule &&
                    rule.GetProperty(propertyName) is ProjectSystem.Properties.IProperty property)
                {
                    IEntityValue propertyValue = await CreateUIPropertyValueValueAsync(parent, configuration, property, requestedProperties);

                    builder.Add(propertyValue);
                }
            }

            return(builder.ToImmutable());
        protected override Task <IEntityValue?> TryCreateEntityOrNullAsync(IQueryExecutionContext queryExecutionContext, EntityIdentity id)
        {
            if (QueryProjectPropertiesContext.TryCreateFromEntityId(id, out QueryProjectPropertiesContext? propertiesContext) &&
                id.TryGetValue(ProjectModelIdentityKeys.PropertyPageName, out string?propertyPageName))
            {
                return(PropertyPageDataProducer.CreatePropertyPageValueAsync(
                           queryExecutionContext,
                           id,
                           _projectService,
                           propertiesContext,
                           propertyPageName,
                           _properties));
            }

            return(NullEntityValue);
        }
Пример #7
0
        public static async Task <IEnumerable <IEntityValue> > CreatePropertyPageValuesAsync(
            IQueryExecutionContext queryExecutionContext,
            IEntityValue parent,
            UnconfiguredProject project,
            IPropertyPagePropertiesAvailableStatus requestedProperties)
        {
            if (await project.GetProjectLevelPropertyPagesCatalogAsync() is IPropertyPagesCatalog projectCatalog)
            {
                return(createPropertyPageValuesAsync());
            }

            return(Enumerable.Empty <IEntityValue>());

            IEnumerable <IEntityValue> createPropertyPageValuesAsync()
            {
                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 Rule rule &&
                        !rule.PropertyPagesHidden)
                    {
                        if (rule.Name == "RazorGeneral" || rule.Name == "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);
                    }
                }
            }
        }
        private IEntityValue CreateLaunchProfileValue(IQueryExecutionContext queryExecutionContext, IEntityValue parent, QueryProjectPropertiesContext propertiesContext, Rule rule, int order, IProjectState projectState)
        {
            EntityIdentity identity = LaunchProfileDataProducer.CreateLaunchProfileId(parent, propertiesContext.ItemType !, propertiesContext.ItemName !);

            return(LaunchProfileDataProducer.CreateLaunchProfileValue(queryExecutionContext, identity, propertiesContext, rule, order, projectState, _properties));
        }
Пример #9
0
        private async Task <IEntityValue?> CreateLaunchProfileValueAsync(IQueryExecutionContext queryExecutionContext, EntityIdentity id, QueryProjectPropertiesContext propertiesContext)
        {
            if (_projectService.GetLoadedProject(propertiesContext.File) is UnconfiguredProject project &&
                project.Services.ExportProvider.GetExportedValueOrDefault <ILaunchSettingsProvider>() is ILaunchSettingsProvider launchSettingsProvider &&
                await project.GetProjectLevelPropertyPagesCatalogAsync() is IPropertyPagesCatalog projectCatalog &&
                await launchSettingsProvider.WaitForFirstSnapshot(Timeout.Infinite) is ILaunchSettings launchSettings)
            {
                foreach ((int index, ProjectSystem.Debug.ILaunchProfile profile) in launchSettings.Profiles.WithIndices())
                {
                    if (StringComparers.LaunchProfileNames.Equals(profile.Name, propertiesContext.ItemName) &&
                        !Strings.IsNullOrEmpty(profile.CommandName))
                    {
                        foreach (Rule rule in DebugUtilities.GetDebugChildRules(projectCatalog))
                        {
                            if (rule.Metadata.TryGetValue("CommandName", out object?commandNameObj) &&
                                commandNameObj is string commandName &&
                                StringComparers.LaunchProfileCommandNames.Equals(commandName, profile.CommandName))
                            {
                                IProjectState projectState = _projectStateProvider.CreateState(project);

                                IEntityValue launchProfileValue = LaunchProfileDataProducer.CreateLaunchProfileValue(
                                    queryExecutionContext,
                                    id,
                                    propertiesContext,
                                    rule,
                                    index,
                                    projectState,
                                    _properties);
                                return(launchProfileValue);
                            }
                        }
                    }
                }
            }

            return(null);
        }
Пример #10
0
        private static IEntityValue CreateLaunchProfileValue(IQueryExecutionContext queryExecutionContext, EntityIdentity id, QueryProjectPropertiesContext propertiesContext, Rule rule, int order, IProjectState cache, ILaunchProfilePropertiesAvailableStatus properties)
        {
            LaunchProfileValue newLaunchProfile = new(queryExecutionContext.EntityRuntime, id, new LaunchProfilePropertiesAvailableStatus());

            if (properties.Name)
            {
                newLaunchProfile.Name = propertiesContext.ItemName;
            }

            if (properties.DisplayName)
            {
                newLaunchProfile.DisplayName = propertiesContext.ItemName;
            }

            if (properties.CommandName)
            {
                if (rule.Metadata.TryGetValue(s_commandNameMetadataName, out object?commandNameObj) &&
                    commandNameObj is string commandName)
                {
                    newLaunchProfile.CommandName = commandName;
                }
            }

            if (properties.Order)
            {
                newLaunchProfile.Order = order;
            }

            ((IEntityValueFromProvider)newLaunchProfile).ProviderState = new ContextAndRuleProviderState(cache, propertiesContext, rule);

            return(newLaunchProfile);
        }
Пример #11
0
        public static IEntityValue CreateUIPropertyValue(IQueryExecutionContext queryExecutionContext, IEntityValue parent, IProjectState cache, QueryProjectPropertiesContext propertiesContext, BaseProperty property, int order, IUIPropertyPropertiesAvailableStatus requestedProperties)
        {
            Requires.NotNull(parent, nameof(parent));
            Requires.NotNull(property, nameof(property));

            var identity = new EntityIdentity(
                ((IEntityWithId)parent).Id,
                new KeyValuePair <string, string>[]
            {
                new(ProjectModelIdentityKeys.UIPropertyName, property.Name)
            });
Пример #12
0
 public ContextAndRuleProviderState(IProjectState projectState, QueryProjectPropertiesContext propertiesContext, Rule rule)
 {
     ProjectState      = projectState;
     PropertiesContext = propertiesContext;
     Rule = rule;
 }
Пример #13
0
        /// <summary>
        /// Retrieves the <see cref="IRule"/> with name "<paramref name="schemaName"/>" within the given <paramref
        /// name="projectConfiguration"/> and <paramref name="propertiesContext"/>.
        /// </summary>
        public async Task <IRule?> BindToRuleAsync(ProjectConfiguration projectConfiguration, string schemaName, QueryProjectPropertiesContext propertiesContext)
        {
            if (_ruleCache.TryGetValue((projectConfiguration, schemaName, propertiesContext), out IRule? cachedRule))
            {
                return(cachedRule);
            }

            IRule?rule = null;

            if (await GetProjectLevelPropertyPagesCatalogAsync(projectConfiguration) is IPropertyPagesCatalog catalog)
            {
                rule = catalog.BindToContext(schemaName, propertiesContext);
            }

            _ruleCache.Add((projectConfiguration, schemaName, propertiesContext), rule);
            return(rule);
        }
        public static IEntityValue CreatePropertyPageValue(IQueryExecutionContext queryExecutionContext, EntityIdentity id, IProjectState cache, QueryProjectPropertiesContext propertiesContext, Rule rule, IPropertyPagePropertiesAvailableStatus requestedProperties)
        {
            Requires.NotNull(rule, nameof(rule));
            var newPropertyPage = new PropertyPageValue(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 IEntityValue CreatePropertyPageValue(IQueryExecutionContext queryExecutionContext, IEntityValue parent, IProjectState cache, QueryProjectPropertiesContext propertiesContext, Rule rule, IPropertyPagePropertiesAvailableStatus requestedProperties)
        {
            Requires.NotNull(parent, nameof(parent));
            Requires.NotNull(rule, nameof(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));
                }
            }
        }
 private IEntityValue CreateLaunchProfileValue(IQueryExecutionContext queryExecutionContext, IEntityValue parent, QueryProjectPropertiesContext propertiesContext, Rule rule, int order, IProjectState projectState)
 {
     EntityIdentity identity = new(
         ((IEntityWithId)parent).Id,
         new Dictionary <string, string>
     {
         { ProjectModelIdentityKeys.SourceItemType, propertiesContext.ItemType ! },