Exemplo n.º 1
0
        public static void ProtectDirectory(this FsPath directory, ILog log)
        {
            var           outp = directory.Combine("index.html");
            StringBuilder sb   = new StringBuilder(4096);

            for (int i = 0; i < 256; i++)
            {
                sb.Append("                ");
            }
            outp.WriteFile(log, sb.ToString());
        }
Exemplo n.º 2
0
 public static string GetSRI(FsPath path)
 {
     using (var fs = File.OpenRead(path.ToString()))
     {
         using (var hashAlgorithm = new SHA384Managed())
         {
             byte[] hash = hashAlgorithm.ComputeHash(fs);
             return("sha384-" + Convert.ToBase64String(hash));
         }
     }
 }
Exemplo n.º 3
0
        public static FileStream CreateStream(this FsPath target, ILog log)
        {
            var dir = Path.GetDirectoryName(target.ToString()) ?? string.Empty;

            if (!Directory.Exists(dir))
            {
                log.Detail("Creating directory: {0}", dir);
                Directory.CreateDirectory(dir);
            }

            return(File.Create(target.ToString()));
        }
Exemplo n.º 4
0
 public static string ReadFile(this FsPath path, ILog log)
 {
     try
     {
         using (var reader = File.OpenText(path.ToString()))
         {
             return(reader.ReadToEnd());
         }
     }
     catch (Exception ex)
     {
         log.Warning("ReadFile failed: {0}", path);
         log.Detail(ex.Message);
         return(string.Empty);
     }
 }
Exemplo n.º 5
0
        private void ValidateBuildConfig(FsPath WorkDirectory, BuildConfig target)
        {
            if (target == null)
            {
                AddError(Resources.MissingSection);
                return;
            }

            if (!string.IsNullOrEmpty(target.TemplateFile) &&
                !WorkDirectory.Combine(target.TemplateFile).IsExisting)
            {
                AddError(Resources.MissingTemplateFile, target.TemplateFile);
            }

            if (target.TemplateAssets == null)
            {
                AddError(Resources.MissingAssets);
            }
            else
            {
                foreach (var asset in target.TemplateAssets)
                {
                    var source = WorkDirectory.Combine(asset.Source);

                    if (!source.IsExisting)
                    {
                        AddError(Resources.MissingAsset, source.ToString());
                    }
                }
            }

            if (target.StyleClasses == null)
            {
                AddError(Resources.MissingStyleClasses);
            }

            ValidateImageOptions(target.ImageOptions);
        }
Exemplo n.º 6
0
 public static bool CreateDir(this FsPath path, ILog log)
 {
     try
     {
         log.Detail("Creating directory: {0}", path);
         if (!FsPath.IsEmptyPath(path))
         {
             Directory.CreateDirectory(path.ToString());
             return(true);
         }
         else
         {
             log.Warning("CreateDir called with empty input path");
             return(false);
         }
     }
     catch (Exception ex)
     {
         log.Warning("CreateDir failed: {0}", path);
         log.Detail(ex.Message);
         return(false);
     }
 }
Exemplo n.º 7
0
 public TocValidator(ITableOfContents toc, string workdir)
 {
     _toc     = toc;
     _workdir = new FsPath(workdir);
 }
Exemplo n.º 8
0
        public override void Validate()
        {
            if (Errors.Count > 0)
            {
                Errors.Clear();
            }

            var WorkDirectory = new FsPath(_workdir);

            switch (ValidationLevel)
            {
            case ValidateFor.Epub:
                ValidateBuildConfig(WorkDirectory, _config.TargetEpub);
                break;

            case ValidateFor.Print:
                ValidateBuildConfig(WorkDirectory, _config.TargetPrint);
                break;

            case ValidateFor.Web:
                ValidateBuildConfig(WorkDirectory, _config.TargetWeb);
                break;

            case ValidateFor.All:
                ValidateBuildConfig(WorkDirectory, _config.TargetEpub);
                ValidateBuildConfig(WorkDirectory, _config.TargetPrint);
                ValidateBuildConfig(WorkDirectory, _config.TargetWeb);
                break;
            }

            if (!string.IsNullOrEmpty(_config.ImageDir) && !WorkDirectory.Combine(_config.ImageDir).IsExisting)
            {
                AddError(Resources.MissingImageDir, _config.ImageDir);
            }

            if (!WorkDirectory.Combine(_config.TOCFile).IsExisting)
            {
                AddError(Resources.MissingTocFile, _config.TOCFile);
            }

            if (string.IsNullOrEmpty(_config.HostName))
            {
                AddError(Resources.MissingHostName);
            }
            else if (!_config.HostName.EndsWith("/"))
            {
                AddError(Resources.MissingTrailingSlash);
            }

            if (string.IsNullOrEmpty(_config.Index))
            {
                AddError(Resources.MissingIndex);
            }

            if (_config.Translations == null)
            {
                AddError(Resources.MissingTranslations);
            }
            if (_config.Metadata == null)
            {
                AddError(Resources.MissingMetadata);
            }
        }
Exemplo n.º 9
0
 public static bool SerializeXml <T>(this FsPath path, T obj, ILog log, IList <(string prefix, string namespac)>?nslist = null) where T : class, new()