Пример #1
0
        private void GetAllVSTemplatesInSubfolder(string templatePath, TemplateManager.TemplateValidator filter, Action <Microsoft.Expression.Project.Templates.VSTemplate, string> acceptor)
        {
            if (!Microsoft.Expression.Framework.Documents.PathHelper.DirectoryExists(templatePath))
            {
                return;
            }
            XmlSerializer templateXmlSerializer = null;

            try
            {
                templateXmlSerializer = TemplateManager.TemplateXmlSerializer;
            }
            catch (TypeInitializationException typeInitializationException)
            {
                this.LogTemplateLoadError(templatePath, typeInitializationException.Message);
            }
            catch (ExternalException externalException)
            {
                this.LogTemplateLoadError(templatePath, externalException.Message);
            }
            if (templateXmlSerializer == null)
            {
                return;
            }
            foreach (string str in new List <string>(Directory.GetFiles(templatePath, "*.vstemplate", SearchOption.AllDirectories)))
            {
                using (FileStream fileStream = new FileStream(str, FileMode.Open, FileAccess.Read))
                {
                    this.readTemplate(Microsoft.Expression.Framework.Documents.PathHelper.GetDirectoryNameOrRoot(str), str, fileStream, templateXmlSerializer, filter, acceptor);
                }
            }
            foreach (string str1 in new List <string>(Directory.GetFiles(templatePath, "*.zip", SearchOption.AllDirectories)))
            {
                try
                {
                    foreach (ZipArchiveFile file in ZipHelper.CreateZipArchive(str1).Files)
                    {
                        try
                        {
                            if (Path.GetExtension(file.Name).Equals(".vstemplate", StringComparison.OrdinalIgnoreCase) && string.IsNullOrEmpty(Path.GetDirectoryName(file.Name)))
                            {
                                using (Stream stream = file.OpenRead())
                                {
                                    this.readTemplate(str1, string.Concat(str1, "[", file.Name, "]"), stream, templateXmlSerializer, filter, acceptor);
                                }
                            }
                        }
                        catch (Exception exception1)
                        {
                            Exception exception = exception1;
                            this.LogTemplateLoadError(string.Concat(str1, "[", file.Name, "]"), exception.Message);
                        }
                    }
                }
                catch (Exception exception2)
                {
                    this.LogTemplateLoadError(str1, exception2.Message);
                }
            }
        }
Пример #2
0
 private void readTemplate(string vsTemplatePath, string vsTemplateLocation, Stream fs, XmlSerializer serializer, TemplateManager.TemplateValidator filter, Action <Microsoft.Expression.Project.Templates.VSTemplate, string> acceptor)
 {
     Microsoft.Expression.Project.Templates.VSTemplate vSTemplate = null;
     try
     {
         vSTemplate = (Microsoft.Expression.Project.Templates.VSTemplate)serializer.Deserialize(fs);
     }
     catch (InvalidOperationException invalidOperationException)
     {
         this.LogTemplateLoadError(vsTemplateLocation, invalidOperationException.Message);
     }
     if (vSTemplate != null && (filter == null || filter(vsTemplateLocation, vSTemplate)) && this.ShouldLoad(vSTemplate))
     {
         acceptor(vSTemplate, vsTemplatePath);
     }
 }
Пример #3
0
 private void GetAllProjectTemplatesInSubfolder(string templatePath, IList <IProjectTemplate> templateCollection, TemplateManager.TemplateValidator filter)
 {
     this.GetAllVSTemplatesInSubfolder(templatePath, filter, (Microsoft.Expression.Project.Templates.VSTemplate vsTemplate, string vsTemplatePath) => {
         IProjectTemplate projectTemplate = new ProjectTemplate(vsTemplate, new Uri(vsTemplatePath));
         templateCollection.Add(projectTemplate);
     });
 }