Пример #1
0
        public static IProject GetCurrentProjectScope(this ISolution solution)
        {
            Guard.NotNull(() => solution, solution);

            var selection = ServiceProvider.GlobalProvider.GetService <SVsShellMonitorSelection, IVsMonitorSelectionFixed>();

            if (selection != null)
            {
                IVsHierarchy        hierarchy;
                uint                pitemid;
                IVsMultiItemSelect  ppMIS;
                ISelectionContainer ppSC;

                if (selection.GetCurrentSelection(out hierarchy, out pitemid, out ppMIS, out ppSC) == Microsoft.VisualStudio.VSConstants.S_OK)
                {
                    if (hierarchy != null)
                    {
                        var project = hierarchy.ToProject();
                        if (project != null)
                        {
                            return(solution.Find <IProject>(p => p.As <EnvDTE.Project>() == project).FirstOrDefault());
                        }
                    }
                }
            }

            // Use first project in the solution
            return(solution.Find <IProject>().FirstOrDefault());
        }
Пример #2
0
        /// <summary>
        /// Gets the equivalent <see cref="IItemContainer"/> for the given <see cref="IVsHierarchy"/>
        /// </summary>
        public static T As <T>(this IVsHierarchy hierarchy, ISolution solution) where T : IItemContainer
        {
            Guard.NotNull(() => hierarchy, hierarchy);
            Guard.NotNull(() => solution, solution);

            return(solution.Find <T>(item => item.As <IVsHierarchy>() == hierarchy).FirstOrDefault());
        }
Пример #3
0
        public static IItem FindItem(this ISolution solution, string itemPathTemplate)
        {
            var item = solution.Find <IItem>(string.Format(itemPathTemplate, solution.Name)).FirstOrDefault();

            Assert.IsNotNull(item, "item not found with path " + itemPathTemplate);
            return(item);
        }
Пример #4
0
        private static void AddDependentFiles(ISolution solution, string modelFile, IEnumerable <string> diagramFiles)
        {
            var item = solution.Find <IItem>(it => it.PhysicalPath == modelFile).Single();

            foreach (var diagramFile in diagramFiles)
            {
                if (!item.Find <IItem>(it => it.PhysicalPath == diagramFile).Any())
                {
                    item.Add(diagramFile);
                }
            }
        }
Пример #5
0
        private void LoadTypes()
        {
            if (loadingTypes)
            {
                return;
            }

            try
            {
                tracer.Verbose(Resources.ProjectTypeProvider_TraceLoadTypes);
                loadingTypes = true;

                this.availableTypes.Clear();

                foreach (var project in solution.Find <IProject>())
                {
                    var hierarchy = project.As <IVsHierarchy>();
                    if (hierarchy != null)
                    {
                        tracer.Verbose(Resources.ProjectTypeProvider_TraceLoadProjectTypes, project.Name);
                        var    typeDiscoveryService = dynamicTypeService.GetTypeDiscoveryService(hierarchy);
                        string currentProjectAssemblyName;

                        try
                        {
                            currentProjectAssemblyName = project.As <EnvDTE.Project>().Properties.Item(@"AssemblyName").Value as string;
                        }
                        catch (Exception)
                        {
                            continue;
                        }

                        // We should be able to leverage Progression for this!
                        var types = typeDiscoveryService.GetTypes(typeof(object), true);

                        foreach (Type type in types)
                        {
                            if (string.Equals(type.Assembly.GetName().Name, currentProjectAssemblyName, StringComparison.InvariantCultureIgnoreCase))
                            {
                                availableTypes.Add(type);
                            }
                        }
                    }
                }
            }
            finally
            {
                loadingTypes = false;
            }
        }
Пример #6
0
        /// <summary>
        /// Resolves the current element paths and filename, and returns the item if exists.
        /// </summary>
        public static IItemContainer ResolveToSolutionItem <T>(object context, ISolution solution, IUriReferenceService uriService, string path = null, string fileName = null) where T : IItemContainer
        {
            // Resolve SourcePath
            var resolver = new PathResolver(context, uriService, path, fileName);

            if (resolver.TryResolve())
            {
                // Load file from solution
                var sourceFile = resolver.Path;
                return(solution.Find <T>(sourceFile).FirstOrDefault());
            }

            return(null);
        }
Пример #7
0
        public static IItem FindItem(this ISolution solution, string itemPathTemplate)
        {
            var item = solution.Find <IItem>(string.Format(itemPathTemplate, solution.Name)).FirstOrDefault();

            return(item);
        }
Пример #8
0
        private static void AddDependentFiles(ISolution solution, string modelFile, IEnumerable<string> diagramFiles)
        {
            var item = solution.Find<IItem>(it => it.PhysicalPath == modelFile).Single();

            foreach (var diagramFile in diagramFiles)
            {
                if (!item.Find<IItem>(it => it.PhysicalPath == diagramFile).Any())
                {
                    item.Add(diagramFile);
                }
            }
        }
Пример #9
0
 public static IEnumerable <IProject> GetAllProjects(this ISolution solution)
 {
     return(solution.Find <IProject>());
 }