Esempio n. 1
0
        /// <summary>
        /// Print a list of the methods (request/responses) discovered in the documentation to the console.
        /// </summary>
        /// <param name="options"></param>
        /// <param name="docset"></param>
        /// <returns></returns>
        private static async Task PrintMethodsAsync(DocSetOptions options, DocSet docset)
        {
            docset = docset ?? await GetDocSetAsync(options);

            if (null == docset)
            {
                return;
            }

            FancyConsole.WriteLine();
            FancyConsole.WriteLine(FancyConsole.ConsoleHeaderColor, "Defined methods:");
            FancyConsole.WriteLine();

            foreach (var method in docset.Methods)
            {
                FancyConsole.WriteLine(FancyConsole.ConsoleHeaderColor, "Method '{0}' in file '{1}'", method.Identifier, method.SourceFile.DisplayName);

                var requestMetadata = options.EnableVerboseOutput ? JsonConvert.SerializeObject(method.RequestMetadata) : string.Empty;
                FancyConsole.WriteLineIndented("  ", FancyConsole.ConsoleSubheaderColor, "Request: {0}", requestMetadata);
                FancyConsole.WriteLineIndented("    ", FancyConsole.ConsoleCodeColor, method.Request);

                if (options.EnableVerboseOutput)
                {
                    FancyConsole.WriteLine();
                    var responseMetadata = JsonConvert.SerializeObject(method.ExpectedResponseMetadata);
                    FancyConsole.WriteLineIndented("  ", FancyConsole.ConsoleSubheaderColor, "Expected Response: {0}", responseMetadata);
                    FancyConsole.WriteLineIndented("    ", FancyConsole.ConsoleCodeColor, method.ExpectedResponse);
                    FancyConsole.WriteLine();
                }
                FancyConsole.WriteLine();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Print a list of the resources detected in the documentation set to the console.
        /// </summary>
        /// <param name="options"></param>
        /// <param name="docset"></param>
        /// <returns></returns>
        private static async Task PrintResourcesAsync(DocSetOptions options, DocSet docset)
        {
            docset = docset ?? await GetDocSetAsync(options);

            if (null == docset)
            {
                return;
            }

            FancyConsole.WriteLine();
            FancyConsole.WriteLine(FancyConsole.ConsoleHeaderColor, "Defined resources:");
            FancyConsole.WriteLine();

            var sortedResources = docset.Resources.OrderBy(x => x.ResourceType);

            foreach (var resource in sortedResources)
            {
                if (options.EnableVerboseOutput)
                {
                    string metadata = JsonConvert.SerializeObject(resource.Metadata);
                    FancyConsole.Write("  ");
                    FancyConsole.Write(FancyConsole.ConsoleHeaderColor, resource.ResourceType);
                    FancyConsole.WriteLine(" flags: {1}", resource.ResourceType, metadata);
                }
                else
                {
                    FancyConsole.WriteLineIndented("  ", FancyConsole.ConsoleHeaderColor, resource.ResourceType);
                }

                FancyConsole.WriteLineIndented("    ", FancyConsole.ConsoleCodeColor, resource.JsonExample);
                FancyConsole.WriteLine();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Create and return a document set based on input options
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        private static async Task <DocSet> GetDocSetAsync(DocSetOptions options)
        {
            FancyConsole.VerboseWriteLine("Opening documentation from {0}", options.DocumentationSetPath);
            DocSet set = new DocSet(options.DocumentationSetPath);

            FancyConsole.VerboseWriteLine("Scanning documentation files...");
            ValidationError[] loadErrors;
            if (!set.ScanDocumentation(out loadErrors))
            {
                await WriteOutErrorsAndFinishTestAsync(loadErrors, options.SilenceWarnings);

                return(null);
            }

            return(set);
        }
Esempio n. 4
0
        public static void LoadCurrentConfiguration(DocSetOptions options)
        {
            if (CurrentConfiguration != null)
            {
                return;
            }

            if (null != options)
            {
                var configurationFiles = DocSet.TryLoadConfigurationFiles <AppConfigFile>(options.DocumentationSetPath);
                CurrentConfiguration = configurationFiles.FirstOrDefault();
                if (null != CurrentConfiguration)
                {
                    Console.WriteLine("Using configuration file: {0}", CurrentConfiguration.SourcePath);
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Prints a list of the documentation files in a docset to the console.
        /// </summary>
        /// <param name="options"></param>
        /// <param name="docset"></param>
        /// <returns></returns>
        private static async Task PrintFilesAsync(DocSetOptions options, DocSet docset)
        {
            docset = docset ?? await GetDocSetAsync(options);

            if (null == docset)
            {
                return;
            }


            if (null == docset)
            {
                return;
            }

            FancyConsole.WriteLine();
            FancyConsole.WriteLine(FancyConsole.ConsoleHeaderColor, "Documentation files");

            string format = null;

            if (options.EnableVerboseOutput)
            {
                format = "{1} (resources: {2}, methods: {3})";
            }
            else
            {
                format = "{0} (r:{2}, m:{3})";
            }

            foreach (var file in docset.Files)
            {
                ConsoleColor color = FancyConsole.ConsoleSuccessColor;
                if (file.Resources.Length == 0 && file.Requests.Length == 0)
                {
                    color = FancyConsole.ConsoleWarningColor;
                }

                FancyConsole.WriteLineIndented("  ", color, format, file.DisplayName, file.FullPath, file.Resources.Length, file.Requests.Length);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Verifies that all markdown links inside the documentation are valid. Prints warnings
        /// to the console for any invalid links. Also checks for orphaned documents.
        /// </summary>
        /// <param name="options"></param>
        /// <param name="docs"></param>
        private static async Task <bool> CheckLinksAsync(DocSetOptions options, DocSet docs = null)
        {
            const string testName = "Check-links";
            var          docset   = docs ?? await GetDocSetAsync(options);

            if (null == docset)
            {
                return(false);
            }


            TestReport.StartTest(testName);

            ValidationError[] errors;
            docset.ValidateLinks(options.EnableVerboseOutput, out errors);

            foreach (var error in errors)
            {
                MessageCategory category;
                if (error.IsWarning)
                {
                    category = MessageCategory.Warning;
                }
                else if (error.IsError)
                {
                    category = MessageCategory.Error;
                }
                else
                {
                    category = MessageCategory.Information;
                }

                string message = string.Format("{1}: {0}", error.Message.FirstLineOnly(), error.Code);
                await TestReport.LogMessageAsync(message, category);
            }

            return(await WriteOutErrorsAndFinishTestAsync(errors, options.SilenceWarnings, successMessage : "No link errors detected.", testName : testName));
        }