Exemple #1
0
        public void RunProcedure(VerbRenderOpts opts)
        {
            string docPath = Path.GetFullPath(opts.entryFile);

            logger.LogInfo($"Start rendering...");
            AssemblyInjectionManager injectionManager = new AssemblyInjectionManager();

            injectionManager.RegisterAssembly("PonyTextRenderer.Pdf", Assembly.GetAssembly(typeof(PdfRenderer)));
            injectionManager.RegisterAssembly("PonyText.Processor", Assembly.GetAssembly(typeof(PonyTextFactory)));

            IProcessorFactory processor         = new ProcessorFactory(injectionManager);
            SimpleTextContext simpleTextContext = new SimpleTextContext(processor);

            processor.LoadProcessorFrom("PonyText.Processor");

            PonyTextStructureBase structureBase = PonyTextFactory.CreateEvaluable(docPath, simpleTextContext);

            try{
                structureBase.Evaluate(simpleTextContext);

                PdfRenderer pdfRenderer = new PdfRenderer(simpleTextContext);
                simpleTextContext.GetCurrentContext().Render(pdfRenderer, simpleTextContext);

                using (FileStream fs = new FileStream(opts.outputFile, FileMode.Create)) {
                    pdfRenderer.RenderContentTo(fs);
                }
                logger.LogInfo($"Exported to {opts.outputFile}");
            }
            catch (Exception e) {
                logger.LogError(e.Message);
                if (e is PreProcessorException)
                {
                    PreProcessorException ppe = e as PreProcessorException;
                    foreach (var item in ppe.GetPonyTextStackTrace())
                    {
                        logger.LogError(item);
                    }
                }
                logger.LogError($"Error in file {docPath}");
                logger.LogDebug(e.StackTrace);
            }
        }
Exemple #2
0
 public void Preporcess(PonyTextContext context, PonyTextStructureBase[] args)
 {
     ctx = context;
     try {
         ProcessorParam?.ValidateParameter(args);
         OnPreProcessInternal(args);
     }
     catch (Exception e) {
         if (e is PreProcessorException)
         {
             PreProcessorException ppe = (PreProcessorException)e;
             ppe.AddToStackTrace(PreProcessTrace.CreateTrace(ProcessorAttribute.ProcessorName));
             throw ppe;
         }
         else
         {
             throw new PreProcessorException(ProcessorAttribute.ProcessorName, e.Message);
         }
     }
 }