Ejemplo n.º 1
0
        private void LoadPackage()
        {
            IRecipeManagerService recipeManager = (IRecipeManagerService)
                                                  GetService(typeof(IRecipeManagerService));

            if (template.Kind == TemplateKind.Solution)
            {
                Package = recipeManager.GetPackage(template.PackageName);
                if (Package == null)
                {
                    Package   = recipeManager.EnablePackage(template.PackageName);
                    didEnable = true;
                }
            }
            else
            {
                Package = recipeManager.GetPackage(template.PackageName);
            }
            if (Package == null)
            {
                string messageText = messageText = String.Format(
                    CultureInfo.CurrentCulture,
                    Properties.Resources.Templates_PackageNotActive,
                    template.PackageName);
                ErrorHelper.Show((IServiceProvider)recipeManager, messageText);
                throw new WizardCancelledException();
            }
        }
Ejemplo n.º 2
0
        protected override void Initialize()
        {
            base.Initialize();
            try
            {
                Environment.SetEnvironmentVariable("RecipeFrameworkPath", Path.GetDirectoryName(this.GetType().Assembly.Location));
                LoadTraceLevelSetting();

                AdviseSolutionEvents();
                AdviseTrackProjectDocumentsEvents();

                IVsRegisterNewDialogFilters filterService =
                    (IVsRegisterNewDialogFilters)GetService(typeof(SVsRegisterNewDialogFilters));
                filterService.RegisterAddNewItemDialogFilter(
                    (IVsFilterAddProjectItemDlg)GetService(typeof(IVsFilterAddProjectItemDlg)), out itemsFilterCookie);
                filterService.RegisterNewProjectDialogFilter(
                    (IVsFilterNewProjectDlg)GetService(typeof(IVsFilterAddProjectItemDlg)), out projectsFilterCookie);

                AddOptionKey(GaxUserDataPersistenceKey);

                ServiceHelper.CheckDependencies(this, (System.IServiceProvider) this);

                guidanceNavigatorManager = new GuidanceNavigatorManager(this as System.IServiceProvider);

                IRecipeManagerService rms = (IRecipeManagerService)GetService(typeof(IRecipeManagerService));
                rms.EnablingPackage += OnEnablingPackage;
                rms.EnabledPackage  += OnEnabledPackage;
            }
            catch (Exception e)
            {
                ErrorHelper.Show((IUIService)GetService(typeof(IUIService)), e);
                throw;
            }
        }
Ejemplo n.º 3
0
 private void RestoreTemplateState()
 {
     // Let's restore the stack, we are
     if (UnfoldingTemplates.Count > 0 && UnfoldingTemplates.Peek() == this)
     {
         UnfoldingTemplates.Pop();
     }
     foreach (ProjectItem prItem in openedItems)
     {
         if (prItem.Document != null)
         {
             prItem.Document.Close(vsSaveChanges.vsSaveChangesNo);
         }
     }
     openedItems.Clear();
     if (didEnable)
     {
         IRecipeManagerService recipeManager = (IRecipeManagerService)
                                               GetService(typeof(IRecipeManagerService));
         if (recipeManager != null)
         {
             recipeManager.DisablePackage(Package);
         }
     }
 }
Ejemplo n.º 4
0
		protected override void OnSited()
		{
			base.OnSited();
			IConfigurationService configService = GetService<IConfigurationService>(true);
			this.recipeConfig =
				(Configuration.Recipe)configService.CurrentPackage[recipeReference.AssetName];
			managerService = GetService<IRecipeManagerService>(true);
		}
Ejemplo n.º 5
0
        //private void ResetStateIfNewInstance(IServiceProvider service)
        //{
        //    // get the current instance of the GatheringServiceData object
        //    // to compare if this is a new instance or not
        //    // so we know when to reset the state.
        //    if (storedInstance == null)
        //    {
        //        // reset the stored values
        //        storedPath = string.Empty;
        //        storedPathStatus = false;
        //        IConfigurationService configService = (IConfigurationService)service.GetService(typeof(IConfigurationService));
        //        storedInstance = configService.CurrentGatheringServiceData;
        //        // note that the instance in storedInstance will be
        //        // disposed upon the recipe ends.
        //    }
        //}

        private void ResetStateIfNewInstance(IServiceProvider service)
        {
            if (!afterRecipeExecutionEventAdded)
            {
                IRecipeManagerService manager = (IRecipeManagerService)service.GetService(typeof(IRecipeManagerService));
                // TODO: add an event or other method to reset the values in case the recipe were cancelled.
                manager.AfterRecipeExecution  += new RecipeEventHandler(OnAfterRecipeExecution);
                afterRecipeExecutionEventAdded = true;
            }
        }
Ejemplo n.º 6
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.º 7
0
        /// <summary>
        /// Executes this instance.
        /// </summary>
        public override void Execute()
        {
            IRecipeManagerService manager = GetService <IRecipeManagerService>();

            try
            {
                manager.EnablePackage(this.packageName);
            }
            catch
            {
                //Do nothing if the package is not loaded
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Performs the validation of all references
 /// and for the ones that are dangling
 /// It will create a dialog in order to get the new valid
 /// targets
 /// </summary>
 public void PerformValidation()
 {
     manager = (IRecipeManagerService)
               ServiceHelper.GetService(this, typeof(IRecipeManagerService));
     vs = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));
     referencesToFix = new ArrayList();
     try
     {
         CheckReferences();
         PerformRestore();
     }
     catch (Exception ex)
     {
         ErrorHelper.Show(this.Site, ex, Properties.Resources.ReferenceRestoreService_Error);
     }
 }
Ejemplo n.º 9
0
        internal GuidanceNavigatorManager(IServiceProvider serviceProvider)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            this.serviceProvider = serviceProvider;
            executedRecipesLog   = new Dictionary <String, List <RecipeExecutionHistory> >();
            rms = (IRecipeManagerService)serviceProvider.GetService(typeof(IRecipeManagerService));
            rms.EnabledPackage       += new PackageEventHandler(OnEnabledDisabledPackage);
            rms.EnablingPackage      += new CancelPackageEventHandler(rms_EnablingPackage);
            rms.DisabledPackage      += new PackageEventHandler(OnEnabledDisabledPackage);
            rms.AfterRecipeExecution += new RecipeEventHandler(OnAfterRecipeExecution);
            enabledGuidancePackages   = new GuidancePackage[] { };
        }
Ejemplo n.º 10
0
            public override void Execute()
            {
                if (OldReference == null)
                {
                    return;
                }
                IRecipeManagerService manager = (IRecipeManagerService)
                                                ServiceHelper.GetService(this, typeof(IRecipeManagerService));
                // Add the references to the target package.
                GuidancePackage        package          = manager.GetPackage(targetPackage);
                IAssetReferenceService referenceService = (IAssetReferenceService)
                                                          ServiceHelper.GetService(package, typeof(IAssetReferenceService), this);
                IPersistenceService persist = (IPersistenceService)
                                              ServiceHelper.GetService(this, typeof(IPersistenceService));

                try
                {
                    IDictionary state = persist.LoadState(package.Configuration.Name, OldReference);
                    if ((target != null) && !(target is DummyDTE.EmptyDteElement))
                    {
                        //We have to get the real object Project for case of Solution Folder
                        object realTarget = target;
                        if (target is SolutionFolder)
                        {
                            realTarget = ((SolutionFolder)target).Parent;
                        }

                        if (OldReference is VsBoundReference)
                        {
                            ((VsBoundReference)OldReference).SetTarget(realTarget);
                        }
                        else if (OldReference is BoundTemplateReference)
                        {
                            ((BoundTemplateReference)OldReference).BoundReference.SetTarget(realTarget);
                        }
                        referenceService.Add(OldReference, state);
                    }
                }
                catch (Exception ex)
                {
                    if (OldReference != null)
                    {
                        referenceService.Remove(OldReference);
                    }
                    ErrorHelper.Show(this.Site, ex);
                }
            }
Ejemplo n.º 11
0
        private void LoadRecipeManager(object automationObject)
        {
            IRecipeManagerService recipeManager = null;

            try
            {
                recipeManager = (IRecipeManagerService)ServiceHelper.GetService(
                    new VsServiceProvider(automationObject),
                    typeof(IRecipeManagerService), this);
                recipeManager.Add(this);
            }
            catch (Exception e)
            {
                ErrorHelper.Show((IUIService)GetService(typeof(IUIService)), e, Properties.Resources.Templates_CannotLoadRecipeManager);
                throw new WizardCancelledException();
            }
        }
Ejemplo n.º 12
0
        int IVsSolutionLoadEvents.OnAfterBackgroundSolutionLoadComplete()
        {
            if (guidanceNavigatorManager == null)
            {
                guidanceNavigatorManager = new GuidanceNavigatorManager(this as System.IServiceProvider);
            }

            IRecipeManagerService rms = (IRecipeManagerService)GetService(typeof(IRecipeManagerService));

            rms.EnabledPackage += new PackageEventHandler(OnEnabledPackage);

            IVsSolutionLoadEvents hostService =
                (IVsSolutionLoadEvents)GetService(typeof(IHostService));
            int result = hostService.OnAfterBackgroundSolutionLoadComplete();

            isOpeningSolution = false;
            return(result);
        }
Ejemplo n.º 13
0
        protected override object GetService(Type serviceType)
        {
            object serviceInstance = base.GetService(serviceType);

            if (serviceInstance == null)
            {
                if (serviceType != typeof(IRecipeManagerService))
                {
                    IRecipeManagerService recipeManager = (IRecipeManagerService)GetService(typeof(IRecipeManagerService));
                    if (recipeManager != null)
                    {
                        IServiceProvider Package = (IServiceProvider)recipeManager.GetPackage(this.PackageName);
                        if (Package != null)
                        {
                            serviceInstance = Package.GetService(serviceType);
                        }
                    }
                }
            }
            return(serviceInstance);
        }
Ejemplo n.º 14
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]);
        }
Ejemplo n.º 15
0
        int IVsSolutionEvents.OnAfterOpenSolution(object pUnkReserved, int fNewSolution)
        {
            if (fNewSolution == 0)
            {
                isOpeningSolution = true;
            }

            if (guidanceNavigatorManager == null)
            {
                guidanceNavigatorManager = new GuidanceNavigatorManager(this as System.IServiceProvider);
            }

            IRecipeManagerService rms = (IRecipeManagerService)GetService(typeof(IRecipeManagerService));

            rms.EnabledPackage += new PackageEventHandler(OnEnabledPackage);

            IVsSolutionEvents hostService =
                (IVsSolutionEvents)GetService(typeof(IHostService));
            int result = hostService.OnAfterOpenSolution(pUnkReserved, fNewSolution);

            isOpeningSolution = false;
            return(result);
        }
Ejemplo n.º 16
0
        int IVsSolutionEvents.OnAfterCloseSolution(object pUnkReserved)
        {
            IRecipeManagerService rms = (IRecipeManagerService)GetService(typeof(IRecipeManagerService));

            rms.EnabledPackage -= new PackageEventHandler(OnEnabledPackage);
            //rms.EnablingPackage -= new PackageEventHandler(rms_EnabledPackage);

            guidanceNavigatorManager.Reset();

            if (IsGuidanceNavigatorToolWindowVisible())
            {
                SetGNavAutoClosedKeyValue(true);
                HideGuidanceNavigatorWindow();
            }
            else
            {
                SetGNavAutoClosedKeyValue(false);
            }

            IVsSolutionEvents hostService =
                (IVsSolutionEvents)GetService(typeof(IHostService));

            return(hostService.OnAfterCloseSolution(pUnkReserved));
        }
        private void AddProjectTemplate(Project project)
        {
            try
            {
                IRecipeManagerService provider = (IRecipeManagerService)this.GetService(typeof(IRecipeManagerService));

                GuidancePackage p  = provider.GetPackage("SharePointSoftwareFactory.Base");
                GuidancePackage p2 = provider.EnablePackage("SharePointSoftwareFactory.Base");
            }
            catch (Exception)
            {
            }

            DTE            service = (DTE)this.GetService(typeof(DTE));
            SolutionFolder folder  = null;

            if (project == null)
            {
                if (string.IsNullOrEmpty(this.Path))
                {
                    //char[] invalidedChars = System.IO.Path.GetInvalidPathChars();
                    //foreach (char c in invalidedChars)
                    //{
                    //    if (this.Template.IndexOf(c) > 0)
                    //    {
                    //    }
                    //    if (this.DestinationFolder.IndexOf(c) > 0)
                    //    {
                    //    }
                    //}
                    this.NewItem = service.Solution.AddFromTemplate(this.Template, this.DestinationFolder, this.ItemName, false);
                }
                else
                {
                    folder       = (SolutionFolder)DteHelper.FindProjectByPath(service.Solution, this.Path).Object;
                    this.NewItem = folder.AddFromTemplate(this.Template, this.DestinationFolder, this.ItemName);
                }
            }
            else
            {
                //sometimes in the solutionfolder a project already exists but is not part of the project
                //so we delete the folder if it already exists
                if (Directory.Exists(this.DestinationFolder))
                {
                    if (MessageBox.Show("Directory '" + this.DestinationFolder + "' already exists in the solution. Delete directory? If you choose 'No' the directory will be renamed to '" + this.DestinationFolder + "_Backup'", "Warning", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        Directory.Delete(this.DestinationFolder, true);
                    }
                    else
                    {
                        string backupDirectoryName = this.DestinationFolder + "_Backup";
                        int    count = 1;
                        while (Directory.Exists(backupDirectoryName))
                        {
                            backupDirectoryName = this.DestinationFolder + "_Backup" + count.ToString();
                            count++;
                        }
                        Directory.Move(this.DestinationFolder, backupDirectoryName);
                    }
                }

                folder       = (SolutionFolder)project.Object;
                this.NewItem = folder.AddFromTemplate(this.Template, this.DestinationFolder, this.ItemName);
            }
            if (this.newItem == null)
            {
                ProjectItems projectItems;
                if (folder != null)
                {
                    projectItems = folder.Parent.ProjectItems;
                }
                else
                {
                    projectItems = service.Solution.Projects as ProjectItems;
                }
                if (projectItems != null)
                {
                    foreach (ProjectItem item in projectItems)
                    {
                        if (item.Name.Contains(this.ItemName))
                        {
                            this.NewItem = item.Object as Project;
                            break;
                        }
                    }
                }
                else
                {
                    this.NewItem = FindProjectByName(service, this.ItemName, false);
                }
            }
        }