/// <summary>
    /// Gets row column content.
    /// </summary>
    /// <param name="dr">DataRow</param>
    /// <param name="dc">DataColumn</param>
    /// <param name="toCompare">Indicates if comparison will be used for content</param>
    /// <returns>String with column content</returns>
    private string GetRowColumnContent(DataRow dr, DataColumn dc, bool toCompare)
    {
        if (dr == null)
        {
            // Data row was not specified
            return(string.Empty);
        }

        if (!dr.Table.Columns.Contains(dc.ColumnName))
        {
            // Data row does not contain the required column
            return(string.Empty);
        }

        var value = dr[dc.ColumnName];

        if (DataHelper.IsEmpty(value))
        {
            // Column is empty
            return(string.Empty);
        }

        var content = ValidationHelper.GetString(value, "");

        Func <string> render = () =>
        {
            if (toCompare)
            {
                return(content);
            }

            content = HTMLHelper.EnsureHtmlLineEndings(content);

            return(content);
        };

        Func <string> standardRender = () =>
        {
            if (toCompare)
            {
                return(content);
            }

            if (EncodeDisplayedData)
            {
                content = HTMLHelper.HTMLEncode(content);
            }
            content = content.Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
            content = "<div style=\"max-height: 300px; overflow: auto;\">" + content + "</div>";
            content = HTMLHelper.EnsureHtmlLineEndings(content);

            return(content);
        };

        // Binary columns
        if (dc.DataType == typeof(byte[]))
        {
            var data = (byte[])dr[dc.ColumnName];
            content = string.Format("<{0}: {1}>", GetString("General.BinaryData"), DataHelper.GetSizeString(data.Length));

            return(standardRender());
        }

        // DataTime columns
        if (dc.DataType == typeof(DateTime))
        {
            var dateTime    = Convert.ToDateTime(content);
            var cultureInfo = CultureHelper.GetCultureInfo(MembershipContext.AuthenticatedUser.PreferredUICultureCode);
            content = dateTime.ToString(cultureInfo);

            return(standardRender());
        }

        switch (dc.ColumnName.ToLowerCSafe())
        {
        // Document content
        case "documentcontent":
            var sb = new StringBuilder();

            Action <MultiKeyDictionary <string>, string, string> addItems = (dictionary, titleClass, textClass) =>
            {
                foreach (DictionaryEntry item in dictionary)
                {
                    var regionContent = HTMLHelper.ResolveUrls((string)item.Value, SystemContext.ApplicationPath);

                    if (toCompare)
                    {
                        sb.AppendLine((string)item.Key);
                        sb.AppendLine(regionContent);
                    }
                    else
                    {
                        sb.AppendFormat("<span class=\"{0}\">{1}</span>", titleClass, item.Key);
                        sb.AppendFormat("<span class=\"{0}\">{1}</span>", textClass, HTMLHelper.HTMLEncode(regionContent));
                    }
                }
            };

            var items = new EditableItems();
            items.LoadContentXml(ValidationHelper.GetString(value, ""));

            // Add regions
            addItems(items.EditableRegions, "VersionEditableRegionTitle", "VersionEditableRegionText");

            // Add web parts
            addItems(items.EditableWebParts, "VersionEditableWebPartTitle", "VersionEditableWebPartText");

            content = sb.ToString();
            return(render());

        // XML columns
        case "pagetemplatewebparts":
        case "webpartproperties":
        case "reportparameters":
        case "classformdefinition":
        case "classxmlschema":
        case "classformlayout":
        case "userdialogsconfiguration":
        case "siteinvoicetemplate":
        case "userlastlogoninfo":
        case "formdefinition":
        case "formlayout":
        case "classsearchsettings":
        case "graphsettings":
        case "tablesettings":
        case "issuetext":
        case "issuewidgets":
        case "savedreportparameters":
        case "emailwidgetproperties":

        // HTML columns
        case "emailtemplatetext":
        case "emailwidgetcode":
        case "templatebody":
        case "templateheader":
        case "templatefooter":
        case "containertextbefore":
        case "containertextafter":
        case "savedreporthtml":
        case "layoutcode":
        case "webpartlayoutcode":
        case "transformationcode":
        case "reportlayout":
#pragma warning disable CS0618 // Type or member is obsolete
            if (BrowserHelper.IsIE())
#pragma warning restore CS0618 // Type or member is obsolete
            {
                content = HTMLHelper.ReformatHTML(content, " ");
            }
            else
            {
                content = HTMLHelper.ReformatHTML(content);
            }
            break;

        // File columns
        case "metafilename":
            var metaFileName = HTMLHelper.HTMLEncode(ValidationHelper.GetString(dr["MetaFileName"], ""));

            if (ShowLinksForMetafiles)
            {
                var metaFileGuid = ValidationHelper.GetGuid(dr["MetaFileGuid"], Guid.Empty);
                if (metaFileGuid != Guid.Empty)
                {
                    var metaFileUrl = ResolveUrl(MetaFileInfoProvider.GetMetaFileUrl(metaFileGuid, metaFileName));
                    content = string.Format("<a href=\"{0}\" target=\"_blank\">{1}</a>", metaFileUrl, metaFileName);
                }
            }
            else
            {
                content = metaFileName;
            }

            return(render());
        }

        return(standardRender());
    }
    /// <summary>
    /// Gets row column content.
    /// </summary>
    /// <param name="dr">DataRow</param>
    /// <param name="dc">DataColumn</param>
    /// <param name="toCompare">Indicates if comparison will be used for content</param>
    /// <returns>String with column content</returns>
    private string GetRowColumnContent(DataRow dr, DataColumn dc, bool toCompare)
    {
        if (dr == null)
        {
            // Data row was not specified
            return(String.Empty);
        }

        if (!dr.Table.Columns.Contains(dc.ColumnName))
        {
            // Data row does not contain the required column
            return(String.Empty);
        }

        var value = dr[dc.ColumnName];

        if (DataHelper.IsEmpty(value))
        {
            // Column is empty
            return(String.Empty);
        }

        string content = null;

        // Binary columns
        if (dc.DataType == typeof(byte[]))
        {
            byte[] data = (byte[])dr[dc.ColumnName];
            content = "<" + GetString("General.BinaryData") + ": " + DataHelper.GetSizeString(data.Length) + ">";
        }
        else
        {
            content = ValidationHelper.GetString(value, "");
        }

        // Possible DataTime columns
        if (dc.DataType == typeof(DateTime))
        {
            DateTime    dateTime    = Convert.ToDateTime(content);
            CultureInfo cultureInfo = new CultureInfo(CMSContext.CurrentUser.PreferredUICultureCode);
            content = dateTime.ToString(cultureInfo);
        }

        bool standard = true;

        switch (dc.ColumnName.ToLowerCSafe())
        {
        // Document content
        case "documentcontent":
            EditableItems items = new EditableItems();
            items.LoadContentXml(ValidationHelper.GetString(value, ""));
            StringBuilder sb = new StringBuilder();
            // Add regions
            foreach (DictionaryEntry region in items.EditableRegions)
            {
                if (toCompare)
                {
                    sb.AppendLine((string)region.Key);
                }
                else
                {
                    sb.Append("<span class=\"VersionEditableRegionTitle\">" + (string)region.Key + "</span>");
                }
                string regionContent = HTMLHelper.ResolveUrls((string)region.Value, URLHelper.ApplicationPath);

                if (toCompare)
                {
                    sb.AppendLine(regionContent);
                }
                else
                {
                    sb.Append("<span class=\"VersionEditableRegionText\">" + HTMLHelper.HTMLEncode(regionContent) + "</span>");
                }
            }

            // Add web parts
            foreach (DictionaryEntry part in items.EditableWebParts)
            {
                if (toCompare)
                {
                    sb.AppendLine((string)part.Key);
                }
                else
                {
                    sb.Append("<span class=\"VersionEditableWebPartTitle\">" + (string)part.Key + "</span>");
                }

                string regionContent = HTMLHelper.ResolveUrls((string)part.Value, URLHelper.ApplicationPath);
                if (toCompare)
                {
                    sb.AppendLine(regionContent);
                }
                else
                {
                    sb.Append("<span class=\"VersionEditableWebPartText\">" + HTMLHelper.HTMLEncode(regionContent) + "</span>");
                }
            }

            content  = sb.ToString();
            standard = false;
            break;

        // XML columns
        case "pagetemplatewebparts":
        case "webpartproperties":
        case "reportparameters":
        case "classformdefinition":
        case "classxmlschema":
        case "classformlayout":
        case "userdialogsconfiguration":
        case "siteinvoicetemplate":
        case "userlastlogoninfo":
        case "formdefinition":
        case "formlayout":
        case "uservisibility":
        case "classsearchsettings":
        case "graphsettings":
        case "tablesettings":
        case "transformationhierarchicalxml":
        case "issuetext":
        case "savedreportparameters":

        // HTML columns
        case "emailtemplatetext":
        case "templatebody":
        case "templateheader":
        case "templatefooter":
        case "containertextbefore":
        case "containertextafter":
        case "savedreporthtml":
        case "layoutcode":
        case "webpartlayoutcode":
        case "transformationcode":
        case "reportlayout":
            if (BrowserHelper.IsIE())
            {
                content = HTMLHelper.ReformatHTML(content, " ");
            }
            else
            {
                content = HTMLHelper.ReformatHTML(content);
            }
            break;

        // File columns
        case "metafilename":
        {
            string metaFileName = HTMLHelper.HTMLEncode(ValidationHelper.GetString(dr["MetaFileName"], ""));

            if (ShowLinksForMetafiles)
            {
                Guid metaFileGuid = ValidationHelper.GetGuid(dr["MetaFileGuid"], Guid.Empty);
                if (metaFileGuid != Guid.Empty)
                {
                    content = "<a href=\"" + ResolveUrl(MetaFileInfoProvider.GetMetaFileUrl(metaFileGuid, metaFileName)) + "\" target=\"_blank\" >" + metaFileName + "</a>";
                }
            }
            else
            {
                content = metaFileName;
            }
            standard = false;
        }
        break;
        }

        // Standard rendering
        if (!toCompare)
        {
            if (standard)
            {
                if (EncodeDisplayedData)
                {
                    content = HTMLHelper.HTMLEncode(content);
                }
                content = content.Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
                content = "<div style=\"max-height: 300px; overflow: auto;\">" + content + "</div>";
            }

            // Ensure line ending
            content = TextHelper.EnsureLineEndings(content, "<br />");
        }

        return(content);
    }
    /// <summary>
    /// Processes the content.
    /// </summary>
    /// <param name="sb">StringBuilder to write</param>
    /// <param name="source">Source object</param>
    /// <param name="column">Column</param>
    /// <param name="content">Content</param>
    protected void ProcessContent(StringBuilder sb, object source, string column, ref string content)
    {
        bool standard = true;
        switch (column.ToLowerCSafe())
        {
                // Document content
            case "documentcontent":
                EditableItems items = new EditableItems();
                items.LoadContentXml(content);

                // Add regions
                foreach (DictionaryEntry region in items.EditableRegions)
                {
                    sb.Append("<span class=\"VersionEditableRegionTitle\">" + (string)region.Key + "</span>");

                    string regionContent = HTMLHelper.ResolveUrls((string)region.Value, SystemContext.ApplicationPath);

                    sb.Append("<span class=\"VersionEditableRegionText\">" + regionContent + "</span>");
                }

                // Add web parts
                foreach (DictionaryEntry part in items.EditableWebParts)
                {
                    sb.Append("<span class=\"VersionEditableWebPartTitle\">" + (string)part.Key + "</span>");

                    string regionContent = HTMLHelper.ResolveUrls((string)part.Value, SystemContext.ApplicationPath);
                    sb.Append("<span class=\"VersionEditableWebPartText\">" + regionContent + "</span>");
                }

                standard = false;
                break;

                // XML columns
            case "pagetemplatewebparts":
            case "webpartproperties":
            case "reportparameters":
            case "classformdefinition":
            case "classxmlschema":
            case "classformlayout":
            case "userdialogsconfiguration":
                content = HTMLHelper.ReformatHTML(content);
                break;

                // File columns
            case "metafilename":
                {
                    Guid metaFileGuid = ValidationHelper.GetGuid(GetValueFromSource(source, "MetaFileGuid"), Guid.Empty);
                    if (metaFileGuid != Guid.Empty)
                    {
                        string metaFileName = ValidationHelper.GetString(GetValueFromSource(source, "MetaFileName"), "");

                        content = "<a href=\"" + ResolveUrl(MetaFileInfoProvider.GetMetaFileUrl(metaFileGuid, metaFileName)) + "\" target=\"_blank\" >" + HTMLHelper.HTMLEncode(metaFileName) + "</a>";
                        sb.Append(content);

                        standard = false;
                    }
                }
                break;
        }

        // Standard rendering
        if (standard)
        {
            if (content.Length > 500)
            {
                content = TextHelper.EnsureMaximumLineLength(content, 50, "&#x200B;", true);
            }
            else
            {
                content = HTMLHelper.HTMLEncode(content);
            }

            content = TextHelper.EnsureHTMLLineEndings(content);
            content = content.Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
            sb.Append("<div style=\"max-height: 300px; overflow: auto;\">" + content + "</div>");
        }
    }
    /// <summary>
    /// Displays data in table.
    /// </summary>
    /// <param name="ds">Dataset with data</param>
    protected void DisplayData(DataSet ds)
    {
        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            // Prepare list of tables
            SortedDictionary <string, DataTable> tables = new SortedDictionary <string, DataTable>();
            foreach (DataTable dt in ds.Tables)
            {
                if (!DataHelper.DataSourceIsEmpty(dt))
                {
                    tables.Add(GetString("ObjectType." + dt.TableName), dt);
                }
            }

            // Generate the tables
            foreach (DataTable dt in tables.Values)
            {
                pnlContent.Controls.Add(new LiteralControl("<h3>" + GetString("ObjectType." + dt.TableName) + "</h3>"));

                if (dt.Columns.Count >= 6)
                {
                    StringBuilder sb;

                    // Write all rows
                    foreach (DataRow dr in dt.Rows)
                    {
                        sb = new StringBuilder();

                        sb.Append("<table class=\"table table-hover\">");

                        // Add header
                        sb.AppendFormat("<thead><tr class=\"unigrid-head\"><th>{0}</th><th class=\"main-column-100\">{1}</th></tr></thead><tbody>", GetString("General.FieldName"), GetString("General.Value"));

                        // Add values
                        foreach (DataColumn dc in dt.Columns)
                        {
                            sb.AppendFormat("<tr><td><strong>{0}</strong></td><td class=\"wrap-normal\">", dc.ColumnName);

                            string content = null;

                            // Binary columns
                            if ((dc.DataType == typeof(byte[])) && (dr[dc.ColumnName] != DBNull.Value))
                            {
                                content = "<binary data>";
                            }
                            else
                            {
                                content = ValidationHelper.GetString(dr[dc.ColumnName], String.Empty);
                            }

                            bool standard = true;
                            switch (dc.ColumnName.ToLowerCSafe())
                            {
                            // Document content
                            case "documentcontent":
                                EditableItems items = new EditableItems();
                                items.LoadContentXml(ValidationHelper.GetString(dr[dc.ColumnName], String.Empty));

                                // Add regions
                                foreach (DictionaryEntry region in items.EditableRegions)
                                {
                                    sb.Append("<span class=\"VersionEditableRegionTitle\">" + (string)region.Key + "</span>");

                                    string regionContent = HTMLHelper.ResolveUrls((string)region.Value, SystemContext.ApplicationPath);

                                    sb.Append("<span class=\"VersionEditableRegionText\">" + regionContent + "</span>");
                                }

                                // Add web parts
                                foreach (DictionaryEntry part in items.EditableWebParts)
                                {
                                    sb.Append("<span class=\"VersionEditableWebPartTitle\">" + (string)part.Key + "</span>");

                                    string regionContent = HTMLHelper.ResolveUrls((string)part.Value, SystemContext.ApplicationPath);
                                    sb.Append("<span class=\"VersionEditableWebPartText\">" + regionContent + "</span>");
                                }

                                standard = false;
                                break;

                            // XML columns
                            case "pagetemplatewebparts":
                            case "webpartproperties":
                            case "reportparameters":
                            case "classformdefinition":
                            case "classxmlschema":
                            case "classformlayout":
                                content = HTMLHelper.ReformatHTML(content);
                                break;
                            }

                            // Standard rendering
                            if (standard)
                            {
                                content = HttpUtility.HtmlEncode(content);
                                content = TextHelper.EnsureHTMLLineEndings(content);
                                content = content.Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
                                sb.Append("<div style=\"max-height: 300px; overflow: auto;\">" + content + "</div>");
                            }

                            sb.Append("</td></tr>");
                        }

                        sb.Append("</tbody></table><br />\n");

                        pnlContent.Controls.Add(new LiteralControl(sb.ToString()));
                    }
                }
                else
                {
                    GridView newGrid = new GridView();
                    newGrid.ID = "grid" + dt.TableName;
                    newGrid.EnableViewState             = false;
                    newGrid.HeaderStyle.HorizontalAlign = HorizontalAlign.Left;
                    newGrid.CellPadding = 3;
                    newGrid.GridLines   = GridLines.Horizontal;

                    pnlContent.Controls.Add(newGrid);

                    newGrid.DataSource = ds;
                    newGrid.DataMember = dt.TableName;

                    newGrid.DataBind();
                }
            }
        }
    }
    /// <summary>
    /// Gets row column content.
    /// </summary>
    /// <param name="dr">DataRow</param>
    /// <param name="dc">DataColumn</param>
    /// <param name="toCompare">Indicates if comparison will be used for content</param>
    /// <returns>String with column content</returns>
    private string GetRowColumnContent(DataRow dr, DataColumn dc, bool toCompare)
    {
        if (dr != null)
        {
            object value = dr[dc.ColumnName];
            if (!DataHelper.IsEmpty(value))
            {
                string content = null;

                // Binary columns
                if ((dc.DataType == typeof(byte[])) && (value != DBNull.Value))
                {
                    byte[] data = (byte[])dr[dc.ColumnName];
                    content = "<" + GetString("General.BinaryData") + ": " + DataHelper.GetSizeString(data.Length) + ">";
                }
                else
                {
                    content = ValidationHelper.GetString(value, "");
                }

                // Possible DataTime columns
                if ((dc.DataType == typeof(DateTime)) && (value != DBNull.Value))
                {
                    DateTime dateTime = Convert.ToDateTime(content);
                    CultureInfo cultureInfo = new CultureInfo(CMSContext.CurrentUser.PreferredUICultureCode);
                    content = dateTime.ToString(cultureInfo);
                }

                bool standard = true;
                switch (dc.ColumnName.ToLowerCSafe())
                {
                        // Document content
                    case "documentcontent":
                        EditableItems items = new EditableItems();
                        items.LoadContentXml(ValidationHelper.GetString(value, ""));
                        StringBuilder sb = new StringBuilder();
                        // Add regions
                        foreach (DictionaryEntry region in items.EditableRegions)
                        {
                            if (toCompare)
                            {
                                sb.AppendLine((string)region.Key);
                            }
                            else
                            {
                                sb.Append("<span class=\"VersionEditableRegionTitle\">" + (string)region.Key + "</span>");
                            }
                            string regionContent = HTMLHelper.ResolveUrls((string)region.Value, URLHelper.ApplicationPath);

                            if (toCompare)
                            {
                                sb.AppendLine(regionContent);
                            }
                            else
                            {
                                sb.Append("<span class=\"VersionEditableRegionText\">" + HTMLHelper.HTMLEncode(regionContent) + "</span>");
                            }
                        }

                        // Add web parts
                        foreach (DictionaryEntry part in items.EditableWebParts)
                        {
                            if (toCompare)
                            {
                                sb.AppendLine((string)part.Key);
                            }
                            else
                            {
                                sb.Append("<span class=\"VersionEditableWebPartTitle\">" + (string)part.Key + "</span>");
                            }

                            string regionContent = HTMLHelper.ResolveUrls((string)part.Value, URLHelper.ApplicationPath);
                            if (toCompare)
                            {
                                sb.AppendLine(regionContent);
                            }
                            else
                            {
                                sb.Append("<span class=\"VersionEditableWebPartText\">" + HTMLHelper.HTMLEncode(regionContent) + "</span>");
                            }
                        }

                        content = sb.ToString();
                        standard = false;
                        break;

                        // XML columns
                    case "pagetemplatewebparts":
                    case "webpartproperties":
                    case "reportparameters":
                    case "classformdefinition":
                    case "classxmlschema":
                    case "classformlayout":
                    case "userdialogsconfiguration":
                    case "siteinvoicetemplate":
                    case "userlastlogoninfo":
                    case "formdefinition":
                    case "formlayout":
                    case "uservisibility":
                    case "classsearchsettings":
                    case "graphsettings":
                    case "tablesettings":
                    case "transformationhierarchicalxml":
                    case "issuetext":
                    case "savedreportparameters":

                        // HTML columns
                    case "emailtemplatetext":
                    case "templatebody":
                    case "templateheader":
                    case "templatefooter":
                    case "containertextbefore":
                    case "containertextafter":
                    case "savedreporthtml":
                    case "layoutcode":
                    case "webpartlayoutcode":
                    case "transformationcode":
                    case "reportlayout":
                        if (BrowserHelper.IsIE())
                        {
                            content = HTMLHelper.ReformatHTML(content, " ");
                        }
                        else
                        {
                            content = HTMLHelper.ReformatHTML(content);
                        }
                        break;

                        // File columns
                    case "metafilename":
                        {
                            string metaFileName = HTMLHelper.HTMLEncode(ValidationHelper.GetString(dr["MetaFileName"], ""));

                            if (ShowLinksForMetafiles)
                            {
                                Guid metaFileGuid = ValidationHelper.GetGuid(dr["MetaFileGuid"], Guid.Empty);
                                if (metaFileGuid != Guid.Empty)
                                {
                                    content = "<a href=\"" + ResolveUrl(MetaFileInfoProvider.GetMetaFileUrl(metaFileGuid, metaFileName)) + "\" target=\"_blank\" >" + metaFileName + "</a>";
                                }
                            }
                            else
                            {
                                content = metaFileName;
                            }
                            standard = false;
                        }
                        break;
                }

                // Standard rendering
                if (!toCompare)
                {
                    if (standard)
                    {
                        if (EncodeDisplayedData)
                        {
                            content = HTMLHelper.HTMLEncode(content);
                        }
                        content = content.Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
                        content = "<div style=\"max-height: 300px; overflow: auto;\">" + content + "</div>";
                    }

                    // Ensure line ending
                    content = TextHelper.EnsureLineEndings(content, "<br />");
                }

                return content;
            }
        }
        return String.Empty;
    }
    /// <summary>
    /// Displays data in table.
    /// </summary>
    /// <param name="ds">Dataset with data</param>
    protected void DisplayData(DataSet ds)
    {
        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            // Prepare list of tables
            SortedDictionary<string, DataTable> tables = new SortedDictionary<string, DataTable>();
            foreach (DataTable dt in ds.Tables)
            {
                if (!DataHelper.DataSourceIsEmpty(dt))
                {
                    tables.Add(GetString("ObjectType." + dt.TableName), dt);
                }
            }

            // Generate the tables
            foreach (DataTable dt in tables.Values)
            {
                pnlContent.Controls.Add(new LiteralControl("<h3>" + GetString("ObjectType." + dt.TableName) + "</h3>"));

                if (dt.Columns.Count >= 6)
                {
                    StringBuilder sb;

                    // Write all rows
                    foreach (DataRow dr in dt.Rows)
                    {
                        sb = new StringBuilder();

                        sb.Append("<table class=\"table table-hover\">");

                        // Add header
                        sb.AppendFormat("<thead><tr class=\"unigrid-head\"><th>{0}</th><th class=\"main-column-100\">{1}</th></tr></thead><tbody>", GetString("General.FieldName"), GetString("General.Value"));

                        // Add values
                        foreach (DataColumn dc in dt.Columns)
                        {
                            sb.AppendFormat("<tr><td><strong>{0}</strong></td><td class=\"wrap-normal\">", dc.ColumnName);

                            string content = null;

                            // Binary columns
                            if ((dc.DataType == typeof(byte[])) && (dr[dc.ColumnName] != DBNull.Value))
                            {
                                content = "<binary data>";
                            }
                            else
                            {
                                content = ValidationHelper.GetString(dr[dc.ColumnName], String.Empty);
                            }

                            bool standard = true;
                            switch (dc.ColumnName.ToLowerCSafe())
                            {
                                    // Document content
                                case "documentcontent":
                                    EditableItems items = new EditableItems();
                                    items.LoadContentXml(ValidationHelper.GetString(dr[dc.ColumnName], String.Empty));

                                    // Add regions
                                    foreach (DictionaryEntry region in items.EditableRegions)
                                    {
                                        sb.Append("<span class=\"VersionEditableRegionTitle\">" + (string)region.Key + "</span>");

                                        string regionContent = HTMLHelper.ResolveUrls((string)region.Value, SystemContext.ApplicationPath);

                                        sb.Append("<span class=\"VersionEditableRegionText\">" + regionContent + "</span>");
                                    }

                                    // Add web parts
                                    foreach (DictionaryEntry part in items.EditableWebParts)
                                    {
                                        sb.Append("<span class=\"VersionEditableWebPartTitle\">" + (string)part.Key + "</span>");

                                        string regionContent = HTMLHelper.ResolveUrls((string)part.Value, SystemContext.ApplicationPath);
                                        sb.Append("<span class=\"VersionEditableWebPartText\">" + regionContent + "</span>");
                                    }

                                    standard = false;
                                    break;

                                    // XML columns
                                case "pagetemplatewebparts":
                                case "webpartproperties":
                                case "reportparameters":
                                case "classformdefinition":
                                case "classxmlschema":
                                case "classformlayout":
                                    content = HTMLHelper.ReformatHTML(content);
                                    break;
                            }

                            // Standard rendering
                            if (standard)
                            {
                                content = HttpUtility.HtmlEncode(content);
                                content = TextHelper.EnsureHTMLLineEndings(content);
                                content = content.Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
                                sb.Append("<div style=\"max-height: 300px; overflow: auto;\">" + content + "</div>");
                            }

                            sb.Append("</td></tr>");
                        }

                        sb.Append("</tbody></table><br />\n");

                        pnlContent.Controls.Add(new LiteralControl(sb.ToString()));
                    }
                }
                else
                {
                    GridView newGrid = new GridView();
                    newGrid.ID = "grid" + dt.TableName;
                    newGrid.EnableViewState = false;
                    newGrid.HeaderStyle.HorizontalAlign = HorizontalAlign.Left;
                    newGrid.CellPadding = 3;
                    newGrid.GridLines = GridLines.Horizontal;

                    pnlContent.Controls.Add(newGrid);

                    newGrid.DataSource = ds;
                    newGrid.DataMember = dt.TableName;

                    newGrid.DataBind();
                }
            }
        }
    }
    /// <summary>
    /// Adds the field to the form.
    /// </summary>
    /// <param name="node">Document node</param>
    /// <param name="compareNode">Document compare node</param>
    /// <param name="columnName">Column name</param>
    private void AddField(TreeNode node, TreeNode compareNode, string columnName)
    {
        FormFieldInfo ffi = null;
        if (fi != null)
        {
            ffi = fi.GetFormField(columnName);
        }

        TableCell valueCell = new TableCell();
        valueCell.EnableViewState = false;
        TableCell valueCompare = new TableCell();
        valueCompare.EnableViewState = false;
        TableCell labelCell = new TableCell();
        labelCell.EnableViewState = false;
        TextComparison comparefirst;
        TextComparison comparesecond;
        bool loadValue = true;
        bool empty = true;
        bool allowLabel = true;

        // Get the caption
        if ((columnName == UNSORTED) || (ffi != null))
        {
            AttachmentInfo aiCompare = null;

            // Compare attachments
            if ((columnName == UNSORTED) || ((ffi != null) && (ffi.DataType == FieldDataType.DocAttachments)))
            {
                allowLabel = false;

                string title = String.Empty;
                if (columnName == UNSORTED)
                {
                    title = GetString("attach.unsorted") + ":";
                }
                else if (ffi != null)
                {
                    string caption = ffi.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, MacroContext.CurrentResolver);
                    title = (String.IsNullOrEmpty(caption) ? ffi.Name : caption) + ":";
                }

                // Prepare DataSource for original node
                loadValue = false;

                dsAttachments = new AttachmentsDataSource();
                dsAttachments.DocumentVersionHistoryID = versionHistoryId;
                if ((ffi != null) && (columnName != UNSORTED))
                {
                    dsAttachments.AttachmentGroupGUID = ffi.Guid;
                }
                dsAttachments.Path = node.NodeAliasPath;
                dsAttachments.CultureCode = LocalizationContext.PreferredCultureCode;
                SiteInfo si = SiteInfoProvider.GetSiteInfo(node.NodeSiteID);
                dsAttachments.SiteName = si.SiteName;
                dsAttachments.OrderBy = "AttachmentOrder, AttachmentName, AttachmentHistoryID";
                dsAttachments.SelectedColumns = "AttachmentHistoryID, AttachmentGUID, AttachmentImageWidth, AttachmentImageHeight, AttachmentExtension, AttachmentName, AttachmentSize, AttachmentOrder, AttachmentTitle, AttachmentDescription";
                dsAttachments.IsLiveSite = false;
                dsAttachments.DataSource = null;
                dsAttachments.DataBind();

                // Get the attachments table
                attachments = GetAttachmentsTable((DataSet)dsAttachments.DataSource, versionHistoryId, node.DocumentID);

                // Prepare data source for compared node
                if (compareNode != null)
                {
                    dsAttachmentsCompare = new AttachmentsDataSource();
                    dsAttachmentsCompare.DocumentVersionHistoryID = versionCompare;
                    if ((ffi != null) && (columnName != UNSORTED))
                    {
                        dsAttachmentsCompare.AttachmentGroupGUID = ffi.Guid;
                    }
                    dsAttachmentsCompare.Path = compareNode.NodeAliasPath;
                    dsAttachmentsCompare.CultureCode = LocalizationContext.PreferredCultureCode;
                    dsAttachmentsCompare.SiteName = si.SiteName;
                    dsAttachmentsCompare.OrderBy = "AttachmentOrder, AttachmentName, AttachmentHistoryID";
                    dsAttachmentsCompare.SelectedColumns = "AttachmentHistoryID, AttachmentGUID, AttachmentImageWidth, AttachmentImageHeight, AttachmentExtension, AttachmentName, AttachmentSize, AttachmentOrder, AttachmentTitle, AttachmentDescription";
                    dsAttachmentsCompare.IsLiveSite = false;
                    dsAttachmentsCompare.DataSource = null;
                    dsAttachmentsCompare.DataBind();

                    // Get the table to compare
                    attachmentsCompare = GetAttachmentsTable((DataSet)dsAttachmentsCompare.DataSource, versionCompare, node.DocumentID);

                    // Switch the sides if older version is on the right
                    if (versionHistoryId > versionCompare)
                    {
                        Hashtable dummy = attachmentsCompare;
                        attachmentsCompare = attachments;
                        attachments = dummy;
                    }

                    // Add comparison
                    AddTableComparison(attachments, attachmentsCompare, "<strong>" + title + "</strong>", true, true);
                }
                else
                {
                    // Normal display
                    if (attachments.Count != 0)
                    {
                        bool first = true;

                        foreach (DictionaryEntry item in attachments)
                        {
                            string itemValue = ValidationHelper.GetString(item.Value, null);
                            if (!String.IsNullOrEmpty(itemValue))
                            {
                                valueCell = new TableCell();
                                labelCell = new TableCell();

                                if (first)
                                {
                                    labelCell.Text = "<strong>" + String.Format(title, item.Key) + "</strong>";
                                    first = false;
                                }
                                valueCell.Text = itemValue;

                                AddRow(labelCell, valueCell);
                            }
                        }
                    }
                }
            }
            // Compare single file attachment
            else if ((ffi != null) && (ffi.DataType == FieldDataType.File))
            {
                // Get the attachment
                AttachmentInfo ai = DocumentHelper.GetAttachment(ValidationHelper.GetGuid(node.GetValue(columnName), Guid.Empty), versionHistoryId, TreeProvider, false);

                if (compareNode != null)
                {
                    aiCompare = DocumentHelper.GetAttachment(ValidationHelper.GetGuid(compareNode.GetValue(columnName), Guid.Empty), versionCompare, TreeProvider, false);
                }

                loadValue = false;

                // Prepare text comparison controls
                if ((ai != null) || (aiCompare != null))
                {
                    string textorig = null;
                    if (ai != null)
                    {
                        textorig = CreateAttachment(ai.Generalized.DataClass, versionHistoryId);
                    }
                    string textcompare = null;
                    if (aiCompare != null)
                    {
                        textcompare = CreateAttachment(aiCompare.Generalized.DataClass, versionCompare);
                    }

                    comparefirst = new TextComparison();
                    comparefirst.SynchronizedScrolling = false;
                    comparefirst.IgnoreHTMLTags = true;
                    comparefirst.ConsiderHTMLTagsEqual = true;
                    comparefirst.BalanceContent = false;

                    comparesecond = new TextComparison();
                    comparesecond.SynchronizedScrolling = false;
                    comparesecond.IgnoreHTMLTags = true;

                    // Source text must be older version
                    if (versionHistoryId < versionCompare)
                    {
                        comparefirst.SourceText = textorig;
                        comparefirst.DestinationText = textcompare;
                    }
                    else
                    {
                        comparefirst.SourceText = textcompare;
                        comparefirst.DestinationText = textorig;
                    }

                    comparefirst.PairedControl = comparesecond;
                    comparesecond.RenderingMode = TextComparisonTypeEnum.DestinationText;

                    valueCell.Controls.Add(comparefirst);
                    valueCompare.Controls.Add(comparesecond);

                    // Add both cells
                    if (compareNode != null)
                    {
                        AddRow(labelCell, valueCell, valueCompare);
                    }
                    // Add one cell only
                    else
                    {
                        valueCell.Controls.Clear();
                        Literal ltl = new Literal();
                        ltl.Text = textorig;
                        valueCell.Controls.Add(ltl);
                        AddRow(labelCell, valueCell);
                    }
                }
            }
        }

        if (allowLabel && String.IsNullOrEmpty(labelCell.Text))
        {
            labelCell.Text = "<strong>" + columnName + ":</strong>";
        }

        if (loadValue)
        {
            string textcompare = null;

            switch (columnName.ToLowerCSafe())
            {
                // Document content - display content of editable regions and editable web parts
                case "documentcontent":
                    EditableItems ei = new EditableItems();
                    ei.LoadContentXml(ValidationHelper.GetString(node.GetValue(columnName), String.Empty));

                    // Add text comparison control
                    if (compareNode != null)
                    {
                        EditableItems eiCompare = new EditableItems();
                        eiCompare.LoadContentXml(ValidationHelper.GetString(compareNode.GetValue(columnName), String.Empty));

                        // Create editable regions comparison
                        Hashtable hashtable;
                        Hashtable hashtableCompare;

                        // Source text must be older version
                        if (versionHistoryId < versionCompare)
                        {
                            hashtable = ei.EditableRegions;
                            hashtableCompare = eiCompare.EditableRegions;
                        }
                        else
                        {
                            hashtable = eiCompare.EditableRegions;
                            hashtableCompare = ei.EditableRegions;
                        }

                        // Add comparison
                        AddTableComparison(hashtable, hashtableCompare, "<strong>" + columnName + " ({0}):</strong>", false, false);

                        // Create editable webparts comparison
                        // Source text must be older version
                        if (versionHistoryId < versionCompare)
                        {
                            hashtable = ei.EditableWebParts;
                            hashtableCompare = eiCompare.EditableWebParts;
                        }
                        else
                        {
                            hashtable = eiCompare.EditableWebParts;
                            hashtableCompare = ei.EditableWebParts;
                        }

                        // Add comparison
                        AddTableComparison(hashtable, hashtableCompare, "<strong>" + columnName + " ({0}):</strong>", false, false);
                    }
                    // No compare node
                    else
                    {
                        // Editable regions
                        Hashtable hashtable = ei.EditableRegions;
                        if (hashtable.Count != 0)
                        {
                            foreach (DictionaryEntry region in hashtable)
                            {
                                string regionValue = ValidationHelper.GetString(region.Value, null);
                                if (!String.IsNullOrEmpty(regionValue))
                                {
                                    string regionKey = ValidationHelper.GetString(region.Key, null);

                                    valueCell = new TableCell();
                                    labelCell = new TableCell();

                                    labelCell.Text = "<strong>" + columnName + " (" + DictionaryHelper.GetFirstKey(regionKey) + "):</strong>";
                                    valueCell.Text = HttpUtility.HtmlDecode(HTMLHelper.StripTags(regionValue, false));

                                    AddRow(labelCell, valueCell);
                                }
                            }
                        }

                        // Editable web parts
                        hashtable = ei.EditableWebParts;
                        if (hashtable.Count != 0)
                        {
                            foreach (DictionaryEntry part in hashtable)
                            {
                                string partValue = ValidationHelper.GetString(part.Value, null);
                                if (!String.IsNullOrEmpty(partValue))
                                {
                                    string partKey = ValidationHelper.GetString(part.Key, null);
                                    valueCell = new TableCell();
                                    labelCell = new TableCell();

                                    labelCell.Text = "<strong>" + columnName + " (" + DictionaryHelper.GetFirstKey(partKey) + "):</strong>";
                                    valueCell.Text = HttpUtility.HtmlDecode(HTMLHelper.StripTags(partValue, false));

                                    AddRow(labelCell, valueCell);
                                }
                            }
                        }
                    }

                    break;

                case "documentwebparts":
                    StringBuilder sbOriginal = new StringBuilder();
                    StringBuilder sbCompared = new StringBuilder();

                    // Set original web parts
                    string originalWebParts = Convert.ToString(node.GetValue(columnName));
                    GenerateWebPartsMarkup(ref sbOriginal, originalWebParts, true);

                    // Add text comparison control
                    if (compareNode != null)
                    {
                        string compareWebParts = Convert.ToString(compareNode.GetValue(columnName));
                        GenerateWebPartsMarkup(ref sbCompared, compareWebParts, false);
                    }

                    // Set empty flag
                    empty = ((sbOriginal.Length == 0) && (sbCompared.Length == 0));

                    if (!empty)
                    {
                        valueCell.Text += sbOriginal.ToString();
                        valueCompare.Text = sbCompared.ToString();
                    }
                    break;

                // Others, display the string value
                default:
                    // Shift date time values to user time zone
                    object origobject = node.GetValue(columnName);
                    string textorig;
                    if (origobject is DateTime)
                    {
                        textorig = TimeZoneHelper.ConvertToUserTimeZone(ValidationHelper.GetDateTime(origobject, DateTimeHelper.ZERO_TIME), true, CurrentUser, SiteContext.CurrentSite);
                    }
                    else
                    {
                        textorig = ValidationHelper.GetString(origobject, String.Empty);
                    }

                    // Add text comparison control
                    if (compareNode != null)
                    {
                        // Shift date time values to user time zone
                        object compareobject = compareNode.GetValue(columnName);
                        if (compareobject is DateTime)
                        {
                            textcompare = TimeZoneHelper.ConvertToUserTimeZone(ValidationHelper.GetDateTime(compareobject, DateTimeHelper.ZERO_TIME), true, CurrentUser, SiteContext.CurrentSite);
                        }
                        else
                        {
                            textcompare = ValidationHelper.GetString(compareobject, String.Empty);
                        }

                        comparefirst = new TextComparison();
                        comparefirst.SynchronizedScrolling = false;

                        comparesecond = new TextComparison();
                        comparesecond.SynchronizedScrolling = false;
                        comparesecond.RenderingMode = TextComparisonTypeEnum.DestinationText;

                        // Source text must be older version
                        if (versionHistoryId < versionCompare)
                        {
                            comparefirst.SourceText = HttpUtility.HtmlDecode(HTMLHelper.StripTags(textorig, false));
                            comparefirst.DestinationText = HttpUtility.HtmlDecode(HTMLHelper.StripTags(textcompare, false));
                        }
                        else
                        {
                            comparefirst.SourceText = HttpUtility.HtmlDecode(HTMLHelper.StripTags(textcompare, false));
                            comparefirst.DestinationText = HttpUtility.HtmlDecode(HTMLHelper.StripTags(textorig, false));
                        }

                        comparefirst.PairedControl = comparesecond;

                        if (Math.Max(comparefirst.SourceText.Length, comparefirst.DestinationText.Length) < 100)
                        {
                            comparefirst.BalanceContent = false;
                        }

                        valueCell.Controls.Add(comparefirst);
                        valueCompare.Controls.Add(comparesecond);
                    }
                    else
                    {
                        valueCell.Text = HttpUtility.HtmlDecode(HTMLHelper.StripTags(textorig, false));
                    }

                    empty = (String.IsNullOrEmpty(textorig)) && (String.IsNullOrEmpty(textcompare));
                    break;
            }
        }

        if (!empty)
        {
            if (compareNode != null)
            {
                AddRow(labelCell, valueCell, valueCompare);
            }
            else
            {
                AddRow(labelCell, valueCell);
            }
        }
    }
Пример #8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get query parameters
        selectedNodeType         = QueryHelper.GetString("selectednodetype", "webpart");
        selectedNodeName         = QueryHelper.GetString("selectednodename", string.Empty);
        hdnCurrentNodeType.Value = selectedNodeType;
        hdnCurrentNodeName.Value = selectedNodeName;

        bool enabled = DocumentManager.AllowSave;

        btnDelete.Enabled = enabled && !string.IsNullOrEmpty(selectedNodeName);
        if (btnDelete.Enabled)
        {
            btnDelete.OnClientClick = "return DeleteItem();";
            btnDelete.ToolTip       = GetString("Development-WebPart_Tree.DeleteItem");
        }

        btnNew.Enabled = enabled;
        if (btnNew.Enabled)
        {
            btnNew.OnClientClick = "return CreateNew();";
            btnNew.ToolTip       = GetString("Development-WebPart_Tree.NewWebPart");
        }

        string imageUrl = "Design/Controls/Tree";

        // Initialize page
        if (CultureHelper.IsUICultureRTL())
        {
            imageUrl = GetImageUrl("RTL/" + imageUrl);
        }
        else
        {
            imageUrl = GetImageUrl(imageUrl);
        }
        webpartsTree.LineImagesFolder = imageUrl;
        regionsTree.LineImagesFolder  = imageUrl;

        if (Node != null)
        {
            string webPartRootAttributes;
            string regionRootAttributes;

            if (string.IsNullOrEmpty(selectedNodeName))
            {
                switch (selectedNodeType)
                {
                case "webpart":
                    webPartRootAttributes = "class=\"ContentTreeSelectedItem\" id=\"treeSelectedNode\"";
                    regionRootAttributes  = "class=\"ContentTreeItem\" ";
                    break;

                case "region":
                    webPartRootAttributes = "class=\"ContentTreeItem\" ";
                    regionRootAttributes  = "class=\"ContentTreeSelectedItem\" id=\"treeSelectedNode\"";
                    break;

                default:
                    webPartRootAttributes = "class=\"ContentTreeSelectedItem\" id=\"treeSelectedNode\"";
                    regionRootAttributes  = "class=\"ContentTreeItem\" ";
                    break;
                }
            }
            else
            {
                webPartRootAttributes = "class=\"ContentTreeSelectedItem\" id=\"treeSelectedNode\"";
                regionRootAttributes  = "class=\"ContentTreeItem\" ";
            }

            // Create tree menus
            TreeElemNode rootWebpartNode = new TreeElemNode();
            rootWebpartNode.Text        = "<span " + webPartRootAttributes + " onclick=\"SelectNode('','webpart', this);\"><span class=\"Name\">" + ScriptHelper.GetLocalizedString("EditableWebparts.Root", false) + "</span></span>";
            rootWebpartNode.Expanded    = true;
            rootWebpartNode.NavigateUrl = "#";

            TreeElemNode rootRegionNode = new TreeElemNode();
            rootRegionNode.Text        = "<span " + regionRootAttributes + " onclick=\"SelectNode('','region', this);\"><span class=\"Name\">" + ScriptHelper.GetLocalizedString("EditableRegions.Root", false) + "</span></span>";
            rootRegionNode.Expanded    = true;
            rootRegionNode.NavigateUrl = "#";

            // Editable web parts
            webpartsTree.Nodes.Add(rootWebpartNode);
            if (Node.DocumentContent.EditableWebParts.Count > 0)
            {
                foreach (DictionaryEntry webPart in Node.DocumentContent.EditableWebParts)
                {
                    string key  = webPart.Key.ToString();
                    string name = EditableItems.GetFirstKey(key);
                    AddNode(rootWebpartNode, name, "webpart");
                }
            }

            // Editable regions
            regionsTree.Nodes.Add(rootRegionNode);
            if (Node.DocumentContent.EditableRegions.Count > 0)
            {
                foreach (DictionaryEntry region in Node.DocumentContent.EditableRegions)
                {
                    string key  = region.Key.ToString();
                    string name = EditableItems.GetFirstKey(key);
                    AddNode(rootRegionNode, name, "region");
                }
            }
        }

        // Delete item if requested from query string
        string nodeType = QueryHelper.GetString("nodetype", null);
        string nodeName = QueryHelper.GetString("nodename", null);

        if (!RequestHelper.IsPostBack() && !String.IsNullOrEmpty(nodeType) && QueryHelper.GetBoolean("deleteItem", false))
        {
            DeleteItem(nodeType, nodeName);
        }
    }
Пример #9
0
    /// <summary>
    /// Processes the content.
    /// </summary>
    /// <param name="sb">StringBuilder to write</param>
    /// <param name="source">Source object</param>
    /// <param name="column">Column</param>
    /// <param name="content">Content</param>
    protected void ProcessContent(StringBuilder sb, object source, string column, ref string content)
    {
        bool standard = true;

        switch (column.ToLowerCSafe())
        {
        // Document content
        case "documentcontent":
            EditableItems items = new EditableItems();
            items.LoadContentXml(content);

            // Add regions
            foreach (DictionaryEntry region in items.EditableRegions)
            {
                sb.Append("<span class=\"VersionEditableRegionTitle\">" + (string)region.Key + "</span>");

                string regionContent = HTMLHelper.ResolveUrls((string)region.Value, SystemContext.ApplicationPath);

                sb.Append("<span class=\"VersionEditableRegionText\">" + regionContent + "</span>");
            }

            // Add web parts
            foreach (DictionaryEntry part in items.EditableWebParts)
            {
                sb.Append("<span class=\"VersionEditableWebPartTitle\">" + (string)part.Key + "</span>");

                string regionContent = HTMLHelper.ResolveUrls((string)part.Value, SystemContext.ApplicationPath);
                sb.Append("<span class=\"VersionEditableWebPartText\">" + regionContent + "</span>");
            }

            standard = false;
            break;

        // XML columns
        case "pagetemplatewebparts":
        case "webpartproperties":
        case "reportparameters":
        case "classformdefinition":
        case "classxmlschema":
        case "classformlayout":
        case "userdialogsconfiguration":
            content = HTMLHelper.ReformatHTML(content);
            break;

        // File columns
        case "metafilename":
        {
            Guid metaFileGuid = ValidationHelper.GetGuid(GetValueFromSource(source, "MetaFileGuid"), Guid.Empty);
            if (metaFileGuid != Guid.Empty)
            {
                string metaFileName = ValidationHelper.GetString(GetValueFromSource(source, "MetaFileName"), "");

                content = "<a href=\"" + ResolveUrl(MetaFileInfoProvider.GetMetaFileUrl(metaFileGuid, metaFileName)) + "\" target=\"_blank\" >" + HTMLHelper.HTMLEncode(metaFileName) + "</a>";
                sb.Append(content);

                standard = false;
            }
        }
        break;
        }

        // Standard rendering
        if (standard)
        {
            if (content.Length > 500)
            {
                content = TextHelper.EnsureMaximumLineLength(content, 50, "&#x200B;", true);
            }
            else
            {
                content = HTMLHelper.HTMLEncode(content);
            }

            content = TextHelper.EnsureHTMLLineEndings(content);
            content = content.Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
            sb.Append("<div style=\"max-height: 300px; overflow: auto;\">" + content + "</div>");
        }
    }
    /// <summary>
    /// Gets row column content.
    /// </summary>
    /// <param name="dr">DataRow</param>
    /// <param name="dc">DataColumn</param>
    /// <param name="toCompare">Indicates if comparison will be used for content</param>
    /// <returns>String with column content</returns>
    private string GetRowColumnContent(DataRow dr, DataColumn dc, bool toCompare)
    {
        if (dr == null)
        {
            // Data row was not specified
            return string.Empty;
        }

        if (!dr.Table.Columns.Contains(dc.ColumnName))
        {
            // Data row does not contain the required column
            return string.Empty;
        }

        var value = dr[dc.ColumnName];

        if (DataHelper.IsEmpty(value))
        {
            // Column is empty
            return string.Empty;
        }

        var content = ValidationHelper.GetString(value, "");

        Func<string> render = () =>
        {
            if (toCompare)
            {
                return content;
            }

            content = TextHelper.EnsureHTMLLineEndings(content);

            return content;
        };

        Func<string> standardRender = () =>
        {
            if (toCompare)
            {
                return content;
            }

            if (EncodeDisplayedData)
            {
                content = HTMLHelper.HTMLEncode(content);
            }
            content = content.Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
            content = "<div style=\"max-height: 300px; overflow: auto;\">" + content + "</div>";
            content = TextHelper.EnsureLineEndings(content, "<br />");

            return content;
        };

        // Binary columns
        if (dc.DataType == typeof(byte[]))
        {
            var data = (byte[])dr[dc.ColumnName];
            content = string.Format("<{0}: {1}>", GetString("General.BinaryData"), DataHelper.GetSizeString(data.Length));

            return standardRender();
        }

        // DataTime columns
        if (dc.DataType == typeof(DateTime))
        {
            var dateTime = Convert.ToDateTime(content);
            var cultureInfo = CultureHelper.GetCultureInfo(MembershipContext.AuthenticatedUser.PreferredUICultureCode);
            content = dateTime.ToString(cultureInfo);

            return standardRender();
        }

        switch (dc.ColumnName.ToLowerCSafe())
        {
            // Document content
            case "documentcontent":
                var sb = new StringBuilder();

                Action<MultiKeyDictionary<string>, string, string> addItems = (dictionary, titleClass, textClass) =>
                {
                    foreach (DictionaryEntry item in dictionary)
                    {
                        var regionContent = HTMLHelper.ResolveUrls((string)item.Value, SystemContext.ApplicationPath);

                        if (toCompare)
                        {
                            sb.AppendLine((string)item.Key);
                            sb.AppendLine(regionContent);
                        }
                        else
                        {
                            sb.AppendFormat("<span class=\"{0}\">{1}</span>", titleClass, item.Key);
                            sb.AppendFormat("<span class=\"{0}\">{1}</span>", textClass, HTMLHelper.HTMLEncode(regionContent));
                        }
                    }
                };

                var items = new EditableItems();
                items.LoadContentXml(ValidationHelper.GetString(value, ""));

                // Add regions
                addItems(items.EditableRegions, "VersionEditableRegionTitle", "VersionEditableRegionText");

                // Add web parts
                addItems(items.EditableWebParts, "VersionEditableWebPartTitle", "VersionEditableWebPartText");

                content = sb.ToString();
                return render();

            // XML columns
            case "pagetemplatewebparts":
            case "webpartproperties":
            case "reportparameters":
            case "classformdefinition":
            case "classxmlschema":
            case "classformlayout":
            case "userdialogsconfiguration":
            case "siteinvoicetemplate":
            case "userlastlogoninfo":
            case "formdefinition":
            case "formlayout":
            case "uservisibility":
            case "classsearchsettings":
            case "graphsettings":
            case "tablesettings":
            case "transformationhierarchicalxml":
            case "issuetext":
            case "savedreportparameters":

            // HTML columns
            case "emailtemplatetext":
            case "templatebody":
            case "templateheader":
            case "templatefooter":
            case "containertextbefore":
            case "containertextafter":
            case "savedreporthtml":
            case "layoutcode":
            case "webpartlayoutcode":
            case "transformationcode":
            case "reportlayout":
                if (BrowserHelper.IsIE())
                {
                    content = HTMLHelper.ReformatHTML(content, " ");
                }
                else
                {
                    content = HTMLHelper.ReformatHTML(content);
                }
                break;

            // File columns
            case "metafilename":
                var metaFileName = HTMLHelper.HTMLEncode(ValidationHelper.GetString(dr["MetaFileName"], ""));

                if (ShowLinksForMetafiles)
                {
                    var metaFileGuid = ValidationHelper.GetGuid(dr["MetaFileGuid"], Guid.Empty);
                    if (metaFileGuid != Guid.Empty)
                    {
                        var metaFileUrl = ResolveUrl(MetaFileInfoProvider.GetMetaFileUrl(metaFileGuid, metaFileName));
                        content = string.Format("<a href=\"{0}\" target=\"_blank\">{1}</a>", metaFileUrl, metaFileName);
                    }
                }
                else
                {
                    content = metaFileName;
                }

                return render();
        }

        return standardRender();
    }
Пример #11
0
    /// <summary>
    /// Fills given list with properties of given object.
    /// </summary>
    /// <param name="properties">List to fill</param>
    /// <param name="dataProperties">List of data properties</param>
    /// <param name="obj">Object the properties of which should be added to the list</param>
    private static void FillObjectProperties(List <string> properties, List <string> dataProperties, object obj)
    {
        if (obj != null)
        {
            if (obj is DataRow)
            {
                // DataRow source, bind column names
                DataRow dr = (DataRow)obj;
                foreach (DataColumn col in dr.Table.Columns)
                {
                    properties.Add(col.ColumnName);
                }
            }
            else if (obj is DataRowView)
            {
                // DataRowView source, bind column names
                DataRowView dr = (DataRowView)obj;
                foreach (DataColumn col in dr.DataView.Table.Columns)
                {
                    properties.Add(col.ColumnName);
                }
            }
            else if (obj is AbstractContext)
            {
                AbstractContext context = (AbstractContext)obj;
                properties.AddRange(context.Properties);
            }
            else if (obj is IHierarchicalObject)
            {
                // Data container source
                IHierarchicalObject hc = (IHierarchicalObject)obj;
                properties.AddRange(hc.Properties);
            }
            else if (obj is IDataContainer)
            {
                // Data container source
                IDataContainer dc = (IDataContainer)obj;
                properties.AddRange(dc.ColumnNames);
            }

            // Named enumerable objects
            if (obj is INamedEnumerable)
            {
                INamedEnumerable namedCol = (INamedEnumerable)obj;
                if (namedCol.ItemsHaveNames)
                {
                    IEnumerator enumerator = namedCol.GetNamedEnumerator();
                    while (enumerator.MoveNext())
                    {
                        // Named item
                        string name = namedCol.GetObjectName(enumerator.Current);
                        if (ValidationHelper.IsIdentifier(name))
                        {
                            dataProperties.Add(name);
                        }
                        else
                        {
                            dataProperties.Add("[\"" + name + "\"]");
                        }
                    }
                }
            }

            // Special case for TreeNode and PageInfo - append ediable parts
            if ((obj is CMS.TreeEngine.TreeNode) || (obj is PageInfo))
            {
                EditableItems eItems = null;

                if (obj is CMS.TreeEngine.TreeNode)
                {
                    // TreeNode editable fields
                    CMS.TreeEngine.TreeNode node = (CMS.TreeEngine.TreeNode)obj;
                    eItems = node.DocumentContent;
                }
                else
                {
                    PageInfo pi = (PageInfo)obj;
                    eItems = pi.EditableItems;
                }

                // Editable regions
                foreach (string item in eItems.EditableRegions.Keys)
                {
                    properties.Add(item);
                }

                // Editable webparts
                foreach (string item in eItems.EditableWebParts.Keys)
                {
                    properties.Add(item);
                }
            }
        }
    }
Пример #12
0
    /// <summary>
    /// Adds the field to the form.
    /// </summary>
    /// <param name="node">Document node</param>
    /// <param name="compareNode">Document compare node</param>
    /// <param name="columnName">Column name</param>
    private void AddField(TreeNode node, TreeNode compareNode, string columnName)
    {
        FormFieldInfo ffi = null;

        if (fi != null)
        {
            ffi = fi.GetFormField(columnName);
        }

        TableCell valueCell = new TableCell();

        valueCell.EnableViewState = false;
        TableCell valueCompare = new TableCell();

        valueCompare.EnableViewState = false;
        TableCell labelCell = new TableCell();

        labelCell.EnableViewState = false;
        TextComparison comparefirst  = null;
        TextComparison comparesecond = null;
        bool           switchSides   = true;
        bool           loadValue     = true;
        bool           empty         = true;
        bool           allowLabel    = true;

        // Get the caption
        if ((columnName == UNSORTED) || (ffi != null))
        {
            AttachmentInfo aiCompare = null;

            // Compare attachments
            if ((columnName == UNSORTED) || (ffi.DataType == FormFieldDataTypeEnum.DocumentAttachments))
            {
                allowLabel = false;

                string title = null;
                if (columnName == UNSORTED)
                {
                    title = GetString("attach.unsorted") + ":";
                }
                else
                {
                    title = (String.IsNullOrEmpty(ffi.Caption) ? ffi.Name : ffi.Caption) + ":";
                }

                // Prepare DataSource for original node
                loadValue = false;

                dsAttachments = new AttachmentsDataSource();
                dsAttachments.DocumentVersionHistoryID = versionHistoryId;
                if (columnName != UNSORTED)
                {
                    dsAttachments.AttachmentGroupGUID = ffi.Guid;
                }
                dsAttachments.Path        = node.NodeAliasPath;
                dsAttachments.CultureCode = CMSContext.PreferredCultureCode;
                SiteInfo si = SiteInfoProvider.GetSiteInfo(node.NodeSiteID);
                dsAttachments.SiteName        = si.SiteName;
                dsAttachments.OrderBy         = "AttachmentOrder, AttachmentName, AttachmentHistoryID";
                dsAttachments.SelectedColumns = "AttachmentHistoryID, AttachmentGUID, AttachmentImageWidth, AttachmentImageHeight, AttachmentExtension, AttachmentName, AttachmentSize, AttachmentOrder, AttachmentTitle, AttachmentDescription";
                dsAttachments.IsLiveSite      = false;
                dsAttachments.DataSource      = null;
                dsAttachments.DataBind();

                // Get the attachments table
                attachments = GetAttachmentsTable((DataSet)dsAttachments.DataSource, versionHistoryId, node.DocumentID);

                // Prepare datasource for compared node
                if (compareNode != null)
                {
                    dsAttachmentsCompare = new AttachmentsDataSource();
                    dsAttachmentsCompare.DocumentVersionHistoryID = versionCompare;
                    if (columnName != UNSORTED)
                    {
                        dsAttachmentsCompare.AttachmentGroupGUID = ffi.Guid;
                    }
                    dsAttachmentsCompare.Path            = compareNode.NodeAliasPath;
                    dsAttachmentsCompare.CultureCode     = CMSContext.PreferredCultureCode;
                    dsAttachmentsCompare.SiteName        = si.SiteName;
                    dsAttachmentsCompare.OrderBy         = "AttachmentOrder, AttachmentName, AttachmentHistoryID";
                    dsAttachmentsCompare.SelectedColumns = "AttachmentHistoryID, AttachmentGUID, AttachmentImageWidth, AttachmentImageHeight, AttachmentExtension, AttachmentName, AttachmentSize, AttachmentOrder, AttachmentTitle, AttachmentDescription";
                    dsAttachmentsCompare.IsLiveSite      = false;
                    dsAttachmentsCompare.DataSource      = null;
                    dsAttachmentsCompare.DataBind();

                    // Get the table to compare
                    attachmentsCompare = GetAttachmentsTable((DataSet)dsAttachmentsCompare.DataSource, versionCompare, node.DocumentID);

                    // Switch the sides if older version is on the right
                    if (versionHistoryId > versionCompare)
                    {
                        Hashtable dummy = attachmentsCompare;
                        attachmentsCompare = attachments;
                        attachments        = dummy;
                    }

                    // Add comparison
                    AddTableComparison(attachments, attachmentsCompare, "<strong>" + title + "</strong>", true, true);
                }
                else
                {
                    // Normal display
                    if (attachments.Count != 0)
                    {
                        bool   first     = true;
                        string itemValue = null;

                        foreach (DictionaryEntry item in attachments)
                        {
                            itemValue = ValidationHelper.GetString(item.Value, null);
                            if (!String.IsNullOrEmpty(itemValue))
                            {
                                valueCell = new TableCell();
                                labelCell = new TableCell();

                                if (first)
                                {
                                    labelCell.Text = "<strong>" + String.Format(title, item.Key) + "</strong>";
                                    first          = false;
                                }
                                valueCell.Text = itemValue;

                                AddRow(labelCell, valueCell, null, even);
                                even = !even;
                            }
                        }
                    }
                }
            }
            // Compare single file attachment
            else if (ffi.DataType == FormFieldDataTypeEnum.File)
            {
                // Get the attachment
                AttachmentInfo ai = DocumentHelper.GetAttachment(ValidationHelper.GetGuid(node.GetValue(columnName), Guid.Empty), versionHistoryId, TreeProvider, false);

                if (compareNode != null)
                {
                    aiCompare = DocumentHelper.GetAttachment(ValidationHelper.GetGuid(compareNode.GetValue(columnName), Guid.Empty), versionCompare, TreeProvider, false);
                }

                loadValue = false;
                empty     = true;

                // Prepare text comparison controls
                if ((ai != null) || (aiCompare != null))
                {
                    string textorig = null;
                    if (ai != null)
                    {
                        textorig = CreateAttachment(ai.Generalized.DataClass, versionHistoryId);
                    }
                    string textcompare = null;
                    if (aiCompare != null)
                    {
                        textcompare = CreateAttachment(aiCompare.Generalized.DataClass, versionCompare);
                    }

                    comparefirst = new TextComparison();
                    comparefirst.SynchronizedScrolling = false;
                    comparefirst.IgnoreHTMLTags        = true;
                    comparefirst.ConsiderHTMLTagsEqual = true;
                    comparefirst.BalanceContent        = false;

                    comparesecond = new TextComparison();
                    comparesecond.SynchronizedScrolling = false;
                    comparesecond.IgnoreHTMLTags        = true;

                    // Source text must be older version
                    if (versionHistoryId < versionCompare)
                    {
                        comparefirst.SourceText      = textorig;
                        comparefirst.DestinationText = textcompare;
                    }
                    else
                    {
                        comparefirst.SourceText      = textcompare;
                        comparefirst.DestinationText = textorig;
                    }

                    comparefirst.PairedControl  = comparesecond;
                    comparesecond.RenderingMode = TextComparisonTypeEnum.DestinationText;

                    valueCell.Controls.Add(comparefirst);
                    valueCompare.Controls.Add(comparesecond);
                    switchSides = false;

                    // Add both cells
                    if (compareNode != null)
                    {
                        AddRow(labelCell, valueCell, valueCompare, switchSides, null, even);
                    }
                    // Add one cell only
                    else
                    {
                        valueCell.Controls.Clear();
                        Literal ltl = new Literal();
                        ltl.Text = textorig;
                        valueCell.Controls.Add(ltl);
                        AddRow(labelCell, valueCell, null, even);
                    }
                    even = !even;
                }
            }
        }

        if (allowLabel && (labelCell.Text == ""))
        {
            labelCell.Text = "<strong>" + columnName + ":</strong>";
        }

        if (loadValue)
        {
            string textcompare = null;

            switch (columnName.ToLower())
            {
            // Document content - display content of editable regions and editable web parts
            case "documentcontent":
                EditableItems ei = new EditableItems();
                ei.LoadContentXml(ValidationHelper.GetString(node.GetValue(columnName), ""));

                // Add text comparison control
                if (compareNode != null)
                {
                    EditableItems eiCompare = new EditableItems();
                    eiCompare.LoadContentXml(ValidationHelper.GetString(compareNode.GetValue(columnName), ""));

                    // Create editable regions comparison
                    Hashtable hashtable;
                    Hashtable hashtableCompare;

                    // Source text must be older version
                    if (versionHistoryId < versionCompare)
                    {
                        hashtable        = ei.EditableRegions;
                        hashtableCompare = eiCompare.EditableRegions;
                    }
                    else
                    {
                        hashtable        = eiCompare.EditableRegions;
                        hashtableCompare = ei.EditableRegions;
                    }

                    // Add comparison
                    AddTableComparison(hashtable, hashtableCompare, "<strong>" + columnName + " ({0}):</strong>", false, false);

                    // Create editable webparts comparison
                    // Source text must be older version
                    if (versionHistoryId < versionCompare)
                    {
                        hashtable        = ei.EditableWebParts;
                        hashtableCompare = eiCompare.EditableWebParts;
                    }
                    else
                    {
                        hashtable        = eiCompare.EditableWebParts;
                        hashtableCompare = ei.EditableWebParts;
                    }

                    // Add comparison
                    AddTableComparison(hashtable, hashtableCompare, "<strong>" + columnName + " ({0}):</strong>", false, false);
                }
                // No compare node
                else
                {
                    // Editable regions
                    Hashtable hashtable = ei.EditableRegions;
                    if (hashtable.Count != 0)
                    {
                        string regionValue = null;
                        string regionKey   = null;

                        foreach (DictionaryEntry region in hashtable)
                        {
                            regionValue = ValidationHelper.GetString(region.Value, null);
                            if (!String.IsNullOrEmpty(regionValue))
                            {
                                regionKey = ValidationHelper.GetString(region.Key, null);

                                valueCell = new TableCell();
                                labelCell = new TableCell();

                                labelCell.Text = "<strong>" + columnName + " (" + MultiKeyHashtable.GetFirstKey(regionKey) + "):</strong>";
                                valueCell.Text = HttpUtility.HtmlDecode(HTMLHelper.StripTags(regionValue, false));

                                AddRow(labelCell, valueCell, null, even);
                                even = !even;
                            }
                        }
                    }

                    // Editable web parts
                    hashtable = ei.EditableWebParts;
                    if (hashtable.Count != 0)
                    {
                        string partValue = null;
                        string partKey   = null;

                        foreach (DictionaryEntry part in hashtable)
                        {
                            partValue = ValidationHelper.GetString(part.Value, null);
                            if (!String.IsNullOrEmpty(partValue))
                            {
                                partKey   = ValidationHelper.GetString(part.Key, null);
                                valueCell = new TableCell();
                                labelCell = new TableCell();

                                labelCell.Text = "<strong>" + columnName + " (" + MultiKeyHashtable.GetFirstKey(partKey) + "):</strong>";
                                valueCell.Text = HttpUtility.HtmlDecode(HTMLHelper.StripTags(partValue, false));

                                AddRow(labelCell, valueCell, null, even);
                                even = !even;
                            }
                        }
                    }
                }

                break;

            // Others, display the string value
            default:
                // Shift date time values to user time zone
                object origobject = node.GetValue(columnName);
                string textorig   = null;
                if (origobject is DateTime)
                {
                    TimeZoneInfo usedTimeZone = null;
                    textorig = TimeZoneHelper.GetCurrentTimeZoneDateTimeString(ValidationHelper.GetDateTime(origobject, DateTimeHelper.ZERO_TIME), CurrentUser, CMSContext.CurrentSite, out usedTimeZone);
                }
                else
                {
                    textorig = ValidationHelper.GetString(origobject, "");
                }

                // Add text comparison control
                if (compareNode != null)
                {
                    // Shift date time values to user time zone
                    object compareobject = compareNode.GetValue(columnName);
                    if (compareobject is DateTime)
                    {
                        TimeZoneInfo usedTimeZone = null;
                        textcompare = TimeZoneHelper.GetCurrentTimeZoneDateTimeString(ValidationHelper.GetDateTime(compareobject, DateTimeHelper.ZERO_TIME), CurrentUser, CMSContext.CurrentSite, out usedTimeZone);
                    }
                    else
                    {
                        textcompare = ValidationHelper.GetString(compareobject, "");
                    }

                    comparefirst = new TextComparison();
                    comparefirst.SynchronizedScrolling = false;

                    comparesecond = new TextComparison();
                    comparesecond.SynchronizedScrolling = false;
                    comparesecond.RenderingMode         = TextComparisonTypeEnum.DestinationText;

                    // Source text must be older version
                    if (versionHistoryId < versionCompare)
                    {
                        comparefirst.SourceText      = HttpUtility.HtmlDecode(HTMLHelper.StripTags(textorig, false));
                        comparefirst.DestinationText = HttpUtility.HtmlDecode(HTMLHelper.StripTags(textcompare, false));
                    }
                    else
                    {
                        comparefirst.SourceText      = HttpUtility.HtmlDecode(HTMLHelper.StripTags(textcompare, false));
                        comparefirst.DestinationText = HttpUtility.HtmlDecode(HTMLHelper.StripTags(textorig, false));
                    }

                    comparefirst.PairedControl = comparesecond;

                    if (Math.Max(comparefirst.SourceText.Length, comparefirst.DestinationText.Length) < 100)
                    {
                        comparefirst.BalanceContent = false;
                    }

                    valueCell.Controls.Add(comparefirst);
                    valueCompare.Controls.Add(comparesecond);
                    switchSides = false;
                }
                else
                {
                    valueCell.Text = HttpUtility.HtmlDecode(HTMLHelper.StripTags(textorig, false));
                }

                empty = (String.IsNullOrEmpty(textorig)) && (String.IsNullOrEmpty(textcompare));
                break;
            }
        }

        if (!empty)
        {
            if (compareNode != null)
            {
                AddRow(labelCell, valueCell, valueCompare, switchSides, null, even);
                even = !even;
            }
            else
            {
                AddRow(labelCell, valueCell, null, even);
                even = !even;
            }
        }
    }
Пример #13
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!RequestHelper.IsPostBack())
        {
            // Fill dropdown list
            InitEditorOptions();

            // Inform user about saving
            if (QueryHelper.GetBoolean("imagesaved", false))
            {
                ShowChangesSaved();
                drpEditControl.SelectedIndex = 1;
            }
        }

        // Initialize HTML editor
        InitHTMLEditor();

        // Find post back invoker
        string invokerName = Page.Request.Params.Get(postEventSourceID);

        invokeControl = !string.IsNullOrEmpty(invokerName) ? Page.FindControl(invokerName) : null;

        // Set whether new item is to be created
        createNew = QueryHelper.GetBoolean("createNew", false);

        if (invokerName != null)
        {
            if (createNew && (invokeControl == drpEditControl))
            {
                createNew = true;
            }
            else
            {
                if (invokeControl == drpEditControl)
                {
                    createNew = false;
                }
            }
        }


        // Get query parameters
        keyName = QueryHelper.GetString("nodename", string.Empty);

        // Set editable content type enumeration
        switch (QueryHelper.GetString("nodetype", "webpart"))
        {
        case "webpart":
            keyType = EditableContentType.webpart;
            break;

        case "region":
            keyType = EditableContentType.region;
            break;
        }

        // Clear error
        ShowError("");


        // Show editing controls
        if ((createNew || (keyName != string.Empty)))
        {
            menuElem.Visible           = true;
            menuElem.ShowSave          = true;
            pnlEditableContent.Visible = true;
        }

        // Get content
        if (node != null)
        {
            // Initialize java scripts
            ltlScript.Text += ScriptHelper.GetScript("mainUrl = '" + ResolveUrl(EDITABLE_CONTENT_FOLDER + "main.aspx") + "?nodeid=" + node.NodeID + "';");

            if ((keyName != string.Empty) || createNew)
            {
                if (!RequestHelper.IsPostBack() && !createNew)
                {
                    txtName.Text = EditableItems.GetFirstKey(keyName);
                }

                if (!createNew)
                {
                    content = GetContent();

                    // Disable HTML editor if content is type of image
                    if (content != null)
                    {
                        if (content.StartsWithCSafe("<image>"))
                        {
                            ListItem li = drpEditControl.Items.FindByValue(Convert.ToInt32(EditingForms.HTMLEditor).ToString());
                            if (li != null)
                            {
                                drpEditControl.Items.Remove(li);
                            }
                        }
                    }
                }
            }
        }

        // Show div with content controls
        advancedEditables.Visible = true;
        // Hide all content controls
        txtAreaContent.Visible = txtContent.Visible = htmlContent.Visible = imageContent.Visible = false;

        // Set up editing forms
        switch (((EditingForms)Convert.ToInt32(drpEditControl.SelectedValue)))
        {
        case EditingForms.TextArea:
            txtAreaContent.Visible = true;
            break;

        case EditingForms.HTMLEditor:
            htmlContent.Visible = true;
            break;

        case EditingForms.EditableImage:
            imageContent.ViewMode   = ViewModeEnum.Edit;
            imageContent.Visible    = true;
            imageContent.ImageTitle = HTMLHelper.HTMLEncode(EditableItems.GetFirstKey(keyName));
            break;

        case EditingForms.TextBox:
            advancedEditables.Visible = false;
            txtContent.Visible        = true;
            break;
        }
        // Set visibility of div based on content controls
        advancedEditables.Visible = txtAreaContent.Visible || htmlContent.Visible || imageContent.Visible;
        lblContent.Visible        = txtContent.Visible;
    }