Пример #1
0
            public override void TestInitialize()
            {
                base.TestInitialize();

                this.OpenSolution("SampleSolution\\SampleSolution.sln");
                this.solution = base.ServiceLocator.GetInstance <ISolutionExplorer>().Solution;
            }
Пример #2
0
            public override void TestInitialize()
            {
                base.TestInitialize();

                this.OpenSolution("SampleSolution\\SampleSolution.sln");
                this.solution = base.ServiceLocator.GetInstance<ISolutionExplorer>().Solution;
            }
        /// <summary>
        /// Finds all the project nodes in the solution.
        /// </summary>
        /// <param name="solution">The solution to traverse.</param>
        /// <returns>All project nodes that were found.</returns>
        public static IEnumerable <IProjectNode> FindProjects(this ISolutionNode solution)
        {
            var visitor = new ProjectsVisitor();

            solution.Accept(visitor);

            return(visitor.Projects);
        }
Пример #4
0
    /// <summary>
    /// Finds all projects in the solution matching the given predicate.
    /// </summary>
    /// <param name="solution">The solution to traverse.</param>
    /// <param name="predicate">Predicate used to match projects.</param>
    /// <returns>All project nodes matching the given predicate that were found.</returns>
    public static IEnumerable <IProjectNode> FindProjects(this ISolutionNode solution, Func <IProjectNode, bool> predicate)
    {
        var visitor = new FilteringProjectsVisitor(predicate);

        solution.Accept(visitor);

        return(visitor.Projects);
    }
Пример #5
0
    /// <summary>
    /// Finds the first project in the solution matching the given predicate.
    /// </summary>
    /// <param name="solution">The solution to traverse.</param>
    /// <param name="predicate">Predicate used to match projects.</param>
    /// <returns>The first project matching the given predicate, or <see langword="null"/>.</returns>
    public static IProjectNode FindProject(this ISolutionNode solution, Func <IProjectNode, bool> predicate)
    {
        var visitor = new FilteringProjectsVisitor(predicate, true);

        solution.Accept(visitor);

        return(visitor.Projects.FirstOrDefault());
    }
Пример #6
0
        public SolutionFixture(string solutionFile)
        {
            if (!Path.IsPathRooted(solutionFile))
            {
                var rootedFile = Path.Combine(Path.GetDirectoryName(GetType().Assembly.ManifestModule.FullyQualifiedName), solutionFile);
                if (!File.Exists(rootedFile))
                {
                    rootedFile = Path.Combine(baseDirectory, solutionFile);
                    var currentDir = new DirectoryInfo(Directory.GetCurrentDirectory());
                    while (!File.Exists(rootedFile) && currentDir != null)
                    {
                        rootedFile = Path.Combine(currentDir.FullName, solutionFile);
                        currentDir = currentDir.Parent;
                    }
                }

                solutionFile = rootedFile;
            }

            if (!File.Exists(solutionFile))
            {
                throw new FileNotFoundException("Could not find solution file " + solutionFile, solutionFile);
            }

            try {
                var dte = GlobalServices.GetService <DTE>();
                if (!dte.Solution.IsOpen || !dte.Solution.FullName.Equals(solutionFile, StringComparison.OrdinalIgnoreCase))
                {
                    // Ensure no .suo is loaded, since that would dirty the state across runs.
                    var suoFile = Path.ChangeExtension(solutionFile, ".suo");
                    if (File.Exists(suoFile))
                    {
                        Try(() => File.Delete(suoFile));
                    }

                    var sdfFile = Path.ChangeExtension(solutionFile, ".sdf");
                    if (File.Exists(sdfFile))
                    {
                        Try(() => File.Delete(sdfFile));
                    }

                    var vsDir = Path.Combine(Path.GetDirectoryName(solutionFile), ".vs");
                    if (Directory.Exists(vsDir))
                    {
                        Try(() => Directory.Delete(vsDir, true));
                    }

                    dte.Solution.Open(solutionFile);
                    GlobalServices.GetService <SVsSolution, IVsSolution4> ()
                    .EnsureSolutionIsLoaded((uint)(__VSBSLFLAGS.VSBSLFLAGS_LoadAllPendingProjects | __VSBSLFLAGS.VSBSLFLAGS_LoadBuildDependencies));
                }
            } catch (Exception ex) {
                throw new ArgumentException("Failed to open and access solution: " + solutionFile, ex);
            }

            solution = GlobalServices.GetService <SComponentModel, IComponentModel> ().GetService <ISolutionExplorer> ().Solution;
        }
Пример #7
0
		public SolutionNodeSpec ()
		{
			var components = GlobalServices.GetService<SComponentModel, IComponentModel>();
			var factory = components.GetService<ISolutionExplorerNodeFactory> ();
			var adapter = components.GetService<IAdapterService> ();
			var manager = components.DefaultExportProvider.GetExportedValue<IVsHierarchyItemManager>(ContractNames.Interop.IVsHierarchyItemManager);
			var selection = components.GetService<IVsSolutionSelection>();
			var solutionExplorer = components.DefaultExportProvider.GetExport<IVsUIHierarchyWindow>(ContractNames.Interop.SolutionExplorerWindow);
			var item = manager.GetHierarchyItem(GlobalServices.GetService<SVsSolution, IVsHierarchy>(), (uint)VSConstants.VSITEMID.Root);

			solution = new SolutionNode (GlobalServices.Instance, item, factory, adapter, selection, solutionExplorer);
		}
Пример #8
0
        public void how_to_convert_IVsSolution_ISolutionNode()
        {
            // Say you have an IVsSolution:
            var vsSolution = (IVsSolution)ServiceProvider.GetService(typeof(SVsSolution));

            ISolutionNode solutionNode = vsSolution.Adapt().AsSolutionNode();

            Assert.IsNotNull(solutionNode);

            // Use the solution node to get the active project, for example:
            IProjectNode activeProject = solutionNode.ActiveProject;
        }
Пример #9
0
        public SolutionNodeSpec()
        {
            var components       = GlobalServices.GetService <SComponentModel, IComponentModel>();
            var factory          = components.GetService <ISolutionExplorerNodeFactory> ();
            var adapter          = components.GetService <IAdapterService> ();
            var manager          = components.DefaultExportProvider.GetExportedValue <IVsHierarchyItemManager>(ContractNames.Interop.IVsHierarchyItemManager);
            var selection        = components.GetService <IVsSolutionSelection>();
            var solutionExplorer = components.DefaultExportProvider.GetExport <IVsUIHierarchyWindow>(ContractNames.Interop.SolutionExplorerWindow);
            var item             = manager.GetHierarchyItem(GlobalServices.GetService <SVsSolution, IVsHierarchy>(), (uint)VSConstants.VSITEMID.Root);

            solution = new SolutionNode(GlobalServices.Instance, item, factory, adapter, selection, solutionExplorer);
        }
Пример #10
0
        public void how_to_convert_DTE_Solution_to_ISolutionNode()
        {
            // Say you have a DTE Solution:
            EnvDTE.Solution dteSolution = Dte.Solution;

            ISolutionNode solutionNode = dteSolution.Adapt().AsSolutionNode();

            Assert.IsNotNull(solutionNode);

            // Use the solution node to get the active project, for example:
            IProjectNode activeProject = solutionNode.ActiveProject;
        }
Пример #11
0
        /// <summary>
        /// Visists the given visitor with the specified solution.
        /// </summary>
        public static bool Accept(ISolutionNode solution, ISolutionVisitor visitor)
        {
            if (visitor.VisitEnter(solution))
            {
                foreach (var node in solution.Nodes)
                {
                    if (!node.Accept(visitor))
                        break;
                }
            }

            return visitor.VisitLeave(solution);
        }
Пример #12
0
        public SolutionNodeSpec()
        {
            var components       = GlobalServices.GetService <SComponentModel, IComponentModel>();
            var factory          = components.GetService <ISolutionExplorerNodeFactory>();
            var adapter          = components.GetService <IAdapterService>();
            var manager          = components.DefaultExportProvider.GetExportedValue <IVsHierarchyItemManager>(ContractNames.Interop.IVsHierarchyItemManager);
            var selection        = components.GetService <IVsSolutionSelection>();
            var solutionExplorer = components.DefaultExportProvider.GetExport <IVsUIHierarchyWindow>(ContractNames.Interop.SolutionExplorerWindow);
            var item             = manager.GetHierarchyItem(GlobalServices.GetService <SVsSolution, IVsHierarchy>(), (uint)VSConstants.VSITEMID.Root);

#pragma warning disable VSSDK005 // Avoid instantiating JoinableTaskContext
            solution = new SolutionNode(GlobalServices.Instance, item, factory, adapter, selection, JoinableLazy.Create(() => solutionExplorer.Value, taskFactory: new JoinableTaskContext().Factory));
#pragma warning restore VSSDK005 // Avoid instantiating JoinableTaskContext
        }
Пример #13
0
        /// <summary>
        /// Visists the given visitor with the specified solution.
        /// </summary>
        public static bool Accept(ISolutionNode solution, ISolutionVisitor visitor)
        {
            if (visitor.VisitEnter(solution))
            {
                foreach (var node in solution.Nodes)
                {
                    if (!node.Accept(visitor))
                    {
                        break;
                    }
                }
            }

            return(visitor.VisitLeave(solution));
        }
Пример #14
0
		public SolutionFixture (string solutionFile)
		{
			if (!Path.IsPathRooted (solutionFile)) {
				var rootedFile = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.ManifestModule.FullyQualifiedName), solutionFile);
				if (!File.Exists (rootedFile)) {
					rootedFile = Path.Combine (baseDirectory, solutionFile);
					var currentDir = new DirectoryInfo(Directory.GetCurrentDirectory());
					while (!File.Exists (rootedFile) && currentDir != null) {
						rootedFile = Path.Combine (currentDir.FullName, solutionFile);
						currentDir = currentDir.Parent;
					}
				}

				solutionFile = rootedFile;
			}

			if (!File.Exists (solutionFile))
				throw new FileNotFoundException ("Could not find solution file " + solutionFile, solutionFile);

			try {
				var dte = GlobalServices.GetService<DTE>();
				if (!dte.Solution.IsOpen || !dte.Solution.FullName.Equals (solutionFile, StringComparison.OrdinalIgnoreCase)) {
					// Ensure no .suo is loaded, since that would dirty the state across runs.
					var suoFile = Path.ChangeExtension(solutionFile, ".suo");
					if (File.Exists (suoFile))
						Try (() => File.Delete (suoFile));

					var sdfFile = Path.ChangeExtension(solutionFile, ".sdf");
					if (File.Exists (sdfFile))
						Try (() => File.Delete (sdfFile));

					var vsDir = Path.Combine(Path.GetDirectoryName(solutionFile), ".vs");
					if (Directory.Exists (vsDir))
						Try (() => Directory.Delete (vsDir, true));

					dte.Solution.Open (solutionFile);
					GlobalServices.GetService<SVsSolution, IVsSolution4> ()
						.EnsureSolutionIsLoaded ((uint)(__VSBSLFLAGS.VSBSLFLAGS_LoadAllPendingProjects | __VSBSLFLAGS.VSBSLFLAGS_LoadBuildDependencies));
				}
			} catch (Exception ex) {
				throw new ArgumentException ("Failed to open and access solution: " + solutionFile, ex);
			}

			solution = GlobalServices.GetService<SComponentModel, IComponentModel> ().GetService<ISolutionExplorer> ().Solution;
		}
Пример #15
0
        /// <summary>
        /// Starts a build of the solution.
        /// </summary>
        public static Task <bool> Build(this ISolutionNode solution)
        {
            var sln = solution.As <EnvDTE.Solution>();

            if (sln == null)
            {
                throw new ArgumentException(Strings.ISolutionNodeExtensions.BuildNotSupported);
            }

            return(System.Threading.Tasks.Task.Factory.StartNew <bool>(() =>
            {
                var mre = new ManualResetEventSlim();
                var events = sln.DTE.Events.BuildEvents;
                EnvDTE._dispBuildEvents_OnBuildDoneEventHandler done = (scope, action) => mre.Set();
                events.OnBuildDone += done;
                try
                {
                    // Let build run async.
                    sln.SolutionBuild.Build(false);

                    // Wait until it's done.
                    mre.Wait();

                    // LastBuildInfo == # of projects that failed to build.
                    return sln.SolutionBuild.LastBuildInfo == 0;
                }
                catch (Exception ex)
                {
                    tracer.Error(ex, Strings.ISolutionNodeExtensions.BuildException);
                    return false;
                }
                finally
                {
                    // Cleanup handler.
                    events.OnBuildDone -= done;
                }
            }, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default));
        }
Пример #16
0
 /// <summary>
 /// Ends visiting the solution.
 /// </summary>
 /// <param name="solution">The solution being visited.</param>
 /// <returns>
 /// The result of the solution traversal operation.
 /// </returns>
 public virtual bool VisitLeave(ISolutionNode solution)
 {
     return(true);
 }
 public bool VisitLeave(ISolutionNode solution)
 {
     throw new NotSupportedException();
 }
Пример #18
0
 public static IProjectNode UnfoldTemplate(this ISolutionNode solution, string templateId, string projectName, string language = "CSharp") =>
 solution.AsProjectContainerNode().UnfoldTemplate(templateId, projectName, language);
Пример #19
0
 /// <summary>
 /// Begins visiting the solution.
 /// </summary>
 /// <param name="solution">The solution being visited.</param>
 /// <returns>
 ///   <see langword="true" /> if the solution child nodes should be visited; <see langword="false" /> otherwise.
 /// </returns>
 public virtual bool VisitEnter(ISolutionNode solution)
 {
     return(true);
 }
		public bool VisitLeave(ISolutionNode solution)
		{
			throw new NotSupportedException();
		}
Пример #21
0
		public bool VisitLeave (ISolutionNode solution) => true;
Пример #22
0
 /// <summary>
 /// Ends visiting the solution.
 /// </summary>
 /// <param name="solution">The solution being visited.</param>
 /// <returns>
 /// The result of the solution traversal operation.
 /// </returns>
 public virtual bool VisitLeave(ISolutionNode solution)
 {
     return true;
 }
Пример #23
0
 /// <summary>
 /// Adapts a <see cref="ISolutionNode"/> to an <see cref="IVsHierarchyItem"/>.
 /// </summary>
 /// <returns>The <see cref="IVsSolution"/> or <see langword="null"/> if conversion is not possible.</returns>
 public static IVsHierarchyItem AsVsHierarchyItem(this ISolutionNode solution) => solution.As <IVsHierarchyItem>();
Пример #24
0
 /// <summary>
 /// Begins visiting the solution.
 /// </summary>
 /// <param name="solution">The solution being visited.</param>
 /// <returns>
 ///   <see langword="true" /> if the solution child nodes should be visited; <see langword="false" /> otherwise.
 /// </returns>
 public virtual bool VisitEnter(ISolutionNode solution) => true;
Пример #25
0
 /// <summary>
 /// Begins visiting the solution.
 /// </summary>
 /// <param name="solution">The solution being visited.</param>
 /// <returns>
 ///   <see langword="true" /> if the solution child nodes should be visited; <see langword="false" /> otherwise.
 /// </returns>
 public virtual bool VisitEnter(ISolutionNode solution)
 {
     return true;
 }
Пример #26
0
 public bool VisitEnter(ISolutionNode solution) => true;
Пример #27
0
 /// <summary>
 /// Ends visiting the solution.
 /// </summary>
 /// <param name="solution">The solution being visited.</param>
 /// <returns>
 /// The result of the solution traversal operation.
 /// </returns>
 public virtual bool VisitLeave(ISolutionNode solution) => true;
Пример #28
0
		/// <summary>
		/// Begins visiting the solution.
		/// </summary>
		/// <param name="solution">The solution being visited.</param>
		/// <returns>
		///   <see langword="true" /> if the solution child nodes should be visited; <see langword="false" /> otherwise.
		/// </returns>
		public virtual bool VisitEnter (ISolutionNode solution) => true;
Пример #29
0
 /// <summary>
 /// Adapts a <see cref="ISolutionNode"/> to an <see cref="IVsSolution"/>.
 /// </summary>
 /// <returns>The <see cref="IVsSolution"/> or <see langword="null"/> if conversion is not possible.</returns>
 public static IVsSolution AsVsSolution(this ISolutionNode solution) => solution.As <IVsSolution>();
 public virtual void Visit(ISolutionNode node)
 {
    DefaultVisit(node);
 }
Пример #31
0
 /// <summary>
 /// Adapts a <see cref="ISolutionNode"/> to a DTE <see cref="Solution"/>.
 /// </summary>
 /// <returns>The DTE <see cref="Solution"/> or <see langword="null"/> if conversion is not possible.</returns>
 public static Solution AsSolution(this ISolutionNode solution) => solution.As <EnvDTE.Solution>();
Пример #32
0
		/// <summary>
		/// Ends visiting the solution.
		/// </summary>
		/// <param name="solution">The solution being visited.</param>
		/// <returns>
		/// The result of the solution traversal operation.
		/// </returns>
		public virtual bool VisitLeave (ISolutionNode solution) => true;
Пример #33
0
 /// <summary>
 /// Adapts a <see cref="ISolutionNode"/> to an <see cref="IVsHierarchy"/>.
 /// </summary>
 /// <returns>The <see cref="IVsSolution"/> or <see langword="null"/> if conversion is not possible.</returns>
 public static IVsHierarchy AsVsHierarchy(this ISolutionNode solution) => solution.As <IVsHierarchy>();
Пример #34
0
		public ProjectContainerNode(ISolutionNode solutionNode)
		{
			this.solutionNode = solutionNode;
			this.hierarchyNode = new Lazy<IVsHierarchyItem>(() => solutionNode.AsVsHierarchyItem());
		}
Пример #35
0
 /// <summary>
 /// Finds all the project nodes in the solution.
 /// </summary>
 /// <param name="solution">The solution to traverse.</param>
 /// <returns>All project nodes that were found.</returns>
 public static IEnumerable <IProjectNode> FindProjects(this ISolutionNode solution) =>
 solution.FindProjects(x => true);
Пример #36
0
		public bool VisitEnter (ISolutionNode solution) => true;
Пример #37
0
 internal static IProjectContainerNode AsProjectContainerNode(this ISolutionNode solution) =>
 solution.As <IProjectContainerNode>();
Пример #38
0
 public ProjectContainerNode(ISolutionNode solutionNode)
 {
     this.solutionNode = solutionNode;
     hierarchyNode     = new Lazy <IVsHierarchyItem>(() => solutionNode.AsVsHierarchyItem());
 }
Пример #39
0
 public bool VisitLeave(ISolutionNode solution) => true;
Пример #40
0
 /// <summary>
 /// Adapts the specified solution to supported target types.
 /// </summary>
 /// <param name="solution">The solution to adapt.</param>
 /// <returns>The entry point that exposes supported target types.</returns>
 public static IAdaptable <ISolutionNode> Adapt(this ISolutionNode solution)
 {
     return(new TreeNodeAdaptable <ISolutionNode>(solution));
 }