예제 #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();
            }
        }
예제 #2
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
            }
        }
        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);
                }
            }
        }