Ejemplo n.º 1
0
        // TODO: refactor the return value to TocRootViewModel
        public static TocItemViewModel LoadSingleToc(string file)
        {
            if (string.IsNullOrEmpty(file))
            {
                throw new ArgumentNullException(nameof(file));
            }

            var fileType = Utility.GetTocFileType(file);

            try
            {
                if (fileType == TocFileType.Markdown)
                {
                    return(new TocItemViewModel
                    {
                        Items = MarkdownTocReader.LoadToc(EnvironmentContext.FileAbstractLayer.ReadAllText(file), file)
                    });
                }
                else if (fileType == TocFileType.Yaml)
                {
                    return(LoadYamlToc(file));
                }
            }
            catch (Exception e)
            {
                var message = $"{file} is not a valid TOC File: {e.Message}";
                Logger.LogError(message);
                throw new DocumentException(message, e);
            }

            throw new NotSupportedException($"{file} is not a valid TOC file, supported toc files could be \"{Constants.TableOfContents.MarkdownTocFileName}\" or \"{Constants.TableOfContents.YamlTocFileName}\".");
        }
Ejemplo n.º 2
0
        public static TocViewModel LoadSingleToc(string file)
        {
            var fileType = GetTocFileType(file);

            try
            {
                if (fileType == TocFileType.Markdown)
                {
                    return(MarkdownTocReader.LoadToc(EnvironmentContext.FileAbstractLayer.ReadAllText(file), file));
                }
                else if (fileType == TocFileType.Yaml)
                {
                    return(YamlUtility.Deserialize <TocViewModel>(file));
                }
            }
            catch (Exception e)
            {
                var message = $"{file} is not a valid TOC File: {e.Message}";
                Logger.LogError(message);
                throw new DocumentException(message, e);
            }

            throw new NotSupportedException($"{file} is not a valid TOC file, supported toc files could be \"{Constants.MarkdownTocFileName}\" or \"{Constants.YamlTocFileName}\".");
        }