Exemplo n.º 1
0
        /// <summary>
        /// String representation of the Frame.
        /// </summary>
        /// <returns>A string representing the frame.</returns>
        public override string ToString()
        {
            StringBuilder str = new StringBuilder();

            str.AppendLine(Command);
            Headers.Do(kvp => str.AppendLine(kvp.Key + ":" + kvp.Value));
            str.AppendLine();

            string contentType = GetHeader(StompHeaders.ContentType);

            if (contentType != null && contentType.StartsWith("text/") && (contentType.Contains("utf-8") || contentType.Contains("ascii")))
            {
                str.Append(Encoding.UTF8.GetString(BodyArray.Take(60).ToArray()));
                if (BodyArray.Length > 60)
                {
                    str.Append(" ...");
                }
            }
            else
            {
                str.Append(string.Join(" ", BodyArray.Take(20).Select(b => b.ToString("X2"))));
                if (BodyArray.Length > 20)
                {
                    str.Append(" ...");
                }
            }

            str.AppendLine();
            return(str.ToString());
        }