コード例 #1
0
 public static MethodDefinition FromRequest(string request, CodeBlockAnnotation annotation, DocFile source)
 {
     var method = new MethodDefinition
     {
         Request = request,
         RequestMetadata = annotation,
         Identifier = annotation.MethodName,
         SourceFile = source
     };
     method.Title = method.Identifier;
     return method;
 }
コード例 #2
0
        public ExampleDefinition(CodeBlockAnnotation annotation, string content, DocFile source, string language)
        {
            if (string.IsNullOrEmpty(language))
                throw new ArgumentNullException("language");

            this.Metadata = annotation;
            this.SourceExample = content;
            this.SourceFile = source;

            switch (language.ToLower())
            {
                case "json":
                    {
                        this.Language = CodeLanguage.Json;
                        try
                        {
                            object inputObject = JsonConvert.DeserializeObject(content);
                            this.ParsedExample = JsonConvert.SerializeObject(inputObject, Formatting.Indented);
                        }
                        catch (Exception ex)
                        {
                            Logging.LogMessage(
                                new ValidationError(
                                    ValidationErrorCode.JsonParserException,
                                    source.DisplayName,
                                    "Error parsing resource definition: {0}",
                                    ex.Message));
                        }
                        break;
                    }
                case "http":
                    this.ParsedExample = this.SourceExample;
                    this.Language = CodeLanguage.Http;
                    break;
                default:
                    this.Language = CodeLanguage.Unsupported;
                    Logging.LogMessage(
                        new ValidationError(
                            ValidationErrorCode.UnsupportedLanguage,
                            source.DisplayName,
                            "The code language for this example is unuspported: {0}", language));
                    break;
            }
        }
コード例 #3
0
        public ResourceDefinition(CodeBlockAnnotation annotation, string content, DocFile source, string language)
        {
            if (null != language && !language.Equals("json", StringComparison.OrdinalIgnoreCase))
            {
                throw new ArgumentException("Resources only support JSON language.", "language");
            }

            this.Metadata = annotation;
            this.OriginalExample = content;
            this.SourceFile = source;

            try
            {
                object inputObject = JsonConvert.DeserializeObject(content);
                this.JsonExample = JsonConvert.SerializeObject(inputObject, Formatting.Indented);
            }
            catch (Exception ex)
            {
                Logging.LogMessage(
                    new ValidationError(
                        ValidationErrorCode.JsonParserException,
                        source.DisplayName,
                        "Error parsing resource definition: {0}",
                        ex.Message));
                throw;
            }

            if (string.IsNullOrEmpty(annotation.ResourceType))
            {
                Logging.LogMessage(
                    new ValidationError(
                        ValidationErrorCode.MissingResourceName,
                        source.DisplayName,
                        "Resource definition is missing a @odata.type name"));
            }
        }
コード例 #4
0
        /// <summary>
        /// Apply the HTML template to the parameters and write the file to the destination.
        /// </summary>
        /// <param name="bodyHtml"></param>
        /// <param name="page"></param>
        /// <param name="destinationFile"></param>
        /// <param name="rootDestinationFolder"></param>
        /// <returns></returns>
        protected virtual async Task WriteHtmlDocumentAsync(string bodyHtml, DocFile page, string destinationFile, string rootDestinationFolder)
        {
            List<string> variablesToReplace = new List<string>();
            string pageHtml = null;
            if (this.TemplateHtml != null)
            {
                var matches = ExtensionMethods.PathVariableRegex.Matches(this.TemplateHtml);
                variablesToReplace.AddRange(from Match match in matches select match.Groups[0].Value);

                string templateHtmlForThisPage = this.TemplateHtml;

                foreach (var key in variablesToReplace.ToArray())
                {
                    if (key == "{page.title}")
                    {
                        templateHtmlForThisPage = templateHtmlForThisPage.Replace(key, page.Annotation.Title);
                    }
                    else if (key == "{body.html}")
                    {
                        templateHtmlForThisPage = templateHtmlForThisPage.Replace(key, bodyHtml);
                    }
                    else if (key.StartsWith("{if "))
                    {
                        string value = this.ParseDocumentIfStatement(key, destinationFile);
                        templateHtmlForThisPage = templateHtmlForThisPage.Replace(key, value);
                    }
                    else
                    {
                        string filename = key.Substring(1, key.Length - 2);
                        string value = DocSet.RelativePathToRootFromFile(destinationFile, Path.Combine(rootDestinationFolder, filename), true);
                        templateHtmlForThisPage = templateHtmlForThisPage.Replace(key, value);
                    }
                }

                pageHtml = templateHtmlForThisPage;
            }
            else
            {
                pageHtml = string.Concat(string.Format(HtmlHeader, page.Annotation.Title, HtmlStyles), bodyHtml, HtmlFooter);
            }

            pageHtml = await this.ConvertLineEndingsAsync(pageHtml, this.OutputLineEndings);
            using (var outputWriter = new StreamWriter(destinationFile))
            {
                await outputWriter.WriteAsync(pageHtml);
            }
        }
コード例 #5
0
        protected override async Task PublishFileToDestinationAsync(FileInfo sourceFile, DirectoryInfo destinationRoot, DocFile page)
        {
            this.LogMessage(new ValidationMessage(sourceFile.Name, "Publishing file to HTML"));

            var destinationPath = this.GetPublishedFilePath(sourceFile, destinationRoot, HtmlOutputExtension);

            // Create a tag processor
            string tagsInput = PageParameters.ValueForKey<string>("tags", StringComparison.OrdinalIgnoreCase) ?? string.Empty;

            TagProcessor tagProcessor = new TagProcessor(tagsInput,
                page.Parent.SourceFolderPath, LogMessage);

            var converter = this.GetMarkdownConverter();
            var html = converter.Transform(tagProcessor.Preprocess(sourceFile));
            html = await tagProcessor.PostProcess(html, sourceFile, converter);

            var pageData = page.Annotation ?? new PageAnnotation();
            if (string.IsNullOrEmpty(pageData.Title))
            {
               pageData.Title = (from b in converter.Blocks
                             where b.BlockType == BlockType.h1
                             select b.Content).FirstOrDefault();
            }
            page.Annotation = pageData;
            await this.WriteHtmlDocumentAsync(html, page, destinationPath, destinationRoot.FullName);
        }
コード例 #6
0
 public JsonResourceDefinition(CodeBlockAnnotation sourceAnnotation, string json, DocFile source)
     : base(sourceAnnotation, json, source, "json")
 {
     ParseJsonInput();
 }
コード例 #7
0
        protected ResourceDefinition(CodeBlockAnnotation sourceAnnotation, string content, DocFile source, string language)
        {
            this.sourceAnnotation = sourceAnnotation;
            this.OriginalExampleText = content;
            this.SourceFile = source;
            this.Name = sourceAnnotation.ResourceType;
            this.KeyPropertyName = sourceAnnotation.KeyPropertyName;

            if (string.IsNullOrEmpty(sourceAnnotation.ResourceType))
            {
                Logging.LogMessage(
                    new ValidationError(
                        ValidationErrorCode.MissingResourceName,
                        source.DisplayName,
                        "Resource definition is missing Name value"));
            }
        }
コード例 #8
0
ファイル: DocSet.cs プロジェクト: vjchkins/markdown-scanner
 internal string RelativePathToFile(DocFile file, bool urlStyle = false)
 {
     return(RelativePathToFile(file.FullPath, this.SourceFolderPath, urlStyle));
 }
コード例 #9
0
        public static MethodDefinition FromRequest(string request, CodeBlockAnnotation annotation, DocFile source)
        {
            var method = new MethodDefinition
            {
                Request             = request,
                RequestMetadata     = annotation,
                Identifier          = annotation.MethodName?.FirstOrDefault(),
                SourceFile          = source,
                RequiredScopes      = annotation.RequiredScopes,
                RequiredApiVersions = annotation.RequiredApiVersions,
                RequiredTags        = annotation.RequiredTags
            };

            method.Title = method.Identifier;
            return(method);
        }
コード例 #10
0
        protected override async Task PublishFileToDestinationAsync(FileInfo sourceFile, DirectoryInfo destinationRoot, DocFile page)
        {
            this.LogMessage(new ValidationMessage(sourceFile.Name, "Publishing file to HTML"));

            var destinationPath = this.GetPublishedFilePath(sourceFile, destinationRoot, HtmlOutputExtension);

            StringWriter writer = new StringWriter();
            StreamReader reader = new StreamReader(sourceFile.OpenRead());

            long lineNumber = 0;
            string nextLine;
            while ((nextLine = await reader.ReadLineAsync()) != null)
            {
                lineNumber++;
                if (this.IsDoubleBlockQuote(nextLine))
                {
                    this.LogMessage(new ValidationMessage(string.Concat(sourceFile.Name, ":", lineNumber), "Removing DoubleBlockQuote"));
                    continue;
                }
                await writer.WriteLineAsync(nextLine);
            }

            var converter = this.GetMarkdownConverter();
            var html = converter.Transform(writer.ToString());

            var pageData = page.Annotation ?? new PageAnnotation();
            if (string.IsNullOrEmpty(pageData.Title))
            {
               pageData.Title = (from b in converter.Blocks
                             where b.BlockType == BlockType.h1
                             select b.Content).FirstOrDefault();
            }
            page.Annotation = pageData;
            await this.WriteHtmlDocumentAsync(html, page, destinationPath, destinationRoot.FullName);
        }
コード例 #11
0
        public static MethodDefinition FromRequest(string request, CodeBlockAnnotation annotation, DocFile source)
        {
            var method = new MethodDefinition
            {
                Request         = request,
                RequestMetadata = annotation,
                Identifier      = annotation.MethodName,
                SourceFile      = source
            };

            method.Title = method.Identifier;
            return(method);
        }