Menu

[59aa80]: / FeedbackGeneratorQQ / Models / AttributeModel.cs  Maximize  Restore  History

Download this file

79 lines (65 with data), 2.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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();
}
}
}
MongoDB Logo MongoDB