/// <summary> /// 组装表情实体 /// </summary> /// <param name="category">表情分类</param> /// <param name="categoryElement">表情分类配置节点</param> private void PopulateEmotion(EmotionCategory category, XElement categoryElement) { string emoticonPath = WebUtility.ResolveUrl(_emotionSettings.EmoticonPath); IEnumerable <XElement> emotionsElements = categoryElement.Elements(); foreach (var emotionElement in emotionsElements) { Emotion emotion = Emotion.New(emotionElement); emotion.FormatedCode = string.Format("[{0}{1}]", !string.IsNullOrEmpty(category.CodePrefix) ? category.CodePrefix + ":" : string.Empty, emotion.Code); emotion.ImageUrl = string.Format("{0}/{1}/{2}", emoticonPath, category.DirectoryName, emotion.FileName); if (category.Emotions.Where(n => n.Code == emotion.Code).Count() == 0) { category.Emotions.Add(emotion); } PrepareTransformsInfo(category); } }
/// <summary> /// 创建实体示例 /// </summary> /// <param name="xElement"></param> /// <returns></returns> public static Emotion New(XElement xElement) { Emotion emotion = new Emotion(); if (xElement != null) { XAttribute attr = xElement.Attribute("code"); if (attr != null) emotion.code = attr.Value; attr = xElement.Attribute("fileName"); if (attr != null) emotion.fileName = attr.Value; attr = xElement.Attribute("description"); if (attr != null) emotion.description = attr.Value; } return emotion; }