-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollectDSValuesFromXML.cs
199 lines (140 loc) · 8.93 KB
/
CollectDSValuesFromXML.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using ShellProgressBar;
namespace CallFlowVisualizer
{
class CollectDSValuesFromXML
{
internal static NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
internal static List<PureConnectFlowElements> CollectDS(string xmlFileName)
{
XElement xmllist = XElement.Load(xmlFileName);
ColorConsole.WriteLine($"Analyzing PureConnect XML file {xmlFileName}", ConsoleColor.Yellow);
IEnumerable<XElement> allEntries = xmllist.Descendants("ENTRY");
var profilesEntiriesList = allEntries.Select(x => x.Attribute("CLASS")).Where(y => y.Value == "Profile");
var schedulesEntiriesList = allEntries.Select(x => x.Attribute("CLASS")).Where(y => y.Value == "Schedule");
var attendantNodeEntiriesList = allEntries.Select(x => x.Attribute("CLASS")).Where(y => y.Value == "AttendantNode");
IEnumerable<XElement> allATTRIBUTE = xmllist.Descendants("ATTRIBUTE");
List<string> nodeNameList = allATTRIBUTE.Select(x => x.Attribute("NAME")).Where(y => y.Value == "Name").Select(y => y.Parent).Select(z => z.Value).ToList();
List<string> nodeFullPathList = allATTRIBUTE.Select(x => x.Attribute("NAME")).Where(y => y.Value == "FullNodePath").Select(y => y.Parent).Select(z => z.Value).ToList();
List<PureConnectFlowElements> flowElementsList = new();
ColorConsole.WriteLine($"{profilesEntiriesList.Count()} profiles found in {xmlFileName}", ConsoleColor.Yellow);
var pboptions = new ProgressBarOptions
{
ProgressCharacter = '─',
ProgressBarOnBottom = true
};
var pcpb = new ProgressBar(nodeFullPathList.Count, "Analyzing XML file...", pboptions);
foreach (var node_i in nodeFullPathList)
{
PureConnectFlowElements flowElements = new PureConnectFlowElements();
flowElements.NodePath = node_i;
flowElements.Name = QueryAttrValue(allATTRIBUTE, node_i, "Name");
flowElements.Type = QueryAttrValue(allATTRIBUTE, node_i, "Type");
flowElements.Active = QueryAttrValue(allATTRIBUTE, node_i, "Active");
flowElements.AudioFile = QueryAttrValue(allATTRIBUTE, node_i, "AudioFile");
flowElements.MenuDigits = QueryAttrValue(allATTRIBUTE, node_i, "MenuDigits");
flowElements.Digit = QueryAttrValue(allATTRIBUTE, node_i, "Digit");
flowElements.Default = QueryAttrValue(allATTRIBUTE, node_i, "Default");
flowElements.Workgroup = QueryAttrValue(allATTRIBUTE, node_i, "Workgroup");
flowElements.Skills = QueryAttrValue(allATTRIBUTE, node_i, "Skills");
flowElements.DNISString = QueryAttrValue(allATTRIBUTE, node_i, "DNISString");
flowElements.ScheduleRef = QueryAttrValue(allATTRIBUTE, node_i, "ScheduleRef");
flowElements.Default = QueryAttrValue(allATTRIBUTE, node_i, "Default");
flowElements.Subroutine = QueryAttrValue(allATTRIBUTE, node_i, "Subroutine");
flowElements.StationGroup = QueryAttrValue(allATTRIBUTE, node_i, "StationGroup");
pcpb.Tick(flowElements.Name);
if (flowElements.Type == "Profile")
{
flowElements.ParentNodePath = "";
}
else
{
flowElements.ParentNodePath = QueryParentNodePath(allATTRIBUTE, node_i, flowElements.Type);
// JumpToLocation is unnecessary for Profile and Schedule.
if (flowElements.Type != "Schedule")
{
var jumpToNodes = QueryJumpToNode(allATTRIBUTE, node_i);
if (jumpToNodes != null)
{
flowElements.ParentNodePath2.AddRange(jumpToNodes);
}
}
}
if (!String.IsNullOrEmpty(flowElements.Name)&&flowElements.Type=="Profile")
{
if (String.IsNullOrEmpty(flowElements.DNISString))
{
Logger.Info($"Profile: {flowElements.Name} DNIS:");
}
else
{
Logger.Info($"Profile: {flowElements.Name} DNIS: {flowElements.DNISString.Trim()}");
}
}
flowElementsList.Add(flowElements);
}
Console.WriteLine();
Console.WriteLine();
return flowElementsList;
}
private static string QueryAttrValue (IEnumerable<XElement> allATTRIBUTE,string eachNode,string searchValue)
{
XElement parentNode = allATTRIBUTE.Select(x => x.Attribute("NAME")).Where(y => y.Value == "FullNodePath").Select(y => y.Parent).Where(z => z.Value == eachNode).Select(a => a.Parent).FirstOrDefault();
XNode firstSiblingFullNodePath = parentNode.FirstNode;
// If the value is top of flowElements, the value results null by ElementsAfterSelf.
string parentNodeNameValue = parentNode.Element("ATTRIBUTE").Value;
string parentNodeNAME = parentNode.Element("ATTRIBUTE").Attribute("NAME").Value;
string queryResult = firstSiblingFullNodePath.ElementsAfterSelf().Select(x => x.Attribute("NAME")).Where(y => y.Value == searchValue).Select(y => y.Parent).Select(z => z.Value).FirstOrDefault()?.ToString();
if (queryResult != null)
{
return queryResult;
}
if (parentNodeNAME == searchValue)
{
return parentNodeNameValue;
}
return null;
}
private static string QueryParentNodePath(IEnumerable<XElement> allATTRIBUTE, string eachNode,string flowElementsType)
{
XElement parentNode = allATTRIBUTE.Select(x => x.Attribute("NAME")).Where(y => y.Value == "FullNodePath").Select(y => y.Parent).Where(z => z.Value == eachNode).Select(a => a.Parent).FirstOrDefault();
string parentNodePath = "";
if (flowElementsType== "Queue Audio" || flowElementsType == "Queue Repeat")
{
string childIndex = parentNode.Descendants("ATTRIBUTE").Select(x => x.Attribute("NAME")).Where(y => y.Value == "ChildIndex").Select(y => y.Parent).Select(z => z.Value).FirstOrDefault()?.ToString();
if (childIndex== "00000")
{
var parentNodeParent = parentNode.Parent;
parentNodePath = parentNodeParent.Descendants("ATTRIBUTE").Select(x => x.Attribute("NAME")).Where(y => y.Value == "FullNodePath").Select(y => y.Parent).Select(z => z.Value).FirstOrDefault()?.ToString();
return parentNodePath;
}
var previousNode = parentNode.PreviousNode;
var previousNodeElement = XElement.Parse(previousNode.ToString());
parentNodePath = previousNodeElement.Descendants("ATTRIBUTE").Select(x => x.Attribute("NAME")).Where(y => y.Value == "FullNodePath").Select(y => y.Parent).Select(z => z.Value).FirstOrDefault()?.ToString();
return parentNodePath;
}
var upperNode = parentNode.Parent;
parentNodePath = upperNode.Descendants("ATTRIBUTE").Select(x => x.Attribute("NAME")).Where(y => y.Value == "FullNodePath").Select(y => y.Parent).Select(z => z.Value).FirstOrDefault()?.ToString();
return parentNodePath;
}
private static List<string> QueryJumpToNode(IEnumerable<XElement> allATTRIBUTE, string eachNode)
{
XElement parentNode = allATTRIBUTE.Select(x => x.Attribute("NAME")).Where(y => y.Value == "FullNodePath").Select(y => y.Parent).Where(z => z.Value == eachNode).Select(a => a.Parent).FirstOrDefault();
List<String> jumpNodePath = new List<String>();
// If there is a node points to itself in JumpToLocation, set the value to parentNode2.
// If there is PlayAudioWorkgroup Transfer under Menu, the line from Menu to Workgroup Transfer will be drawn. Unable to delete this line because Workgroup Transfer and Select Digit are sibling node.
XElement jumpToNode = allATTRIBUTE.Select(x => x.Attribute("NAME")).Where(y => y.Value == "JumpLocation").Select(y => y.Parent).Where(z => z.Value == eachNode).Select(a => a.Parent).FirstOrDefault();
if (jumpToNode != null)
{
jumpNodePath = jumpToNode.Descendants("ATTRIBUTE").Select(x => x.Attribute("NAME")).Where(y => y.Value == "FullNodePath").Select(y => y.Parent).Select(z => z.Value).ToList();
return jumpNodePath;
}
return jumpNodePath;
}
}
}