/// <summary>
        /// Appends a specified header and value using a specified display name and tooltip
        /// </summary>
        /// <param name="headerToDisplay">The HTTP header to display</param>
        /// <param name="headerDisplayName">The display name to use in the output</param>
        /// <param name="toolTip">The tooltip to use for the header, output as a Title attribute</param>
        public void DisplayHeader(string headerToDisplay, string headerDisplayName, string toolTip)
        {
            if (this.BaseHeaders.Exists(headerToDisplay))
            {
                string headerData = this.BaseHeaders[headerToDisplay];

                if (headerToDisplay == "User-Agent")
                {
                    // Special case
                    this.oEasViewControl.SetLabel2(InspectorUtilities.GetExtendedUserAgentInfo(headerData));
                }
                else
                {
                    // To reduce clutter in the display, only show the header if we don't have a special case
                    // e.g. User-Agent has a label in the status bar
                    if (headerData.IndexOf(',') > -1)
                    {
                        var values    = headerData.Split(',');
                        var valueList = new StringBuilder();

                        foreach (var value in values)
                        {
                            valueList.AppendLine($@"<div class=""level1"">{value}</div>");
                        }

                        this.oEasViewControl.AppendLine($@"<span title=""{toolTip}"" class=""headerItem"">{headerDisplayName}:</span><br/>{valueList.ToString()}");
                    }
                    else
                    {
                        // Just display the header
                        this.oEasViewControl.AppendLine(string.Format(@"<span title=""{2}"" class=""headerItem"">{0}: {1}</span>", headerDisplayName, headerData, toolTip));
                    }
                }
            }
        }
        /// <summary>
        /// Parse the bytes from Fiddler and append the parsed
        /// string to the WebBrowser document window
        /// </summary>
        /// <param name="bytesFromFiddler">byte[] from Fiddler</param>
        public void Parse(byte[] bytesFromFiddler)
        {
            if (bytesFromFiddler.Length == 0)
            {
                return;
            }

            InspectorUtilities.SetFiddlerStatus("Parsing payload...");

            // Try to only decode valid EAS requests/responses
            try
            {
                ASWBXMLHandler byteHandler  = new ASWBXMLHandler(bytesFromFiddler);
                var            rawXmlString = byteHandler.GetXmlString();

                if (!string.IsNullOrEmpty(rawXmlString) && rawXmlString.StartsWith(@"<?xml"))
                {
                    this.oEasViewControl.SetRaw(rawXmlString);
                    string outputDoc = InspectorUtilities.TransformXml(byteHandler.GetXmlDoc(false, true, true));
                    this.oEasViewControl.AppendLine(outputDoc);
                }
            }
            catch (Exception ex)
            {
                oEasViewControl.Append(InspectorUtilities.FriendlyException(@"Error in decoding EAS body.", ex.ToString()));
            }

            InspectorUtilities.SetFiddlerStatus(this.session.fullUrl);
        }
        /// <summary>
        /// Parse the bytes from Fiddler and append the parsed
        /// string to the WebBrowser document window
        /// </summary>
        /// <param name="bytesFromFiddler">byte[] from Fiddler</param>
        public void Parse(byte[] bytesFromFiddler)
        {
            if (bytesFromFiddler.Length == 0)
            {
                return;
            }

            InspectorUtilities.SetFiddlerStatus("Parsing payload...");

            // Try to only decode valid EAS requests/responses
            try
            {
                ASCommandResponse commandResponse = new ASCommandResponse(bytesFromFiddler);

                if (!string.IsNullOrEmpty(commandResponse.XMLString) && commandResponse.XMLString.Contains(@"<?xml"))
                {
                    this.oEasViewControl.SetRaw(commandResponse.XMLString);

                    XmlDocument doc       = commandResponse.XmlDoc;
                    string      outputDoc = InspectorUtilities.TransformXml(doc);
                    this.oEasViewControl.AppendLine(outputDoc);
                }

                commandResponse = null;
            }
            catch (Exception ex)
            {
                oEasViewControl.Append(InspectorUtilities.FriendlyException(@"Error in decoding EAS body.", ex.ToString()));
            }

            InspectorUtilities.SetFiddlerStatus(this.session.fullUrl);
        }
        internal void SetRaw(string text)
        {
            // mstehle - 7/19/2013 - Ran into a response were text had "\0\0" in the ConversationIndex element
            // the TextBox and RichTextBox controls will truncate the display
            if (text.Contains("\0\0"))
            {
                InspectorUtilities.LogDebug("Cleaning up double null to make sure all data is displayed in text box.");
                text = text.Replace("\0\0", "    ");
            }

            txtEasResults.Text = text;
        }
        public static string TransformXml(XmlDocument doc)
        {
            StringBuilder sb  = new StringBuilder();
            XmlWriter     xml = XmlWriter.Create(sb);

            XslCompiledTransform xsl = new XslCompiledTransform();

            // Load the XSL from the embedded resources
            xsl.Load(XmlReader.Create(InspectorUtilities.GetEmbeddedResourceAsStream("EasInspector", "Embedded.XmlTransform.xslt")));

            // Write the XSLT transformed document
            xsl.Transform(doc, null, xml);

            return(sb.ToString());
        }
 public static string FriendlyException(string description, string exception)
 {
     return(string.Format(@"{0}<br/><br/><div class=""level1""><code>{1}</code></div>", description, InspectorUtilities.ExceptionCleanup(exception)));
 }
        public static void LogDebug(string logString)
        {
#if (DEBUG)
            InspectorUtilities.Log(logString);
#endif
        }
 /// <summary>
 /// Flushes the internal StringBuilder to the document window
 /// </summary>
 public void UpdateBrowser()
 {
     this.browser.DocumentText = InspectorUtilities.GetEmbeddedResourceAsString("EasInspector", "Embedded.BrowserTemplate.html").Replace("##ParsedData##", this.sb.ToString().Replace(@"<?xml version=""1.0"" encoding=""utf-16""?>", ""));
 }