Ejemplo n.º 1
0
        private IEnumerable <IDocumentProcessor> LoadSchemaDrivenDocumentProcessors(DocumentBuildParameters parameter)
        {
            using (var resource = parameter?.TemplateManager?.CreateTemplateResource())
            {
                if (resource == null || resource.IsEmpty)
                {
                    yield break;
                }

                foreach (var pair in resource.GetResourceStreams(@"^schemas/.*\.schema\.json"))
                {
                    var fileName = Path.GetFileName(pair.Key);
                    using (new LoggerFileScope(fileName))
                    {
                        using (var stream = pair.Value)
                        {
                            using (var sr = new StreamReader(stream))
                            {
                                var schema = DocumentSchema.Load(sr, fileName.Remove(fileName.Length - ".schema.json".Length));
                                var sdp    = new SchemaDrivenDocumentProcessor(schema, new CompositionContainer(CompositionContainer.DefaultContainer));
                                Logger.LogVerbose($"\t{sdp.Name} with build steps ({string.Join(", ", from bs in sdp.BuildSteps orderby bs.BuildOrder select bs.Name)})");
                                yield return(sdp);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private List <IDocumentProcessor> LoadSchemaDrivenDocumentProcessors(DocumentBuildParameters parameter)
        {
            using (new LoggerPhaseScope(nameof(LoadSchemaDrivenDocumentProcessors)))
            {
                var result = new List <IDocumentProcessor>();

                SchemaValidateService.RegisterLicense(parameter.SchemaLicense);
                using (var resource = parameter?.TemplateManager?.CreateTemplateResource())
                {
                    if (resource == null || resource.IsEmpty)
                    {
                        return(result);
                    }

                    var markdigMarkdownService = CreateMarkdigMarkdownService(parameter);
                    foreach (var pair in resource.GetResourceStreams(@"^schemas/.*\.schema\.json"))
                    {
                        var fileName = Path.GetFileName(pair.Key);
                        using (new LoggerFileScope(fileName))
                        {
                            using (var stream = pair.Value)
                            {
                                using (var sr = new StreamReader(stream))
                                {
                                    DocumentSchema schema;
                                    try
                                    {
                                        schema = DocumentSchema.Load(sr, fileName.Remove(fileName.Length - ".schema.json".Length));
                                    }
                                    catch (Exception e)
                                    {
                                        Logger.LogError(e.Message);
                                        throw;
                                    }
                                    var sdp = new SchemaDrivenDocumentProcessor(
                                        schema,
                                        new CompositionContainer(CompositionContainer.DefaultContainer),
                                        markdigMarkdownService,
                                        new FolderRedirectionManager(parameter.OverwriteFragmentsRedirectionRules));
                                    Logger.LogVerbose($"\t{sdp.Name} with build steps ({string.Join(", ", from bs in sdp.BuildSteps orderby bs.BuildOrder select bs.Name)})");
                                    result.Add(sdp);
                                }
                            }
                        }
                    }
                }

                if (result.Count > 0)
                {
                    Logger.LogInfo($"{result.Count} schema driven document processor plug-in(s) loaded.");
                    Processors = Processors.Union(result);
                }
                return(result);
            }
        }