added some development tools
[windows-sources.git] / developer / VSSDK / Samples / Code_Sweep / C# / Scanner / TermTable.cs
blob7f199edf30261b43c4472a134d5962f7e8a47033
1 /***************************************************************************
3 Copyright (c) Microsoft Corporation. All rights reserved.
4 THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
5 ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
6 IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
7 PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
9 ***************************************************************************/
11 using System;
12 using System.Collections.Generic;
13 using System.Globalization;
14 using System.Runtime.Serialization;
15 using System.Xml;
17 namespace Microsoft.Samples.VisualStudio.CodeSweep.Scanner
19 [Serializable]
20 class TermTable : ITermTable, ISerializable
22 const string FilePathKey = "FilePath";
23 const string TermsKey = "Terms";
25 readonly string _filePath;
26 readonly List<ISearchTerm> _terms;
28 public TermTable(string filePath)
30 _filePath = filePath;
31 _terms = new List<ISearchTerm>();
33 XmlDocument document = new XmlDocument();
34 document.Load(filePath);
36 foreach (XmlNode node in document.SelectNodes("xmldata/PLCKTT/Lang/Term"))
38 string text = node.Attributes["Term"].InnerText;
39 int severity = int.Parse(node.Attributes["Severity"].InnerText, CultureInfo.InvariantCulture);
40 string termClass = node.Attributes["TermClass"].InnerText;
41 string comment = node.SelectSingleNode("Comment").InnerText;
43 string recommended = null;
44 XmlNode recommendedNode = node.SelectSingleNode("RecommendedTerm");
45 if (recommendedNode != null)
47 recommended = recommendedNode.InnerText;
50 SearchTerm term = new SearchTerm(this, text, severity, termClass, comment, recommended);
52 foreach (XmlNode exclusionNode in node.SelectNodes("Exclusion"))
54 term.AddExclusion(exclusionNode.InnerText);
56 foreach (XmlNode exclusionNode in node.SelectNodes("ExclusionContext"))
58 term.AddExclusion(exclusionNode.InnerText);
61 _terms.Add(term);
64 if (_terms.Count == 0)
66 throw new ArgumentException("The file did not specify a valid term table.", "filePath");
70 protected TermTable(SerializationInfo info, StreamingContext context)
72 _filePath = info.GetString(FilePathKey);
73 _terms = (List<ISearchTerm>)info.GetValue(TermsKey, typeof(List<ISearchTerm>));
76 #region ITermTable Members
78 public string SourceFile
80 get { return _filePath; }
83 public IEnumerable<ISearchTerm> Terms
85 get { return _terms; }
88 #endregion ITermTable Members
90 #region ISerializable Members
92 public void GetObjectData(SerializationInfo info, StreamingContext context)
94 info.AddValue(FilePathKey, _filePath);
95 info.AddValue(TermsKey, _terms);
98 #endregion ISerializable Members