namespace FeedbackGeneratorQQ.Models
{
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using FeedbackGeneratorQQ.Utils;
public class AttributeModel
{
/// <summary>
/// Gets or sets a value indicating whether attribute is selected
/// </summary>
public bool IsSelected { get; set; }
/// <summary>
/// Gets or sets attribute type
/// </summary>
public string Type { get; set; }
/// <summary>
/// Gets or sets attribute name
/// </summary>
public string Name { get; private set; }
/// <summary>
/// Gets or sets attribute available types
/// </summary>
public List<string> Types { get; private set; }
/// <summary>
/// List of type, type_phrase pairs
/// </summary>
private readonly List<KeyValuePair<string, string>> content;
public AttributeModel()
{
this.IsSelected = false;
this.Types = new List<string>();
this.content = new List<KeyValuePair<string, string>>();
}
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<string, string>(childNode.Name, childNode.InnerText.Trim()));
}
this.Types = this.content.Select(x => x.Key).Distinct().ToList();
}
public List<string> GetMessages()
{
return this.content.Where(x => x.Key.Equals(this.Type))
.Select(x => x.Value)
.ToList();
}
}
}