Exemplo n.º 1
0
        private DescriptionEntry GenerateDescriptionEntry(Dictionary <string, string> values)
        {
            DateTime now = DateTime.UtcNow;
            DescriptionTextRenderType renderType = DescriptionTextRenderType.Plaintext;
            string text = values[FieldNames.Incident.Description];
            string xhtmlValid;
            string errors;

            // Try to convert from HTML to XHTML, if failed, just leave it as plain text
            if (XmlSanitizer.TryMakeXHtml(text, out xhtmlValid, out errors))
            {
                string xhtmlSanitized;
                if (XmlSanitizer.SanitizeXml(xhtmlValid, false, false, out xhtmlSanitized, out errors))
                {
                    text       = xhtmlSanitized;
                    renderType = DescriptionTextRenderType.Html;
                }
            }

            return(new DescriptionEntry
            {
                Cause = DescriptionEntryCause.Created,
                Date = now,
                ChangedBy = values[FieldNames.Incident.CreatedBy],
                SubmitDate = now,
                SubmittedBy = values[FieldNames.Incident.CreatedBy],
                Text = text,
                RenderType = renderType
            });
        }
        public static DescriptionEntry GenerateDescriptionEntry(Dictionary <string, string> values, int maxHyperlinkLength)
        {
            DateTime now = DateTime.UtcNow;
            DescriptionTextRenderType renderType = DescriptionTextRenderType.Plaintext;
            string text = values[FieldNames.Incident.Description];

            if (text.IndexOf("html", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                // Try to convert from HTML to XHTML, if failed, just leave it as plain text
                string xhtmlValid;
                string errors;
                if (XmlSanitizer.TryMakeXHtml(text, out xhtmlValid, out errors))
                {
                    string xhtmlSanitized;
                    if (XmlSanitizer.SanitizeXml(xhtmlValid, false, false, out xhtmlSanitized, out errors))
                    {
                        text       = xhtmlSanitized;
                        renderType = DescriptionTextRenderType.Html;
                    }
                }

                if (!string.IsNullOrEmpty(errors))
                {
                    Logger.Info("Failed to convert message body to HTML. Defaulting to plain text. Conversion message: " + errors);
                }
                else if (text.Length > DescriptionLengthMax)
                {
                    // Truncate string if too long. IcM limits the number of characters in the DescriptionEntry.Text property.
                    text = TruncateXml(text, DescriptionLengthMax, maxHyperlinkLength);
                }
            }
            else if (text.Length > DescriptionLengthMax)
            {
                // Truncate string if too long. IcM limits the number of characters in the DescriptionEntry.Text property.
                text  = text.Substring(0, DescriptionLengthMax);
                text += TruncationMessage;
            }


            var descriptionEntry = new DescriptionEntry
            {
                Cause       = DescriptionEntryCause.Created,
                Date        = now,
                ChangedBy   = values[FieldNames.Incident.CreatedBy],
                SubmitDate  = now,
                SubmittedBy = values[FieldNames.Incident.CreatedBy],
                Text        = text,
                RenderType  = renderType,
            };

            return(descriptionEntry);
        }