internal Recipe GetRecipeConfiguration(GuidancePackage guidancePackage, string recipeName) { foreach (Recipe recipe in guidancePackage.Configuration.Recipes) { if (recipe.Name == recipeName) { return(recipe); } } return(null); }
internal List <RecipeExecutionHistory> GetExecutedRecipes(GuidancePackage guidancePackage) { string packageName = guidancePackage.Configuration.Name; if (executedRecipesLog.ContainsKey(packageName)) { return(executedRecipesLog[guidancePackage.Configuration.Name]); } else { return(new List <RecipeExecutionHistory> ()); } }
public void SetUp() { manager = new RecipeManager(); var extensionManager = new MockServices.MockExtensionManager(); extensionManager.AddGuidancePackage(Utils.MakeTestRelativePath(@"Services\AssetReferenceServiceTests.xml")); manager.AddService(typeof(IPersistenceService), new MockServices.MockPersistenceService()); manager.AddService(typeof(SVsExtensionManager), extensionManager); package = new GuidancePackage(Utils.MakeTestRelativePath(@"Services\AssetReferenceServiceTests.xml")); manager.EnablePackage(package); }
void guidanceNavigatorManager_RecipeExecuted(object sender, RecipeEventArgs e) { GuidancePackage package = (GuidancePackage)sender; if (package != selectedGuidancePackage) { SelectPackage(package); } GuidanceNavigatorManager.RecipeExecutionHistory[] history = guidanceNavigatorManager.GetExecutedRecipes(package).ToArray(); GuidanceNavigatorManager.RecipeExecutionHistory historyItem = history.GetValue(history.Length - 1) as GuidanceNavigatorManager.RecipeExecutionHistory; AddHistoryRecipeEntry(historyItem); ShowHistoryRecipes(); }
public AssetMenuCommand(GuidancePackage guidancePackage, Microsoft.Practices.ComponentModel.ServiceContainer serviceProvider, CommandID commandId) : base(null, commandId) { if (serviceProvider == null || guidancePackage == null || commandId == null) { throw new ArgumentNullException("RecipeMenuCommand"); } this.serviceProvider = serviceProvider; this.guidancePackage = guidancePackage; this.Supported = true; this.Visible = true; this.Enabled = true; this.BeforeQueryStatus += new EventHandler(OnBeforeQueryStatus); }
public void LoadNoValidateOrInclusions() { XIncludingReader ir = new XIncludingReader(new XmlTextReader(BaseDir + "smallconfig.xml")); XmlReaderSettings validateReaderSettings = new XmlReaderSettings(); // Add the schema to validate against. validateReaderSettings.ValidationType = ValidationType.Schema; validateReaderSettings.Schemas.Add("http://schemas.microsoft.com/pag/gax-core", "GuidancePackageConfig.xsd"); XmlReader vr = XmlReader.Create(ir, validateReaderSettings); // Deserialize with validating reader. XmlSerializer ser = new GuidancePackageSerializer(); GuidancePackage package = (GuidancePackage)ser.Deserialize(vr); // Done! }
internal void RemoveLogRecipeExecution(GuidancePackage guidancePackage, RecipeExecutionHistory recipeExecutionHistory) { string packageName = guidancePackage.Configuration.Name; if (!executedRecipesLog.ContainsKey(packageName)) { return; } List <RecipeExecutionHistory> log = executedRecipesLog[packageName]; if (log.Contains(recipeExecutionHistory)) { log.Remove(recipeExecutionHistory); } }
void OnAfterRecipeExecution(object sender, RecipeEventArgs e) { GuidancePackage package = (GuidancePackage)sender; // we don't want the toolwindow to get notificatins of recipes // that executed because of the unfolding of a template if (e.ExecutedFromTemplate) { return; } LogRecipeExecution(package.Configuration.Name, e.Recipe.Name); if (RecipeExecuted != null) { RecipeExecuted(sender, e); } }
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); } }
private void OnExecuteRecipe(object sender, System.EventArgs e) { GuidancePackage Package = null; try { if (lstRecipes.SelectedItems.Count == 0) { MessageBox.Show(this, Configuration.Resources.PackageManager_MustSelectRecipe, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } IHostService host = (IHostService)ServiceHelper.GetService(this, typeof(IHostService)); IAssetReference reference = ((ReferenceInfo)lstRecipes.SelectedItems[0].Tag).Reference; bool execute = false; if (reference is IBoundAssetReference) { execute = host.SelectTarget(((IBoundAssetReference)reference).Target); } else if (reference is IUnboundAssetReference) { execute = host.SelectTarget(this, (IUnboundAssetReference)reference); } if (execute) { Package = (GuidancePackage)ServiceHelper.GetService(reference, typeof(IExecutionService)); Package.TurnOnOutput(); reference.Execute(); LoadReferences(); } } catch (Exception ex) { ErrorHelper.Show((IUIService)GetService(typeof(IUIService)), ex); } finally { if (Package != null) { Package.TurnOffOutput(); } } }
/// <summary> /// Selects the package. /// </summary> /// <param name="guidancePackage">The guidance package.</param> private void SelectPackage(GuidancePackage guidancePackage) { int index = 0; foreach (object item in this.cbGuidancePackages.Items) { GuidancePackageEntry entry = item as GuidancePackageEntry; if (entry != null) { if (entry.GuidancePackage == guidancePackage) { cbGuidancePackages.SelectedIndex = index; break; } } index++; } selectedGuidancePackage = guidancePackage; }
public FixupReference(GuidancePackage owningPackage, string asset, IBoundAssetReference oldReference) { this.OwningPackage = owningPackage; this.ReferencedAsset = asset; VsBoundReference realReference = null; if (oldReference is VsBoundReference) { realReference = (VsBoundReference)oldReference; } else if (oldReference is BoundTemplateReference) { realReference = (VsBoundReference)((BoundTemplateReference)oldReference).BoundReference; } this.SavedTarget = realReference.SubPath; this.ExpectedTargetKind = GetTargetKind(realReference); this.OldReference = oldReference; }
//[Ignore("Validation with inclusions fails as per bug #")] public void FullLoadAndValidation() { XIncludingReader ir = new XIncludingReader(BaseDir + "mainconfig.xml"); XmlReaderSettings validateReaderSettings = new XmlReaderSettings(); validateReaderSettings.ValidationType = ValidationType.Schema; validateReaderSettings.Schemas.Add(XmlSchema.Read( new XmlTextReader("GuidancePackageConfig.xsd"), null)); // Dump for debugging purposes. XmlReader vr = XmlReader.Create(ir, validateReaderSettings); XmlWriter tw = XmlWriter.Create(Console.Out); tw.WriteNode(ir, false); // Read into memory with full inclusions as workaround ir = new XIncludingReader(BaseDir + "mainconfig.xml"); MemoryStream mem = new MemoryStream(); vr = XmlReader.Create(ir, validateReaderSettings); tw = XmlWriter.Create(mem); tw.WriteNode(ir, false); tw.Flush(); mem.Position = 0; vr = XmlReader.Create(mem, validateReaderSettings); XmlSerializer ser = new GuidancePackageSerializer(); // Deserialize with validating reader GuidancePackage package = (GuidancePackage)ser.Deserialize(vr); // Check included recipe Assert.AreEqual("ReusableRecipe", package.Recipes[0].Name); // Check included types in included recipe Assert.AreEqual("Page", package.Recipes[0].Types[1].Name); XmlSerializer wzser = new XmlSerializer(typeof(Wizard)); Wizard wz = (Wizard)wzser.Deserialize(new XmlNodeReader(package.Recipes[0].GatheringServiceData.Any)); Assert.AreEqual("ExistingWizard", wz.Name); }
int IVsTaskItem.NavigateTo() { GuidancePackage package = null; try { package = (GuidancePackage)ServiceHelper.GetService(this.recipeReference, typeof(IExecutionService)); package.TurnOnOutput(); // Execute the recipe through the reference. this.recipeReference.Execute(); } catch (Exception e) { ErrorHelper.Show(this.Site, e); } finally { if (package != null) { package.TurnOffOutput(); } } return VSConstants.S_OK; }
/// <summary> /// refresh the DropDownList showing currently enabled packages /// </summary> private void UpdateAvailablePackages() { cbGuidancePackages.Items.Clear(); foreach (GuidancePackage guidancePackage in guidanceNavigatorManager.EnabledGuidancePackages) { cbGuidancePackages.Items.Add(new GuidancePackageEntry(guidancePackage)); } if (cbGuidancePackages.Items.Count > 0) { cbGuidancePackages.SelectedIndex = 0; selectedGuidancePackage = ((GuidancePackageEntry)cbGuidancePackages.Items[0]).GuidancePackage; } else if (cbGuidancePackages.Items.Count == 0) { selectedGuidancePackage = null; } // the list should always include an ending "Guidance Package Manager..." item // which should fire up the Guidance Package Manager dialog box cbGuidancePackages.Items.Add(Properties.Resources.GuidanceNavigatorWindow_GuidancePackageManagerOptionText); }
/// <summary> /// Updates the package information. /// </summary> private void UpdatePackagesInformation() { UpdateAvailablePackages(); UpdateRecipesHistory(); if (this.cbGuidancePackages.Items.Count > 1) { if ((GuidancePackageEntry)cbGuidancePackages.SelectedItem != null) { selectedGuidancePackage = ((GuidancePackageEntry)cbGuidancePackages.SelectedItem).GuidancePackage; } UpdatePackage(); this.toolStripPackage.Enabled = true; } else { selectedGuidancePackage = null; this.availableRecipesTreeView.Nodes.Clear(); this.historyRecipesTreeView.Nodes.Clear(); SelectToolStripElement(null, this.toolStripPackage); this.toolStripPackage.Enabled = false; UpdatePackageOverview(); } }
/// <summary> /// It creates a dynamic recipe in order to show a dialog that asks the user /// to introduce new targets for all dangling references /// </summary> private void PerformRestore() { if (referencesToFix.Count == 0) { return; } #region Asking to the user string msg; string details; BuildMessage(out msg, out details); if (ErrorHelper.Ask(Properties.Resources.ReferenceRestoreService_StartTitle, msg, details, Properties.Resources.ReferenceRestoreService_ResolveButton, Properties.Resources.ReferenceRestoreService_RemoveButton) == System.Windows.Forms.DialogResult.No) { IAssetReferenceService referenceService = null; GuidancePackage lastPackage = null; foreach (FixupReference lostReference in referencesToFix) { if (lastPackage != lostReference.OwningPackage) { referenceService = (IAssetReferenceService)ServiceHelper.GetService(lostReference.OwningPackage, typeof(IAssetReferenceService), this); } referenceService.Remove(lostReference.OldReference); } return; } #endregion // The pending FixupReferences we added to the list will be ordered // by the template they were in, so we can just build a wizard page // for each group of X of fields for fixup. int maxfields = 5; // Used to create configuration attributes XmlDocument xmlfactory = new XmlDocument(); // Create a package dynamically. Config.GuidancePackage package = CreateDynamicPackage(); Config.Recipe recipe; ArrayList arguments; ArrayList actions; CreateDynamicRecipe(package, out recipe, out arguments, out actions); Page lastpage = null; ArrayList pages = new ArrayList(); ArrayList fields = new ArrayList(maxfields); Hashtable argumentNamesUsed = new Hashtable(7); int nPages = referencesToFix.Count / maxfields; if ((referencesToFix.Count % maxfields) != 0) { nPages++; } Hashtable referenceDictionary = CreateFixupPages(maxfields, xmlfactory, arguments, actions, ref lastpage, pages, ref fields, nPages); lastpage.Fields = new Field[fields.Count]; fields.CopyTo(lastpage.Fields, 0); recipe.Arguments = new Config.Argument[arguments.Count]; arguments.CopyTo(recipe.Arguments, 0); if (recipe.Actions == null) { recipe.Actions = new Config.RecipeActions(); } recipe.Actions.Action = new Config.Action[actions.Count]; actions.CopyTo(recipe.Actions.Action, 0); Wizard wizard = new Wizard(); wizard.SchemaVersion = "1.0"; wizard.Pages = new Page[pages.Count]; pages.CopyTo(wizard.Pages, 0); // Get the wizard in XML form so that it's passed to the recipe execution. SerializeToAny(recipe, wizard); EnableAndExecute(package, referenceDictionary); }
internal Dictionary <string, IAssetReference> GetAvailableRecipes(GuidancePackage guidancePackage) { #if DEBUG DateTime startTime = DateTime.Now; Debug.WriteLine(String.Format("GetAvailableRecipes - Start time {0}.", startTime.ToLongTimeString())); #endif Dictionary <string, IAssetReference> availableRecipes = new Dictionary <string, IAssetReference>(); IAssetReferenceService referenceService = (IAssetReferenceService)guidancePackage.GetService(typeof(IAssetReferenceService), true); IOutputWindowService outputWindow = guidancePackage.GetService <IOutputWindowService>(); IPersistenceService persistenceService = guidancePackage.GetService <IPersistenceService>(); IAssetReference[] allReferences = null; allReferences = persistenceService.LoadReferences(guidancePackage.Configuration.Name); #if DEBUG Debug.WriteLine(String.Format("GetAvailableRecipes - Probing using {0} references.", allReferences.Length)); #endif List <IUnboundAssetReference> unboundAssetReferenceList; List <IAssetReference> otherAssetList; GetAssetLists(allReferences, out unboundAssetReferenceList, out otherAssetList); #if DEBUG Debug.WriteLine(String.Format("GetAvailableRecipes - Probing using {0} unbound references.", unboundAssetReferenceList.Count)); Debug.WriteLine(String.Format("GetAvailableRecipes - Probing using {0} other references.", otherAssetList.Count)); #endif List <object> allPossibleTargets = GetAllSolutionExplorerItems(); #if DEBUG Debug.WriteLine(String.Format("GetAvailableRecipes - Probing against {0} targets.", allPossibleTargets.Count)); #endif List <IUnboundAssetReference> unboundAssetReferenceWithNoTargetList = new List <IUnboundAssetReference>(); foreach (IUnboundAssetReference unboundAssetReference in unboundAssetReferenceList) { bool referenceHasValidTarget = false; foreach (object item in allPossibleTargets) { try { if (unboundAssetReference.IsEnabledFor(item)) { referenceHasValidTarget = true; break; } } catch (Exception resolveReferenceException) { // The reference is not valid for this item. outputWindow.Display(string.Format(Resources.Navigator_ReferenceThrowException, unboundAssetReference.AssetName, resolveReferenceException.Message)); } } if (!referenceHasValidTarget) { unboundAssetReferenceWithNoTargetList.Add(unboundAssetReference); } } #if DEBUG Debug.WriteLine(String.Format("GetAvailableRecipes - Removing {0} unbound referenes with no valid targets", unboundAssetReferenceWithNoTargetList.Count)); #endif // remove those unbound asset references that don't have a valid target in the whole solution foreach (IUnboundAssetReference reference in unboundAssetReferenceWithNoTargetList) { unboundAssetReferenceList.Remove(reference); } // add the unbound asset references that have a valid target foreach (IAssetReference reference in unboundAssetReferenceList) { otherAssetList.Add(reference); } foreach (IAssetReference reference in otherAssetList) { if (!availableRecipes.ContainsKey(reference.AssetName)) { availableRecipes.Add(reference.AssetName, reference); } } #if DEBUG DateTime endTime = DateTime.Now; Debug.WriteLine(String.Format("GetAvailableRecipes - End time {0}.", endTime.ToLongTimeString())); TimeSpan ts = endTime.Subtract(startTime); Debug.WriteLine(String.Format("GetAvailableRecipes - Executed in {0} ms.", ts.Milliseconds)); #endif return(availableRecipes); }
/// <summary> /// Initializes the data class. /// </summary> /// <param name="package">The package instance for the event.</param> /// <param name="cancel">Indicates whether the operation is canceled by default.</param> public CancelPackageEventArgs(GuidancePackage package, bool cancel) : base(package) { this.cancel = cancel; }
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); } } }
public VsGuidancePackage(GuidancePackage guidancePackage) { this.guidancePackage = guidancePackage; }
/// <summary> /// Initializes the data class. /// </summary> /// <param name="package">The package instance for the event.</param> public PackageEventArgs(GuidancePackage package) { this.package = package; }
public GuidancePackageEntry(GuidancePackage guidancePackage) { this.GuidancePackage = guidancePackage; }