Ejemplo n.º 1
0
        public override bool OnBeginRecipe(object currentValue, out object newValue)
        {
            if (currentValue != null)
            {
                newValue = null;
                return(false);
            }

            IConfigurationService b = (IConfigurationService)GetService(typeof(IConfigurationService));

            Microsoft.Practices.RecipeFramework.Configuration.Recipe recipe = b.CurrentRecipe;

            newValue = recipe.Name;
            return(true);
        }
        /// <summary>
        /// Adds all arguments to the template code and adds all arguments with values to the arguments list
        /// </summary>
        /// <param name="templateCodeLines"></param>
        private void AddAllArguments(StringBuilder templateCodeLines, NameValueCollection overrideArguments)
        {
            IDictionaryService    dictionaryService = GetService <IDictionaryService>();
            IConfigurationService b = (IConfigurationService)GetService(typeof(IConfigurationService));

            Microsoft.Practices.RecipeFramework.Configuration.Recipe recipe = b.CurrentRecipe;

            foreach (Microsoft.Practices.RecipeFramework.Configuration.Argument argument in recipe.Arguments)
            {
                if (!argument.Type.StartsWith("EnvDTE", StringComparison.InvariantCultureIgnoreCase))
                {
                    object currentValue = dictionaryService.GetValue(argument.Name);

                    //is there a override for this key
                    if (overrideArguments[argument.Name] != null)
                    {
                        currentValue = overrideArguments[argument.Name];
                        if (!base.additionalArguments.Contains(argument.Name))
                        {
                            base.additionalArguments.Add(argument.Name, currentValue);
                        }
                        else
                        {
                            //force override of that value
                            base.additionalArguments[argument.Name] = currentValue;
                        }
                    }
                    else
                    {
                        if (!base.additionalArguments.Contains(argument.Name))
                        {
                            base.additionalArguments.Add(argument.Name, currentValue);
                        }
                    }

                    templateCodeLines.AppendLine("<#@ property processor=\"PropertyProcessor\" name=\"" + argument.Name + "\" #>");
                }
            }

            templateCodeLines.AppendLine("<#@ assembly name=\"System.dll\" #>");
            templateCodeLines.AppendLine("<#@ assembly name=\"SPALM.SPSF.Library.dll\" #>");
            templateCodeLines.AppendLine("<#@ import namespace=\"SPALM.SPSF.Library\" #>");
        }
        private bool SetValue(object currentValue, out object newValue)
        {
            if (currentValue != null)
            {
                newValue = null;
                return(false);
            }

            EnvDTE.DTE dte = this.GetService <EnvDTE.DTE>(true);

            //first we need the xpath, which is needed by the manifest-recipe
            string manifestXpath          = "";
            string manifestXpathNamespace = "";
            IConfigurationService b       = (IConfigurationService)GetService(typeof(IConfigurationService));

            Microsoft.Practices.RecipeFramework.Configuration.Recipe recipe = b.CurrentRecipe;
            if (recipe.HostData.Any.Attributes["XPath"] != null)
            {
                manifestXpath = recipe.HostData.Any.Attributes["XPath"].Value;
            }
            if (recipe.HostData.Any.Attributes["XPathNamespace"] != null)
            {
                manifestXpathNamespace = recipe.HostData.Any.Attributes["XPathNamespace"].Value;
            }

            //if file is selected we check, if the xpath can be found in this item
            //if folder is selected we search in this folder for the elements.xml which contains the xpath
            if (dte.SelectedItems.Count > 0)
            {
                SelectedItem item         = dte.SelectedItems.Item(1);
                ProjectItem  selectedItem = null;

                if (item is ProjectItem)
                {
                    selectedItem = item as ProjectItem;
                }
                else if (item.ProjectItem is ProjectItem)
                {
                    selectedItem = item.ProjectItem as ProjectItem;
                }

                if (selectedItem != null)
                {
                    if (selectedItem.Kind == EnvDTE.Constants.vsProjectItemKindPhysicalFile)
                    {
                        if (selectedItem.Collection.Parent is ProjectItem)
                        {
                            ProjectItem parentItem = selectedItem.Collection.Parent as ProjectItem;
                            newValue = parentItem;
                            return(true);
                        }
                    }
                    else if (selectedItem.Kind == EnvDTE.Constants.vsProjectItemKindPhysicalFolder)
                    {
                        newValue = selectedItem;
                        return(true);
                    }
                }
            }

            newValue = null;
            return(false);
        }
        private bool SetValue(object currentValue, out object newValue)
        {
            if (currentValue != null)
            {
                newValue = null;
                return(false);
            }

            EnvDTE.DTE dte = this.GetService <EnvDTE.DTE>(true);

            //first we need the xpath, which is needed by the manifest-recipe
            string manifestXpath          = "";
            string manifestXpathNamespace = "";
            IConfigurationService b       = (IConfigurationService)GetService(typeof(IConfigurationService));

            Microsoft.Practices.RecipeFramework.Configuration.Recipe recipe = b.CurrentRecipe;
            if (recipe.HostData.Any.Attributes["XPath"] != null)
            {
                manifestXpath = recipe.HostData.Any.Attributes["XPath"].Value;
            }
            if (recipe.HostData.Any.Attributes["XPathNamespace"] != null)
            {
                manifestXpathNamespace = recipe.HostData.Any.Attributes["XPathNamespace"].Value;
            }

            //if file is selected we check, if the xpath can be found in this item
            //if folder is selected we search in this folder for the elements.xml which contains the xpath
            if (dte.SelectedItems.Count > 0)
            {
                SelectedItem item         = dte.SelectedItems.Item(1);
                ProjectItem  selectedItem = null;

                if (item is ProjectItem)
                {
                    selectedItem = item as ProjectItem;
                }
                else if (item.ProjectItem is ProjectItem)
                {
                    selectedItem = item.ProjectItem as ProjectItem;
                }

                if (selectedItem != null)
                {
                    if (selectedItem.Kind == EnvDTE.Constants.vsProjectItemKindPhysicalFile)
                    {
                        //is the xml file clicked?
                        try
                        {
                            if (Helpers2.IsXPathInFile(selectedItem, manifestXpath, manifestXpathNamespace))
                            {
                                newValue = selectedItem;
                                return(true);
                            }
                        }
                        catch { }
                    }
                    else
                    {
                        //folder is clicked, we search for xml files below the folder which contains the needed xpath
                        foreach (ProjectItem childItem in selectedItem.ProjectItems)
                        {
                            if (Helpers2.IsXPathInFile(childItem, manifestXpath, manifestXpathNamespace))
                            {
                                newValue = childItem;
                                return(true);
                            }
                        }
                    }
                }
            }
            //string projectId = currentProject.

            newValue = null;
            return(false);
        }