private void ProcessT4Templates()
        {
            T4UnfoldAction action   = new T4UnfoldAction();
            UnfoldTemplate template = (UnfoldTemplate)UnfoldTemplate.UnfoldingTemplates.Peek();

            if (template.Template.VSKind == WizardRunKind.AsMultiProject)
            {
                // We dont process any T4 template for a multiproject template
                return;
            }
            try
            {
                package.Add(action);
                IConfigurationService configService = package.GetService <IConfigurationService>(true);
                IVsTemplate           vsTemplate    = template.Template;
                Configuration.Recipe  recipe        = null;
                if (vsTemplate != null && vsTemplate.ExtensionData != null && !string.IsNullOrEmpty(vsTemplate.ExtensionData.Recipe))
                {
                    recipe = configService.CurrentPackage[vsTemplate.ExtensionData.Recipe];
                }
                if (recipe != null && recipe.Arguments != null)
                {
                    IDictionaryService           dictService = GetService <IDictionaryService>();
                    PropertyDescriptorCollection properties  = TypeDescriptor.GetProperties(action);
                    foreach (Configuration.Argument recipeArg in recipe.Arguments)
                    {
                        object value = dictService.GetValue(recipeArg.Name);
                        properties[recipeArg.Name].SetValue(action, value);
                    }
                }
                action.Project = template.generatedProject;
                action.ProjectItemCollection = template.generatedItems;
                action.Execute();
            }
            catch (Exception ex)
            {
                // We will swallow the exception, the erroneous references did not get added
                ErrorHelper.Show(this, ex);
            }
            finally
            {
                if (action != null)
                {
                    package.Remove(action);
                    action.Dispose();
                    action = null;
                }
            }
        }
示例#2
0
 EnvDTE.wizardResult EnvDTE._DTE.LaunchWizard(string VSZFile, ref object[] ContextParams)
 {
     if (this.replacementDictionary == null && UnfoldTemplate.UnfoldingTemplates.Count > 0)
     {
         UnfoldTemplate unfoldTemplate = (UnfoldTemplate)UnfoldTemplate.UnfoldingTemplates.Peek();
         this.replacementDictionary = unfoldTemplate.ReplacementDictionary;
     }
     for (int i = 0; i < ContextParams.Length; i++)
     {
         if (ContextParams[i] is string)
         {
             ContextParams[i] = DteHelper.ReplaceParameters(ContextParams[i] as string, this.replacementDictionary);
         }
     }
     return(dte.LaunchWizard(VSZFile, ref ContextParams));
 }
示例#3
0
 private void LoadDictionary()
 {
     if (UnfoldingTemplates.Count > 0)
     {
         UnfoldTemplate parentTemplate = (UnfoldTemplate)UnfoldingTemplates.Peek();
         CheckConflictingArguments(parentTemplate);
         foreach (DictionaryEntry keyValuePair in parentTemplate.templateDictionary.State)
         {
             if (this.templateDictionary.GetValue(keyValuePair.Key) == null)
             {
                 this.templateDictionary.SetValue(keyValuePair.Key, keyValuePair.Value);
             }
         }
     }
     // After we load the Dictionary, now push ourselves into the unfolding templates stack
     UnfoldTemplate.UnfoldingTemplates.Push(this);
 }
示例#4
0
 private void CheckConflictingArguments(UnfoldTemplate parentTemplate)
 {
     Configuration.Recipe parentRecipe = parentTemplate.RecipeConfig;
     if (RecipeConfig != null && parentRecipe != null && RecipeConfig.Arguments != null)
     {
         foreach (Configuration.Argument arg in RecipeConfig.Arguments)
         {
             foreach (Configuration.Argument argParent in parentRecipe.Arguments)
             {
                 if (arg.Name.Equals(argParent.Name))
                 {
                     throw new RecipeFrameworkException(
                               String.Format(CultureInfo.CurrentCulture,
                                             Properties.Resources.Templates_ArgumentsShared,
                                             arg.Name,
                                             RecipeConfig.Name,
                                             parentRecipe.Name));
                 }
             }
         }
     }
 }