GetResourceStream() public abstract method

public abstract GetResourceStream ( string name ) : Stream
name string
return Stream
コード例 #1
0
 private void ProcessDependenciesCore(string outputDirectory, IEnumerable <TemplateBundle> templateBundles)
 {
     foreach (var resourceInfo in templateBundles.SelectMany(s => s.Resources).Distinct())
     {
         try
         {
             // TODO: support glob pattern
             if (resourceInfo.IsRegexPattern)
             {
                 var regex = new Regex(resourceInfo.ResourceKey, RegexOptions.IgnoreCase);
                 foreach (var name in _resourceProvider.Names)
                 {
                     if (regex.IsMatch(name))
                     {
                         using (var stream = _resourceProvider.GetResourceStream(name))
                         {
                             ProcessSingleDependency(stream, outputDirectory, name);
                         }
                     }
                 }
             }
             else
             {
                 using (var stream = _resourceProvider.GetResourceStream(resourceInfo.ResourceKey))
                 {
                     ProcessSingleDependency(stream, outputDirectory, resourceInfo.FilePath);
                 }
             }
         }
         catch (Exception e)
         {
             Logger.Log(LogLevel.Info, $"Unable to get relative resource for {resourceInfo.FilePath}: {e.Message}");
         }
     }
 }
コード例 #2
0
        public Nustache.Core.Template GetTemplate(string name)
        {
            if (_resourceProvider == null)
            {
                return(null);
            }
            var resourceName = name + PartialTemplateExtension;

            return(_templateCache.GetOrAdd(resourceName, s =>
            {
                lock (_resourceProvider)
                {
                    using (var stream = _resourceProvider.GetResourceStream(s))
                    {
                        if (stream == null)
                        {
                            return null;
                        }

                        var template = new Nustache.Core.Template(name);
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            template.Load(reader);
                        }
                        return template;
                    }
                }
            }));
        }
コード例 #3
0
        public static string ExpandMasterPage(ResourceCollection resource, TemplateRendererResource info, Regex masterRegex, Regex bodyRegex)
        {
            var template               = info.Content;
            var templateName           = info.TemplateName;
            var masterPageResourceName = ExtractMasterPageResourceName(resource, info, masterRegex).FirstOrDefault();

            template = masterRegex.Replace(template, string.Empty);
            if (masterPageResourceName != null)
            {
                using (var stream = resource.GetResourceStream(masterPageResourceName))
                {
                    if (stream != null)
                    {
                        using (var sr = new StreamReader(stream))
                        {
                            var master = sr.ReadToEnd();
                            if (bodyRegex.IsMatch(master))
                            {
                                return(bodyRegex.Replace(master, template));
                            }
                            else
                            {
                                Logger.LogInfo($"Master page {masterPageResourceName} does not contain {{{{!body}}}} element, content in current template {templateName} is ignored.");
                                return(master);
                            }
                        }
                    }
                }
            }

            return(template);
        }
コード例 #4
0
ファイル: TemplateProcessor.cs プロジェクト: tintoy/docfx
 private void ProcessDependenciesCore(string outputDirectory, IEnumerable <TemplateBundle> templateBundles)
 {
     foreach (var resourceInfo in templateBundles.SelectMany(s => s.Resources).Distinct())
     {
         try
         {
             using (var stream = _resourceProvider.GetResourceStream(resourceInfo.ResourceKey))
             {
                 ProcessSingleDependency(stream, outputDirectory, resourceInfo.ResourceKey);
             }
         }
         catch (Exception e)
         {
             Logger.Log(LogLevel.Info, $"Unable to get relative resource for {resourceInfo.ResourceKey}: {e.Message}");
         }
     }
 }