Exemplo n.º 1
0
        private object GetActionOutputValue(Configuration.Action config, Configuration.Input parameter, object value)
        {
            string[] actionoutvalues = parameter.ActionOutput.Split(new char[] { '.' });
            object   outaction       = actionInstances[actionoutvalues[0]];

            if (outaction == null)
            {
                throw new ArgumentException(String.Format(
                                                System.Globalization.CultureInfo.CurrentCulture,
                                                Properties.Resources.Recipe_ActionOutputNull,
                                                config.Name, parameter.Name, actionoutvalues[0]));
            }
            // Use the type descriptor for the object, so it can be extensible.
            PropertyDescriptor outprop = GetComponentProperty(outaction, actionoutvalues[1]);
            bool HasOutputAttribute    = false;

            if (outprop != null)
            {
                HasOutputAttribute = (outprop.Attributes[typeof(OutputAttribute)] != null);
            }
            if (!HasOutputAttribute)
            {
                throw new NotSupportedException(String.Format(
                                                    System.Globalization.CultureInfo.CurrentCulture,
                                                    Properties.Resources.Recipe_ActionOutputMissing,
                                                    actionoutvalues[1], actionoutvalues[0], config.Name, outaction.GetType()));
            }

            return(outprop.GetValue(outaction));
        }
Exemplo n.º 2
0
        private Hashtable CreateFixupPages(int maxfields, XmlDocument xmlfactory, ArrayList arguments, ArrayList actions, ref Page lastpage, ArrayList pages, ref ArrayList fields, int nPages)
        {
            int  iPage     = 1;
            int  iArgument = 1;
            bool firstPage = true;

            Hashtable referenceDictionary = new Hashtable();

            foreach (FixupReference fixup in referencesToFix)
            {
                if (firstPage ||
                    (lastpage != null) && (fields.Count == maxfields))
                {
                    #region Create new page
                    firstPage = false;

                    // If we have fields and a previous page, set all fields in one shot.
                    if (lastpage != null && fields != null)
                    {
                        lastpage.Fields = new Field[fields.Count];
                        fields.CopyTo(lastpage.Fields, 0);
                    }

                    // Start a new page for the fields.
                    lastpage = new Page();
                    pages.Add(lastpage);
                    fields         = new ArrayList(maxfields);
                    lastpage.Title = String.Format(
                        CultureInfo.CurrentCulture,
                        Properties.Resources.ReferenceRestoreService_PageTitle,
                        iPage, nPages);
                    lastpage.Help = String.Format(
                        CultureInfo.CurrentCulture,
                        Properties.Resources.ReferenceRestoreService_PageHelp);
                    lastpage.LinkTitle = String.Format(
                        CultureInfo.CurrentCulture,
                        Properties.Resources.ReferenceRestoreService_PageLinkTitle,
                        iPage, nPages);
                    iPage++;

                    #endregion Create new page
                }

                #region Setup recipe arguments

                Config.Argument argument = new Config.Argument();

                argument.Name           = string.Format(CultureInfo.InvariantCulture, "Argument{0}", iArgument);
                argument.Type           = GetTargetType(fixup.ExpectedTargetKind).AssemblyQualifiedName;
                argument.Converter      = new Config.Converter();
                argument.Converter.Type = GetConverterType(fixup.ExpectedTargetKind);
                arguments.Add(argument);

                Config.Argument argumentKeyRef = new Config.Argument();
                argumentKeyRef.Name = string.Format(CultureInfo.InvariantCulture, "Reference{0}", iArgument);
                argumentKeyRef.Type = "Microsoft.Practices.RecipeFramework.IAssetReference, Microsoft.Practices.RecipeFramework.Common";
                referenceDictionary.Add(argumentKeyRef.Name, fixup.OldReference);

                arguments.Add(argumentKeyRef);
                iArgument++;

                #endregion Setup recipe arguments

                #region Create new field



                Field field = new Field();
                if (fixup.OldReference is BoundTemplateReference)
                {
                    int templateLength = fixup.OwningPackage.BasePath.Length + 11;                     //11 corresponds to Lenght of string "\Template\"
                    if (templateLength > fixup.ReferencedAsset.Length)
                    {
                        templateLength = 0;
                    }
                    field.Label = string.Format("{0} ({1})", fixup.ReferencedAsset.Substring(templateLength), fixup.SavedTarget);
                    field.Help  = String.Format(
                        CultureInfo.CurrentCulture,
                        Properties.Resources.ReferenceRestoreService_FieldTemplateHelp,
                        fixup.ExpectedTargetKind, fixup.ReferencedAsset.Substring(templateLength));
                }
                else                 // case of recipe reference
                {
                    IConfigurationService configService =
                        (IConfigurationService)fixup.OwningPackage.GetService(typeof(IConfigurationService), true);
                    Config.Recipe recipeReference = configService.CurrentPackage[fixup.OldReference.AssetName];
                    field.Label = string.Format("{0} ({1})", recipeReference.Caption, fixup.SavedTarget);
                    field.Help  = String.Format(
                        CultureInfo.CurrentCulture,
                        Properties.Resources.ReferenceRestoreService_FieldRecipeHelp,
                        fixup.ExpectedTargetKind, recipeReference.Caption);
                }
                field.Tooltip = String.Format(
                    CultureInfo.CurrentCulture,
                    Properties.Resources.ReferenceRestoreService_FieldTooltip,
                    fixup.SavedTarget, fixup.ExpectedTargetKind);
                field.InvalidValueMessage = String.Format(
                    CultureInfo.CurrentCulture,
                    Properties.Resources.ReferenceRestoreService_FieldInvalid,
                    fixup.ExpectedTargetKind);
                field.ValueName = argument.Name;
                field.Editor    = new Editor();
                // Again, we can't use the type directly to avoid circular references.
                field.Editor.Type = "Microsoft.Practices.RecipeFramework.Library.Editors.SolutionPickerEditor, Microsoft.Practices.RecipeFramework.Library";
                field.PanelType   = "Microsoft.Practices.RecipeFramework.VisualStudio.Services.CustomArgumentPanel, Microsoft.Practices.RecipeFramework.VisualStudio";
                fields.Add(field);

                #endregion Create new field

                #region Setup an action for it

                Config.Action action = new Config.Action();
                // Name will be ugly, but we need to ensure uniqueness too.
                action.Name = argument.Name;
                action.Type = typeof(AddFixedReferenceAction).AssemblyQualifiedName;
                XmlAttribute assetattr;
                assetattr       = xmlfactory.CreateAttribute("Recipe");
                assetattr.Value = fixup.ReferencedAsset;

                XmlAttribute packageattr = xmlfactory.CreateAttribute("TargetPackage");
                packageattr.Value = fixup.OwningPackage.Configuration.Name;
                action.AnyAttr    = new XmlAttribute[] { assetattr, packageattr };
                // Sync action input with collected argument for the target.
                Config.Input input = new Config.Input();
                input.Name           = "Target";
                input.RecipeArgument = argument.Name;
                Config.Input inputRef = new Config.Input();
                inputRef.Name           = "OldReference";
                inputRef.RecipeArgument = argumentKeyRef.Name;
                action.Input            = new Config.Input[] { input, inputRef };
                actions.Add(action);

                #endregion Setup an action for it
            }
            return(referenceDictionary);
        }