示例#1
0
 private void OnDeleteRecipe(object sender, EventArgs e)
 {
     if (this.lstRecipes.SelectedItems.Count != 1)
     {
         return;
     }
     if (MessageBox.Show(this, Configuration.Resources.PackageManager_ConfirmDeleteReference,
                         this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
     {
         try
         {
             ReferenceInfo          refinfo = (ReferenceInfo)lstRecipes.SelectedItems[0].Tag;
             IAssetReferenceService refsvc  = (IAssetReferenceService)
                                              ServiceHelper.GetService(refinfo.Reference, typeof(IAssetReferenceService));
             refsvc.Remove(refinfo.Reference);
             this.lstRecipes.Items.Remove(lstRecipes.SelectedItems[0]);
             if (this.lstRecipes.Items.Count != 0)
             {
                 this.lstRecipes.SelectedIndices.Clear();
                 this.lstRecipes.SelectedIndices.Add(0);
             }
             else
             {
                 this.txtDescription.Clear();
             }
         }
         catch (Exception ex)
         {
             ErrorHelper.Show((IUIService)GetService(typeof(IUIService)), ex);
         }
     }
 }
示例#2
0
 /// <summary>
 /// Removes the previously added reference, if it was created
 /// </summary>
 public override void Undo()
 {
     if (newReference != null)
     {
         IAssetReferenceService referenceService = (IAssetReferenceService)GetService(typeof(IAssetReferenceService));
         referenceService.Remove(newReference);
     }
 }
 /// <summary>
 /// Removes the previously added reference, if it was created
 /// </summary>
 public override void Undo()
 {
     if (addedReference != null)
     {
         IAssetReferenceService referenceService = GetService <IAssetReferenceService>(true);
         referenceService.Remove(addedReference);
     }
 }
        /// <summary>
        /// <seealso cref="IAction.Undo"/>
        /// </summary>
        public override void Undo()
        {
            IAssetReferenceService referenceService = GetService <IAssetReferenceService>(true);

            foreach (IAssetReference asset in this.referencesAdded)
            {
                referenceService.Remove(asset);
            }
            referencesAdded.Clear();
        }
示例#5
0
        /// <summary>
        /// Removes the previously added reference
        /// </summary>
        public override void Undo()
        {
            IAssetReferenceService service = GetService <IAssetReferenceService>(true);

            if (reference != null)
            {
                service.Remove(reference);
                reference = null;
            }
        }
示例#6
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);
                }
            }
示例#7
0
        /// <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);
        }
示例#8
0
        private ExecutionResult Execute(string recipe, IAssetReference reference, IDictionary arguments)
        {
            if (recipe == null)
            {
                throw new ArgumentNullException("recipe");
            }
            ThrowIfAlreadyExecutingRecipe();
            Config.Recipe config = ThrowIfRecipeNotConfigured(recipe);

            ReferenceService referenceService = null;

            try
            {
                string appliesTo = GetReferenceAppliesToOrErrorMessage(reference);
                this.TraceInformation(Properties.Resources.Recipe_StartingExecution, recipe,
                                      reference != null ? String.Format(Properties.Resources.Recipe_ReferenceApplied, appliesTo) : "");

                // This "parent" loader service is the one we created in OnSited that
                // wraps the one provided by the recipe manager itself, and adds resolution
                // relative to the package assembly location.
                ITypeResolutionService loader = GetService <ITypeResolutionService>(true);

                // Create the recipe from the configuration.
                currentRecipe    = new Recipe(config);
                currentReference = reference;

                // Setup the alias resolution "gateway" loader service.
                // This resolves aliases defined for the recipe only.
                // This service will go away together with the recipe.
                currentRecipe.AddService(typeof(ITypeResolutionService), new AliasResolutionService(
                                             config.TypeAliasesByName, loader));

                bool isPersisted;
                IPersistenceService persistenceService;
                arguments = LoadPersitedState(reference, arguments, out isPersisted, out persistenceService);

                // Construct the dictionary service. We don't pass the arguments at this
                // point as we want to go over the process of setting each in turn, so they are validated.
                DictionaryService dictionarysvc = new DictionaryService(null);
                AddService(typeof(IDictionaryService), dictionarysvc);
                // Expose the IComponentChangeService implementation too.
                AddService(typeof(IComponentChangeService), dictionarysvc);

                if (arguments != null && arguments.Count > 0)
                {
                    bool shouldUpdateState = InitializeDictionaryService(arguments, dictionarysvc);

                    // Persist changes if appropriate.
                    if (isPersisted && shouldUpdateState)
                    {
                        persistenceService.SaveState(Configuration.Name, reference, arguments);
                    }
                }

                // Construct the dictionary service, passing the persisted state (or null) as well
                // as the arguments configuration.

                // Site and execute the recipe.
                Add(currentRecipe);
                referenceService = new ReferenceService();
                currentRecipe.AddService(typeof(IReferenceService), referenceService);

                bool allowsuspend = (reference != null && reference is IBoundAssetReference) ||
                                    (arguments != null);
                EnsureInitializeMetadataForCurrentRecipe();
                ExecutionResult result = currentRecipe.Execute(allowsuspend);
                this.TraceInformation(Properties.Resources.Recipe_ExecutionResult, result);

                if (result == ExecutionResult.Finish)
                {
                    // If recipe is not recurrent and it's a bound reference, remove it.
                    if (!currentRecipe.Configuration.Recurrent && reference is IBoundAssetReference)
                    {
                        IAssetReferenceService refsvc = GetService <IAssetReferenceService>(true);
                        refsvc.Remove(reference);
                        // Remove the persisted state.
                        persistenceService.RemoveState(Configuration.Name, reference);
                    }
                    // Fire the AfterRecipeExecution event
                    // note this will happen only when the recipe is finished (not suspend nor cancelled)
                    if (AfterRecipeExecution != null)
                    {
                        this.AfterRecipeExecution(this, new RecipeEventArgs(config, isExecutingRecipeFromTemplate));
                    }
                }

                return(result);
            }
            finally
            {
                #region Cleanup

                if (referenceService != null)
                {
                    currentRecipe.RemoveService(typeof(IReferenceService));
                }

                // Remove recipe from container.
                Remove(currentRecipe);
                // Remove services we added.
                RemoveService(typeof(IDictionaryService));
                RemoveService(typeof(IComponentChangeService));
                // Dispose and clean current variables.
                if (currentRecipe != null)
                {
                    currentRecipe.Dispose();
                    currentRecipe = null;
                }
                currentReference = null;

                #endregion Cleanup
                // Write a separator on the trace.
                this.TraceInformation(new string('-', 150));
            }
        }