示例#1
0
        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)
        {
            if (file.Type != DocumentType.Article)
            {
                throw new NotSupportedException();
            }
            var content = MarkdownReader.ReadMarkdownAsConceptual(file.BaseDir, file.File);

            foreach (var item in metadata)
            {
                if (!content.ContainsKey(item.Key))
                {
                    content[item.Key] = item.Value;
                }
            }
            return(new FileModel(
                       file,
                       content,
                       serializer: new BinaryFormatter())
            {
                LocalPathFromRepoRoot = (content["source"] as SourceDetail)?.Remote?.RelativePath
            });
        }
示例#3
0
        public static FileModel Read(FileAndType file)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            if (file.Type != DocumentType.Overwrite)
            {
                throw new NotSupportedException(file.Type.ToString());
            }

            var overwrites = MarkdownReader.ReadMarkdownAsOverwrite(file.BaseDir, file.File);

            if (overwrites == null || overwrites.Count == 0)
            {
                return(null);
            }

            var displayLocalPath = overwrites[0].Documentation?.Remote?.RelativePath ?? Path.Combine(file.BaseDir, file.File).ToDisplayPath();

            return(new FileModel(file, overwrites, serializer: new BinaryFormatter())
            {
                Uids = (from item in overwrites
                        select new UidDefinition(
                            item.Uid,
                            displayLocalPath,
                            item.Documentation.StartLine + 1
                            )).ToImmutableArray(),
                Properties =
                {
                    LinkToFiles = new HashSet <string>(),
                    LinkToUids  = new HashSet <string>(),
                },
                LocalPathFromRepoRoot = displayLocalPath,
            });
        }
示例#4
0
        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();
            }
        }
示例#5
0
        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();
            }
        }