public override FileModel Load(FileAndType file, ImmutableDictionary<string, object> metadata) { switch (file.Type) { case DocumentType.Article: var filePath = Path.Combine(file.BaseDir, file.File); var swaggerContent = File.ReadAllText(filePath); var swagger = SwaggerJsonParser.Parse(swaggerContent); swagger.Metadata[DocumentTypeKey] = RestApiDocumentType; swagger.Raw = swaggerContent; var repoInfo = GitUtility.GetGitDetail(filePath); if (repoInfo != null) { swagger.Metadata["source"] = new SourceDetail() { Remote = repoInfo }; } swagger.Metadata = MergeMetadata(swagger.Metadata, metadata); var vm = SwaggerModelConverter.FromSwaggerModel(swagger); var displayLocalPath = PathUtility.MakeRelativePath(EnvironmentContext.BaseDirectory, file.FullPath); return new FileModel(file, vm, serializer: Environment.Is64BitProcess ? null : new BinaryFormatter()) { Uids = new[] { new UidDefinition(vm.Uid, displayLocalPath) } .Concat(from item in vm.Children select new UidDefinition(item.Uid, displayLocalPath)) .Concat(from tag in vm.Tags select new UidDefinition(tag.Uid, displayLocalPath)).ToImmutableArray(), LocalPathFromRepoRoot = repoInfo?.RelativePath ?? filePath.ToDisplayPath(), LocalPathFromRoot = displayLocalPath }; case DocumentType.Overwrite: // TODO: Refactor current behavior that overwrite file is read multiple times by multiple processors return OverwriteDocumentReader.Read(file); default: throw new NotSupportedException(); } }
public override FileModel Load(FileAndType file, ImmutableDictionary <string, object> metadata) { switch (file.Type) { case DocumentType.Article: // TODO: Support dynamic in YAML deserializer try { // MUST be a dictionary var obj = YamlUtility.Deserialize <Dictionary <string, object> >(file.File); // Validate against the schema first // Temporarily disable schema validation as Json.NET schema has limitation of 1000 calls per hour // TODO: Reenable schema validation // _schemaValidator.Validate(obj); var content = ConvertToObjectHelper.ConvertToDynamic(obj); var pageMetadata = _schema.MetadataReference.GetValue(content) as IDictionary <string, object>; if (pageMetadata == null) { pageMetadata = new ExpandoObject(); _schema.MetadataReference.SetValue(ref content, pageMetadata); } foreach (var pair in metadata) { if (!pageMetadata.ContainsKey(pair.Key)) { pageMetadata[pair.Key] = pair.Value; } } var localPathFromRoot = PathUtility.MakeRelativePath(EnvironmentContext.BaseDirectory, EnvironmentContext.FileAbstractLayer.GetPhysicalPath(file.File)); var fm = new FileModel( file, content, serializer: new BinaryFormatter()) { LocalPathFromRoot = localPathFromRoot, }; fm.Properties.Schema = _schema; fm.Properties.Metadata = pageMetadata; return(fm); } catch (YamlDotNet.Core.YamlException e) { throw new DocumentException($"{file.File} is not in supported format: {e.Message}", e); } case DocumentType.Overwrite: return(OverwriteDocumentReader.Read(file)); default: throw new NotSupportedException(); } }
public override FileModel Load(FileAndType file, ImmutableDictionary <string, object> metadata) { switch (file.Type) { case DocumentType.Article: var page = YamlUtility.Deserialize <PageViewModel>(Path.Combine(file.BaseDir, file.File)); if (page.Items == null || page.Items.Count == 0) { return(null); } if (page.Metadata == null) { page.Metadata = metadata.ToDictionary(p => p.Key, p => p.Value); } else { foreach (var item in metadata) { if (!page.Metadata.ContainsKey(item.Key)) { page.Metadata[item.Key] = item.Value; } } } var filePath = Path.Combine(file.BaseDir, file.File); var displayLocalPath = filePath.ToDisplayPath(); object baseDirectory; if (metadata.TryGetValue("baseRepositoryDirectory", out baseDirectory)) { displayLocalPath = PathUtility.MakeRelativePath((string)baseDirectory, filePath); } return(new FileModel(file, page, serializer: new BinaryFormatter()) { Uids = (from item in page.Items select new UidDefinition(item.Uid, displayLocalPath)).ToImmutableArray(), Properties = { LinkToFiles = new HashSet <string>(), LinkToUids = new HashSet <string>(), }, LocalPathFromRepoRoot = displayLocalPath, }); case DocumentType.Overwrite: // TODO: Refactor current behavior that overwrite file is read multiple times by multiple processors return(OverwriteDocumentReader.Read(file)); default: throw new NotSupportedException(); } }
public override FileModel Load(FileAndType file, ImmutableDictionary <string, object> metadata) { switch (file.Type) { case DocumentType.Article: // TODO: Support dynamic in YAML deserializer try { // MUST be a dictionary var obj = YamlUtility.Deserialize <Dictionary <string, object> >(file.File); foreach (var pair in metadata) { if (!obj.ContainsKey(pair.Key)) { obj[pair.Key] = pair.Value; } } var content = ConvertToObjectHelper.ConvertToDynamic(obj); var localPathFromRoot = PathUtility.MakeRelativePath(EnvironmentContext.BaseDirectory, EnvironmentContext.FileAbstractLayer.GetPhysicalPath(file.File)); var fm = new FileModel( file, content, serializer: new BinaryFormatter()) { LocalPathFromRoot = localPathFromRoot, }; fm.Properties.Schema = _schema; return(fm); } catch (YamlDotNet.Core.YamlException e) { throw new DocumentException($"{file.File} is not in supported format: {e.Message}", e); } case DocumentType.Overwrite: return(OverwriteDocumentReader.Read(file)); default: throw new NotSupportedException(); } }
public override FileModel Load(FileAndType file, ImmutableDictionary <string, object> metadata) { switch (file.Type) { case DocumentType.Article: var page = YamlUtility.Deserialize <PageViewModel>(Path.Combine(file.BaseDir, file.File)); if (page.Metadata == null) { page.Metadata = metadata.ToDictionary(p => p.Key, p => p.Value); } else { foreach (var item in metadata) { if (!page.Metadata.ContainsKey(item.Key)) { page.Metadata[item.Key] = item.Value; } } } // Item's source is the path for the original code, should not be used here var displayLocalPath = Path.Combine(file.BaseDir, file.File).ToDisplayPath(); return(new FileModel(file, page, serializer: new BinaryFormatter()) { Uids = (from item in page.Items select new UidDefinition(item.Uid, displayLocalPath)).ToImmutableArray(), Properties = { LinkToFiles = new HashSet <string>(), LinkToUids = new HashSet <string>(), }, LocalPathFromRepoRoot = displayLocalPath, }); case DocumentType.Overwrite: // TODO: Refactor current behavior that overwrite file is read multiple times by multiple processors return(OverwriteDocumentReader.Read(file)); default: throw new NotSupportedException(); } }
public override FileModel Load(FileAndType file, ImmutableDictionary <string, object> metadata) { switch (file.Type) { case DocumentType.Article: var page = YamlUtility.Deserialize <PageViewModel>(Path.Combine(file.BaseDir, file.File)); if (page.Items == null || page.Items.Count == 0) { return(null); } if (page.Metadata == null) { page.Metadata = metadata.ToDictionary(p => p.Key, p => p.Value); } else { foreach (var item in metadata) { if (!page.Metadata.ContainsKey(item.Key)) { page.Metadata[item.Key] = item.Value; } } } var displayLocalPath = TypeForwardedToPathUtility.MakeRelativePath(EnvironmentContext.BaseDirectory, file.FullPath); return(new FileModel(file, page, serializer: Environment.Is64BitProcess?null: new BinaryFormatter()) { Uids = (from item in page.Items select new UidDefinition(item.Uid, displayLocalPath)).ToImmutableArray(), LocalPathFromRepoRoot = displayLocalPath, LocalPathFromRoot = displayLocalPath }); case DocumentType.Overwrite: // TODO: Refactor current behavior that overwrite file is read multiple times by multiple processors return(OverwriteDocumentReader.Read(file)); default: throw new NotSupportedException(); } }
public override FileModel Load(FileAndType file, ImmutableDictionary <string, object> metadata) { switch (file.Type) { case DocumentType.Article: // TODO: Support dynamic in YAML deserializer try { // MUST be a dictionary var obj = YamlUtility.Deserialize <Dictionary <string, object> >(file.File); // Validate against the schema first _schemaValidator.Validate(obj); // load overwrite segments string markdownFragmentsContent = null; var markdownFragmentsFile = file.File + ".md"; if (EnvironmentContext.FileAbstractLayer.Exists(markdownFragmentsFile)) { markdownFragmentsContent = EnvironmentContext.FileAbstractLayer.ReadAllText(markdownFragmentsFile); } var content = ConvertToObjectHelper.ConvertToDynamic(obj); var pageMetadata = _schema.MetadataReference.GetValue(content) as IDictionary <string, object>; if (pageMetadata == null) { pageMetadata = new ExpandoObject(); _schema.MetadataReference.SetValue(ref content, pageMetadata); } foreach (var pair in metadata) { if (!pageMetadata.ContainsKey(pair.Key)) { pageMetadata[pair.Key] = pair.Value; } } var localPathFromRoot = PathUtility.MakeRelativePath(EnvironmentContext.BaseDirectory, EnvironmentContext.FileAbstractLayer.GetPhysicalPath(file.File)); var fm = new FileModel( file, content, serializer: new BinaryFormatter()) { LocalPathFromRoot = localPathFromRoot, }; if (markdownFragmentsContent != null) { fm.MarkdownFragmentsModel = new FileModel( file, markdownFragmentsContent, new FileAndType( file.BaseDir, markdownFragmentsFile, DocumentType.MarkdownFragments, file.SourceDir, file.DestinationDir), new BinaryFormatter()) { LocalPathFromRoot = PathUtility.MakeRelativePath( EnvironmentContext.BaseDirectory, EnvironmentContext.FileAbstractLayer.GetPhysicalPath(markdownFragmentsFile)) }; fm.MarkdownFragmentsModel.Properties.MarkdigMarkdownService = _markdigMarkdownService; } fm.Properties.Schema = _schema; fm.Properties.Metadata = pageMetadata; return(fm); } catch (YamlDotNet.Core.YamlException e) { throw new DocumentException($"{file.File} is not in supported format: {e.Message}", e); } case DocumentType.Overwrite: return(OverwriteDocumentReader.Read(file)); default: throw new NotSupportedException(); } }