Ejemplo n.º 1
0
        protected override void OnSited()
        {
            base.OnSited();
            IRecipeManagerService recipeManager =
                (IRecipeManagerService)GetService(typeof(IRecipeManagerService));

            foreach (Configuration.Manifest.GuidancePackage package in recipeManager.GetInstalledPackages("VisualStudio"))
            {
                Guid   packageGuid           = new Guid(package.Guid);
                string newProjectTemplateKey = string.Format(CultureInfo.InvariantCulture,
                                                             RegistryPath,
                                                             packageGuid.ToString("B"));

                RecipeManagerPackage gaxPackage = (RecipeManagerPackage)GetService(typeof(RecipeManagerPackage));
                if (package != null)
                {
                    using (RegistryKey key = gaxPackage.ApplicationRegistryRoot.OpenSubKey(newProjectTemplateKey))
                    {
                        if (key != null)
                        {
                            foreach (var subKeyName in key.GetSubKeyNames())
                            {
                                using (RegistryKey subKey = key.OpenSubKey(subKeyName))
                                {
#if DEBUG
                                    Debug.WriteLine(string.Format("Retrieving projects templates information from {0}", gaxPackage.ApplicationRegistryRoot.ToString()));
                                    Debug.WriteLine(string.Format("User Registry root is {0}", gaxPackage.UserRegistryRoot.ToString()));
#endif
                                    string templateDir = (string)subKey.GetValue("TemplatesDir");
                                    if (!templatesInFolder.ContainsKey(templateDir))
                                    {
                                        templatesInFolder.Add(templateDir, packageGuid);
                                    }
                                    else
                                    {
                                        this.TraceWarning(
                                            String.Format(
                                                CultureInfo.CurrentCulture,
                                                Properties.Resources.Template_MultipleTemplateDirs,
                                                templateDir));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            var dte = (EnvDTE.DTE) this.GetService(typeof(EnvDTE.DTE));

            this.newProjectCommandEvents = dte.Events.get_CommandEvents(typeof(VSConstants.VSStd97CmdID).GUID.ToString("B"), (int)VSConstants.VSStd97CmdID.NewProject);
            this.newProjectCommandEvents.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(newProjectCommandEvents_BeforeExecute);
            this.newProjectCommandEvents.AfterExecute  += new _dispCommandEvents_AfterExecuteEventHandler(newProjectCommandEvents_AfterExecute);
        }
Ejemplo n.º 2
0
        private Hashtable GetItemsTemplates(Guid projectFactory)
        {
            if (!itemTemplatesInFolder.ContainsKey(projectFactory))
            {
                Hashtable             templatesInProject = new Hashtable(7);
                IRecipeManagerService recipeManager      =
                    (IRecipeManagerService)GetService(typeof(IRecipeManagerService));
                foreach (Configuration.Manifest.GuidancePackage package in recipeManager.GetInstalledPackages("VisualStudio"))
                {
                    Guid   packageGuid     = new Guid(package.Guid);
                    string itemTemplateKey = string.Format(CultureInfo.InvariantCulture,
                                                           ItemTemplatesRegistryPath,
                                                           projectFactory.ToString("B"),
                                                           packageGuid.ToString("B"));
                    DefaultRegistryRootAttribute registryRoot =
                        (DefaultRegistryRootAttribute)Attribute.GetCustomAttribute(
                            typeof(RecipeManagerPackage),
                            typeof(DefaultRegistryRootAttribute));

                    RecipeManagerPackage gaxPackage = (RecipeManagerPackage)GetService(typeof(RecipeManagerPackage));
                    if (gaxPackage != null)
                    {
#if DEBUG
                        Debug.WriteLine(string.Format("Retrieving item templates information from {0}", gaxPackage.ApplicationRegistryRoot.ToString()));
#endif
                        using (RegistryKey key = gaxPackage.ApplicationRegistryRoot.OpenSubKey(itemTemplateKey))
                        {
                            if (key != null)
                            {
                                string templateDir = (string)key.GetValue("TemplatesDir");
                                templatesInProject.Add(templateDir, packageGuid);
                            }
                        }
                    }
                }
                itemTemplatesInFolder.Add(projectFactory, templatesInProject);
            }
            return((Hashtable)itemTemplatesInFolder[projectFactory]);
        }