/// <summary>
        /// 访问并呈现当前标签实例。
        /// </summary>
        /// <param name="context">当前HTML标签上下文,包含当前HTML相关信息。</param>
        /// <param name="output">当前标签输出实例,用于呈现标签相关信息。</param>
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            var type = _typeManager.Find(TypeId);

            if (type == null)
            {
                output.SuppressOutput();
                return;
            }
            var builder = new TagBuilder("div");

            if (!string.IsNullOrEmpty(type.IconUrl))
            {
                if (type.IconUrl.IndexOf('.') == -1)
                {
                    output.TagName = "i";
                    builder.AddCssClass(type.IconUrl);
                }
                else
                {
                    output.TagName = "img";
                    builder.MergeAttribute("src", type.IconUrl);
                }
            }
            else
            {
                builder.InnerHtml.AppendHtml(type.Name);
            }

            string style = null;

            if (!string.IsNullOrEmpty(type.BgColor))
            {
                style += $"background-color:{type.BgColor};";
            }
            if (!string.IsNullOrEmpty(type.Color))
            {
                style += $"color:{type.Color};";
            }
            if (style != null)
            {
                builder.MergeAttribute("style", style);
            }
            output.MergeAttributes(builder);
        }
示例#2
0
        private void Init(string eventType, EventMessage message)
        {
            if (string.IsNullOrEmpty(message.Message))
            {
                throw new ArgumentNullException(nameof(message.Message), Resources.EventMessage_NullMessage);
            }

            if (message.EventId == 0)
            {
                var type = _eventTypeManager.Find(x => x.Name.Equals(eventType, StringComparison.OrdinalIgnoreCase));
                if (type == null)
                {
                    type = new EventType {
                        Name = eventType
                    };
                    _eventTypeManager.Save(type);
                }

                message.EventId = type.Id;
            }

            var httpContext = _httpContextAccessor.HttpContext;

            if (string.IsNullOrEmpty(message.IPAdress))
            {
                message.IPAdress = httpContext.GetUserAddress();
            }

            if (message.UserId == 0)
            {
                var userId = httpContext.User.GetUserId();
                if (userId == 0)
                {
                    throw new ArgumentNullException(nameof(message.UserId), Resources.EventMessage_NullUserId);
                }

                message.UserId = userId;
            }
        }
示例#3
0
 /// <summary>
 /// 获取事件类型。
 /// </summary>
 /// <param name="id">事件类型Id。</param>
 /// <returns>返回事件类型名称。</returns>
 public string GetEventType(int id) => _eventTypeManager.Find(id)?.Name;