-
Notifications
You must be signed in to change notification settings - Fork 0
/
NavigationHelper.cs
168 lines (126 loc) · 5.51 KB
/
NavigationHelper.cs
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
using System.Xml;
using System.IO;
using System.Xml.Xsl;
using System.Text.RegularExpressions;
using Artech.Architecture.Common.Objects;
using Artech.Architecture.UI.Framework.Services;
namespace GUG.Packages.KBCodeReview
{
class NavigationHelper
{
public static XmlDocument GetObjectNavigationXML(KBObject obj)
{
XmlDocument doc = new XmlDocument();
IKBService kbserv = UIServices.KB;
string fileWildcard = @"" + obj.Name + ".xml";
var searchSubDirsArg = System.IO.SearchOption.AllDirectories;
string specpath = Functions.SpcDirectory(kbserv);
string[] xFiles = System.IO.Directory.GetFiles(specpath, fileWildcard, searchSubDirsArg);
foreach (string x in xFiles)
{
if (Path.GetFileNameWithoutExtension(x).Equals(obj.Name))
{
string xmlstring = NavigationHelper.AddXMLHeader(x);
if (!ObjectsHelper.isGeneratedbyPattern(obj))
{
doc.LoadXml(xmlstring);
}
}
}
return (doc);
}
public static string GetObjectNavigationFile(KBObject obj)
{
string filename = "";
IKBService kbserv = UIServices.KB;
string fileWildcard = @"" + obj.Name + ".xml";
var searchSubDirsArg = System.IO.SearchOption.AllDirectories;
string specpath = Functions.SpcDirectory(kbserv);
string[] xFiles = System.IO.Directory.GetFiles(specpath, fileWildcard, searchSubDirsArg);
foreach (string x in xFiles)
{
if (Path.GetFileNameWithoutExtension(x).Equals(obj.Name))
{
filename = x;
}
}
return (filename);
}
public static string GetNavigation(KBObject obj)
{
string specFilePath = GetObjectNavigationFile(obj);
//Copy the navigation file to an .xxx file
string xmlstring = AddXMLHeader(specFilePath);
string tempSpecFilePath = specFilePath.Replace(".xml", ".xxx");
File.WriteAllText(tempSpecFilePath, xmlstring);
//Output file
IKBService kbserv = UIServices.KB;
string navigationPath = Functions.SpcDirectory(kbserv);
string navigationFilePath = navigationPath + Path.GetFileNameWithoutExtension(specFilePath) + ".nvg";
XslTransform xsl = NavigationHelper._GetNavigationTemplate();
xsl.Transform(tempSpecFilePath, navigationFilePath);
string readText = File.ReadAllText(navigationFilePath);
//now clean up all intermediate files
File.Delete(tempSpecFilePath);
File.Delete(navigationFilePath);
return readText;
}
private static XslTransform _GetNavigationTemplate()
{
IKBService kbserv = UIServices.KB;
string outputFile = kbserv.CurrentKB.UserDirectory + @"\NavigationHtmlToText.xslt";
XslTransform xsl = new XslTransform();
xsl.Load(outputFile);
return xsl;
}
static string ExtractSpcInfo(string file, string containsTextArg)
{
string sourcestring = AddXMLHeader(file);
sourcestring = sourcestring.Replace(System.Environment.NewLine, "");
Regex re = new Regex("");
RegexOptions myRegexOptions = RegexOptions.Multiline;
string mTxt = "";
switch (containsTextArg)
{
case "Error":
re = new Regex(@"<Errors>(.)*<\/Errors>", myRegexOptions);
break;
case "Warning":
re = new Regex(@"<Warnings>(.)*<\/Warnings>", myRegexOptions);
break;
case "deprecated":
re = new Regex(@"<Warnings>(.)*<\/Warnings>", myRegexOptions);
break;
case "client":
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(sourcestring);
XmlNode node = xmlDocument.DocumentElement.SelectSingleNode(@"//Condition[Icon='client']");
mTxt = node.InnerXml.ToString();
Regex r = new Regex(@"<AttriId>(.)*<\/AttriId>", RegexOptions.Singleline);
mTxt = r.Replace(mTxt, string.Empty);
Regex r2 = new Regex(@"<Description>(.)*<\/Description>", RegexOptions.Singleline);
mTxt = r2.Replace(mTxt, string.Empty);
mTxt = mTxt.Replace("client", System.Environment.NewLine);
return Functions.StripHTML(mTxt);
default:
return Functions.linkFile(file);
}
MatchCollection mc = re.Matches(sourcestring);
foreach (Match m in mc)
{
for (int gIdx = 0; gIdx < m.Groups.Count; gIdx++)
if (gIdx <= 4)
mTxt += m.Groups[gIdx].Value;
}
mTxt = Functions.StripHTML(mTxt);
mTxt = mTxt.Replace(">", "");
return mTxt;
}
public static string AddXMLHeader(string fileName)
{
string xmlstring = File.ReadAllText(fileName);
xmlstring = "<?xml version='1.0' encoding='iso-8859-1'?>" + xmlstring;
return xmlstring;
}
}
}