public string RenderRow(string operationName)
        {
            var show = HostContext.DebugMode && //Show in DebugMode
                       !MetadataConfig.AlwaysHideInMetadata(operationName); //Hide When [Restrict(VisibilityTo = None)]

            // use a fully qualified path if WebHostUrl is set
            string baseUrl = Request.ResolveAbsoluteUrl("~/");

            var op = GetOperation(operationName);

            var icons = CreateIcons(op);

            var opTemplate = StringBuilderCache.Allocate();

            opTemplate.Append($"<tr><th data-tags=\"" +
                              op.Tags.Map(x => x.Name).Join(",") +
                              "\">" + icons + "{0}</th>");
            foreach (var config in MetadataConfig.AvailableFormatConfigs)
            {
                var uri = baseUrl.CombineWith(config.DefaultMetadataUri);
                if (MetadataConfig.IsVisible(Request, config.Format.ToFormat(), operationName))
                {
                    show = true;
                    opTemplate.Append($@"<td><a href=""{uri}?op={{0}}"">{config.Name}</a></td>");
                }
                else
                {
                    opTemplate.Append($"<td>{config.Name}</td>");
                }
            }

            opTemplate.Append("</tr>");

            return(show ? string.Format(StringBuilderCache.ReturnAndFree(opTemplate), operationName) : "");
        }
        /// <summary>
        /// Changes the links for the servicestack/metadata page
        /// </summary>
        public static ServiceEndpointsMetadataConfig Create(string serviceStackHandlerPath)
        {
            var config = new MetadataConfig("{0}", "{0}", "/{0}/reply", "/{0}/oneway", "/{0}/metadata");

            return(new ServiceEndpointsMetadataConfig
            {
                DefaultMetadataUri = "/metadata",
                Soap11 = new SoapMetadataConfig("soap11", "SOAP 1.1", "/soap11", "/soap11", "/soap11/metadata", "soap11"),
                Soap12 = new SoapMetadataConfig("soap12", "SOAP 1.2", "/soap12", "/soap12", "/soap12/metadata", "soap12"),
                Custom = config
            });
        }
 /// <summary>
 /// Changes the links for the servicestack/metadata page
 /// </summary>
 /// <param name="serviceStackHandlerPrefix"></param>
 /// <returns></returns>
 public static ServiceEndpointsMetadataConfig Create(string serviceStackHandlerPrefix)
 {
     var config = new MetadataConfig("{0}", "{0}", "/{0}/reply", "/{0}/oneway", "/{0}/metadata");
     return new ServiceEndpointsMetadataConfig {
         DefaultMetadataUri = "/metadata",
         Soap11 = new SoapMetadataConfig("soap11", "SOAP 1.1", "/soap11", "/soap11", "/soap11/metadata", "soap11"),
         Soap12 = new SoapMetadataConfig("soap12", "SOAP 1.2", "/soap12", "/soap12", "/soap12/metadata", "soap12"),
         Xml = config.Create("xml"),
         Json = config.Create("json"),
         Jsv = config.Create("jsv"),
         Custom = config
     };
 }
        public Task RenderAsync(Stream output)
        {
            var operationsPart = new TableTemplate
            {
                Title       = "Operations",
                Items       = this.OperationNames,
                ForEachItem = RenderRow
            }.ToString();

#if !NETCORE
            var xsdsPart = new ListTemplate
            {
                Title            = "XSDS:",
                ListItemsIntMap  = this.Xsds,
                ListItemTemplate = @"<li><a href=""?xsd={0}"">{1}</a></li>"
            }.ToString();
#else
            var xsdsPart = "";
#endif

            var wsdlTemplate = StringBuilderCache.Allocate();
            var soap11Config = MetadataConfig.GetMetadataConfig("soap11") as SoapMetadataConfig;
            var soap12Config = MetadataConfig.GetMetadataConfig("soap12") as SoapMetadataConfig;
            if (soap11Config != null || soap12Config != null)
            {
                wsdlTemplate.AppendLine("<h3>WSDLS:</h3>");
                wsdlTemplate.AppendLine("<ul>");
                if (soap11Config != null)
                {
                    wsdlTemplate.AppendFormat(
                        @"<li><a href=""{0}"">{0}</a></li>",
                        soap11Config.WsdlMetadataUri);
                }
                if (soap12Config != null)
                {
                    wsdlTemplate.AppendFormat(
                        @"<li><a href=""{0}"">{0}</a></li>",
                        soap12Config.WsdlMetadataUri);
                }
                wsdlTemplate.AppendLine("</ul>");
            }

            var metadata    = HostContext.GetPlugin <MetadataFeature>();
            var pluginLinks = metadata != null && metadata.PluginLinks.Count > 0
                ? new ListTemplate
            {
                Title            = metadata.PluginLinksTitle,
                ListItemsMap     = ToAbsoluteUrls(metadata.PluginLinks),
                ListItemTemplate = @"<li><a href=""{0}"">{1}</a></li>"
            }.ToString()
                : "";

            var debugOnlyInfo = HostContext.DebugMode && metadata != null && metadata.DebugLinks.Count > 0
                ? new ListTemplate
            {
                Title            = metadata.DebugLinksTitle,
                ListItemsMap     = ToAbsoluteUrls(metadata.DebugLinks),
                ListItemTemplate = @"<li><a href=""{0}"">{1}</a></li>"
            }.ToString()
                : "";

            var errorCount    = HostContext.AppHost.StartUpErrors.Count;
            var plural        = errorCount > 1 ? "s" : "";
            var startupErrors = "";
            if (HostContext.DebugMode)
            {
                startupErrors = errorCount > 0
                    ? $"<div class='error-popup'><a href='?debug=requestinfo'>Review {errorCount} Error{plural} on Startup</a></div>"
                    : LicenseUtils.LicenseWarningMessage != null
                        ? $"<div class='error-popup'>{LicenseUtils.LicenseWarningMessage}</div>"
                        : "";
            }

            var renderedTemplate = Templates.HtmlTemplates.Format(
                Templates.HtmlTemplates.GetIndexOperationsTemplate(),
                this.Title,
                this.XsdServiceTypesIndex,
                operationsPart,
                xsdsPart,
                StringBuilderCache.ReturnAndFree(wsdlTemplate),
                pluginLinks,
                debugOnlyInfo,
                Env.VersionString,
                startupErrors);

            return(output.WriteAsync(renderedTemplate));
        }