Added CXMLReader for all XML-reading operations

Added GetIntValueRange to force a value to be in a specific range
This commit is contained in:
Flamefire committed 2013-02-21 17:07:09 +01:00
1 parent 1a644ab22c
commit 506d98bd3c
30 files changed
+1107 -1302

No files matched your search

-182
View File
@@ -4,8 +4,6 @@ using System.Drawing;
using System.Globalization;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.XPath;
namespace Vocaluxe.Menu
{
@@ -127,187 +125,7 @@ namespace Vocaluxe.Menu
Rect = new RectangleF(Left, Upper, Rigth - Left, Lower - Upper);
}
public static bool TryGetEnumValueFromXML<T>(string Cast, XPathNavigator Navigator, ref T value)
where T : struct
{
string val = String.Empty;
if (GetValueFromXML(Cast, Navigator, ref val, Enum.GetName(typeof(T), value)))
{
TryParse<T>(val, out value, true);
return true;
}
return false;
}
public static bool TryGetIntValueFromXML(string Cast, XPathNavigator Navigator, ref int value)
{
string val = String.Empty;
if (GetValueFromXML(Cast, Navigator, ref val, value.ToString()))
{
int res = 0;
if (int.TryParse(val, out res))
{
value = res;
return true;
}
}
return false;
}
public static bool TryGetFloatValueFromXML(string Cast, XPathNavigator Navigator, ref float value)
{
string val = String.Empty;
if (GetValueFromXML(Cast, Navigator, ref val, value.ToString()))
{
float res = 0;
if (TryParse(val, out res))
{
value = res;
return true;
}
}
return false;
}
public static bool GetValueFromXML(string Cast, XPathNavigator Navigator, ref string Value, string DefaultValue)
{
XPathNodeIterator iterator;
int results = 0;
string val = string.Empty;
try
{
Navigator.MoveToFirstChild();
iterator = Navigator.Select(Cast);
while (iterator.MoveNext())
{
val = iterator.Current.Value;
results++;
}
}
catch (Exception)
{
results = 0;
}
if ((results == 0) || (results > 1))
{
Value = DefaultValue;
return false;
}
else
{
Value = val;
return true;
}
}
public static List<string> GetValuesFromXML(string Cast, XPathNavigator Navigator)
{
List<string> values = new List<string>();
try
{
Navigator.MoveToRoot();
Navigator.MoveToFirstChild();
Navigator.MoveToFirstChild();
while (Navigator.Name != Cast)
Navigator.MoveToNext();
Navigator.MoveToFirstChild();
values.Add(Navigator.LocalName);
while (Navigator.MoveToNext())
values.Add(Navigator.LocalName);
}
catch (Exception)
{
}
return values;
}
public static List<string> GetAttributesFromXML(string Cast, XPathNavigator Navigator, string attribute)
{
List<string> values = new List<string>();
try
{
Navigator.MoveToRoot();
Navigator.MoveToFirstChild();
while (Navigator.Name != Cast)
Navigator.MoveToNext();
Navigator.MoveToFirstChild();
values.Add(Navigator.LocalName);
while (Navigator.MoveToNext())
values.Add(Navigator.GetAttribute(attribute, ""));
}
catch (Exception)
{
}
return values;
}
public static bool GetInnerValuesFromXML(string Cast, XPathNavigator Navigator, ref List<string> Values)
{
try
{
Navigator.MoveToRoot();
Navigator.MoveToFirstChild();
Navigator.MoveToFirstChild();
while (Navigator.Name != Cast)
Navigator.MoveToNext();
Navigator.MoveToFirstChild();
Values.Add(Navigator.Value);
while (Navigator.MoveToNext())
Values.Add(Navigator.Value);
}
catch
{
return false;
}
return true;
}
public static bool ItemExistsInXML(string Cast, XPathNavigator Navigator)
{
XPathNodeIterator iterator;
int results = 0;
try
{
Navigator.MoveToFirstChild();
iterator = Navigator.Select(Cast);
while (iterator.MoveNext())
results++;
}
catch (Exception)
{
results = 0;
}
if (results == 0)
return false;
return true;
}
public List<string> ListFiles(string path, string cast)
{