namespace FeedbackGeneratorQQ.Models { using System.Collections.Generic; using System.IO; using System.Linq; using System.Xml; using FeedbackGeneratorQQ.Utils; public class AttributeModel { /// /// Gets or sets a value indicating whether attribute is selected /// public bool IsSelected { get; set; } /// /// Gets or sets attribute type /// public string Type { get; set; } /// /// Gets or sets attribute name /// public string Name { get; private set; } /// /// Gets or sets attribute available types /// public List Types { get; private set; } /// /// List of type, type_phrase pairs /// private readonly List> content; public AttributeModel() { this.IsSelected = false; this.Types = new List(); this.content = new List>(); } public AttributeModel(string path) : this() { DirectoryInfo directoryInfo = new DirectoryInfo(path); this.Name = directoryInfo.Name; string templatePath = AttributesHelper.GetAttributePath(path); if (!File.Exists(templatePath)) { return; } XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(templatePath); XmlNode rootNode = xmlDocument.SelectSingleNode(AttributesHelper.TemplateRootNode); if (rootNode == null) { return; } foreach (XmlNode childNode in rootNode.ChildNodes) { this.content.Add(new KeyValuePair(childNode.Name, childNode.InnerText.Trim())); } this.Types = this.content.Select(x => x.Key).Distinct().ToList(); } public List GetMessages() { return this.content.Where(x => x.Key.Equals(this.Type)) .Select(x => x.Value) .ToList(); } } }