예제 #1
0
 public WebBrowserServices(ICoreShell coreShell)
 {
     _coreShell = coreShell;
     _wbs       = _coreShell.GetService <IVsWebBrowsingService>(typeof(SVsWebBrowsingService));
     _ps        = _coreShell.Process();
     _settings  = _coreShell.GetService <IRToolsSettings>();
 }
예제 #2
0
        public int OnLinkClicked(int iField, int iLinkIndex)
        {
            TextFinder startFinder =
                delegate(string text, int startIndex)
            {
                return(text.IndexOf("@", startIndex));
            };

            TextFinder endFinder =
                delegate(string text, int startIndex)
            {
                return(text.IndexOf("@", startIndex + 1));
            };

            Span span = FindNthSpan(_comment, iLinkIndex, startFinder, endFinder);

            if (span != null)
            {
                IVsWebBrowsingService browser = _serviceProvider.GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService;
                IVsWindowFrame        frame   = null;

                int hr = browser.Navigate(_comment.Substring(span.Start + 1, span.Length - 2), 0, out frame);
                Debug.Assert(hr == VSConstants.S_OK, "Navigate did not return S_OK.");
                return(VSConstants.S_OK);
            }
            else
            {
                Debug.Assert(false, "Invalid link index sent to OnLinkClicked.");
                return(VSConstants.E_INVALIDARG);
            }
        }
        /// <summary>
        /// Launches the specified Url either in the internal VS browser or the
        /// user's default web browser.
        /// </summary>
        /// <param name="browserService">VS's browser service for interacting with the internal browser.</param>
        /// <param name="launchUrl">Url to launch.</param>
        /// <param name="useInternalBrowser">true to use the internal browser; false to use the default browser.</param>
        private void LaunchWebBrowser(IVsWebBrowsingService browserService, string launchUrl, bool useInternalBrowser)
        {
            try
            {
                if (useInternalBrowser == true)
                {
                    // if set to use internal browser, then navigate via the browser service.
                    IVsWindowFrame ppFrame;

                    // passing 0 to the NavigateFlags allows the browser service to reuse open instances
                    // of the internal browser.
                    browserService.Navigate(launchUrl, 0, out ppFrame);
                }
                else
                {
                    // if not, launch the user's default browser by starting a new one.
                    StartInfo.FileName = launchUrl;
                    Process.Start(StartInfo);
                }
            }
            catch
            {
                // if the process could not be started, show an error.
                MessageBox.Show("Cannot launch this url.", "Extension Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #4
0
        /// <summary>
        /// Open a URL within Visual Studio using the <see cref="IVsWebBrowsingService"/> service
        /// </summary>
        /// <param name="url">The URL to display</param>
        public static void OpenUrl(string url)
        {
            IVsWindowFrame        frame;
            IVsWebBrowsingService webBrowsingService = GetServiceFromPackage <IVsWebBrowsingService,
                                                                              SVsWebBrowsingService>(true);
            bool useExternalBrowser = false;

            if (String.IsNullOrEmpty(url))
            {
                return;
            }

            var options = SandcastleBuilderPackage.Instance.GeneralOptions;

            if (options != null)
            {
                useExternalBrowser = options.UseExternalWebBrowser;
            }

            if (!useExternalBrowser && webBrowsingService != null)
            {
                ErrorHandler.ThrowOnFailure(webBrowsingService.Navigate(url, 0, out frame));

                if (frame != null)
                {
                    frame.Show();
                }
            }
            else
            {
                System.Diagnostics.Process.Start(url);
            }
        }
예제 #5
0
 /// <summary>
 /// The OpenReport.
 /// </summary>
 /// <param name="webBrowserSvc">The webBrowserSvc<see cref="IVsWebBrowsingService"/>.</param>
 /// <param name="report">The report<see cref="string"/>.</param>
 private void OpenReport(IVsWebBrowsingService webBrowserSvc, string report)
 {
     // ThreadHelper.ThrowIfNotOnUIThread();
     try
     {
         ThreadHelper.Generic.BeginInvoke(() => webBrowserSvc.Navigate(report, 0, out _));
     }
     catch { }
 }
예제 #6
0
        private void Navigate(string url)
        {
            IVsWebBrowsingService webBrowsingService = this.GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService;

            if (webBrowsingService != null)
            {
                IVsWindowFrame frame;
                ErrorHandler.ThrowOnFailure(webBrowsingService.Navigate(url, 0, out frame));
            }
        }
예제 #7
0
        public void OpenInBrowser(string url)
        {
            IVsWebBrowsingService service = (IVsWebBrowsingService)GetService(typeof(SVsWebBrowsingService));

            if (service != null)
            {
                IVsWindowFrame frame = null;
                service.Navigate(url, (uint)(__VSWBNAVIGATEFLAGS.VSNWB_WebURLOnly | __VSWBNAVIGATEFLAGS.VSNWB_ForceNew), out frame);
                frame.Show();
            }
        }
예제 #8
0
        private void OpenWebPage(string url)
        {
            // Open the specified URL in Visual Studio's built-in web browser.
            IVsWebBrowsingService service = (IVsWebBrowsingService)GetService(
                typeof(SVsWebBrowsingService));

            if (service != null)
            {
                IVsWindowFrame frame;
                service.Navigate(url, (uint)__VSWBNAVIGATEFLAGS.VSNWB_ForceNew,
                                 out frame);
            }
        }
예제 #9
0
        /// <summary>
        /// The RunCoverage.
        /// </summary>
        /// <param name="dte">The dte<see cref="DTE2"/>.</param>
        /// <param name="webBrowserSvc">The webBrowserSvc<see cref="IVsWebBrowsingService"/>.</param>
        private void RunCoverage(DTE2 dte, IVsWebBrowsingService webBrowserSvc)
        {
            var slnFile          = dte.Solution.FileName;
            var testOutputFolder = $"{Path.GetTempPath()}{Guid.NewGuid().ToString().ToLowerInvariant()}\\";

            Debug.WriteLine("---CoverletRunner: Set output folder to " + testOutputFolder);

            this.RunCoverageTool(slnFile, testOutputFolder);
            var report = this.RunCoverageReporter(testOutputFolder);

            this.ParseTestResults(testOutputFolder);

            this.OpenReport(webBrowserSvc, report);
        }
예제 #10
0
        private bool OpenUri(Uri uri)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }

            if (!uri.IsAbsoluteUri)
            {
                return(false);
            }

            /* First try to use the Web Browsing Service. This is not known to work because the
             * CreateExternalWebBrowser method always returns E_NOTIMPL. However, it is presumably
             * safer than a Shell Execute for arbitrary URIs.
             */
            IVsWebBrowsingService service = ServiceProvider.GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService;

            if (service != null)
            {
                __VSCREATEWEBBROWSER createFlags = __VSCREATEWEBBROWSER.VSCWB_AutoShow;
                VSPREVIEWRESOLUTION  resolution  = VSPREVIEWRESOLUTION.PR_Default;
                int result = ErrorHandler.CallWithCOMConvention(() => { ThreadHelper.ThrowIfNotOnUIThread(); return(service.CreateExternalWebBrowser((uint)createFlags, resolution, uri.AbsoluteUri)); });
                if (ErrorHandler.Succeeded(result))
                {
                    return(true);
                }
            }

            // Fall back to Shell Execute, but only for http or https URIs
            if (uri.Scheme != "http" && uri.Scheme != "https")
            {
                return(false);
            }

            try
            {
                Process.Start(uri.AbsoluteUri);
                return(true);
            }
            catch (Win32Exception)
            {
            }
            catch (FileNotFoundException)
            {
            }

            return(false);
        }
예제 #11
0
        public void OpenInBrowser(string url)
        {
            ThreadHelper.JoinableTaskFactory.Run(async delegate
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                IVsWebBrowsingService service = await GetServiceAsync(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService;
                if (service != null)
                {
                    IVsWindowFrame frame = null;
                    service.Navigate(url, (uint)(__VSWBNAVIGATEFLAGS.VSNWB_WebURLOnly | __VSWBNAVIGATEFLAGS.VSNWB_ForceNew), out frame);
                    frame.Show();
                }
            });
        }
예제 #12
0
        private void Navigate(string yUMLExpression)
        {
            string url          = "http://yuml.me/diagram/scruffy/class/" + yUMLExpression;
            string tempFileName = Path.GetTempFileName() + ".htm";

            using (var sw = File.CreateText(tempFileName))
            {
                sw.Write(string.Format("<html><body><img src=\"{0}\" /><br /><br />yUML Expression: <b>{1}</b></body></html>", url, HttpUtility.HtmlEncode(yUMLExpression)));
            }

            IVsWebBrowsingService browser = GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService;
            IVsWindowFrame        newWnd;

            browser.Navigate(tempFileName, (uint)__VSWBNAVIGATEFLAGS.VSNWB_ForceNew, out newWnd);
        }
예제 #13
0
        public void Navigate(Uri url, AnkhBrowserArgs args, out AnkhBrowserResults results)
        {
            IVsWebBrowsingService browserSvc = GetService <IVsWebBrowsingService>(typeof(SVsWebBrowsingService));

            Guid           windowGuid = new Guid(ToolWindowGuids80.WebBrowserWindow);
            IVsWebBrowser  browser;
            IVsWindowFrame ppFrame;
            int            hr = browserSvc.CreateWebBrowser(
                (uint)args.CreateFlags,
                ref windowGuid,
                args.BaseCaption,
                url.ToString(),
                new BrowserUser(),
                out browser,
                out ppFrame);

            results = new Results(browser, ppFrame);
        }
예제 #14
0
        private void HandleNavigateToVsBaseServicesExtension(object sender, EventArgs e)
        {
            const string          vsbaseDebugExtensionLocation = "https://visualstudiogallery.msdn.microsoft.com/fca95a59-3fc6-444e-b20c-cc67828774cd";
            IVsWebBrowsingService webBrowsingService           = GetService <SVsWebBrowsingService, IVsWebBrowsingService>();

            if (webBrowsingService != null)
            {
                IVsWindowFrame windowFrame;
                webBrowsingService.Navigate(vsbaseDebugExtensionLocation, 0, out windowFrame);
                return;
            }

            IVsUIShellOpenDocument openDocument = GetService <SVsUIShellOpenDocument, IVsUIShellOpenDocument>();

            if (openDocument != null)
            {
                openDocument.OpenStandardPreviewer(0, vsbaseDebugExtensionLocation, VSPREVIEWRESOLUTION.PR_Default, 0);
            }
        }
예제 #15
0
        private static void OpenVsBrowser(string url)
        {
            VsAppShell.Current.DispatchOnUIThread(() => {
                IVsWebBrowsingService web = VsAppShell.Current.GetGlobalService <IVsWebBrowsingService>(typeof(SVsWebBrowsingService));
                if (web == null)
                {
                    OpenExternalBrowser(url);
                    return;
                }

                try {
                    IVsWindowFrame frame;
                    ErrorHandler.ThrowOnFailure(web.Navigate(url, (uint)__VSWBNAVIGATEFLAGS.VSNWB_ForceNew, out frame));
                    frame.Show();
                } catch (COMException) {
                    OpenExternalBrowser(url);
                }
            });
        }
예제 #16
0
        private void HandleNavigateToVsBaseServicesExtension(object sender, EventArgs e)
        {
            IVsWebBrowsingService webBrowsingService = GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService;

            if (webBrowsingService != null)
            {
                IVsWindowFrame windowFrame;
                webBrowsingService.Navigate("https://visualstudiogallery.msdn.microsoft.com/fca95a59-3fc6-444e-b20c-cc67828774cd", 0, out windowFrame);
                return;
            }

            IVsUIShellOpenDocument openDocument = GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;

            if (openDocument != null)
            {
                openDocument.OpenStandardPreviewer(0, "https://visualstudiogallery.msdn.microsoft.com/fca95a59-3fc6-444e-b20c-cc67828774cd", VSPREVIEWRESOLUTION.PR_Default, 0);
                return;
            }
        }
        /// <summary>
        /// The RunCoverage.
        /// </summary>
        /// <param name="dte">The dte <see cref="DTE2"/>.</param>
        /// <param name="webBrowserSvc">The webBrowserSvc <see cref="IVsWebBrowsingService"/>.</param>
        private void RunCoverage(DTE2 dte, IVsWebBrowsingService webBrowserSvc)
        {
            var    slnFile          = dte.Solution.FileName;
            string testOutputFolder = this.GetOutputFolder();

            Debug.WriteLine("---CoverletRunner: Set output folder to " + testOutputFolder);

            var useMSBuild = CoverageResultsProvider.Instance.Options.IntegrationType == Options.IntegrationType.MSBuild;

            (string cmd, string args)cmdArgs;
            if (!useMSBuild)
            {
                cmdArgs = this.GetCommandArgsForCoverletCollector(slnFile, testOutputFolder);
            }
            else
            {
                cmdArgs = this.GetCommandArgsForCoverletMSBuild(slnFile, testOutputFolder);
            }

            this.RunCoverageTool(cmdArgs.cmd, cmdArgs.args);

            if (!Directory.Exists(testOutputFolder))
            {
                var errorMessage = @"Unable to find test coverage output folder that Coverlet should have created.
1. Check that your solution builds. You may also want to check your unit tests pass.
2. Check you have both Coverlet and Report Generator setup correctly.
3. If you have set 'Restore NuGet Packages' to 'False', make sure you have restored them yourself.
4. If you have decided to use the 'Coverlet.Collector' NuGet package to collect code coverage make sure you have the 'Integration type' set to 'Collector'.
If you are using 'Coverlet.MSBuild' then make sure to select 'MSBuild' instead.
See 'Tools | Options | Run Coverlet Report' for settings.

Folder searched: " + testOutputFolder;

                this.ShowErrorMessage("Coverlet Output Not Found", errorMessage);
            }
            else
            {
                var report = this.RunCoverageReporter(testOutputFolder);
                this.OpenReport(webBrowserSvc, report.reportFile);
                this.ParseTestResults(report.coberturaXmlFile);
            }
        }
예제 #18
0
        public int VsBrowseUrl(Uri uri)
        {
            if (uri == null)
            {
                OutputGeneral("ERROR: url cannot be null");
                ErrorHandler.ThrowOnFailure(VSConstants.E_POINTER);
            }

            IVsWebBrowsingService browserService = GetWebBrowsingService();

            if (browserService == null)
            {
                OutputGeneral("ERROR: Cannot create browser service");
                ErrorHandler.ThrowOnFailure(VSConstants.E_UNEXPECTED);
            }

            Guid           guidNull = Guid.Empty;
            IVsWindowFrame frame;
            IVsWebBrowser  browser;
            uint           flags = (uint)(__VSCREATEWEBBROWSER.VSCWB_AutoShow | __VSCREATEWEBBROWSER.VSCWB_StartCustom | __VSCREATEWEBBROWSER.VSCWB_ReuseExisting);

            return(browserService.CreateWebBrowser(flags, ref guidNull, "", uri.AbsoluteUri, null, out browser, out frame));
        }
예제 #19
0
        private bool IntervalHandler(IVsWebBrowser browser, DispatcherTimer tmr)
        {
            IVsWebBrowsingService webBrowserService = ServiceProvider.GlobalProvider.GetService(typeof(IVsWebBrowsingService)) as IVsWebBrowsingService;

            if (webBrowserService != null)
            {
                IVsWebBrowser  ppBrowser;
                IVsWindowFrame ppFrame;
                webBrowserService.GetFirstWebBrowser(Guid.Empty, out ppFrame, out ppBrowser);
                if (ppFrame.IsVisible() == VSConstants.S_FALSE)
                {
                    tmr.Stop();
                    tmr.IsEnabled = false;
                }
                object urlObject;
                browser.GetDocumentInfo((uint)__VSWBDOCINFOINDEX.VSWBDI_DocURL, out urlObject);
                var url = urlObject as string;

                if (url != null && url.Contains(ConstValues.Params.AccessToken))
                {
                    SetKey(_authentication.GetTokenBasedOnUrl(url));
                    ppFrame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave);
                    VsShellUtilities.ShowMessageBox(
                        ServiceProvider.GlobalProvider,
                        "Plugin has been authorized!",
                        "Success",
                        OLEMSGICON.OLEMSGICON_INFO,
                        OLEMSGBUTTON.OLEMSGBUTTON_OK,
                        OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                    tmr.Stop();
                    tmr.IsEnabled = false;
                    return(true);
                }
            }
            return(false);
        }
 public VsBrowserReportViewer(IFileSystem fileSystem, TextWriter output, IVsWebBrowsingService webBrowsingService)
 {
     _fileSystem = fileSystem;
     _output = output;
     _browserService = webBrowsingService;
 }
예제 #21
0
 public YouTrackService(ISettingsStore store, IVsWebBrowsingService wbs, Lifetime lifetime)
 {
     this.wbs = wbs;
       this.lifetime = lifetime;
       this.store = store.BindToContextLive(lifetime, ContextRange.ApplicationWide);
 }
 public VsBrowserReportViewer(IFileSystem fileSystem, TextWriter output, IVsWebBrowsingService webBrowsingService)
 {
     _fileSystem     = fileSystem;
     _output         = output;
     _browserService = webBrowsingService;
 }
예제 #23
0
 public YouTrackService(ISettingsStore store, IVsWebBrowsingService wbs, Lifetime lifetime)
 {
     this.wbs      = wbs;
     this.lifetime = lifetime;
     this.store    = store.BindToContextLive(lifetime, ContextRange.ApplicationWide);
 }
예제 #24
0
        private static bool TryStartBrowser(IVsWebBrowsingService service, Uri uri)
        {
            IVsWindowFrame unused;

            return(ErrorHandler.Succeeded(service.Navigate(uri.AbsoluteUri, 0, out unused)));
        }
예제 #25
0
        private bool OpenUri(Uri uri)
        {
            if (uri == null)
            {
                throw new ArgumentNullException(nameof(uri));
            }

            if (string.Equals(uri.Scheme, PrefixOpenInVisualStudio, StringComparison.InvariantCultureIgnoreCase))
            {
                if (File.Exists(uri.LocalPath))
                {
                    DTEHelper.Singleton?.OpenFileInVisualStudio(null, uri.LocalPath);
                }

                return(true);
            }

            if (string.Equals(uri.Scheme, PrefixOpenInVisualStudioRelativePath, StringComparison.InvariantCultureIgnoreCase))
            {
                DTEHelper.Singleton?.OpenFileInVisualStudioRelativePath(null, uri.LocalPath);

                return(true);
            }

            if (string.Equals(uri.Scheme, PrefixOpenInTextEditor, StringComparison.InvariantCultureIgnoreCase))
            {
                if (File.Exists(uri.LocalPath))
                {
                    DTEHelper.Singleton?.OpenFileInTextEditor(null, uri.LocalPath);
                }

                return(true);
            }

            if (string.Equals(uri.Scheme, PrefixOpenInExcel, StringComparison.InvariantCultureIgnoreCase))
            {
                if (File.Exists(uri.LocalPath))
                {
                    DTEHelper.Singleton?.OpenFileInExcel(null, uri.LocalPath);
                }

                return(true);
            }

            if (string.Equals(uri.Scheme, PrefixShowDifference, StringComparison.InvariantCultureIgnoreCase))
            {
                DTEHelper.Singleton?.ShowDifference(uri);

                return(true);
            }

            if (string.Equals(uri.Scheme, PrefixOpenSolution, StringComparison.InvariantCultureIgnoreCase))
            {
                DTEHelper.Singleton?.OpenSolution(uri);

                return(true);
            }

            if (string.Equals(uri.Scheme, PrefixOpenSolutionList, StringComparison.InvariantCultureIgnoreCase))
            {
                DTEHelper.Singleton?.OpenSolutionList(uri);

                return(true);
            }

            if (string.Equals(uri.Scheme, PrefixSelectFileInFolder, StringComparison.InvariantCultureIgnoreCase))
            {
                if (File.Exists(uri.LocalPath))
                {
                    DTEHelper.Singleton?.SelectFileInFolder(null, uri.LocalPath);
                }

                return(true);
            }

            IVsWebBrowsingService service = _provider.ServiceProvider.GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService;

            if (service != null)
            {
                var createFlags = __VSCREATEWEBBROWSER.VSCWB_AutoShow;
                var resolution  = VSPREVIEWRESOLUTION.PR_Default;

                int result = ErrorHandler.CallWithCOMConvention(() => service.CreateExternalWebBrowser((uint)createFlags, resolution, uri.AbsoluteUri));

                if (ErrorHandler.Succeeded(result))
                {
                    return(true);
                }
            }

            if (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps)
            {
                return(false);
            }

            try
            {
                Process.Start(uri.AbsoluteUri);
                return(true);
            }
            catch (Exception)
            {
            }

            return(false);
        }
예제 #26
0
        internal static void ShowError(string message, string document, string helpSubPage = "", int lineNo = 0, int column = 0)
        {
            ErrorTask task = new ErrorTask()
            {
                Category      = TaskCategory.Misc,
                ErrorCategory = TaskErrorCategory.Error,
                Text          = message
            };

            DTE dte = (DTE)(_serviceProvider.GetService(typeof(DTE)));
            IServiceProvider serviceProvider = new ServiceProvider(dte as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);

            if (document != null)
            {
                task.Document = document;

                task.Navigate += (s, e) =>
                {
                    try
                    {
                        IVsUIHierarchy hierarchy;
                        uint           itemID;
                        IVsWindowFrame docFrame;
                        IVsTextView    textView;
                        VsShell.OpenDocument(serviceProvider, document, Guids.LOGVIEWID_Code, out hierarchy, out itemID, out docFrame, out textView);
                        ThrowOnFailure(docFrame.Show());
                        if (textView != null)
                        {
                            ThrowOnFailure(textView.SetCaretPos(lineNo, column));
                        }
                    }catch (Exception)
                    {
                        // don't trow crazy exceptions when trying to navigate to errors
                    }
                };
            }

            task.Help += (s, e) =>
            {
                var mainPage = "http://fsprojects.github.io/Paket/";
                var errorUrl = mainPage;
                if (!String.IsNullOrWhiteSpace(helpSubPage))
                {
                    errorUrl += helpSubPage;
                }

                IVsWebBrowsingService webBrowsingService = serviceProvider.GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService;
                if (webBrowsingService != null)
                {
                    IVsWindowFrame windowFrame;
                    webBrowsingService.Navigate(errorUrl, 0, out windowFrame);
                    return;
                }

                IVsUIShellOpenDocument openDocument = serviceProvider.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
                if (openDocument != null)
                {
                    openDocument.OpenStandardPreviewer(0, errorUrl, VSPREVIEWRESOLUTION.PR_Default, 0);
                    return;
                }
            };
            _paketErrorProvider.Tasks.Add(task);
            _paketErrorProvider.Show();
            _paketErrorProvider.BringToFront();
        }
예제 #27
0
 public WebBrowserServices(IVsWebBrowsingService wbs, IProcessServices ps, IRToolsSettings settings) {
     _wbs = wbs;
     _ps = ps;
     _settings = settings;
 }
예제 #28
0
 public WebBrowserServices(IVsWebBrowsingService wbs, IProcessServices ps, IRToolsSettings settings)
 {
     _wbs      = wbs;
     _ps       = ps;
     _settings = settings;
 }
예제 #29
0
        internal static void GotoSource(this LocationInfo location, IServiceProvider serviceProvider, GeneroLanguageVersion languageVersion)
        {
            if (location.Line > 0 && location.Column > 0)
            {
                VSGeneroPackage.NavigateTo(
                    location.FilePath,
                    Guid.Empty,
                    location.Line - 1,
                    location.Column - 1);
            }
            else if (location.DefinitionURL != null)
            {
                var urlStr = location.GetUrlString(languageVersion);

                Uri definitionUrl;
                if (Uri.TryCreate(urlStr, UriKind.Absolute, out definitionUrl))
                {
                    if (serviceProvider != null)
                    {
                        IVsWebBrowsingService service = serviceProvider.GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService;
                        if (service != null)
                        {
                            if (VSGeneroPackage.Instance.AdvancedOptions4GL.OpenExternalBrowser)
                            {
                                __VSCREATEWEBBROWSER createFlags = __VSCREATEWEBBROWSER.VSCWB_AutoShow;
                                VSPREVIEWRESOLUTION  resolution  = VSPREVIEWRESOLUTION.PR_Default;
                                int result = ErrorHandler.CallWithCOMConvention(() => service.CreateExternalWebBrowser((uint)createFlags, resolution, definitionUrl.AbsoluteUri));
                                if (ErrorHandler.Succeeded(result))
                                {
                                    return;
                                }
                            }
                            else
                            {
                                IVsWindowFrame ppFrame;
                                int            result = ErrorHandler.CallWithCOMConvention(() => service.Navigate(definitionUrl.AbsoluteUri, 0, out ppFrame));
                                if (ErrorHandler.Succeeded(result))
                                {
                                    return;
                                }
                            }
                        }
                    }

                    // Fall back to Shell Execute, but only for http or https URIs
                    if (definitionUrl.Scheme != "http" && definitionUrl.Scheme != "https")
                    {
                        return;
                    }

                    try
                    {
                        Process.Start(definitionUrl.AbsoluteUri);
                    }
                    catch (Win32Exception)
                    {
                    }
                    catch (FileNotFoundException)
                    {
                    }
                }
            }
            else
            {
                VSGeneroPackage.NavigateTo(location.FilePath, Guid.Empty, location.Index);
            }
        }
        /// <summary>
        /// Launches the specified Url either in the internal VS browser or the
        /// user's default web browser.
        /// </summary>
        /// <param name="browserService">VS's browser service for interacting with the internal browser.</param>
        /// <param name="launchUrl">Url to launch.</param>
        /// <param name="useInternalBrowser">true to use the internal browser; false to use the default browser.</param>
        private void LaunchWebBrowser(IVsWebBrowsingService browserService, string launchUrl, bool useInternalBrowser)
        {
            try
            {
                if (useInternalBrowser == true)
                {
                    // if set to use internal browser, then navigate via the browser service.
                    IVsWindowFrame ppFrame;

                    // passing 0 to the NavigateFlags allows the browser service to reuse open instances
                    // of the internal browser.
                    browserService.Navigate(launchUrl, 0, out ppFrame);
                }
                else
                {
                    // if not, launch the user's default browser by starting a new one.
                    StartInfo.FileName = launchUrl;
                    System.Diagnostics.Process.Start(StartInfo);
                }
            }
            catch
            {
                // if the process could not be started, show an error.
                MessageBox.Show("Cannot launch this url.", "Extension Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #31
0
 private static bool TryStartBrowser(IVsWebBrowsingService service, Uri uri)
 {
     return ErrorHandler.Succeeded(service.CreateExternalWebBrowser((uint)__VSCREATEWEBBROWSER.VSCWB_ForceNew, VSPREVIEWRESOLUTION.PR_Default, uri.AbsoluteUri));
 }