Example #1
0
        /// <summary>
        /// Sends server control content to a provided <see cref="T:System.Web.UI.HtmlTextWriter" /> object, which writes the content to be rendered on the client.
        /// </summary>
        /// <param name="writer">The <see cref="T:System.Web.UI.HtmlTextWriter" /> object that receives the server control content.</param>
        protected override void Render(HtmlTextWriter writer)
        {
#pragma warning disable CS0618 // Type or member is obsolete
            var personBadgeCache = new PersonBadgeCache(BadgeCache);
#pragma warning restore CS0618 // Type or member is obsolete
            var badgeComponent = BadgeCache?.BadgeComponent;

            if (badgeComponent == null)
            {
                return;
            }

            var entity = Entity;
            if (entity == null)
            {
                entity = ContextEntityBlock?.Entity;
            }

            if (entity == null)
            {
                return;
            }

            if (!BadgeService.DoesBadgeApplyToEntity(BadgeCache, entity))
            {
                return;
            }

            try
            {
                badgeComponent.ParentContextEntityBlock = ContextEntityBlock;
                badgeComponent.Entity = entity;
                badgeComponent.Render(BadgeCache, writer);

#pragma warning disable CS0618 // Type or member is obsolete
                badgeComponent.Render(personBadgeCache, writer);
#pragma warning restore CS0618 // Type or member is obsolete

                var script = badgeComponent.GetWrappedJavaScript(BadgeCache);

                if (!script.IsNullOrWhiteSpace())
                {
                    ScriptManager.RegisterStartupScript(this, GetType(), $"badge_{ClientID}", script, true);
                }
            }
            catch (Exception ex)
            {
                var errorMessage = $"An error occurred rendering badge: {BadgeCache?.Name }, badge-id: {BadgeCache?.Id}";
                ExceptionLogService.LogException(new Exception(errorMessage, ex));
                var badgeNameClass = BadgeCache?.Name.ToLower().RemoveAllNonAlphaNumericCharacters() ?? "error";
                writer.Write($"<div class='badge badge-{badgeNameClass} badge-id-{BadgeCache?.Id} badge-error' data-toggle='tooltip' data-original-title='{errorMessage}'>");
                writer.Write($"  <i class='fa fa-exclamation-triangle badge-icon text-warning'></i>");
                writer.Write("</div>");
            }
            finally
            {
                const string script = "$('.badge[data-toggle=\"tooltip\"]').tooltip({html: true}); $('.badge[data-toggle=\"popover\"]').popover();";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "badge-popover", script, true);
            }
        }
Example #2
0
        /// <summary>
        /// Sends server control content to a provided <see cref="T:System.Web.UI.HtmlTextWriter" /> object, which writes the content to be rendered on the client.
        /// </summary>
        /// <param name="writer">The <see cref="T:System.Web.UI.HtmlTextWriter" /> object that receives the server control content.</param>
        protected override void Render(HtmlTextWriter writer)
        {
#pragma warning disable CS0618 // Type or member is obsolete
            var personBadgeCache = new PersonBadgeCache(BadgeCache);
#pragma warning restore CS0618 // Type or member is obsolete
            var badgeComponent = BadgeCache?.BadgeComponent;
            if (badgeComponent != null)
            {
                var contextEntityBlock = ContextEntityBlock;
                if (contextEntityBlock != null)
                {
                    if (BadgeService.DoesBadgeApplyToEntity(BadgeCache, contextEntityBlock.Entity))
                    {
                        badgeComponent.ParentContextEntityBlock = contextEntityBlock;
                        badgeComponent.Entity = contextEntityBlock.Entity;
                        badgeComponent.Render(BadgeCache, writer);
#pragma warning disable CS0618 // Type or member is obsolete
                        badgeComponent.Render(personBadgeCache, writer);
#pragma warning restore CS0618 // Type or member is obsolete

                        const string script = "$('.badge[data-toggle=\"tooltip\"]').tooltip({html: true}); $('.badge[data-toggle=\"popover\"]').popover();";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "badge-popover", script, true);
                    }
                }
            }
        }