예제 #1
0
 public static void DoCreateMdFiles(ILog log, FsPath workdir)
 {
     log.Info("Creating index.md...");
     ResourceHandler.ExtractKnownFile(KnownFile.IndexMd, workdir.ToString(), log);
     log.Info("Creating Summary.md...");
     ResourceHandler.ExtractKnownFile(KnownFile.SummaryMd, workdir.ToString(), log);
 }
예제 #2
0
        private void InlineImage(FsPath file, RuntimeSettings settings, SKData data, string?extensionOverride)
        {
            string base64 = Convert.ToBase64String(data.ToArray());
            string mime   = Framework.Server.MimeTypes.GetMimeForExtension(file.Extension);
            string fnmame = file.ToString();

            if (extensionOverride != null)
            {
                mime   = Framework.Server.MimeTypes.GetMimeForExtension(extensionOverride);
                fnmame = Path.ChangeExtension(file.ToString(), extensionOverride);
            }

            string key = fnmame.Replace(settings.SourceDirectory.ToString(), settings.OutputDirectory.ToString());

            settings.InlineImgCache.TryAdd(key, $"data:{mime};base64,{base64}");
        }
예제 #3
0
        public static SKData EncodeSvg(FsPath svgFile, int maxWidht, int maxHeight, SKEncodedImageFormat format = SKEncodedImageFormat.Png)
        {
            var svg = new SKSvg();

            svg.Load(svgFile.ToString());

            if (svg.Picture == null)
            {
                return(SKData.Empty);
            }

            SKRect svgSize = svg.Picture.CullRect;

            (int renderWidth, int renderHeight, float scale)sizeData = CalcNewSize(svgSize, maxWidht, maxHeight);

            var matrix = SKMatrix.CreateScale(sizeData.scale, sizeData.scale);

            using (SKBitmap bitmap = new SKBitmap(sizeData.renderWidth, sizeData.renderHeight))
            {
                using (SKCanvas canvas = new SKCanvas(bitmap))
                {
                    canvas.DrawPicture(svg.Picture, ref matrix);
                    canvas.Flush();
                }

                using (SKImage image = SKImage.FromBitmap(bitmap))
                {
                    return(image.Encode(format, 100));
                }
            }
        }
예제 #4
0
 public void Upload(FsLocalPath src_path, FsPath dest_path, FileUploadParameters parameters)
 {
     this.RestClients.FileSystemClient.FileSystem.UploadFile(
         this.Account.Name,
         src_path.ToString(),
         dest_path.ToString(), parameters.NumThreads, parameters.Resume, parameters.Overwrite, parameters.UploadAsBinary);
 }
예제 #5
0
        public void SetFileExpiryAbsolute(StoreAccount account, FsPath path, System.DateTimeOffset expiretime)
        {
            var ut        = new FsUnixTime(expiretime);
            var unix_time = ut.MillisecondsSinceEpoch;

            this.RestClient.FileSystem.SetFileExpiry(account.Name, path.ToString(), ExpiryOptionType.Absolute, unix_time);
        }
예제 #6
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);
                    }
                }
            }
        }
예제 #7
0
        public FsAcl GetAclStatus(StoreAccount store, FsPath path)
        {
            var acl_result = this.RestClient.FileSystem.GetAclStatus(store.Name, path.ToString());
            var acl_status = acl_result.AclStatus;

            var fs_acl = new FsAcl(acl_status);

            return(fs_acl);
        }
예제 #8
0
        public static FsPath Combine(FsPath left, FsPath right)
        {
            if (right.IsRooted)
            {
                throw new System.ArgumentException(nameof(right));
            }


            if (left.EndsWithSeparator)
            {
                var p = new FsPath(left.ToString() + right.ToString());
                return(p);
            }
            else
            {
                var p = new FsPath(left.ToString() + "/" + right.ToString());
                return(p);
            }
        }
예제 #9
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);
            }
        }
예제 #10
0
        public void Document(FsPath assembly, FsPath xmlFile, FsPath outputDir)
        {
            IEnumerable <Type> documentableTypes = GetDocumentableTypes(assembly);
            XElement           documentation     = XElement.Load(xmlFile.ToString());

            foreach (var type in documentableTypes)
            {
                _log.Info("Documenting type: {0}", type.FullName);
                DocumentType(type, documentation, outputDir);
            }
        }
예제 #11
0
        public void FSPath_Constructor_Root()
        {
            var p0 = new FsPath("/");

            Assert.AreEqual("/", p0.ToString());

            var p1 = FsPath.Root;

            Assert.AreEqual("/", p1.ToString());

            Assert.AreEqual(p1.ToString(), p1.ToString());
        }
예제 #12
0
        public void FSPath_Constructor_Combine_Unrooted()
        {
            var p0 = new FsPath("test");
            var p1 = p0.Append("foo");
            var p2 = p0.Append("foo/bar");

            Assert.AreEqual("test", p0.ToString());
            Assert.AreEqual("test/foo", p1.ToString());
            Assert.AreEqual("test/foo/bar", p2.ToString());
            Assert.IsFalse(p0.IsRooted);
            Assert.IsFalse(p1.IsRooted);
            Assert.IsFalse(p2.IsRooted);
        }
예제 #13
0
        public static void DoCreateConfig(ILog log,
                                          FsPath ConfigFile,
                                          bool createdmdFiles,
                                          bool extractedTemplate,
                                          bool createdScript)
        {
            Config configuration = Config.CreateDefault(Program.CurrentState.ConfigVersion);

            if (createdmdFiles)
            {
                configuration.Index   = "index.md";
                configuration.TOCFile = "summary.md";
            }

            if (createdScript)
            {
                configuration.ScriptsDirectory = "Scripts";
            }

            if (extractedTemplate)
            {
                configuration.TargetEpub.TemplateFile  = EpubTemplateLocation;
                configuration.TargetPrint.TemplateFile = PrintTemplateLocation;
                configuration.TargetWeb.TemplateFile   = WebTemplate;
                configuration.TargetWeb.TemplateAssets = new List <Asset>
                {
                    new Asset
                    {
                        Source = "Templates\\Assets\\prism.css",
                        Target = "Assets\\prism.css"
                    },
                    new Asset
                    {
                        Source = "Templates\\Assets\\prism.js",
                        Target = "Assets\\prism.js"
                    }
                };
            }

            log.Info("Creating config file: {0}", ConfigFile.ToString());
            ConfigFile.SerializeJson(configuration, log);
        }
예제 #14
0
        private List <string> ReadStopWords(FsPath stopwordsFile)
        {
            string?       line    = null;
            List <string> results = new List <string>(100);

            using (var textreader = System.IO.File.OpenText(stopwordsFile.ToString()))
            {
                do
                {
                    line = textreader.ReadLine();
                    if (line != null &&
                        !line.StartsWith("#"))
                    {
                        results.Add(line);
                    }
                }while (line != null);
            }

            return(results);
        }
예제 #15
0
        public static void CleanDirectory(FsPath outputDirectory, ILog log)
        {
            DirectoryInfo di = new DirectoryInfo(outputDirectory.ToString());

            if (!di.Exists)
            {
                log.Warning("Directory doesn't exist: {0}", outputDirectory);
                return;
            }
            foreach (var file in di.GetFiles())
            {
                log.Detail("Deleting: {0}", file);
                file.Delete();
            }

            foreach (var dir in di.GetDirectories())
            {
                log.Detail("Deleting: {0}", dir);
                dir.Delete(true);
            }
        }
        public IEnumerable <FsFileStatusPage> ListFilesPaged(AdlClient.Models.StoreAccountRef account, FsPath path, FileListingParameters parameters)
        {
            string after = null;

            while (true)
            {
                var result = RestClient.FileSystem.ListFileStatus(account.Name, path.ToString(), parameters.PageSize, after);

                if (result.FileStatuses.FileStatus.Count > 0)
                {
                    var page = new FsFileStatusPage();
                    page.Path = path;

                    page.FileItems = result.FileStatuses.FileStatus.Select(i => new FsFileStatus(i)).ToList();
                    yield return(page);

                    after = result.FileStatuses.FileStatus[result.FileStatuses.FileStatus.Count - 1].PathSuffix;
                }
                else
                {
                    break;
                }
            }
        }
예제 #17
0
        public IEnumerable <FsFileStatusPage> ListFilesPaged(StoreAccount store, FsPath path, ListFilesOptions options)
        {
            string after = null;

            while (true)
            {
                var result = RestClient.FileSystem.ListFileStatus(store.Name, path.ToString(), options.PageSize, after);

                if (result.FileStatuses.FileStatus.Count > 0)
                {
                    var page = new FsFileStatusPage();
                    page.Path = path;

                    page.FileItems = result.FileStatuses.FileStatus.Select(i => new FsFileStatus(i)).ToList();
                    yield return(page);

                    after = result.FileStatuses.FileStatus[result.FileStatuses.FileStatus.Count - 1].PathSuffix;
                }
                else
                {
                    break;
                }
            }
        }
예제 #18
0
        public void SetAcl(StoreAccount store, FsPath path, IEnumerable <FsAclEntry> entries)
        {
            var s = FsAclEntry.EntriesToString(entries);

            this.RestClient.FileSystem.SetAcl(store.Name, path.ToString(), s);
        }
예제 #19
0
 public void RemoveDefaultAcl(StoreAccount store, FsPath path)
 {
     this.RestClient.FileSystem.RemoveDefaultAcl(store.Name, path.ToString());
 }
예제 #20
0
        public ContentSummary GetContentSummary(StoreAccount store, FsPath path)
        {
            var summary = this.RestClient.FileSystem.GetContentSummary(store.Name, path.ToString());

            return(summary.ContentSummary);
        }
예제 #21
0
 public void ModifyAclEntries(StoreAccount store, FsPath path, FsAclEntry entry)
 {
     this.RestClient.FileSystem.ModifyAclEntries(store.Name, path.ToString(), entry.ToString());
 }
예제 #22
0
        public FsFileStatus GetFileStatus(StoreAccount store, FsPath path)
        {
            var info = RestClient.FileSystem.GetFileStatus(store.Name, path.ToString());

            return(new FsFileStatus(info.FileStatus));
        }
예제 #23
0
 public void Create(StoreAccount store, FsPath path, System.IO.Stream streamContents, CreateFileOptions options)
 {
     RestClient.FileSystem.Create(store.Name, path.ToString(), streamContents, options.Overwrite);
 }
예제 #24
0
 public void Move(StoreAccount store, FsPath src_path, FsPath dest_path)
 {
     this.RestClient.FileSystem.Rename(store.Name, src_path.ToString(), dest_path.ToString());
 }
예제 #25
0
        public void Concat(StoreAccount store, IEnumerable <FsPath> src_paths, FsPath dest_path)
        {
            var src_file_strings = src_paths.Select(i => i.ToString()).ToList();

            this.RestClient.FileSystem.Concat(store.Name, dest_path.ToString(), src_file_strings);
        }
예제 #26
0
 public System.IO.Stream Open(StoreAccount store, FsPath path)
 {
     return(this.RestClient.FileSystem.Open(store.Name, path.ToString()));
 }
예제 #27
0
 public System.IO.Stream Open(StoreAccount store, FsPath path, long offset, long bytesToRead)
 {
     return(this.RestClient.FileSystem.Open(store.Name, path.ToString(), bytesToRead, offset));
 }
예제 #28
0
 public void Mkdirs(StoreAccount store, FsPath path)
 {
     var result = RestClient.FileSystem.Mkdirs(store.Name, path.ToString());
 }
예제 #29
0
 public void SetOwner(StoreAccount store, FsPath path, string owner, string group)
 {
     this.RestClient.FileSystem.SetOwner(store.Name, path.ToString(), owner, group);
 }
예제 #30
0
 public void Delete(StoreAccount store, FsPath path, bool recursive)
 {
     var result = RestClient.FileSystem.Delete(store.Name, path.ToString(), recursive);
 }