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(); } }
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); } }
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); }
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); } } }