コード例 #1
0
        public static bool GenerateSummaryFile(string workDir, Config configuration, ILog log)
        {
            FsPath source = new FsPath(workDir, ".chapters");

            if (source.IsExisting)
            {
                log.Info(".chapters file doesn't exist.");
                return(false);
            }

            StringBuilder buffer = new StringBuilder();

            List <Chapter>?chapters = source.DeserializeYaml <List <Chapter> >(log);

            if (chapters == null)
            {
                log.Detail(".chapters file reading failed. Bad markup?");
                return(false);
            }

            ConvertChaptersToMarkdown(workDir, log, buffer, chapters);

            FsPath destination = new FsPath(workDir, configuration.TOCFile);

            if (destination.IsExisting)
            {
                destination.CreateBackup(log);
            }
            destination.WriteFile(log, buffer.ToString());

            return(true);
        }
コード例 #2
0
        public void RunStep(RuntimeSettings settings, ILog log)
        {
            log.Info("Creating epub file from contents...");
            FsPath output = settings.OutputDirectory.Combine("book.epub");
            FsPath input  = settings.OutputDirectory.Combine("epubtemp");

            output.WriteFile(log, "");

            string[] files = input.GetAllFiles().Select(f => f.ToString()).ToArray();

            int removeLength = input.ToString().Length + 1;

            using (var fs = File.Create(output.ToString()))
            {
                using (var zip = new ZipArchive(fs, ZipArchiveMode.Create))
                {
                    //note: 1st entry is mimetype. It must not be compressed for correct epub export
                    zip.CreateEntryFromFile(files[0], GetEntryName(files[0], removeLength), CompressionLevel.NoCompression);
                    for (int i = 1; i < files.Length; i++)
                    {
                        zip.CreateEntryFromFile(files[i], GetEntryName(files[i], removeLength), CompressionLevel.Optimal);
                    }
                }
            }
        }
コード例 #3
0
        public override bool Execute(string[] arguments)
        {
            var args = new InstallPsArguments();

            if (!ArgumentParser.ParseArguments(arguments, args))
            {
                return(false);
            }


            FsPath target = new FsPath(args.Files[0]);

            StringBuilder contents = new StringBuilder(4096);

            if (args.Dotnet)
            {
                var dnc = ResourceHandler.GetResourceFile <KnownFile>("Powershell/completer.dn.ps1");
                contents.Append(dnc);
            }

            var completer = ResourceHandler.GetResourceFile <KnownFile>("Powershell/completer.ps1");

            contents.Append(completer);

            target.WriteFile(CurrentState.Log, contents.ToString());

            return(true);
        }
コード例 #4
0
ファイル: PagegenModule.cs プロジェクト: shuizhugeju/BookGen
        private void RunChapterSummary(RuntimeSettings settings, ILog log)
        {
            var stopwordsFile = settings.SourceDirectory.Combine(settings.Configuration.StopwordsFile);

            if (!stopwordsFile.IsExisting)
            {
                log.Critical("Stopwords file specified in config doesn't exist.");
                return;
            }

            List <string> stopwords = ReadStopWords(stopwordsFile);

            if (stopwords.Count < 1)
            {
                log.Warning("Stopwords file doesn't contain words. Output may be unusable.");
                stopwords.Add(" "); //add a single space as fallback;
            }

            var    chapterSummerizer = new ChapterSummarizer(stopwords);
            string?content           = chapterSummerizer.RunStep(settings, log);

            log.Info("Writing file: chaptersummary.md...");
            FsPath output = settings.SourceDirectory.Combine("chaptersummary.md");

            output.WriteFile(log, content);
        }
コード例 #5
0
        public override bool Execute(string[] arguments)
        {
            var args = new InstallPsArguments();

            if (!ArgumentParser.ParseArguments(arguments, args))
            {
                return(false);
            }


            ILog   log    = new ConsoleLog(LogLevel.Info);
            FsPath target = new FsPath(args.Files[0]);

            StringBuilder contents = new StringBuilder(4096);

            if (args.Dotnet)
            {
                var dnc = ResourceHandler.GetResourceFile <GeneratorRunner>("Resources/completer.dn.ps1");
                contents.Append(dnc);
            }

            var completer = ResourceHandler.GetResourceFile <GeneratorRunner>("Resources/completer.ps1");

            contents.Append(completer);

            target.WriteFile(log, contents.ToString());

            return(true);
        }
コード例 #6
0
        public void EnsureThat_FsUtils_WriteFile_Fails_PathNotCorrect(string path)
        {
            var file = new FsPath(path);

            bool result = file.WriteFile(TestEnvironment.GetMockedLog(), "hello");

            Assert.IsFalse(result);
        }
コード例 #7
0
ファイル: Php.cs プロジェクト: webmaster442/BookGen
        protected override void SerializeHostInfo(string scriptPath)
        {
            FsPath     hostinfo = new FsPath(scriptPath, "hostinfo.php");
            ScriptHost host     = new ScriptHost(_settings, _log);
            var        content  = JsonInliner.InlinePhp(nameof(host), host);

            hostinfo.WriteFile(_log, content);
        }
コード例 #8
0
ファイル: PagegenModule.cs プロジェクト: shuizhugeju/BookGen
        private void RunGetLinks(RuntimeSettings settings, ILog log)
        {
            var    generator = new GetLinksGenerator();
            string?content   = generator.RunStep(settings, log);

            log.Info("Writing file: links.md...");
            FsPath output = settings.SourceDirectory.Combine("links.md");

            output.WriteFile(log, content);
        }
コード例 #9
0
        public void EnsureThat_FsUtils_WriteFile_CreatesFile()
        {
            var file = new FsPath(_testDir, "test.txt");

            file.WriteFile(TestEnvironment.GetMockedLog(), "test");

            Assert.IsTrue(file.IsExisting);

            var content = File.ReadAllText(Path.Combine(_testDir, "test.txt"));

            Assert.AreEqual("test", content);
        }
コード例 #10
0
        public void RunStep(RuntimeSettings settings, ILog log)
        {
            log.Info("Generating pages.js...");
            List <string> pages = new List <string>();

            foreach (var file in settings.TocContents.Files)
            {
                pages.Add(settings.Configuration.HostName + Path.ChangeExtension(file, ".html"));
            }
            FsPath target = settings.OutputDirectory.Combine("pages.js");

            string javaScript = JsonInliner.InlineJs("pages", pages);

            target.WriteFile(log, javaScript);
        }
コード例 #11
0
        public string Generate(IArguments arguments)
        {
            var file = new FsPath(arguments.GetArgumentOrThrow <string>("file"));

            _log.Info("Trying to execute {0}", file);

            var nodeProgram = ProcessInterop.AppendExecutableExtension(processName);

            string?programPath = ProcessInterop.ResolveProgramFullPath(nodeProgram);

            if (programPath == null)
            {
                _log.Warning("{0} was not found on path.", processName);
                return($"{processName} was not found on path");
            }

            StringBuilder script = new StringBuilder(16 * 1024);

            script.AppendLine(SerializeHostInfo());
            script.AppendLine(file.ReadFile(_log));

            var temp = new FsPath(Path.GetTempFileName());

            temp.WriteFile(_log, script.ToString());

            var(exitcode, output) = ProcessInterop.RunProcess("node", temp.ToString(), ScriptTimeOut);

            if (temp.IsExisting)
            {
                File.Delete(temp.ToString());
            }

            if (exitcode != 0)
            {
                _log.Warning("Script run failed. Exit code: {0}", exitcode);
                _log.Detail("Script output: {0}", output);
                return($"Script run failed: {temp}");
            }
            else
            {
                return(output);
            }
        }