Exemplo n.º 1
0
 internal static void OpenWebBrowser(System.IServiceProvider serviceProvider, string url)
 {
     // TODO: In a future VS 2017 release, SVsWebBrowsingService will have the ability
     // to open in an external browser, and we may want to switch to using that, as it
     // may be safer/better than Process.Start.
     serviceProvider.GetUIThread().Invoke(() =>
     {
         try
         {
             var uri = new Uri(url);
             Process.Start(new ProcessStartInfo(uri.AbsoluteUri));
         }
         catch (Exception ex) when(!ex.IsCriticalException())
         {
             Utilities.ShowMessageBox(
                 serviceProvider,
                 SR.GetString(SR.WebBrowseNavigateError, url, ex.Message),
                 null,
                 OLEMSGICON.OLEMSGICON_CRITICAL,
                 OLEMSGBUTTON.OLEMSGBUTTON_OK,
                 OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST
                 );
         }
     });
 }
Exemplo n.º 2
0
        internal static void OpenVsWebBrowser(System.IServiceProvider serviceProvider, string url)
        {
            serviceProvider.GetUIThread().Invoke(() =>
            {
                var web = serviceProvider.GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService;
                if (web == null)
                {
                    OpenWebBrowser(serviceProvider, url);
                    return;
                }

                try
                {
                    IVsWindowFrame frame;
                    ErrorHandler.ThrowOnFailure(web.Navigate(url, (uint)__VSWBNAVIGATEFLAGS.VSNWB_ForceNew, out frame));
                    frame.Show();
                }
                catch (Exception ex) when(!ex.IsCriticalException())
                {
                    Utilities.ShowMessageBox(
                        serviceProvider,
                        SR.GetString(SR.WebBrowseNavigateError, url, ex.Message),
                        null,
                        OLEMSGICON.OLEMSGICON_CRITICAL,
                        OLEMSGBUTTON.OLEMSGBUTTON_OK,
                        OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST
                        );
                }
            });
        }
Exemplo n.º 3
0
        /// <summary>
        /// Use this instead of VsShellUtilities.ShowMessageBox because VSU uses ThreadHelper which
        /// uses a private interface that can't be mocked AND goes to the global service provider.
        /// </summary>
        public static int ShowMessageBox(IServiceProvider serviceProvider, string message, string title, OLEMSGICON icon, OLEMSGBUTTON msgButton, OLEMSGDEFBUTTON defaultButton)
        {
            IVsUIShell uiShell = serviceProvider.GetService(typeof(IVsUIShell)) as IVsUIShell;

            Debug.Assert(uiShell != null, "Could not get the IVsUIShell object from the services exposed by this serviceprovider");
            if (uiShell == null)
            {
                throw new InvalidOperationException();
            }

            Guid emptyGuid = Guid.Empty;
            int  result    = 0;

            serviceProvider.GetUIThread().Invoke(() =>
            {
                ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
                                                0,
                                                ref emptyGuid,
                                                title,
                                                message,
                                                null,
                                                0,
                                                msgButton,
                                                defaultButton,
                                                icon,
                                                0,
                                                out result));
            });
            return(result);
        }