Beispiel #1
0
        protected override FileModel LoadArticle(FileAndType file, ImmutableDictionary <string, object> metadata)
        {
            var filePath = Path.Combine(file.BaseDir, file.File);
            var swagger  = SwaggerJsonParser.Parse(filePath);

            swagger.Metadata[DocumentTypeKey] = RestApiDocumentType;
            swagger.Raw = EnvironmentContext.FileAbstractLayer.ReadAllText(filePath);
            CheckOperationId(swagger, file.File);

            var repoInfo = GitUtility.TryGetFileDetail(filePath);

            if (repoInfo != null)
            {
                swagger.Metadata["source"] = new SourceDetail()
                {
                    Remote = repoInfo
                };
            }

            swagger.Metadata = MergeMetadata(swagger.Metadata, metadata);
            var vm = SwaggerModelConverter.FromSwaggerModel(swagger);

            vm.Metadata[Constants.PropertyName.SystemKeys] = SystemKeys;
            var displayLocalPath = PathUtility.MakeRelativePath(EnvironmentContext.BaseDirectory, file.FullPath);

            return(new FileModel(file, vm, serializer: 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(),
                LocalPathFromRoot = displayLocalPath
            });
        }
Beispiel #2
0
        private static OverwriteDocumentModel TransformModel(string filePath, YamlHtmlPart part)
        {
            if (part == null)
            {
                return(null);
            }

            var    properties = part.YamlHeader;
            string checkPropertyMessage;
            var    checkPropertyStatus = CheckRequiredProperties(properties, RequiredProperties, out checkPropertyMessage);

            if (!checkPropertyStatus)
            {
                throw new InvalidDataException(checkPropertyMessage);
            }

            var overriden = RemoveRequiredProperties(properties, RequiredProperties);
            var repoInfo  = GitUtility.TryGetFileDetail(filePath);

            return(new OverwriteDocumentModel
            {
                Uid = properties[Constants.PropertyName.Uid].ToString(),
                LinkToFiles = part.LinkToFiles.ToImmutableHashSet(),
                LinkToUids = part.LinkToUids,
                Metadata = overriden,
                Conceptual = part.Conceptual,
                Documentation = new SourceDetail
                {
                    Remote = repoInfo,
                    StartLine = part.StartLine,
                    EndLine = part.EndLine,
                    Path = part.SourceFile
                }
            });
        }
Beispiel #3
0
        public override FileModel Load(FileAndType file, ImmutableDictionary <string, object> metadata)
        {
            var filePath = file.FullPath;
            var toc      = TocHelper.LoadSingleToc(filePath);

            var repoDetail       = GitUtility.TryGetFileDetail(filePath);
            var displayLocalPath = PathUtility.MakeRelativePath(EnvironmentContext.BaseDirectory, file.FullPath);

            // todo : metadata.
            return(new FileModel(file, toc)
            {
                Uids = new[] { new UidDefinition(file.File, displayLocalPath) }.ToImmutableArray(),
                LocalPathFromRoot = displayLocalPath
            });
        }
Beispiel #4
0
        public static Dictionary <string, object> ReadMarkdownAsConceptual(string baseDir, string file)
        {
            var filePath = Path.Combine(baseDir, file);
            var repoInfo = GitUtility.TryGetFileDetail(filePath);

            return(new Dictionary <string, object>
            {
                [Constants.PropertyName.Conceptual] = File.ReadAllText(filePath),
                [Constants.PropertyName.Type] = "Conceptual",
                [Constants.PropertyName.Source] = new SourceDetail {
                    Remote = repoInfo
                },
                [Constants.PropertyName.Path] = file,
            });
        }
Beispiel #5
0
        public static Dictionary <string, object> ReadMarkdownAsConceptual(string file)
        {
            var filePath = EnvironmentContext.FileAbstractLayer.GetPhysicalPath(file);
            var repoInfo = GitUtility.TryGetFileDetail(filePath);

            return(new Dictionary <string, object>
            {
                [Constants.PropertyName.Conceptual] = EnvironmentContext.FileAbstractLayer.ReadAllText(file),
                [Constants.PropertyName.Type] = "Conceptual",
                [Constants.PropertyName.Source] = new SourceDetail {
                    Remote = repoInfo
                },
                [Constants.PropertyName.Path] = file,
            });
        }
Beispiel #6
0
        private static void MergeGitContributeToConfig(BuildJsonConfig config)
        {
            var repoInfoFromBaseDirectory = GitUtility.TryGetFileDetail(Path.Combine(Directory.GetCurrentDirectory(), config.BaseDirectory));

            if (repoInfoFromBaseDirectory?.RelativePath != null)
            {
                repoInfoFromBaseDirectory.RelativePath = Path.Combine(repoInfoFromBaseDirectory.RelativePath, DocAsCode.Constants.DefaultOverwriteFolderName);
            }
            object gitRespositoryOpenToPublicContributors;

            if (config.GlobalMetadata.TryGetValue("_gitContribute", out gitRespositoryOpenToPublicContributors))
            {
                GitDetail repoInfo;
                try
                {
                    repoInfo = JObject.FromObject(gitRespositoryOpenToPublicContributors).ToObject <GitDetail>();
                }
                catch (Exception e)
                {
                    throw new DocumentException($"Unable to convert _gitContribute to GitDetail in globalMetadata: {e.Message}", e);
                }
                if (repoInfoFromBaseDirectory != null)
                {
                    if (repoInfo.RelativePath == null)
                    {
                        repoInfo.RelativePath = repoInfoFromBaseDirectory.RelativePath;
                    }
                    if (repoInfo.RemoteBranch == null)
                    {
                        repoInfo.RemoteBranch = repoInfoFromBaseDirectory.RemoteBranch;
                    }
                    if (repoInfo.RemoteRepositoryUrl == null)
                    {
                        repoInfo.RemoteRepositoryUrl = repoInfoFromBaseDirectory.RemoteRepositoryUrl;
                    }
                }
                config.GlobalMetadata["_gitContribute"] = repoInfo;
            }
            else
            {
                config.GlobalMetadata["_gitContribute"] = repoInfoFromBaseDirectory;
            }
        }
        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;
                CheckOperationId(swagger, file.File);

                var repoInfo = GitUtility.TryGetFileDetail(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 ?? StringExtension.ToDisplayPath(filePath),
                    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();
            }
        }
Beispiel #8
0
        public static SourceDetail GetSourceDetail(ISymbol symbol)
        {
            // For namespace, definition is meaningless
            if (symbol == null || symbol.Kind == SymbolKind.Namespace)
            {
                return(null);
            }

            var syntaxRef = symbol.DeclaringSyntaxReferences.LastOrDefault();

            if (symbol.IsExtern || syntaxRef == null)
            {
                return(new SourceDetail
                {
                    IsExternalPath = true,
                    Path = symbol.ContainingAssembly?.Name,
                });
            }

            var syntaxNode = syntaxRef.GetSyntax();

            Debug.Assert(syntaxNode != null);
            if (syntaxNode != null)
            {
                var source = new SourceDetail
                {
                    StartLine = syntaxNode.SyntaxTree.GetLineSpan(syntaxNode.Span).StartLinePosition.Line,
                    Path      = syntaxNode.SyntaxTree.FilePath,
                    Name      = symbol.Name
                };

                source.Remote = GitUtility.TryGetFileDetail(source.Path);
                if (source.Remote != null)
                {
                    source.Path = PathUtility.FormatPath(source.Path, UriKind.Relative, EnvironmentContext.BaseDirectory);
                }
                return(source);
            }

            return(null);
        }
        public override FileModel Load(FileAndType file, ImmutableDictionary <string, object> metadata)
        {
            var filePath = file.FullPath;
            var toc      = TocHelper.LoadSingleToc(filePath);

            var repoDetail       = GitUtility.TryGetFileDetail(filePath);
            var displayLocalPath = PathUtility.MakeRelativePath(EnvironmentContext.BaseDirectory, file.FullPath);

            // Apply metadata to TOC
            foreach (var pair in metadata)
            {
                if (!toc.Metadata.TryGetValue(pair.Key, out var val))
                {
                    toc.Metadata[pair.Key] = pair.Value;
                }
            }

            return(new FileModel(file, toc)
            {
                LocalPathFromRoot = displayLocalPath
            });
        }
Beispiel #10
0
        private static OverwriteDocumentModel TransformModel(string filePath, YamlHtmlPart part)
        {
            if (part == null)
            {
                return(null);
            }

            var properties          = part.YamlHeader;
            var checkPropertyStatus = CheckRequiredProperties(properties, RequiredProperties, out string checkPropertyMessage);

            if (!checkPropertyStatus)
            {
                throw new InvalidDataException(checkPropertyMessage);
            }

            var overriden = RemoveRequiredProperties(properties, RequiredProperties);
            var repoInfo  = GitUtility.TryGetFileDetail(filePath);

            return(new OverwriteDocumentModel
            {
                Uid = properties[Constants.PropertyName.Uid].ToString(),
                LinkToFiles = new HashSet <string>(part.LinkToFiles),
                LinkToUids = new HashSet <string>(part.LinkToUids),
                FileLinkSources = part.FileLinkSources.ToDictionary(p => p.Key, p => p.Value.ToList()),
                UidLinkSources = part.UidLinkSources.ToDictionary(p => p.Key, p => p.Value.ToList()),
                Metadata = overriden,
                Conceptual = part.Conceptual,
                Documentation = new SourceDetail
                {
                    Remote = repoInfo,
                    StartLine = part.StartLine,
                    EndLine = part.EndLine,
                    Path = part.SourceFile
                },
                Dependency = part.Origin.Dependency
            });
        }
Beispiel #11
0
        public void Environment_ForBranchName()
        {
            var info = GitUtility.TryGetFileDetail(Directory.GetCurrentDirectory());

            Assert.Equal("special-branch", info.RemoteBranch);
        }