public static void ForEachProject(DTE vs, Predicate <Project> processAndBreak)
 {
     try
     {
         foreach (Project project in ((Projects)vs.GetObject("CSharpProjects")))
         {
             if (processAndBreak(project))
             {
                 return;
             }
         }
     }
     catch (Exception)
     {
     }
     try
     {
         foreach (Project project in ((Projects)vs.GetObject("VBProjects")))
         {
             if (processAndBreak(project))
             {
                 return;
             }
         }
     }
     catch (Exception)
     {
     }
 }
        // ------------------------------------------------------
        /// <summary>
        /// Add the CxxTest and Dereferee paths to the Visual C++ settings,
        /// if they aren't already there.
        /// </summary>
        private void AddIncludesAndLibrariesPaths()
        {
            DTE dte = (DTE)GetService(typeof(DTE));

            Projects        projects      = (Projects)dte.GetObject("VCProjects");
            VCProjectEngine projectEngine = (VCProjectEngine)
                                            projects.Properties.Item("VCProjectEngine").Object;
            IVCCollection platforms = (IVCCollection)projectEngine.Platforms;

            VCPlatform vcp = (VCPlatform)platforms.Item("Win32");

            string packageDir = Path.GetDirectoryName(
                Assembly.GetExecutingAssembly().Location);

            string cxxTestIncludePath = Path.Combine(
                packageDir, "Include\\cxxtest");
            string derefereeIncludePath = Path.Combine(
                packageDir, "Include\\dereferee");
            string supportLibPath = Path.Combine(packageDir, "Libraries");

            string newIncludes = AddPathsToDirectories(
                vcp.IncludeDirectories, new string[] {
                cxxTestIncludePath, derefereeIncludePath
            });

            vcp.IncludeDirectories = newIncludes;

            string newLibraries = AddPathsToDirectories(
                vcp.LibraryDirectories, new string[] {
                supportLibPath
            });

            vcp.LibraryDirectories = newLibraries;

            vcp.CommitChanges();
        }
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            try
            {
                DTE dte = (DTE)this.ServiceProvider.GetService(typeof(DTE));
                var sourceControlURL = string.Empty;

                // 1.) Get TFS URL
                //Plan A - Team Explorer Reflection
                try
                {
                    /****** Reflection Hacks to access private DLLs for both Visual Studio 2015 and Visual Studio 2017 ******/
                    var ext = dte.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt");

                    System.Type type = ext.GetType();
                    System.Reflection.PropertyInfo property = type.GetProperty("ActiveProjectContext");
                    object activeProjectContext             = property.GetValue(ext);

                    System.Type type2 = activeProjectContext.GetType();
                    System.Reflection.PropertyInfo property2 = type2.GetProperty("DomainUri");
                    object domainUri = property2.GetValue(activeProjectContext);

                    sourceControlURL = domainUri.ToString();
                    /********************************************************************************************************/
                }
                catch (Exception ex)
                {
                    //Swallowing this exception on purpose
                }

                //Get TFS or GitHub URL - Plan B - LibGit2Sharp
                if (string.IsNullOrEmpty(sourceControlURL))
                {
                    var directory = new DirectoryInfo(dte.ActiveDocument.Path);
                    while (directory.Parent != null && directory.Parent.Name != directory.Root.Name)
                    {
                        if (Repository.IsValid(directory.FullName))
                        {
                            using (var repo = new Repository(directory.FullName))
                            {
                                var origin            = repo.Network.Remotes["origin"].Url;
                                var uri               = new Uri(origin);
                                var root              = uri.GetLeftPart(UriPartial.Authority);
                                var projectCollection = uri.Segments[1];

                                if (root.Contains(visualStudioBaseURL)) //VisualStudioOnline
                                {
                                    sourceControlURL = String.Format("{0}/{1}", root, projectCollection);
                                }
                                else if (root.Contains(gitHubBaseURL)) //GitHub
                                {
                                    var gitHubRepo = uri.Segments[2].Replace(".git", string.Empty);
                                    sourceControlURL = String.Format("{0}/{1}/{2}", root, projectCollection, gitHubRepo);
                                }

                                break;
                            }
                        }

                        directory = directory.Parent;
                    }
                }

                //2.) Open Browser with Search URL
                var selection        = (TextSelection)dte.ActiveDocument.Selection;
                var encodedSelection = HttpUtility.UrlEncode(selection.Text);
                var searchURL        = string.Empty;

                if (sourceControlURL.Contains(gitHubBaseURL)) //GitHub
                {
                    searchURL = string.Format("{0}/search?q={1}", sourceControlURL, encodedSelection);
                }
                else //VisualStudioOnline or network hosted TFS Server
                {
                    searchURL = string.Format("{0}/_search?type=Code&lp=search-project&text={1}&preview=1&_a=contents", sourceControlURL, encodedSelection);
                }

                System.Diagnostics.Process.Start(searchURL);
            }
            catch (Exception ex)
            {
                ShowError(string.Format(CultureInfo.CurrentCulture, ex.Message + ex.StackTrace, this.GetType().FullName));
            }
        }
Exemplo n.º 4
0
 private IPythonOptions GetOptions() => (IPythonOptions)_dte.GetObject("VsPython");
Exemplo n.º 5
0
 public object GetObject(string Name)
 {
     return(_dte.GetObject(Name));
 }