public void HtmlEncode_LineFeedNewLine() { Assert.That(HtmlUtility.HtmlEncode("a\r\nb"), Is.EqualTo("a<br />b")); }
public void HtmlEncode_DoubleQuote() { Assert.That(HtmlUtility.HtmlEncode("a\"b"), Is.EqualTo("a"b")); }
public void HtmlEncode_SingleQuote() { Assert.That(HtmlUtility.HtmlEncode("a'b"), Is.EqualTo("a'b")); }
public virtual void WriteHtmlDescription(TextWriter tw, bool appendAllDeclarations, bool appendChildren) { ChangeType nestedChange = CalculateNestedChanges(); string changeClass = ChangeTypeUtil.GetChangeClass(nestedChange); tw.Write("<div class='item"); if (changeClass != null) { tw.Write(' '); tw.Write(changeClass); } tw.WriteLine("'>"); if (!this.ExcludeFromReport) { FilterStatus filterThisInstance; if (appendAllDeclarations) { filterThisInstance = GetStrongestFilterStatus(); if (this.CollapseChildren && filterThisInstance == FilterStatus.ExcludedButIncludeForChildren) { filterThisInstance = FilterStatus.Include; } } else { filterThisInstance = FilterStatus.Include; } if ((!appendChildren) || (filterThisInstance >= FilterStatus.DontCare)) { string nestedChangeText = ChangeTypeUtil.GetSummaryText(nestedChange); tw.Write("<h2>"); if (nestedChangeText != null) { tw.Write("<span class='item-change'>"); tw.Write(HtmlUtility.HtmlEncode(nestedChangeText)); tw.Write("</span>"); } RootDetail namedItem; if (appendAllDeclarations) { namedItem = FindItemWithStatusPresent(); } else { namedItem = this; } tw.Write("<span class='name'>"); if ((namedItem == null) || (namedItem.Status == Status.Missing)) { tw.Write(this.Name); } else { tw.Write(HtmlUtility.HtmlEncode(namedItem.GetTextTitle())); } tw.Write("</span>"); tw.Write("</h2>"); tw.Write("<div class='item-body'>"); RootDetail eachItem = this; while (eachItem != null) { tw.Write("<div class='item-entry'>"); eachItem.WriteHtmlDeclaration(tw); eachItem.WriteHtmlSummaryForChange(tw); tw.Write("</div>"); eachItem = appendAllDeclarations ? (RootDetail)eachItem.NavigateForward : null; } tw.WriteLine("</div>"); } } if (appendChildren && !this.ExcludeChildrenFromReport) { foreach (RootDetail child in FilterChildrenInAll <RootDetail>()) { // if ((child.FullNameRoot) || (child.GetStrongestFilterStatus() != FilterStatus.ExcludedButIncludeForChildren)) // Dont include public stuff inside internal classes for -publiconly { child.WriteHtmlDescription(tw, appendAllDeclarations, appendChildren); } } } tw.WriteLine("</div>"); }
private void RenderBootstrapHtmlPrefix(StringBuilder html, string title) { html.Append("<!DOCTYPE html><html lang=\"en\"><head><title>"); html.Append(HtmlUtility.HtmlEncode(title)); html.Append("</title><link rel=\"stylesheet\" href=\"http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css\"><link rel=\"stylesheet\" href=\"http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css\"></head><body>"); }
public void BrowseRequest(IDictionary <string, object> environment, Guid id) { var request = GetRequestData(id); if (request == null) { EnvironmentHelper.SetResponse(environment, 404, "text/html", "Cannot find the request."); } var sb = new StringBuilder(4096); RenderBootstrapHtmlPrefix(sb, request.Method + ": " + request.Url); sb.Append("<p><h1>"); sb.Append(HtmlUtility.HtmlEncode(request.Method)); sb.Append(": "); sb.Append(HtmlUtility.HtmlEncode(request.Url)); sb.Append(" <small>"); sb.Append(request.Id.ToString("N")); sb.Append("</small>"); sb.Append("</h1></p>"); sb.Append("<p><h2>UserAgent: "); sb.Append(HtmlUtility.HtmlEncode(request.UserAgent)); sb.Append("</h2></p>"); sb.Append("<p><h2>IP Address: "); sb.Append(HtmlUtility.HtmlEncode(request.IpAddress)); sb.Append("</h2></p>"); sb.Append("<p><h2>Request Headers</h2><br/>"); sb.Append("<table class=\"table table-hover\"><thead><tr><td>Key</td><td>Value</td></tr></thead><tbody>"); foreach (var pair in request.RequestHeaders) { sb.Append("<tr><td>"); sb.Append(HtmlUtility.HtmlEncode(pair.Key)); sb.Append("</td><td>"); sb.Append(HtmlUtility.HtmlEncode(pair.Value)); sb.Append("</td></tr>"); } sb.Append("</tbody></table>"); sb.Append("</p>"); sb.Append("<p><h2>Request Body: "); sb.Append(request.RequestBodyLength); sb.Append(" bytes</h2><br/>"); sb.Append("<textarea class=\"form-control\" rows=\"10\" style=\"margin-right:20px;\">"); sb.Append(HtmlUtility.HtmlEncode(Encoding.UTF8.GetString(request.RequestBody))); sb.Append("</textarea></p>"); sb.Append("<p><h2>Time: "); sb.Append((request.ProcessedTime - request.ProcessingTime).TotalMilliseconds); sb.Append("ms</h2><br/>ProcessingTime(UTC): "); sb.Append(HtmlUtility.HtmlEncode(request.ProcessingTime.ToString("yyyy-MM-dd hh:mm:ss.fff"))); sb.Append("<br/>ProcessedTime(UTC): "); sb.Append(HtmlUtility.HtmlEncode(request.ProcessedTime.ToString("yyyy-MM-dd hh:mm:ss.fff"))); sb.Append("<p><h2>Response Code: "); sb.Append(request.ResponseHttpCode); sb.Append("</h2></p>"); if (!string.IsNullOrEmpty(request.Exception)) { sb.Append("<p><h2>Exception</h2><br/>"); sb.Append("<textarea class=\"form-control\" rows=\"10\" style=\"margin-right:20px;\">"); sb.Append(HtmlUtility.HtmlEncode(request.Exception)); sb.Append("</textarea></p>"); } sb.Append("<p><h2>Response Headers</h2><br/>"); sb.Append("<table class=\"table table-hover\"><thead><tr><td>Key</td><td>Value</td></tr></thead><tbody>"); foreach (var pair in request.ResponseHeaders) { sb.Append("<tr><td>"); sb.Append(HtmlUtility.HtmlEncode(pair.Key)); sb.Append("</td><td>"); sb.Append(HtmlUtility.HtmlEncode(pair.Value)); sb.Append("</td></tr>"); } sb.Append("</tbody></table>"); sb.Append("</p>"); sb.Append("<p><h2>Response Body: "); sb.Append(request.ResponseBodyLength); sb.Append(" bytes</h2><br/>"); sb.Append("<textarea class=\"form-control\" rows=\"10\" style=\"margin-right:20px;\">"); if (request.ResponseBody != null) { sb.Append(HtmlUtility.HtmlEncode(Encoding.UTF8.GetString(request.ResponseBody))); } sb.Append("</textarea></p>"); RenderBootstrapHtmlPostfix(sb); EnvironmentHelper.SetResponse(environment, 200, "text/html", sb.ToString()); }
public void BrowseRequests(IDictionary <string, object> environment, int?count, string ipAddress, string userAgent, string accessToken) { if (EnvironmentHelper.GetRequestMethod(environment) == "GET") { if (!count.HasValue) { count = 100; } if (string.IsNullOrEmpty(ipAddress)) { ipAddress = EnvironmentHelper.GetServerRemoteIpAddress(environment, string.Empty); } } var requests = GenerateSnapshot(count, ipAddress, userAgent, accessToken); var sb = new StringBuilder(4096); RenderBootstrapHtmlPrefix(sb, "Request Tracker"); sb.Append("<p><h3>Request Count:" + requests.Count + "</h3></p>"); sb.Append("<p><form class=\"form-inline\" role=\"form\" method=\"post\">"); sb.Append("<div class=\"form-group\" style=\"margin-left:20px;\"><label for=\"countInput\" class=\"control-label\">Count:</label></div><div class=\"form-group\"><input type=\"number\" class=\"form-control\" id=\"countInput\" placeholder=\"Count\" name=\"count\" value=\""); sb.Append(count.HasValue ? count.Value.ToString() : string.Empty); sb.Append("\"></div>"); sb.Append("<div class=\"form-group\" style=\"margin-left:20px;\"><label for=\"ipInput\" class=\"control-label\">IP Address:</label></div><div class=\"form-group\"><input type=\"text\" class=\"form-control\" id=\"ipInput\" placeholder=\"IP address\" name=\"ipAddress\" value=\""); sb.Append(ipAddress ?? string.Empty); sb.Append("\"></div>"); sb.Append("<div class=\"form-group\" style=\"margin-left:20px;\"><label for=\"userAgentInput\" class=\"control-label\">User Agent:</label></div><div class=\"form-group\"><input type=\"text\" class=\"form-control\" id=\"userAgentInput\" placeholder=\"User Agent\" name=\"userAgent\" value=\""); sb.Append(userAgent ?? string.Empty); sb.Append("\"></div>"); sb.Append("<div class=\"form-group\" style=\"margin-left:20px;\"><label for=\"accessTokenInput\" class=\"control-label\">Access Token:</label></div><div class=\"form-group\"><input type=\"text\" class=\"form-control\" id=\"accessTokenInput\" placeholder=\"Access Token\" name=\"accessToken\" value=\""); sb.Append(accessToken ?? string.Empty); sb.Append("\"></div>"); sb.Append("<button type=\"submit\" class=\"btn btn-primary\" style=\"margin-left:15px;\">Query</button></form></p>"); sb.Append("<table class=\"table table-hover\"><thead><tr><td></td><td>ExecutingTime(UTC)</td><td>Duration(ms)</td><td>IpAddress</td><td>Method</td><td>RequestLen</td><td>StatusCode</td><td>ResponseLen</td><td>Exception</td><td>Url</td><td>UserAgent</td><td>AccessToken</td></tr></thead><tbody>"); foreach (var request in requests) { sb.Append("<tr"); if ((request.ResponseHttpCode >= 500) || (!string.IsNullOrEmpty(request.Exception))) { sb.Append(" class=\"danger\""); } else if ((request.ResponseHttpCode < 200) || (request.ResponseHttpCode >= 300)) { sb.Append(" class=\"warning\""); } sb.Append("><td>"); sb.Append("<a class=\"btn btn-default btn-xs\" target=\"_blank\" href=\""); sb.Append(HtmlUtility.HtmlEncode("../RequestTracker/BR/" + request.Id.ToString("N"))); sb.Append("\">Detail</a>"); sb.Append("</td><td>"); sb.Append(HtmlUtility.HtmlEncode(request.ProcessingTime.ToString("yyyy-MM-dd hh:mm:ss.fff"))); sb.Append("</td><td>"); if (request.ProcessedTime == DateTime.MinValue) { sb.Append("Processing"); } else { sb.Append((request.ProcessedTime - request.ProcessingTime).TotalMilliseconds); } sb.Append("</td><td>"); sb.Append(HtmlUtility.HtmlEncode(request.IpAddress)); sb.Append("</td><td>"); sb.Append(request.Method); sb.Append("</td><td>"); sb.Append(request.RequestBodyLength); sb.Append("</td><td>"); sb.Append(request.ResponseHttpCode); sb.Append("</td><td>"); sb.Append(request.ResponseBodyLength); sb.Append("</td><td>"); sb.Append(string.IsNullOrEmpty(request.Exception) ? string.Empty : "Yes"); sb.Append("</td><td>"); sb.Append(HtmlUtility.HtmlEncode(request.Url)); sb.Append("</td><td>"); sb.Append(HtmlUtility.HtmlEncode(request.UserAgent)); sb.Append("</td><td>"); sb.Append(HtmlUtility.HtmlEncode(request.AccessToken)); sb.Append("</td></tr>"); } sb.Append("</tbody></table>"); RenderBootstrapHtmlPostfix(sb); EnvironmentHelper.SetResponse(environment, 200, "text/html", sb.ToString()); }
public virtual void WriteHtmlDescription(TextWriter tw, bool appendAllDeclarations, bool appendChildren) { if (!this.ExcludeFromReport) { FilterStatus filterThisInstance; if (appendAllDeclarations) { filterThisInstance = GetStrongestFilterStatus(); if (this.CollapseChildren && filterThisInstance == FilterStatus.ExcludedButIncludeForChildren) { filterThisInstance = FilterStatus.Include; } } else { filterThisInstance = FilterStatus.Include; } if ((!appendChildren) || (filterThisInstance >= FilterStatus.DontCare)) { tw.Write("<p class='hdr'>"); RootDetail namedItem; if (appendAllDeclarations) { namedItem = FindItemWithStatusPresent(); } else { namedItem = this; } if ((namedItem == null) || (namedItem.Status == Status.Missing)) { tw.Write(this.Name); } else { tw.Write(HtmlUtility.HtmlEncode(namedItem.GetTextTitle())); } tw.Write("</p>"); RootDetail eachItem = this; while (eachItem != null) { eachItem.WriteHtmlDeclaration(tw); eachItem.WriteHtmlSummaryForChange(tw); eachItem = appendAllDeclarations ? (RootDetail)eachItem.NavigateForward : null; } } } if (appendChildren && !this.CollapseChildren && !ChangeTypeUtil.IsAddRemove(CombineAllChangesThisInstanceGoingForward())) { foreach (RootDetail child in FilterChildrenInAll <RootDetail>()) { // if ((child.FullNameRoot) || (child.GetStrongestFilterStatus() != FilterStatus.ExcludedButIncludeForChildren)) // Dont include public stuff inside internal classes for -publiconly { child.WriteHtmlDescription(tw, appendAllDeclarations, appendChildren); } } } }