Skip to content

Commit 6b252fb

Browse files
committed
Beginning XMLToClassModel converter and some fixes to XML output for Action classes with spaces in name
1 parent f458e79 commit 6b252fb

File tree

17 files changed

+242
-22
lines changed

17 files changed

+242
-22
lines changed

UI++Editor/Controllers/XMLToClassModel.cs

Lines changed: 226 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Xml;
77
using UI__Editor.Models;
88
using UI__Editor.Interfaces;
9+
using UI__Editor.Models.ActionClasses;
910

1011
namespace UI__Editor.Controllers
1112
{
@@ -46,27 +47,246 @@ public static UIpp GenerateUIpp(XmlDocument xmlDoc)
4647
uipp.RootXMLPath = uippNode.GetAttribute("RootXMLPath");
4748
uipp.Title = uippNode.GetAttribute("Title");
4849

50+
// Add Messages Node
51+
XmlNode mNode = xmlDoc.SelectSingleNode("/UIpp/Messages");
52+
uipp.Messages = GetMessagesNode(mNode);
53+
4954
// Add Software Node
5055
XmlNode swNode = xmlDoc.SelectSingleNode("/UIpp/Software");
5156
uipp.Software = GetSoftwareNode(swNode);
5257

5358
// Add Actions Node
5459
XmlNode aNode = xmlDoc.SelectSingleNode("/UIpp/Actions");
55-
// uipp.Actions = GetActionsNode(aNode);
60+
uipp.Actions = GetActionsNode(aNode);
5661

5762
return uipp;
5863
}
5964

65+
// Generate Actions Node
66+
private static Actions GetActionsNode(XmlNode xmlNode)
67+
{
68+
Actions a = new Actions();
69+
a.actions = new System.Collections.ObjectModel.ObservableCollection<IElement>();
70+
foreach(XmlNode child in xmlNode.ChildNodes)
71+
{
72+
IElement element = NewAction(child);
73+
if(null != element)
74+
{
75+
a.actions.Add(element);
76+
}
77+
}
78+
return a;
79+
}
80+
81+
private static string StringToBoolString(string s)
82+
{
83+
if(s.ToLower() == "true")
84+
{
85+
return "true";
86+
}
87+
else if(s.ToLower() == "false")
88+
{
89+
return "false";
90+
}
91+
else
92+
{
93+
return null;
94+
}
95+
}
96+
97+
private static IElement NewAction(XmlNode xmlNode)
98+
{
99+
IElement element = null;
100+
IElement ne = null; // child elements
101+
XmlElement importNode = (xmlNode as XmlElement);
102+
if (xmlNode.Name == "Action")
103+
{
104+
switch (importNode.GetAttribute("Type"))
105+
{
106+
case "AppTree":
107+
AppTree appTree = new AppTree(Globals.EventAggregator)
108+
{
109+
ApplicationVariableBase = importNode.GetAttribute("ApplicationVariableBase"),
110+
PackageVariableBase = importNode.GetAttribute("PackageVariableBase"),
111+
Title = importNode.GetAttribute("Title"),
112+
Condition = importNode.GetAttribute("Condition")
113+
};
114+
if (!string.IsNullOrEmpty(importNode.GetAttribute("CenterTitle")))
115+
appTree.CenterTitle = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("CenterTitle")));
116+
if (!string.IsNullOrEmpty(importNode.GetAttribute("Size")))
117+
appTree.Size = importNode.GetAttribute("Size");
118+
if (!string.IsNullOrEmpty(importNode.GetAttribute("Expanded")))
119+
appTree.Expanded = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("Expanded")));
120+
if (!string.IsNullOrEmpty(importNode.GetAttribute("ShowBack")))
121+
appTree.ShowBack = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("ShowBack")));
122+
if (!string.IsNullOrEmpty(importNode.GetAttribute("ShowCancel")))
123+
appTree.ShowCancel = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("ShowCancel")));
124+
foreach (XmlNode x in importNode.ChildNodes)
125+
{
126+
ne = NewAction(x);
127+
if(ne is IChildElement)
128+
{
129+
appTree.SubChildren.Add(ne as IChildElement);
130+
}
131+
}
132+
element = appTree;
133+
break;
134+
case "DefaultValues":
135+
DefaultValues defaultValues = new DefaultValues(Globals.EventAggregator)
136+
{
137+
Condition = importNode.GetAttribute("Condition")
138+
};
139+
if (!string.IsNullOrEmpty(importNode.GetAttribute("ValueTypes")))
140+
{
141+
string[] defaultValueTypes = importNode.GetAttribute("ValueTypes").Split(',');
142+
defaultValues.ValueTypeList.Where(x => x.Name == "All").First().IsSelected = false;
143+
foreach (string defaultValueType in defaultValueTypes)
144+
{
145+
if(defaultValues.ValueTypeList.Where(x => x.Name == defaultValueType).Count() > 0)
146+
defaultValues.ValueTypeList.Where(x => x.Name == defaultValueType).First().IsSelected = true;
147+
}
148+
}
149+
if (!string.IsNullOrEmpty(importNode.GetAttribute("ShowProgress")))
150+
defaultValues.ShowProgress = Convert.ToBoolean(StringToBoolString(importNode.GetAttribute("ShowProgress")));
151+
element = defaultValues;
152+
break;
153+
case "ErrorInfo":
154+
break;
155+
case "ExternalCall":
156+
break;
157+
case "FileRead":
158+
break;
159+
case "Info":
160+
break;
161+
case "InfoFullScreen":
162+
break;
163+
case "Input":
164+
break;
165+
case "Preflight":
166+
break;
167+
case "RandomString":
168+
break;
169+
case "RegRead":
170+
break;
171+
case "RegWrite":
172+
break;
173+
case "SaveItems":
174+
break;
175+
case "SoftwareDiscovery":
176+
break;
177+
case "Switch":
178+
break;
179+
case "TSVar":
180+
break;
181+
case "TSVarList":
182+
break;
183+
case "UserAuth":
184+
break;
185+
case "Vars":
186+
break;
187+
case "WMIRead":
188+
break;
189+
case "WMIWrite":
190+
break;
191+
}
192+
}
193+
else
194+
{
195+
switch (xmlNode.Name)
196+
{
197+
case "ActionGroup":
198+
199+
break;
200+
case "Case":
201+
break;
202+
case "Check":
203+
break;
204+
case "Choice":
205+
break;
206+
case "ChoiceList":
207+
break;
208+
case "Field":
209+
break;
210+
case "InputCheckbox":
211+
case "CheckboxInput":
212+
break;
213+
case "InputChoice":
214+
case "ChoiceInput":
215+
break;
216+
case "InputInfo":
217+
case "InfoInput":
218+
break;
219+
case "InputText":
220+
case "TextInput":
221+
break;
222+
case "Match":
223+
break;
224+
case "Property":
225+
break;
226+
case "Set":
227+
break;
228+
case "SoftwareGroup":
229+
break;
230+
case "SoftwareListRef":
231+
break;
232+
case "SoftwareRef":
233+
break;
234+
case "SoftwareSets":
235+
break;
236+
case "Text":
237+
break;
238+
case "Variable":
239+
break;
240+
}
241+
}
242+
return element;
243+
}
244+
245+
// Generate Messages Node
246+
private static Messages GetMessagesNode(XmlNode xmlNode)
247+
{
248+
Messages messages = new Messages();
249+
if(null != xmlNode)
250+
{
251+
XmlNodeList messagesList = xmlNode.ChildNodes;
252+
List<Message> xmlMessages = GetMessages(messagesList);
253+
foreach (Message m in xmlMessages)
254+
{
255+
messages.MessageCollection.Where(x => x.Id == m.Id).FirstOrDefault().Content = m.Content;
256+
}
257+
}
258+
return messages;
259+
}
260+
261+
private static List<Message> GetMessages(XmlNodeList messages)
262+
{
263+
List<Message> returnMessages = new List<Message>();
264+
foreach(XmlElement message in messages)
265+
{
266+
Message m = new Message()
267+
{
268+
Id = message.GetAttribute("Id"),
269+
Content = message.InnerText
270+
};
271+
returnMessages.Add(m);
272+
}
273+
return returnMessages;
274+
}
275+
60276
// Generate Software Objects
61277
private static Software GetSoftwareNode(XmlNode xmlNode)
62278
{
63279
Software software = new Software();
64-
XmlNodeList apps = xmlNode.ChildNodes;
65-
software.Softwares = new System.Collections.ObjectModel.ObservableCollection<ISoftware>();
66-
List<ISoftware> softwares = GetSoftwares(apps);
67-
foreach(ISoftware s in softwares)
280+
if (null != xmlNode)
68281
{
69-
software.Softwares.Add(s);
282+
XmlNodeList apps = xmlNode.ChildNodes;
283+
software.Softwares = new System.Collections.ObjectModel.ObservableCollection<ISoftware>();
284+
List<ISoftware> softwares = GetSoftwares(apps);
285+
foreach (ISoftware s in softwares)
286+
{
287+
software.Softwares.Add(s);
288+
}
289+
70290
}
71291
return software;
72292
}

UI++Editor/Models/ActionClasses/AppTree.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public XmlNode GenerateXML()
6464
XmlAttribute condition = d.CreateAttribute("Condition");
6565

6666
// Assign attribute values
67-
type.Value = ActionType;
67+
type.Value = "AppTree";
6868
applicationVariableBase.Value = ApplicationVariableBase;
6969
packageVariableBase.Value = PackageVariableBase;
7070
showBack.Value = ShowBack.ToString();

UI++Editor/Models/ActionClasses/DefaultValues.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public XmlNode GenerateXML()
108108
XmlAttribute condition = d.CreateAttribute("Condition");
109109

110110
// Assign attribute values
111-
type.Value = ActionType;
111+
type.Value = "DefaultValues";
112112
showProgress.Value = ShowProgress.ToString();
113113
valueTypes.Value = GenerateValueTypes();
114114
condition.Value = Condition;

UI++Editor/Models/ActionClasses/ErrorInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public XmlNode GenerateXML()
5959
XmlAttribute condition = d.CreateAttribute("Condition");
6060

6161
// Assign attribute values
62-
type.Value = ActionType;
62+
type.Value = "ErrorInfo";
6363
showBack.Value = ShowBack.ToString();
6464
showCancel.Value = ShowCancel.ToString();
6565
name.Value = Name;

UI++Editor/Models/ActionClasses/ExternalCall.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public XmlNode GenerateXML()
4949
XmlAttribute condition = d.CreateAttribute("Condition");
5050

5151
// Assign attribute values
52-
type.Value = ActionType;
52+
type.Value = "ExternalCall";
5353
maxRunTime.Value = MaxRunTime.ToString();
5454
title.Value = Title;
5555
condition.Value = Condition;

UI++Editor/Models/ActionClasses/FileRead.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public XmlNode GenerateXML()
5151
XmlAttribute condition = d.CreateAttribute("Condition");
5252

5353
// Assign attribute values
54-
type.Value = ActionType;
54+
type.Value = "FileRead";
5555
deleteLine.Value = DeleteLine.ToString();
5656
fileName.Value = FileName;
5757
variable.Value = Variable;

UI++Editor/Models/ActionClasses/InfoFullScreen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public XmlNode GenerateXML()
5151
XmlAttribute condition = d.CreateAttribute("Condition");
5252

5353
// Assign attribute values
54-
type.Value = ActionType;
54+
type.Value = "InfoFullScreen";
5555
image.Value = Image;
5656
backgroundColor.Value = BackgroundColor;
5757
textColor.Value = TextColor;

UI++Editor/Models/ActionClasses/RandomString.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public XmlNode GenerateXML()
5151
XmlAttribute condition = d.CreateAttribute("Condition");
5252

5353
// Assign attribute values
54-
type.Value = ActionType;
54+
type.Value = "RandomString";
5555
allowedChars.Value = AllowedChars;
5656
length.Value = Length.ToString();
5757
variable.Value = Variable;

UI++Editor/Models/ActionClasses/RegRead.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public XmlNode GenerateXML()
5757
XmlAttribute condition = d.CreateAttribute("Condition");
5858

5959
// Assign attribute values
60-
type.Value = ActionType;
60+
type.Value = "RegRead";
6161
_default.Value = Default;
6262
hive.Value = Hive;
6363
key.Value = Key;

UI++Editor/Models/ActionClasses/RegWrite.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public XmlNode GenerateXML()
5656
XmlAttribute condition = d.CreateAttribute("Condition");
5757

5858
// Assign attribute values
59-
type.Value = ActionType;
59+
type.Value = "RegWrite";
6060
hive.Value = Hive;
6161
key.Value = Key;
6262
reg64.Value = Reg64.ToString();

0 commit comments

Comments
 (0)