Esempio n. 1
0
        public override void Initialize()
        {
            _serviceprovider_sys = this.Site;
            IVsFontAndColorCacheManager mgr = this.GetService(typeof(SVsFontAndColorCacheManager)) as IVsFontAndColorCacheManager;

            mgr.ClearAllCaches();
        }
Esempio n. 2
0
        private void ValidateFontAndColorCacheManagerIsUpToDate()
        {
            IVsFontAndColorCacheManager cacheManager =
                (IVsFontAndColorCacheManager)GetService(typeof(SVsFontAndColorCacheManager));

            if (cacheManager == null)
            {
                return;
            }

            bool alreadyInitialized = false;

            try
            {
                const string registryValueName = "InstalledVersion";
                string       expectedVersion   = Assembly.GetExecutingAssembly().GetName().Version.ToString();

                using (RegistryKey rootKey = UserRegistryRoot)
                    using (RegistryKey ourKey = rootKey.CreateSubKey("NShader"))
                    {
                        if (ourKey != null)
                        {
                            object registryValue      = ourKey.GetValue(registryValueName);
                            string initializedVersion = Convert.ToString(registryValue, CultureInfo.InvariantCulture);
                            alreadyInitialized = (initializedVersion == expectedVersion);
                            ourKey.SetValue(registryValueName, expectedVersion, RegistryValueKind.String);
                        }
                    }
            }
            // ReSharper disable EmptyGeneralCatchClause
            catch
            // ReSharper restore EmptyGeneralCatchClause
            {
                // Ignore any errors since it's not a big deal if we can't read
                // this setting. We just always refresh the cache in that case.
            }

            // Actually refresh the Fonts and Colors cache now if we detected we have
            // to do so.
            if (alreadyInitialized)
            {
                return;
            }

            ErrorHandler.ThrowOnFailure(cacheManager.ClearAllCaches());
            Guid categoryGuid = Guid.Empty;

            ErrorHandler.ThrowOnFailure(cacheManager.RefreshCache(ref categoryGuid));
            categoryGuid = new Guid("a27b4e24-a735-4d1d-b8e7-9716e1e3d8e0");
            ErrorHandler.ThrowOnFailure(cacheManager.RefreshCache(ref categoryGuid));
        }
Esempio n. 3
0
        private void ValidateFontAndColorCacheManagerIsUpToDate()
        {
            // The Fonts and Colors cache has to be refreshed after each marker change
            // (during development) and of course after install/uninstall.

            // To identify when we have to refresh the cache we store a custom value
            // in the Visual Studio registry hive. Downsides of this approach:
            //
            //     1. The cache is not refreshed until the package is loaded for the
            //        first time. That means that our text markers don't show up in
            //        the Fonts and Colors settings after install. They will only
            //        show up after the first solution has been opened.
            //
            //     2. Since this code is part of the package we can't execute it
            //        after uninstall. That means that the user will see our markers
            //        in the Fonts and Colors settings dialog even after he has
            //        uninstalled the package. That is very ugly!

            IVsFontAndColorCacheManager cacheManager = (IVsFontAndColorCacheManager)GetService(typeof(SVsFontAndColorCacheManager));

            if (cacheManager == null)
            {
                return;
            }

            // We need to know whether we already refreshed the fonts and colors
            // cache to reflect the text markers we registered. We have to do this
            // on a per-user basis.
            bool alreadyInitialized = false;

            try
            {
                string registryValueName = "InstalledVersion";
                string expectedVersion   = Assembly.GetExecutingAssembly().GetName().Version.ToString();

                using (RegistryKey rootKey = UserRegistryRoot)
                    using (RegistryKey ourKey = rootKey.CreateSubKey(ProductName))
                    {
                        object registryValue      = ourKey.GetValue(registryValueName);
                        string initializedVersion = Convert.ToString(registryValue, CultureInfo.InvariantCulture);

                        alreadyInitialized = (initializedVersion == expectedVersion);

                        ourKey.SetValue(registryValueName, expectedVersion, RegistryValueKind.String);
                    }
            }
            catch
            {
                // Ignore any errors since it's not a big deal if we can't read
                // this setting. We just always refresh the cache in that case.
            }

            // Actually refresh the Fonts and Colors cache now if we detected we have
            // to do so.
            if (!alreadyInitialized)
            {
                ErrorHandler.ThrowOnFailure(cacheManager.ClearAllCaches());

                Guid categoryGuid = Guid.Empty;
                ErrorHandler.ThrowOnFailure(cacheManager.RefreshCache(ref categoryGuid));
                categoryGuid = Guids.GuidFontsAndColorsTextEditor;
                ErrorHandler.ThrowOnFailure(cacheManager.RefreshCache(ref categoryGuid));
            }
        }