Beispiel #1
0
        private string GetBasePath(XmlReader reader)
        {
            string baseuri;

            // If we have a BaseURI, we'll use that one. Otherwise, default to framework
            // location, after a warning.
            if (reader.BaseURI.Length == 0)
            {
                this.TraceWarning(Properties.Resources.GuidancePackage_NoBaseURI);
                // UNDONE: change when we add GAC support.
                baseuri = typeof(RecipeManager).Assembly.CodeBase;
            }
            else
            {
                baseuri = reader.BaseURI;
            }

            Uri baselocation = new CompatibleUri(baseuri);

            if (!baselocation.IsFile)
            {
                throw new System.Configuration.ConfigurationException(
                          Properties.Resources.GuidancePackage_UriNoFile);
            }

            return(Path.GetDirectoryName(baselocation.LocalPath));
        }
Beispiel #2
0
 private void LoadTemplateData(Dictionary <string, string> replacementsDictionary, string templateFileName)
 {
     try
     {
         templateFileName        = new CompatibleUri(templateFileName).LocalPath;
         this.templateDictionary = new TemplateDictionaryService(replacementsDictionary);
         IVsTemplatesService templatesService =
             (IVsTemplatesService)GetService(typeof(IVsTemplatesService));
         this.template = templatesService.GetTemplate(templateFileName);
     }
     catch (Exception e)
     {
         ErrorHelper.Show((IUIService)GetService(typeof(IUIService)), e, Properties.Resources.Templates_InvalidWizardData);
         throw new WizardCancelledException();
     }
 }
        /// <summary>
        /// See <see cref="ITypeResolutionService.GetPathOfAssembly"/>.
        /// </summary>
        /// <remarks>
        /// Returns either the local file name of the assembly or its
        /// <see cref="Assembly.CodeBase"/> if it doesn't point to a file name.
        /// </remarks>
        public virtual string GetPathOfAssembly(AssemblyName name)
        {
            Assembly asm = GetAssembly(name);

            if (asm == null)
            {
                return(null);
            }

            Uri location = new CompatibleUri(asm.CodeBase);

            if (location.IsFile)
            {
                return(location.LocalPath);
            }
            else
            {
                return(asm.CodeBase);
            }
        }
        /// <summary>
        /// <seealso cref="IAction.Execute"/>
        /// </summary>
        public override void Execute()
        {
            if (Template.ExtensionData.References == null)
            {
                return;
            }
            int length = 0;

            if (Template.ExtensionData.References.RecipeReference != null)
            {
                length = Template.ExtensionData.References.RecipeReference.Length;
            }
            if (Template.ExtensionData.References.TemplateReference != null)
            {
                length += Template.ExtensionData.References.TemplateReference.Length;
            }

            referencesAdded = new ArrayList(length);

            IAssetReferenceService referenceService = GetService <IAssetReferenceService>(true);
            StringBuilder          errorList        = new StringBuilder();

            if (this.Template.ExtensionData.References.RecipeReference != null)
            {
                foreach (Microsoft.Practices.RecipeFramework.VisualStudio.VsTemplate.AssetReference reference in Template.ExtensionData.References.RecipeReference)
                {
                    Hashtable hashInitialState;
                    try
                    {
                        hashInitialState = ReadReferenceState(reference.InitialState);
                    }
                    catch (Exception ex)
                    {
                        errorList.AppendFormat(
                            CultureInfo.CurrentCulture,
                            Properties.Resources.Templates_InitialStateError,
                            reference.Name,
                            DteHelper.ReplaceParameters(reference.Target, this.ReplacementDictionary),
                            ex);
                        // Don't add the offending reference.
                        continue;
                    }
                    VsBoundReference vsTarget = this.GetReferenceTarget(reference.Target, reference.Name);
                    if (vsTarget != null)
                    {
                        try
                        {
                            referenceService.Add(vsTarget, hashInitialState);
                            referencesAdded.Add(vsTarget);
                        }
                        catch (Exception ex)
                        {
                            errorList.AppendFormat(ex.Message).AppendLine();
                        }
                    }
                    else
                    {
                        errorList.AppendFormat(
                            CultureInfo.CurrentCulture,
                            Properties.Resources.Templates_CantFindTarget,
                            DteHelper.ReplaceParameters(reference.Target, this.ReplacementDictionary),
                            reference.Name).AppendLine();
                    }
                }
            }
            if (this.Item != null && this.Template.ExtensionData.References.TemplateReference != null)
            {
                throw new ArgumentException(String.Format(
                                                CultureInfo.CurrentCulture,
                                                Properties.Resources.Templates_ItemCantHaveTemplates,
                                                Path.GetFileName(this.Template.FileName)),
                                            "TemplateReference");
            }
            if (this.Template.ExtensionData.References.TemplateReference != null)
            {
                string basePath = this.Package.BasePath;
                foreach (VsTemplate.AssetReference reference in this.Template.ExtensionData.References.TemplateReference)
                {
                    Hashtable hashInitialState;
                    try
                    {
                        hashInitialState = ReadReferenceState(reference.InitialState);
                    }
                    catch (Exception ex)
                    {
                        errorList.AppendFormat(
                            CultureInfo.CurrentCulture,
                            Properties.Resources.Templates_InitialStateError,
                            reference.Name, reference.Target, ex);
                        continue;
                    }
                    string templateFileName = basePath + @"\Templates\" + reference.Name;
                    templateFileName = new CompatibleUri(templateFileName).LocalPath;
                    // Normalize path as it may contain double back slashes which usually shouldn't hurt but will break some of the checkings GAX does against registry keys
                    // this is necessary due to Uri.LocalPath behaving differently under Vista -- reported as VS bug #
                    //templateFileName = WinXpUriLocalPathBehavior(
                    //templateFileName = templateFileName.Replace(@"\\", @"\");
                    VsBoundReference vsTarget = this.GetReferenceTarget(reference.Target, templateFileName);
                    if (File.Exists(templateFileName) && templateFileName.EndsWith(".vstemplate", StringComparison.InvariantCultureIgnoreCase) && vsTarget != null)
                    {
                        BoundTemplateReference tmpref = new BoundTemplateReference(templateFileName, vsTarget);
                        referencesAdded.Add(tmpref);
                        referenceService.Add(tmpref, hashInitialState);
                    }
                    else if (vsTarget == null)
                    {
                        errorList.Append(String.Format(
                                             CultureInfo.CurrentCulture,
                                             Properties.Resources.Templates_CantFindTarget,
                                             DteHelper.ReplaceParameters(reference.Target, this.ReplacementDictionary),
                                             reference.Name));
                        errorList.Append(Environment.NewLine);
                    }
                    else
                    {
                        errorList.Append(String.Format(
                                             CultureInfo.CurrentCulture,
                                             Properties.Resources.Template_DoesntExist,
                                             reference.Name));
                        errorList.Append(Environment.NewLine);
                    }
                }
            }
            if (errorList.Length > 0)
            {
                // Enclose full list of errors in a simpler message for display in the dialog.
                throw new RecipeFrameworkException(string.Format(CultureInfo.CurrentCulture,
                                                                 Properties.Resources.Templates_ErrorsProcessingReferences,
                                                                 this.Template.Name),
                                                   new ArgumentException(errorList.ToString()));
            }
        }