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; } } } var result = new FileModel(file, page, serializer: new BinaryFormatter()) { Uids = (from item in page.Items select item.Uid).ToImmutableArray(), }; result.Properties.LinkToFiles = new HashSet <string>(); result.Properties.LinkToUids = new HashSet <string>(); return(result); case DocumentType.Override: var overrides = MarkdownReader.ReadMarkdownAsOverride(file.BaseDir, file.File); return(new FileModel(file, overrides, serializer: new BinaryFormatter()) { Uids = (from item in overrides select item.Uid).ToImmutableArray(), Properties = { LinkToFiles = new HashSet <string>(), LinkToUids = new HashSet <string>(), } }); 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.Override: var overrides = MarkdownReader.ReadMarkdownAsOverride <ItemViewModel>(file.BaseDir, file.File); if (overrides == null || overrides.Count == 0) { return(null); } displayLocalPath = overrides[0].Documentation?.Remote?.RelativePath ?? Path.Combine(file.BaseDir, file.File).ToDisplayPath(); return(new FileModel(file, overrides, serializer: new BinaryFormatter()) { Uids = (from item in overrides select new UidDefinition( item.Uid, displayLocalPath, item.Documentation.StartLine + 1 )).ToImmutableArray(), Properties = { LinkToFiles = new HashSet <string>(), LinkToUids = new HashSet <string>(), }, LocalPathFromRepoRoot = displayLocalPath, }); default: throw new NotSupportedException(); } }
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 = GetModelWithoutRef <SwaggerModel>(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 = RestApiItemViewModel.FromSwaggerModel(swagger); var displayLocalPath = repoInfo?.RelativePath ?? Path.Combine(file.BaseDir, file.File).ToDisplayPath(); return(new FileModel(file, vm, serializer: new BinaryFormatter()) { Uids = new UidDefinition[] { new UidDefinition(vm.Uid, displayLocalPath) }.Concat(from item in vm.Children select new UidDefinition(item.Uid, displayLocalPath)).ToImmutableArray(), LocalPathFromRepoRoot = displayLocalPath, Properties = { LinkToFiles = new HashSet <string>(), LinkToUids = new HashSet <string>(), }, }); case DocumentType.Override: var overrides = MarkdownReader.ReadMarkdownAsOverride <RestApiItemViewModel>(file.BaseDir, file.File); if (overrides == null || overrides.Count == 0) { return(null); } displayLocalPath = overrides[0].Documentation?.Remote?.RelativePath ?? Path.Combine(file.BaseDir, file.File).ToDisplayPath(); return(new FileModel(file, overrides, serializer: new BinaryFormatter()) { Uids = (from item in overrides select new UidDefinition( item.Uid, displayLocalPath, item.Documentation.StartLine + 1 )).ToImmutableArray(), Properties = { LinkToFiles = new HashSet <string>(), LinkToUids = new HashSet <string>(), }, LocalPathFromRepoRoot = displayLocalPath, }); default: throw new NotSupportedException(); } }