public string Generate(HelpSource hs, string id, Dictionary <string, string> context)
        {
            string specialPage;

            if (context != null && context.TryGetValue("specialpage", out specialPage) && specialPage == "master-root")
            {
                return(GenerateMasterRootPage(hs != null ? hs.RootTree : null));
            }

            if (hs == null || string.IsNullOrEmpty(id))
            {
                return(MakeHtmlError(string.Format("Your request has found no candidate provider [hs=\"{0}\", id=\"{1}\"]",
                                                   hs == null ? "(null)" : hs.Name, id ?? "(null)")));
            }
            var cache = defaultCache ?? hs.Cache;

            if (cache != null && cache.IsCached(MakeCacheKey(hs, id, null)))
            {
                return(cache.GetCachedString(MakeCacheKey(hs, id, null)));
            }

            IEnumerable <string> parts;

            if (hs.IsMultiPart(id, out parts))
            {
                return(GenerateMultiPart(hs, parts, id, context));
            }

            if (hs.IsRawContent(id))
            {
                return(hs.GetText(id) ?? string.Empty);
            }

            DocumentType type = hs.GetDocumentTypeForId(id);

            if (cache != null && context != null && cache.IsCached(MakeCacheKey(hs, id, context)))
            {
                return(cache.GetCachedString(MakeCacheKey(hs, id, context)));
            }

            IHtmlExporter exporter;

            if (!converters.TryGetValue(type, out exporter))
            {
                return(MakeHtmlError(string.Format("Input type '{0}' not supported",
                                                   type.ToString())));
            }
            var result = hs.IsGeneratedContent(id) ?
                         exporter.Export(hs.GetCachedText(id), context) :
                         exporter.Export(hs.GetCachedHelpStream(id), context);

            if (cache != null)
            {
                cache.CacheText(MakeCacheKey(hs, id, context), result);
            }
            return(result);
        }
Пример #2
0
        public string Generate(HelpSource hs, string id)
        {
            if (hs == null || string.IsNullOrEmpty(id))
            {
                return(MakeHtmlError("Your request has found no candidate provider"));
            }
            var cache = defaultCache ?? hs.Cache;

            if (cache != null && cache.IsCached(MakeCacheKey(hs, id, null)))
            {
                return(cache.GetCachedString(MakeCacheKey(hs, id, null)));
            }

            IEnumerable <string> parts;

            if (hs.IsMultiPart(id, out parts))
            {
                return(GenerateMultiPart(hs, parts, id));
            }

            if (hs.IsRawContent(id))
            {
                return(hs.GetText(id) ?? string.Empty);
            }

            Dictionary <string, string> extraParams = null;
            DocumentType type = hs.GetDocumentTypeForId(id, out extraParams);

            if (cache != null && extraParams != null && cache.IsCached(MakeCacheKey(hs, id, extraParams)))
            {
                return(cache.GetCachedString(MakeCacheKey(hs, id, extraParams)));
            }

            IHtmlExporter exporter;

            if (!converters.TryGetValue(type, out exporter))
            {
                return(MakeHtmlError(string.Format("Input type '{0}' not supported",
                                                   type.ToString())));
            }
            var result = hs.IsGeneratedContent(id) ?
                         exporter.Export(hs.GetCachedText(id), extraParams) :
                         exporter.Export(hs.GetCachedHelpStream(id), extraParams);

            if (cache != null)
            {
                cache.CacheText(MakeCacheKey(hs, id, extraParams), result);
            }
            return(result);
        }