/// <summary>
        /// Gets an IRule to attach to a project item so that browse object properties will be displayed.
        /// </summary>
        private IRule GetRuleForUnresolvableReference(IProjectPropertiesContext unresolvedContext,
                                                      IProjectCatalogSnapshot catalogs,
                                                      ConfiguredProjectExports configuredProjectExports)
        {
            Requires.NotNull(unresolvedContext, nameof(unresolvedContext));
            Requires.NotNull(configuredProjectExports, nameof(configuredProjectExports));

            var namedCatalogs = GetNamedCatalogs(catalogs);
            var schemas       = GetSchemaForReference(unresolvedContext.ItemType, false, namedCatalogs).ToList();

            if (schemas.Count == 1)
            {
                Requires.NotNull(namedCatalogs, nameof(namedCatalogs));
                var browseObjectCatalog = namedCatalogs[PropertyPageContexts.BrowseObject];
                return(browseObjectCatalog.BindToContext(schemas[0].Name, unresolvedContext));
            }

            if (schemas.Count > 1)
            {
                TraceUtilities.TraceWarning(
                    "Too many rule schemas ({0}) in the BrowseObject context were found. Only 1 is allowed.",
                    schemas.Count);
            }

            // Since we have no browse object, we still need to create *something* so that standard property
            // pages can pop up.
            var emptyRule = RuleExtensions.SynthesizeEmptyRule(unresolvedContext.ItemType);

            return(configuredProjectExports.PropertyPagesDataModelProvider.GetRule(
                       emptyRule,
                       unresolvedContext.File,
                       unresolvedContext.ItemType,
                       unresolvedContext.ItemName));
        }
Пример #2
0
 public IProjectTree CreateTree(
     string caption,
     IProjectPropertiesContext itemContext,
     IPropertySheet?propertySheet     = null,
     IRule?browseObjectProperties     = null,
     ProjectImageMoniker?icon         = null,
     ProjectImageMoniker?expandedIcon = null,
     bool visible           = true,
     ProjectTreeFlags?flags = default)
 {
     // Note that all the parameters are specified so we can force this call to an
     // overload of NewTree available prior to 15.5 versions of CPS. Once a 15.5 build
     // is publicly available we can move this to an overload with default values for
     // most of the parameters, and we'll only need to pass the interesting ones.
     return(NewTree(
                caption: caption,
                item: itemContext,
                propertySheet: propertySheet,
                browseObjectProperties: browseObjectProperties,
                icon: icon,
                expandedIcon: expandedIcon,
                visible: visible,
                flags: flags,
                isLinked: false));
 }
Пример #3
0
        public async Task <IProjectItem?> GetItemAsync(IProjectPropertiesContext context)
        {
            if (context.ItemType is not null &&
                !StringComparers.ItemTypes.Equals(ItemType, context.ItemType))
            {
                return(null);
            }

            IEnumerable <IProjectItem> items = await GetItemsAsync();

            return(items.FirstOrDefault(item => StringComparers.ItemNames.Equals(item.EvaluatedInclude, context.ItemName)));
        }
 public IProjectTree CreateTree(
     string caption,
     IProjectPropertiesContext itemContext,
     IPropertySheet?propertySheet     = null,
     IRule?browseObjectProperties     = null,
     ProjectImageMoniker?icon         = null,
     ProjectImageMoniker?expandedIcon = null,
     bool visible           = true,
     ProjectTreeFlags?flags = null)
 {
     return(NewTree(
                caption: caption,
                item: itemContext,
                propertySheet: propertySheet,
                browseObjectProperties: browseObjectProperties,
                icon: icon,
                expandedIcon: expandedIcon,
                visible: visible,
                flags: flags));
 }
 public IProjectTree CreateTree(
     string caption,
     IProjectPropertiesContext itemContext,
     IPropertySheet?propertySheet     = null,
     IRule?browseObjectProperties     = null,
     ProjectImageMoniker?icon         = null,
     ProjectImageMoniker?expandedIcon = null,
     bool visible           = true,
     ProjectTreeFlags?flags = null)
 {
     return(new TestProjectTree
     {
         Caption = caption,
         BrowseObjectProperties = browseObjectProperties,
         Icon = icon,
         ExpandedIcon = expandedIcon,
         Visible = visible,
         Flags = flags ?? ProjectTreeFlags.Empty,
         IsProjectItem = true
     });
 }
        /// <summary>
        /// Gets an IRule to attach to a project item so that browse object properties will be displayed.
        /// </summary>
        private IRule GetRuleForResolvableReference(
            IProjectPropertiesContext unresolvedContext,
            KeyValuePair <string, IImmutableDictionary <string, string> > resolvedReference,
            IProjectCatalogSnapshot catalogs,
            ConfiguredProjectExports configuredProjectExports,
            bool isGenericDependency = true)
        {
            Requires.NotNull(unresolvedContext, nameof(unresolvedContext));

            var namedCatalogs = GetNamedCatalogs(catalogs);
            var schemas       = GetSchemaForReference(unresolvedContext.ItemType, isGenericDependency, namedCatalogs).ToList();

            if (schemas.Count == 1)
            {
                IRule rule = configuredProjectExports.RuleFactory.CreateResolvedReferencePageRule(
                    schemas[0],
                    unresolvedContext,
                    resolvedReference.Key,
                    resolvedReference.Value);
                return(rule);
            }
            else
            {
                if (schemas.Count > 1)
                {
                    TraceUtilities.TraceWarning(
                        "Too many rule schemas ({0}) in the BrowseObject context were found.  Only 1 is allowed.",
                        schemas.Count);
                }

                // Since we have no browse object, we still need to create *something* so that standard property
                // pages can pop up.
                var emptyRule = RuleExtensions.SynthesizeEmptyRule(unresolvedContext.ItemType);
                return(configuredProjectExports.PropertyPagesDataModelProvider.GetRule(
                           emptyRule,
                           unresolvedContext.File,
                           unresolvedContext.ItemType,
                           unresolvedContext.ItemName));
            }
        }
 public IProjectTree CreateTree(
     string caption,
     IProjectPropertiesContext itemContext,
     IPropertySheet propertySheet     = null,
     IRule browseObjectProperties     = null,
     ProjectImageMoniker icon         = null,
     ProjectImageMoniker expandedIcon = null,
     bool visible           = true,
     ProjectTreeFlags?flags = default(ProjectTreeFlags?))
 {
     return(new TestProjectTree()
     {
         Caption = caption,
         FilePath = itemContext.File ?? caption,
         BrowseObjectProperties = browseObjectProperties,
         Icon = icon,
         ExpandedIcon = expandedIcon,
         Visible = visible,
         Flags = flags.Value,
         IsProjectItem = true
     });
 }
 public IProjectItemTree SetItem(IProjectPropertiesContext projectPropertiesContext)
 {
     throw new NotImplementedException();
 }
Пример #9
0
        public override async Task RemoveAsync(IImmutableSet <IProjectTree> nodes,
                                               DeleteOptions deleteOptions = DeleteOptions.None)
        {
            if (deleteOptions.HasFlag(DeleteOptions.DeleteFromStorage))
            {
                throw new NotSupportedException();
            }

            // Get the list of shared import nodes.
            IEnumerable <IProjectTree> sharedImportNodes = nodes.Where(node =>
                                                                       node.Flags.Contains(DependencyTreeFlags.SharedProjectFlags));

            // Get the list of normal reference Item Nodes (this excludes any shared import nodes).
            IEnumerable <IProjectTree> referenceItemNodes = nodes.Except(sharedImportNodes);

            await _projectAccessor.OpenProjectForWriteAsync(ActiveConfiguredProject, project =>
            {
                // Handle the removal of normal reference Item Nodes (this excludes any shared import nodes).
                foreach (IProjectTree node in referenceItemNodes)
                {
                    if (node.BrowseObjectProperties?.Context == null)
                    {
                        // if node does not have an IRule with valid ProjectPropertiesContext we can not
                        // get its itemsSpec. If nodes provided by custom IProjectDependenciesSubTreeProvider
                        // implementation, and have some custom IRule without context, it is not a problem,
                        // since they would not have DependencyNode.GenericDependencyFlags and we would not
                        // end up here, since CanRemove would return false and Remove command would not show
                        // up for those nodes.
                        continue;
                    }

                    IProjectPropertiesContext nodeItemContext = node.BrowseObjectProperties.Context;
                    ProjectItem unresolvedReferenceItem       = project.GetItemsByEvaluatedInclude(nodeItemContext.ItemName)
                                                                .FirstOrDefault(
                        (item, t) => string.Equals(item.ItemType, t, StringComparisons.ItemTypes),
                        nodeItemContext.ItemType);

                    Report.IfNot(unresolvedReferenceItem != null, "Cannot find reference to remove.");
                    if (unresolvedReferenceItem != null)
                    {
                        project.RemoveItem(unresolvedReferenceItem);
                    }
                }

                IDependenciesSnapshot snapshot = _dependenciesSnapshotProvider.CurrentSnapshot;
                Requires.NotNull(snapshot, nameof(snapshot));
                if (snapshot == null)
                {
                    return;
                }

                // Handle the removal of shared import nodes.
                ProjectRootElement projectXml = project.Xml;
                foreach (IProjectTree sharedImportNode in sharedImportNodes)
                {
                    string sharedFilePath = UnconfiguredProject.MakeRelative(sharedImportNode.FilePath);
                    if (string.IsNullOrEmpty(sharedFilePath))
                    {
                        continue;
                    }

                    IDependency?sharedProjectDependency = snapshot.FindDependency(sharedFilePath, topLevel: true);
                    if (sharedProjectDependency != null)
                    {
                        sharedFilePath = sharedProjectDependency.Path;
                    }

                    // Find the import that is included in the evaluation of the specified ConfiguredProject that
                    // imports the project file whose full path matches the specified one.
                    IEnumerable <ResolvedImport> matchingImports = from import in project.Imports
                                                                   where import.ImportingElement.ContainingProject == projectXml &&
                                                                   PathHelper.IsSamePath(import.ImportedProject.FullPath, sharedFilePath)
                                                                   select import;
                    foreach (ResolvedImport importToRemove in matchingImports)
                    {
                        ProjectImportElement importingElementToRemove = importToRemove.ImportingElement;
                        Report.IfNot(importingElementToRemove != null,
                                     "Cannot find shared project reference to remove.");
                        if (importingElementToRemove != null)
                        {
                            importingElementToRemove.Parent.RemoveChild(importingElementToRemove);
                        }
                    }
                }
            });
        }
Пример #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProjectProperties"/> class.
 /// </summary>
 public ProjectProperties(ConfiguredProject configuredProject, IProjectPropertiesContext projectPropertiesContext)
     : base(configuredProject, projectPropertiesContext)
 {
 }
Пример #11
0
 IRule IPropertyPagesCatalog.BindToContext(string schemaName, IProjectPropertiesContext context)
 {
     throw new NotImplementedException();
 }
Пример #12
0
        public IProjectTree SetProperties(string caption           = null, string filePath = null, IRule browseObjectProperties = null,
                                          ProjectImageMoniker icon = null, ProjectImageMoniker expandedIcon = null, bool?
                                          visible = null, ProjectTreeFlags?flags                   = null, IProjectPropertiesContext context = null,
                                          IPropertySheet propertySheet     = null, bool?isLinked   = null, bool resetFilePath                = false,
                                          bool resetBrowseObjectProperties = false, bool resetIcon = false, bool resetExpandedIcon           = false)
        {
            Icon                   = icon ?? Icon;
            ExpandedIcon           = expandedIcon ?? ExpandedIcon;
            BrowseObjectProperties = browseObjectProperties ?? BrowseObjectProperties;
            Caption                = caption ?? Caption;

            return(this);
        }
Пример #13
0
 public IProjectItemTree SetItem(IProjectPropertiesContext context, IPropertySheet propertySheet, bool isLinked)
 {
     return(null);
 }
Пример #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RuleProperties"/> class.
 /// </summary>
 public RuleProperties(ConfiguredProject configuredProject, IProjectPropertiesContext projectPropertiesContext)
     : base(configuredProject, projectPropertiesContext)
 {
 }
 public void Equal(IProjectPropertiesContext a, IProjectPropertiesContext b)
 {
     Assert.True(a.Equals(b));
     Assert.True(b.Equals(a));
     Assert.True(a.GetHashCode() == b.GetHashCode());
 }
 IProjectItemTree IProjectItemTree.SetProperties(string caption, string filePath, IRule browseObjectProperties, ProjectImageMoniker icon, ProjectImageMoniker expandedIcon, bool?visible, ProjectTreeFlags?flags, IProjectPropertiesContext context, IPropertySheet propertySheet, bool?isLinked, bool resetFilePath, bool resetBrowseObjectProperties, bool resetIcon, bool resetExpandedIcon)
 {
     throw new NotImplementedException();
 }
Пример #17
0
 public SourceFileProperties(IProjectPropertiesContext projectPropertiesContext, Workspace workspace, IProjectThreadingService threadingService)
 {
     _projectPropertiesContext = projectPropertiesContext;
     _workspace        = workspace;
     _threadingService = threadingService;
 }
 public IProjectTree2 SetProperties(string caption = null, string filePath = null, IRule browseObjectProperties = null, ProjectImageMoniker icon = null, ProjectImageMoniker expandedIcon = null, bool?visible = null, ProjectTreeFlags?flags = null, IProjectPropertiesContext context = null, IPropertySheet propertySheet = null, bool?isLinked = null, bool resetFilePath = false, bool resetBrowseObjectProperties = false, bool resetIcon = false, bool resetExpandedIcon = false, int?displayOrder = null)
 {
     throw new NotImplementedException();
 }
            public IProjectTree SetProperties(string caption = null, string filePath = null, IRule browseObjectProperties = null, ProjectImageMoniker icon = null, ProjectImageMoniker expandedIcon = null, bool?visible = default, ProjectTreeFlags?flags = default, IProjectPropertiesContext context = null, IPropertySheet propertySheet = null, bool?isLinked = default, bool resetFilePath = false, bool resetBrowseObjectProperties = false, bool resetIcon = false, bool resetExpandedIcon = false)
            {
                if (caption != null)
                {
                    Caption = caption;
                }

                if (filePath != null)
                {
                    FilePath = filePath;
                }

                if (visible != null)
                {
                    Visible = visible.Value;
                }

                if (flags != null)
                {
                    Flags = flags.Value;
                }

                return(this);
            }
 IProjectItemTree IProjectTree.SetItem(IProjectPropertiesContext context, IPropertySheet propertySheet, bool isLinked)
 {
     throw new NotImplementedException();
 }
 public void NotEqual(IProjectPropertiesContext a, IProjectPropertiesContext b)
 {
     Assert.False(a.Equals(b));
     Assert.False(a.GetHashCode() == b.GetHashCode());
 }