/// <summary> /// Initializes a new instance of the <see cref="GuidancePackage"/> class with a /// configuration model, ready for use. /// </summary> /// <param name="configuration">The configuration for the package.</param> /// <param name="basePath">Location to use as the base folder to resolve types used by the package. /// Can be <see langword="null"/> or an empty string to use the <see cref="RecipeManager"/> installation folder.</param> /// <remarks> /// Types used by the package configuration are resolved relative to the framework installation only. /// Use the overload receiving the base path to change this behavior. /// </remarks> public GuidancePackage(Configuration.GuidancePackage configuration, string basePath) { if (configuration == null) { throw new ArgumentNullException("configuration"); } InitializeServices(); // We need to serialize it and reprocess, to ensure validity and indexing. using (Stream mem = new MemoryStream()) { // We avoid the perf. cost of generating a runtime serialization assembly // by using a design-time generated one that knows how to deal with out config. GuidancePackageSerializer ser = new GuidancePackageSerializer(); ser.Serialize(mem, configuration); // Reinitialize with the other overload. mem.Seek(0, SeekOrigin.Begin); Initialize(new XmlTextReader(mem)); } // Force Path validation if non-empty. if (basePath != null && basePath.Length > 0) { this.basePath = Path.GetDirectoryName(basePath); } }
private void EnableAndExecute(Config.GuidancePackage package, Hashtable referenceDictionary) { GuidancePackage loadedpackage = null; try { loadedpackage = manager.EnablePackage(package); bool stop = true; do { stop = (loadedpackage.Execute("ReferenceRestoreRecipe", referenceDictionary) == ExecutionResult.Finish); if (!stop) { stop = (MessageBox.Show(Properties.Resources.ReferenceRestoreService_Cancelled, Properties.Resources.ReferenceRestoreService_DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No); } } while (!stop); } finally { try { if (loadedpackage != null) { manager.DisablePackage(loadedpackage); loadedpackage.Dispose(); } } catch (Exception ex) { ErrorHelper.Show(this.Site, ex); } } }
/// <summary> /// Retrieves the full in-memory model of the package configuration. /// </summary> /// <param name="packageName">The package to get the configuration information for.</param> /// <returns> /// The configuration information for the given package. /// </returns> /// <exception cref="ConfigurationException">A package with the given name is not installed.</exception> public Configuration.GuidancePackage GetConfiguration(string packageName) { if (packageName == null) { throw new ArgumentNullException("packageName"); } GuidancePackage package = GetPackage(packageName); if (package != null) { return(package.Configuration); } else { if (configurationCache.ContainsKey(packageName)) { return((Configuration.GuidancePackage)configurationCache[packageName]); } // Otherwise, we have to read the entire file. XmlReader reader = GetConfigurationReader(this, packageName); // We don't perform extensive validation at this point, as this is just for displaying // purposes. Just XSD validation will happen. Configuration.GuidancePackage packageconfig = (Configuration.GuidancePackage) new Configuration.Serialization.GuidancePackageSerializer().Deserialize(reader); // Cache the configuration for later retrievals. configurationCache.Add(packageName, packageconfig); return(packageconfig); } }
private void CreateDynamicRecipe(Config.GuidancePackage package, out Config.Recipe recipe, out ArrayList arguments, out ArrayList actions) { // Recipe to execute and add references. recipe = new Config.Recipe(); package.Recipes = new Config.Recipe[] { recipe }; recipe.Name = "ReferenceRestoreRecipe"; recipe.Caption = Properties.Resources.ReferenceRestoreService_DialogTitle; arguments = new ArrayList(referencesToFix.Count); actions = new ArrayList(referencesToFix.Count); }
private static Config.GuidancePackage CreateDynamicPackage() { Config.GuidancePackage package = new Config.GuidancePackage(); package.SchemaVersion = "1.0"; package.SourceLevels = Config.SourceLevels.Off; package.Host = "VisualStudio"; package.Name = "DynamicPackage"; package.Caption = "DynamicPackage"; package.Guid = Guid.NewGuid().ToString(); return(package); }
public void LoadPackage() { RecipeManager mgr = new RecipeManager(); // Setup dependent services. mgr.RemoveService(typeof(System.ComponentModel.Design.ITypeResolutionService)); mgr.AddService(typeof(System.ComponentModel.Design.ITypeResolutionService), new MockServices.MockTypeResolutionService()); mgr.AddService(typeof(Services.IPersistenceService), new MockServices.MockPersistenceService()); Configuration.GuidancePackage config = new Configuration.GuidancePackage(); config.Name = "Test package"; config.SchemaVersion = "1.0"; config.Caption = "Test package caption"; GuidancePackage package = new GuidancePackage(config); mgr.Add(package); }
/// <summary> /// Initializes the package with a new configuration. /// </summary> /// <param name="configuration">The reader to load configuration from.</param> /// <remarks> /// <para>External included files will be resolved as relative paths based on the /// <paramref name="configuration"/> reader <see cref="XmlReader.BaseURI"/> property. /// </para> /// Another overload is provided for using a custom provided resolver. /// </remarks> private void Initialize(XmlReader configuration) { if (configuration == null) { throw new ArgumentNullException("configuration"); } if (basePath.Length == 0) { basePath = GetBasePath(configuration); } this.config = ReadConfiguration(configuration); tracing = new SourceSwitch(Configuration.Caption); tracing.Level = SourceLevels.Off; tracingLevel = (SourceLevels)Enum.Parse(typeof(SourceLevels), Configuration.SourceLevels.ToString()); this.sortPriority = Configuration.SortPriority; }
public void SetUp() { Manager = new RecipeManager(); Manager.AddService(typeof(IPersistenceService), new MockPersistenceService()); Manager.AddService(typeof(EnvDTE._DTE), new MockServices.MockDte()); Manager.AddService(typeof(IValueGatheringService), new WizardFramework.WizardGatheringService()); Flags = new bool[10]; Configuration.GuidancePackage package = GuidancePackage.ReadConfiguration( Utils.MakeTestRelativePath("PackageManagementTest.xml")); Manager.AddService(typeof(IHostService), new TestHost(package.Host)); //// Install host //ManifestInstallerTest.InstallHost(package.Host, typeof(TestInstaller), false); //// Install package. //ManifestInstallerTest.InstallPackage( // Utils.MakeTestRelativePath("PackageManagementTest.xml"), false); }
/// <summary> /// Enables a package. /// </summary> /// <param name="configuration"> /// Configuration to use for the new package. /// </param> /// <returns> /// Returns the loaded and enabled package. /// </returns> public GuidancePackage EnablePackage(Configuration.GuidancePackage configuration) { if (configuration == null) { throw new ArgumentNullException("configuration"); } GuidancePackage package = new GuidancePackage(configuration); try { package.AfterRecipeExecution += new RecipeEventHandler(package_AfterRecipeExecution); Add(package); } catch { package.Dispose(); throw; } return(package); }
/// <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); }
public void UninstallPackage(System.Configuration.Install.InstallContext context, Configuration.GuidancePackage packageConfig) { context.LogMessage(this.GetType().AssemblyQualifiedName); }
/// <summary> /// Initializes a new instance of the <see cref="GuidancePackage"/> class with a /// configuration model, ready for use. /// </summary> /// <param name="configuration">The configuration for the package.</param> /// <remarks>To let the contained components publish additional services, use /// the overload that is receiving the <c>exposeServiceContainerService</c> flag.</remarks> public GuidancePackage(Configuration.GuidancePackage configuration) : this(configuration, String.Empty) { }
protected override void OnLoad(EventArgs e) { try { base.OnLoad(e); tvRecipes.Nodes.Clear(); this.SuspendLayout(); if (GuidancePackage != null) { TreeNode Packagenode = tvRecipes.Nodes.Add(String.Format( System.Globalization.CultureInfo.CurrentCulture, GuidancePackage.Caption, GuidancePackage.Version)); Packagenode.ImageIndex = 1; Packagenode.SelectedImageIndex = 1; Packagenode.Tag = GuidancePackage; TreeNode recipes = Packagenode.Nodes.Add( Configuration.Resources.PackageViewer_RecipesNode); recipes.ImageIndex = 2; recipes.SelectedImageIndex = 2; // Read the Package configuration. Config.GuidancePackage configuration = RecipeFramework.GuidancePackage.ReadConfiguration( GuidancePackage.ConfigurationFile); foreach (Config.Recipe recipe in configuration.Recipes) { TreeNode recipenode = recipes.Nodes.Add(recipe.Caption); recipenode.Tag = new AssetDescription( Configuration.Resources.PackageViewer_RecipesNode, recipe.Caption, recipe.Description); recipenode.ImageIndex = 6; recipenode.SelectedImageIndex = 6; if (recipe.Arguments != null && recipe.Arguments.Length > 0) { TreeNode argumentsnode = recipenode.Nodes.Add(Configuration.Resources.PackageViewer_ArgumentsNode); argumentsnode.ImageIndex = 3; argumentsnode.SelectedImageIndex = 3; foreach (Config.Argument argument in recipe.Arguments) { TreeNode argnode = argumentsnode.Nodes.Add(argument.Name); argnode.Tag = argument; // UNDONE: we can provide as the description of the selected // argument its type and maybe converter and value provider by creating a properly formatted // AssetDescription and that's it. The node selection code will pull it automatically. } } if (recipe.Actions != null && recipe.Actions.Action.Length > 0) { TreeNode actionsnode = recipenode.Nodes.Add(Configuration.Resources.PackageViewer_ActionsNode); actionsnode.ImageIndex = 4; actionsnode.SelectedImageIndex = 4; foreach (Config.Action action in recipe.Actions.Action) { TreeNode actionnode = actionsnode.Nodes.Add(action.Name); actionnode.Tag = action; // UNDONE: we can provide as the description of the selected // action its input and output values by creating a properly formatted // AssetDescription and that's it. The node selection code will pull it automatically. } } } // Call host for additional assets that may be available. if (base.HostService != null) { IAssetDescription[] descriptions = base.HostService.GetHostAssets( System.IO.Path.GetDirectoryName(GuidancePackage.ConfigurationFile), configuration); if (descriptions != null) { foreach (IAssetDescription asset in descriptions) { TreeNode categorynode = GetCategoryNode(Packagenode, asset.Category.Split(new char[] { '\\', '/' }), 0); categorynode.ImageIndex = 5; categorynode.SelectedImageIndex = 5; TreeNode assetnode = new TreeNode(asset.Caption); assetnode.Tag = asset; assetnode.ImageIndex = 6; assetnode.SelectedImageIndex = 6; categorynode.Nodes.Add(assetnode); } } } } this.ResumeLayout(); } catch (Exception ex) { ErrorHelper.Show(this.Site, ex); } }