Ejemplo n.º 1
0
        public void TestHashFex()
        {
            //arrange
            var configModel      = TestHelper.GetConfigModel();
            var metaDataService1 = new MetaDataService(configModel, TestHelper.GetInputFilePath("simple.fex"));
            var metaDataService2 = new MetaDataService(configModel, TestHelper.GetInputFilePath("advanced.fex"));

            //act
            var metaData1 = metaDataService1.Process();
            var metaData2 = metaDataService2.Process();

            //assert
            Assert.AreNotEqual(metaData1.Hash, metaData2.Hash);
        }
Ejemplo n.º 2
0
        protected override void TestFex(string fileName)
        {
            //arrange
            var configModel     = TestHelper.GetConfigModel();
            var metaDataService = new MetaDataService(configModel, TestHelper.GetInputFilePath(fileName));

            //act
            var metaData = metaDataService.Process();

            //assert
            Assert.AreEqual(metaData.Title, fileName.Substring(0, fileName.Length - 4));
            Assert.AreEqual(metaData.Author, configModel.Author);
            Assert.IsTrue(!string.IsNullOrEmpty(metaData.Hash));
            Assert.IsTrue(metaData.ChangedAt > DateTime.MinValue);
            Assert.IsTrue(metaData.GeneratedAt > DateTime.Today);
        }
Ejemplo n.º 3
0
        private bool?CompileFile(string path)
        {
            (string folder, string filenamePrefix, string[] exportFormats) = ParsePath(path);

            //get version information
            var metaDataService   = new MetaDataService(_configModel, path);
            var metaData          = metaDataService.Process();
            var fexVersionService = new FexVersionService(metaData, folder, filenamePrefix);

            if (fexVersionService.NoChangesNeeded())
            {
                return(null);
            }

            var document = new DocumentModel()
            {
                MetaDataModel = metaData
            };

            //read out file
            StepStarted("read out lines");
            document.RawLines = _fileService.ReadFile(path);
            StepCompleted();

            //convert to fexLines
            StepStarted("parsing lines");
            var fexService = new FexService(document.RawLines);

            document.FexLines = fexService.Process();
            StepCompleted();

            //create statistic
            StepStarted("gathering statistics");
            var statisticService = new StatisticService(document.FexLines);

            document.StatisticModel = statisticService.Process();
            StepCompleted();

            //convert to content
            StepStarted("processing content");
            var contentService = new ContentService(document.FexLines);

            document.RootSection = contentService.Process();
            StepCompleted();

            var successful = true;

            if (exportFormats.Contains("json") || exportFormats.Contains("xlsx"))
            {
                //learning cards create
                StepStarted("creating learning cards");
                var learningCardsService = new GenerationService(document.StatisticModel, document.MetaDataModel,
                                                                 document.RootSection.Children);
                var cards = learningCardsService.Process();
                StepCompleted();

                if (exportFormats.Contains("json"))
                {
                    //learning cards persist
                    StepStarted("persisting learning cards (json)");
                    var learningCardsExportService = new JsonExportService(cards, folder, filenamePrefix);
                    var learningCardsFeedback      = learningCardsExportService.Process();
                    StepCompleted(learningCardsFeedback);

                    successful &= learningCardsFeedback;
                }

                if (exportFormats.Contains("xlsx"))
                {
                    //learning cards persist
                    StepStarted("persisting learning cards (xlsx)");
                    var learningCardsExportService = new XlsxExportService(cards, folder, filenamePrefix);
                    var learningCardsFeedback      = learningCardsExportService.Process();
                    StepCompleted(learningCardsFeedback);

                    successful &= learningCardsFeedback;
                }
            }

            if (exportFormats.Contains("md"))
            {
                //latex create
                StepStarted("creating & storing markdown");
                var markdownService = new Services.Markdown.ExportService(document.RootSection.Children,
                                                                          document.MetaDataModel.Title, folder, filenamePrefix);
                var markdownFeedback = markdownService.Process();
                StepCompleted();

                successful &= markdownFeedback;
            }

            if (exportFormats.Contains("pdf") || exportFormats.Contains("handout_pdf"))
            {
                //latex create
                StepStarted("creating latex");
                var latexService = new Services.Latex.GenerationService(document.RootSection.Children);
                var latex        = latexService.Process();
                StepCompleted();

                if (exportFormats.Contains("pdf"))
                {
                    //latex template
                    StepStarted("preparing PDF template");
                    var latexTemplateService = new TemplateService(latex, document.StatisticModel, document.MetaDataModel,
                                                                   TemplateService.DefaultTemplate);
                    var templatedLatex = latexTemplateService.Process();
                    StepCompleted();

                    //latex compile
                    StepStarted("compiling PDF latex");
                    var latexCompilerService = new CompilationService(templatedLatex, folder, filenamePrefix);
                    var latexCompileFeedback = latexCompilerService.Process();
                    StepCompleted(latexCompileFeedback);

                    successful &= latexCompileFeedback;
                }

                if (exportFormats.Contains("handout_pdf"))
                {
                    //latex template
                    StepStarted("preparing handout PDF template");
                    var latexTemplateService = new TemplateService(latex, document.StatisticModel, document.MetaDataModel,
                                                                   TemplateService.HandoutTemplate);
                    var templatedLatex = latexTemplateService.Process();
                    StepCompleted();

                    //latex compile
                    StepStarted("compiling handout PDF latex");
                    var latexCompilerService = new CompilationService(templatedLatex, folder, filenamePrefix + "_handout");
                    var latexCompileFeedback = latexCompilerService.Process();
                    StepCompleted(latexCompileFeedback);

                    successful &= latexCompileFeedback;
                }
            }

            if (successful)
            {
                StepStarted("saving version information");
                fexVersionService.MarkFexCompileSuccessful();
                StepCompleted();
            }

            return(successful);
        }