An out-of-process implementation of Visual Studio's singleton OLE ServiceProvider.
Visual Studio services use this class, both through MEF SVsServiceProvider and Shell.ServiceProvider.GlobalProvider, to load COM services. I need to provide every service used in editor and theme codepaths. Most of the service methods are never actually called. This must be initialized before theme dictionaries or editor services are used
Inheritance: Microsoft.VisualStudio.OLE.Interop.IServiceProvider, SVsServiceProvider
Example #1
0
        ///<summary>Creates a new <see cref="VsThemeDictionary"/>, initializing the <see cref="VsServiceProvider"/> if it has not been initialized.</summary>
        public VsThemeDictionary()
        {
            if (ServiceProvider.GlobalProvider.GetService(typeof(SVsFrameworkMultiTargeting)) != null)
            {
                return;                 // Do nothing when hosted in VS
            }
            VsServiceProvider.Initialize();
            service = Activator.CreateInstance(WindowManagement.GetType("Microsoft.VisualStudio.Platform.WindowManagement.ColorThemeService"));

            // Add an empty dictionary for the loader to replace.
            MergedDictionaries.Add(new ResourceDictionary());
            ThemeIndex = 0;

            typeof(EnvironmentRenderCapabilities)
            .GetProperty("VisualEffectsAllowed")
            .SetValue(EnvironmentRenderCapabilities.Current, 1 | 2);

            Themes = Enumerable.Range(0, (int)service.Themes.Count)
                     .Select(i => new ColorTheme(i, service.Themes[i]))
                     .ToList()
                     .AsReadOnly();
        }
Example #2
0
		public static void Initialize() {
			// If we're in a real VS process, or if we already initialized, do nothing.
			if (Shell.ServiceProvider.GlobalProvider.GetService(typeof(SVsSettingsManager)) != null)
				return;

			// If the App() ctor didn't set a version, we're in the designer
			// The designer pre-loads our referenced assemblies, so we can't
			// use any other version.
			if (VsLoader.VsVersion == null)
				VsLoader.Load(new Version(11, 0, 0, 0));

			var esm = ExternalSettingsManager.CreateForApplication(Path.Combine(VsLoader.InstallationDirectory, "devenv.exe"));
			var sp = new VsServiceProvider
			{
				UIShell = new ThemedVsUIShell(),
				serviceInstances = {
					// Used by Shell.ServiceProvider initialization
					{ typeof(SVsActivityLog).GUID, new StubVsActivityLog() },

					// Used by ColorThemeService
					{ typeof(SVsSettingsManager).GUID, new SettingsManagerWrapper(esm) },

					// Used by Shell.VsResourceKeys
					{ new Guid("45652379-D0E3-4EA0-8B60-F2579AA29C93"), new SimpleVsWindowManager() },

					// Used by KnownUIContexts
					{ typeof(IVsMonitorSelection).GUID, new StubVsMonitorSelection() },

					// Used by ShimCodeLensPresenterStyle
					{ typeof(SUIHostLocale).GUID, new SystemUIHostLocale() },
					{ typeof(SVsFontAndColorCacheManager).GUID, new StubVsFontAndColorCacheManager() },

					// Used by Roslyn's VisualStudioWaitIndicator
					{ typeof(SVsThreadedWaitDialogFactory).GUID, new BaseWaitDialogFactory() },

					// Used by Dev14's VsImageLoader, which is needed for Roslyn IntelliSense
					{ typeof(SVsAppId).GUID, new SimpleVsAppId() },

					// Used by DocumentPeekResult; service is SVsUIThreadInvokerPrivate
					{ new Guid("72FD1033-2341-4249-8113-EF67745D84EA"), new AppDispatcherInvoker() },

					// Used by KeyBindingHelper.GetKeyBinding, which is used by VSLightBulbPresenterStyle.
					{ typeof(SDTE).GUID, new StubDTE() },

					// Used by VsTaskSchedulerService; see below
					{ typeof(SVsShell).GUID, new StubVsShell() },

				}
			};

			sp.AddService(typeof(SVsUIShell), sp.UIShell);

			Shell.ServiceProvider.CreateFromSetSite(sp);
			Instance = sp;

			// Add services that use IServiceProvider here
			sp.AddTaskSchedulerService();

			// The designer loads Microsoft.VisualStudio.Shell.XX.0,
			// which we cannot reference directly (to avoid breaking
			// older versions). Therefore, I set the global property
			// for every available version using Reflection instead.
			foreach (var vsVersion in VsLoader.FindAllVersions().Where(v => v.Major >= 10)) {
				var type = Type.GetType("Microsoft.VisualStudio.Shell.ServiceProvider, Microsoft.VisualStudio.Shell." + vsVersion.ToString(2));
				if (type == null)
					continue;
				type.GetMethod("CreateFromSetSite", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static)
					.Invoke(null, new[] { sp });
			}
		}
Example #3
0
        public static void Initialize()
        {
            // If we're in a real VS process, or if we already initialized, do nothing.
            if (Shell.ServiceProvider.GlobalProvider.GetService(typeof(SVsSettingsManager)) != null)
            {
                return;
            }

            // If the App() ctor didn't set a version, we're in the designer
            // The designer pre-loads our referenced assemblies, so we can't
            // use any other version.
            if (VsLoader.VsVersion == null)
            {
                VsLoader.Load(new Version(11, 0, 0, 0));
            }

            var esm = ExternalSettingsManager.CreateForApplication(Path.Combine(VsLoader.InstallationDirectory, "devenv.exe"));
            var sp  = new VsServiceProvider
            {
                UIShell          = new ThemedVsUIShell(),
                serviceInstances =
                {
                    // Used by Shell.ServiceProvider initialization
                    { typeof(SVsActivityLog).GUID,                      new StubVsActivityLog()              },

                    // Used by ColorThemeService
                    { typeof(SVsSettingsManager).GUID,                  new SettingsManagerWrapper(esm)      },

                    // Used by Shell.VsResourceKeys
                    { new Guid("45652379-D0E3-4EA0-8B60-F2579AA29C93"), new SimpleVsWindowManager()          },

                    // Used by KnownUIContexts
                    { typeof(IVsMonitorSelection).GUID,                 new StubVsMonitorSelection()         },

                    // Used by ShimCodeLensPresenterStyle
                    { typeof(SUIHostLocale).GUID,                       new SystemUIHostLocale()             },
                    { typeof(SVsFontAndColorCacheManager).GUID,         new StubVsFontAndColorCacheManager() },

                    // Used by Roslyn's VisualStudioWaitIndicator
                    { typeof(SVsThreadedWaitDialogFactory).GUID,        new BaseWaitDialogFactory()          },

                    // Used by Dev14's VsImageLoader, which is needed for Roslyn IntelliSense
                    { typeof(SVsAppId).GUID,                            new SimpleVsAppId()                  },

                    // Used by DocumentPeekResult; service is SVsUIThreadInvokerPrivate
                    { new Guid("72FD1033-2341-4249-8113-EF67745D84EA"), new AppDispatcherInvoker()           },

                    // Used by KeyBindingHelper.GetKeyBinding, which is used by VSLightBulbPresenterStyle.
                    { typeof(SDTE).GUID,                                new StubDTE()                        },

                    // Used by VsTaskSchedulerService; see below
                    { typeof(SVsShell).GUID,                            new StubVsShell()                    },
                }
            };

            sp.AddService(typeof(SVsUIShell), sp.UIShell);

            Shell.ServiceProvider.CreateFromSetSite(sp);
            Instance = sp;

            // Add services that use IServiceProvider here
            sp.AddTaskSchedulerService();

            // The designer loads Microsoft.VisualStudio.Shell.XX.0,
            // which we cannot reference directly (to avoid breaking
            // older versions). Therefore, I set the global property
            // for every available version using Reflection instead.
            foreach (var vsVersion in VsLoader.FindAllVersions().Where(v => v.Major >= 10))
            {
                var type = Type.GetType("Microsoft.VisualStudio.Shell.ServiceProvider, Microsoft.VisualStudio.Shell." + vsVersion.ToString(2));
                if (type == null)
                {
                    continue;
                }
                type.GetMethod("CreateFromSetSite", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static)
                .Invoke(null, new[] { sp });
            }
        }