Example #1
0
        public SystemMetadata Generate(InternalManifestItem item)
        {
            var attrs = new SystemMetadata
            {
                Language = Constants.DefaultLanguage,
            };

            string key = GetFileKey(item.Key);

            attrs.Key = ((RelativePath)key).RemoveWorkingFolder();
            var file = (RelativePath)(item.FileWithoutExtension + item.Extension);

            attrs.RelativePathToRoot = (RelativePath.Empty).MakeRelativeTo(file);
            var fileWithoutWorkingFolder = file.RemoveWorkingFolder();

            attrs.Path = fileWithoutWorkingFolder;

            if (!string.IsNullOrEmpty(_context.VersionName))
            {
                attrs.VersionName   = _context.VersionName;
                attrs.VersionFolder = _context.VersionFolder;
            }

            // 1. Root Toc is specified by RootTocKey, or by default in the top directory of output folder
            if (!string.IsNullOrEmpty(_context.RootTocPath))
            {
                attrs.RootTocKey = _context.RootTocPath;
                var rootTocPath = ((RelativePath)_context.RootTocPath).RemoveWorkingFolder();
                attrs.RootTocPath           = rootTocPath;
                attrs.RelativePathToRootToc = rootTocPath.MakeRelativeTo(file);
            }
            else
            {
                GetRootTocFromOutputRoot(attrs, file);
            }

            // 2. The algorithm of toc current article belongs to:
            //    a. If toc can be found in TocMap, return that toc
            //    b. Elsewise, get the nearest toc, **nearest** means nearest toc in **OUTPUT** folder
            var parentTocFiles = _context.GetTocFileKeySet(key)?.Select(s => new FileInfo(s, (RelativePath)_context.GetFilePath(s)));
            var parentToc      = GetNearestToc(parentTocFiles, file) ?? GetDefaultToc(key);

            if (parentToc != null)
            {
                var parentTocPath = parentToc.File.RemoveWorkingFolder();
                attrs.TocPath = parentTocPath;
                var tocRelativePath = parentTocPath.MakeRelativeTo(file);
                attrs.RelativePathToToc = tocRelativePath;
                attrs.TocKey            = parentToc.Key;
                Logger.LogDiagnostic($"TOC file {parentTocPath} is found for {item.LocalPathFromRoot}.");
            }
            else
            {
                Logger.LogDiagnostic($"TOC file for {item.LocalPathFromRoot} is not found.");
            }

            return(attrs);
        }
Example #2
0
        public SystemMetadata Generate(InternalManifestItem item)
        {
            var attrs = new SystemMetadata
            {
                Language = Constants.DefaultLanguage,
            };

            string key  = GetFileKey(item.Key);
            var    file = (TypeForwardedToRelativePath)(item.FileWithoutExtension + item.Extension);

            attrs.RelativePathToRoot = (TypeForwardedToRelativePath.Empty).MakeRelativeTo(file);
            var fileWithoutWorkingFolder = file.RemoveWorkingFolder();

            attrs.Path = fileWithoutWorkingFolder;

            // 1. Root Toc is always in the top directory of output folder
            var rootToc = _toc.FirstOrDefault();

            if (rootToc != null)
            {
                var rootTocPath = rootToc.File.RemoveWorkingFolder();
                if (rootTocPath.SubdirectoryCount == 0)
                {
                    attrs.RootTocPath = rootTocPath;
                    var rootTocRelativePath = rootTocPath.MakeRelativeTo(file);
                    attrs.RelativePathToRootToc = rootTocRelativePath;
                    attrs.RootTocKey            = rootToc.Key;
                    Logger.LogVerbose($"Root TOC file {rootTocPath} is found.");
                }
                else
                {
                    Logger.LogVerbose($"Root TOC file from output folder is not found, the toppest TOC file is {rootTocPath}");
                }
            }

            // 2. The algorithm of toc current article belongs to:
            //    a. If toc can be found in TocMap, return that toc
            //    b. Elsewise, get the nearest toc, **nearest** means nearest toc in **OUTPUT** folder
            var parentTocFiles = _context.GetTocFileKeySet(key)?.Select(s => new FileInfo(s, (TypeForwardedToRelativePath)_context.GetFilePath(s)));
            var parentToc      = GetNearestToc(parentTocFiles, file) ?? GetDefaultToc(key);

            if (parentToc != null)
            {
                var parentTocPath = parentToc.File.RemoveWorkingFolder();
                attrs.TocPath = parentTocPath;
                var tocRelativePath = parentTocPath.MakeRelativeTo(file);
                attrs.RelativePathToToc = tocRelativePath;
                attrs.TocKey            = parentToc.Key;
                Logger.LogVerbose($"TOC file {parentTocPath} is found for {item.LocalPathFromRoot}.");
            }
            else
            {
                Logger.LogVerbose($"TOC file for {item.LocalPathFromRoot} is not found.");
            }

            return(attrs);
        }
Example #3
0
        public SystemMetadata Generate(InternalManifestItem item)
        {
            var attrs = new SystemMetadata
            {
                Language = Constants.DefaultLanguage,
            };

            string key = GetFileKey(item.Key);
            var file = (TypeForwardedToRelativePath)(item.FileWithoutExtension + item.Extension);

            attrs.RelativePathToRoot = (TypeForwardedToRelativePath.Empty).MakeRelativeTo(file);
            var fileWithoutWorkingFolder = file.RemoveWorkingFolder();
            attrs.Path = fileWithoutWorkingFolder;

            // 1. Root Toc is always in the top directory of output folder
            var rootToc = _toc.FirstOrDefault();
            if (rootToc != null)
            {
                var rootTocPath = rootToc.File.RemoveWorkingFolder();
                if (rootTocPath.SubdirectoryCount == 0)
                {
                    attrs.RootTocPath = rootTocPath;
                    var rootTocRelativePath = rootTocPath.MakeRelativeTo(file);
                    attrs.RelativePathToRootToc = rootTocRelativePath;
                    attrs.RootTocKey = rootToc.Key;
                    Logger.LogVerbose($"Root TOC file {rootTocPath} is found.");
                }
                else
                {
                    Logger.LogVerbose($"Root TOC file from output folder is not found, the toppest TOC file is {rootTocPath}");
                }
            }

            // 2. The algorithm of toc current article belongs to:
            //    a. If toc can be found in TocMap, return that toc
            //    b. Elsewise, get the nearest toc, **nearest** means nearest toc in **OUTPUT** folder
            var parentTocFiles = _context.GetTocFileKeySet(key)?.Select(s => new FileInfo(s, (TypeForwardedToRelativePath)_context.GetFilePath(s)));
            var parentToc = GetNearestToc(parentTocFiles, file) ?? GetDefaultToc(key);

            if (parentToc != null)
            {
                var parentTocPath = parentToc.File.RemoveWorkingFolder();
                attrs.TocPath = parentTocPath;
                var tocRelativePath = parentTocPath.MakeRelativeTo(file);
                attrs.RelativePathToToc = tocRelativePath;
                attrs.TocKey = parentToc.Key;
                Logger.LogVerbose($"TOC file {parentTocPath} is found for {item.LocalPathFromRoot}.");
            }
            else
            {
                Logger.LogVerbose($"TOC file for {item.LocalPathFromRoot} is not found.");
            }

            return attrs;
        }
Example #4
0
 private void GetRootTocFromOutputRoot(SystemMetadata attrs, RelativePath file)
 {
     var rootToc = _toc.FirstOrDefault();
     if (rootToc != null)
     {
         var rootTocPath = rootToc.File.RemoveWorkingFolder();
         if (rootTocPath.SubdirectoryCount == 0)
         {
             attrs.RootTocPath = rootTocPath;
             var rootTocRelativePath = rootTocPath.MakeRelativeTo(file);
             attrs.RelativePathToRootToc = rootTocRelativePath;
             attrs.RootTocKey = rootToc.Key;
             Logger.LogVerbose($"Root TOC file {rootTocPath} is found.");
         }
         else
         {
             Logger.LogVerbose(
                 $"Root TOC file from output folder is not found, the toppest TOC file is {rootTocPath}");
         }
     }
 }
Example #5
0
        private void GetRootTocFromOutputRoot(SystemMetadata attrs, RelativePath file)
        {
            var rootToc = _toc.FirstOrDefault();

            if (rootToc != null)
            {
                var rootTocPath = rootToc.File.RemoveWorkingFolder();
                if (rootTocPath.SubdirectoryCount == 0)
                {
                    attrs.RootTocPath = rootTocPath;
                    var rootTocRelativePath = rootTocPath.MakeRelativeTo(file);
                    attrs.RelativePathToRootToc = rootTocRelativePath;
                    attrs.RootTocKey            = rootToc.Key;
                    Logger.LogDiagnostic($"Root TOC file {rootTocPath} is found.");
                }
                else
                {
                    Logger.LogDiagnostic(
                        $"Root TOC file from output folder is not found, the toppest TOC file is {rootTocPath}");
                }
            }
        }