public void OpenUrl(Uri uri)
        {
            if (!uri.IsAbsoluteUri)
            {
                return;
            }

            /* 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.
             */
            var service = serviceProvider.GetWebBrowsingService();

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

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

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

            try
            {
                processManager.Start(uri.ToString(), string.Empty);
                return;
            }
            catch /*(Exception ex)*/
            {
                //log.Warn("Opening URL in default browser failed", ex);
            }

            try
            {
                processManager.Start(
                    Path.Combine(environment.GetProgramFilesPath(), @"Internet Explorer", "iexplore.exe"),
                    uri.ToString());
            }
            catch /*(Exception ex)*/
            {
                //log.Error("Really can't open the URL, even in IE", ex);
            }
        }
示例#2
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);
        }
 public int OpenStandardPreviewer(uint ospOpenDocPreviewer, string pszURL, VSPREVIEWRESOLUTION resolution, uint dwReserved) {
     throw new NotImplementedException();
 }
 public int OpenStandardPreviewer(uint ospOpenDocPreviewer, string pszURL, VSPREVIEWRESOLUTION resolution, uint dwReserved)
 {
     throw new Exception("The method or operation is not implemented.");
 }
 /// <summary>
 /// The create external web browser.
 /// </summary>
 /// <param name="dwCreateFlags">
 /// The dw create flags.
 /// </param>
 /// <param name="dwResolution">
 /// The dw resolution.
 /// </param>
 /// <param name="lpszURL">
 /// The lpsz url.
 /// </param>
 /// <returns>
 /// The create external web browser.
 /// </returns>
 /// <exception cref="Exception">
 /// </exception>
 public int CreateExternalWebBrowser(uint dwCreateFlags, VSPREVIEWRESOLUTION dwResolution, string lpszURL)
 {
     throw new Exception("The method or operation is not implemented.");
 }
 public int OpenStandardPreviewer(uint ospOpenDocPreviewer, string pszURL, VSPREVIEWRESOLUTION resolution, uint dwReserved)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// The open standard previewer.
 /// </summary>
 /// <param name="ospOpenDocPreviewer">
 /// The osp open doc previewer.
 /// </param>
 /// <param name="pszURL">
 /// The psz url.
 /// </param>
 /// <param name="resolution">
 /// The resolution.
 /// </param>
 /// <param name="dwReserved">
 /// The dw reserved.
 /// </param>
 /// <returns>
 /// The open standard previewer.
 /// </returns>
 /// <exception cref="Exception">
 /// </exception>
 public int OpenStandardPreviewer(uint ospOpenDocPreviewer, string pszURL, VSPREVIEWRESOLUTION resolution, uint dwReserved)
 {
     throw new Exception("The method or operation is not implemented.");
 }
示例#8
0
 /// <summary>
 /// The create external web browser.
 /// </summary>
 /// <param name="dwCreateFlags">
 /// The dw create flags.
 /// </param>
 /// <param name="dwResolution">
 /// The dw resolution.
 /// </param>
 /// <param name="lpszURL">
 /// The lpsz url.
 /// </param>
 /// <returns>
 /// The create external web browser.
 /// </returns>
 /// <exception cref="Exception">
 /// </exception>
 public int CreateExternalWebBrowser(uint dwCreateFlags, VSPREVIEWRESOLUTION dwResolution, string lpszURL)
 {
     throw new Exception("The method or operation is not implemented.");
 }
示例#9
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);
            }
        }