Change values of xml argument to xPath only to make it more consistent
This commit is contained in:
1 parent
f7202ee9b0
commit
41480797e2
6 files changed
+50
-87
No files matched your search
@@ -188,7 +188,7 @@ namespace Vocaluxe.Base
|
||||
if (xmlReader != null)
|
||||
{
|
||||
_Covers.Clear();
|
||||
List<string> cover = xmlReader.GetValues("Cover");
|
||||
List<string> cover = xmlReader.GetNames("//root/Cover/*");
|
||||
foreach (string coverName in cover)
|
||||
{
|
||||
string name;
|
||||
|
||||
@@ -168,7 +168,7 @@ namespace Vocaluxe.Base
|
||||
private static bool _LoadLanguageEntries(CXMLReader xmlReader, out Dictionary<string, string> texts)
|
||||
{
|
||||
texts = new Dictionary<string, string>();
|
||||
IEnumerable<string> names = xmlReader.GetAttributes("resources", "name");
|
||||
IEnumerable<string> names = xmlReader.GetAttributes("//resources/string", "name");
|
||||
foreach (string name in names)
|
||||
{
|
||||
string value;
|
||||
|
||||
@@ -246,10 +246,10 @@ namespace Vocaluxe.Base
|
||||
loaded &= xmlReader.GetValue("//root/Info/Author", out pm.Author, "ERROR Author");
|
||||
loaded &= xmlReader.GetValue("//root/Info/Folder", out pm.Folder, "ERROR Folder");
|
||||
loaded &= xmlReader.GetValue("//root/Info/PartyModeFile", out pm.PartyModeFile, "ERROR PartyModeFile");
|
||||
loaded &= xmlReader.GetInnerValues("PartyScreens", ref pm.ScreenFiles);
|
||||
loaded &= xmlReader.TryGetIntValue("//root/Info/PartyModeVersionMajor", ref pm.PartyModeVersionMajor);
|
||||
loaded &= xmlReader.TryGetIntValue("//root/Info/PartyModeVersionMinor", ref pm.PartyModeVersionMinor);
|
||||
loaded &= xmlReader.GetValue("//root/Info/TargetAudience", out pm.TargetAudience, "ERROR TargetAudience");
|
||||
loaded &= xmlReader.GetValues("//root/PartyScreens/*", ref pm.ScreenFiles);
|
||||
|
||||
if (!loaded)
|
||||
{
|
||||
|
||||
@@ -485,12 +485,12 @@ namespace Vocaluxe.Base
|
||||
skin.PartyModeID = theme.PartyModeID;
|
||||
|
||||
skin.SkinList = new Dictionary<string, CSkinElement>();
|
||||
List<string> names = xmlReader.GetValues("Skins");
|
||||
List<string> names = xmlReader.GetNames("//root/Skins/*");
|
||||
foreach (string str in names)
|
||||
skin.SkinList[str] = new CSkinElement();
|
||||
|
||||
skin.VideoList = new Dictionary<string, CVideoSkinElement>();
|
||||
names = xmlReader.GetValues("Videos");
|
||||
names = xmlReader.GetNames("//root/Videos/*");
|
||||
foreach (string str in names)
|
||||
skin.VideoList[str] = new CVideoSkinElement();
|
||||
_Skins.Add(skin);
|
||||
@@ -665,7 +665,7 @@ namespace Vocaluxe.Base
|
||||
}
|
||||
|
||||
var colorScheme = new List<SColorScheme>();
|
||||
List<string> names = xmlReader.GetValues("ColorSchemes");
|
||||
List<string> names = xmlReader.GetNames("//root/ColorSchemes/*");
|
||||
foreach (string str in names)
|
||||
{
|
||||
var scheme = new SColorScheme {Name = str};
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace Vocaluxe.Lib.Playlist
|
||||
|
||||
Songs = new List<CPlaylistSong>();
|
||||
|
||||
List<string> songs = xmlReader.GetValues("Songs");
|
||||
List<string> songs = xmlReader.GetNames("//root/Songs/*");
|
||||
|
||||
foreach (string songEntry in songs)
|
||||
{
|
||||
|
||||
+43
-80
@@ -57,49 +57,44 @@ namespace VocaluxeLib
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryGetEnumValue<T>(string cast, ref T value)
|
||||
public bool TryGetEnumValue<T>(string xPath, ref T value)
|
||||
where T : struct
|
||||
{
|
||||
string val;
|
||||
if (GetValue(cast, out val, Enum.GetName(typeof(T), value)))
|
||||
if (GetValue(xPath, out val, Enum.GetName(typeof(T), value)))
|
||||
return CHelper.TryParse(val, out value, true);
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryGetIntValue(string cast, ref int value)
|
||||
public bool TryGetIntValue(string xPath, ref int value)
|
||||
{
|
||||
string val;
|
||||
if (GetValue(cast, out val, value.ToString()))
|
||||
if (GetValue(xPath, out val, value.ToString()))
|
||||
return int.TryParse(val, out value);
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryGetIntValueRange(string cast, ref int value, int min = 0, int max = 100)
|
||||
public bool TryGetIntValueRange(string xPath, ref int value, int min = 0, int max = 100)
|
||||
{
|
||||
bool result = TryGetIntValue(cast, ref value);
|
||||
bool result = TryGetIntValue(xPath, ref value);
|
||||
if (result)
|
||||
{
|
||||
if (value < min)
|
||||
value = min;
|
||||
else if (value > max)
|
||||
value = max;
|
||||
}
|
||||
value = value.Clamp(min, max);
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool TryGetFloatValue(string cast, ref float value)
|
||||
public bool TryGetFloatValue(string xPath, ref float value)
|
||||
{
|
||||
string val;
|
||||
return GetValue(cast, out val, value.ToString()) && CHelper.TryParse(val, out value);
|
||||
return GetValue(xPath, out val, value.ToString()) && CHelper.TryParse(val, out value);
|
||||
}
|
||||
|
||||
public bool GetValue(string cast, out string value, string defaultValue)
|
||||
public bool GetValue(string xPath, out string value, string defaultValue)
|
||||
{
|
||||
int resultCt = 0;
|
||||
string val = string.Empty;
|
||||
|
||||
_Navigator.MoveToFirstChild();
|
||||
XPathNodeIterator iterator = _Navigator.Select(cast);
|
||||
_Navigator.MoveToRoot();
|
||||
XPathNodeIterator iterator = _Navigator.Select(xPath);
|
||||
|
||||
while (iterator.MoveNext())
|
||||
{
|
||||
@@ -116,77 +111,45 @@ namespace VocaluxeLib
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<string> GetValues(string cast)
|
||||
public List<string> GetNames(string xPath)
|
||||
{
|
||||
var values = new List<string>();
|
||||
|
||||
_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);
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetAttributes(string cast, string attribute)
|
||||
{
|
||||
var values = new List<string>();
|
||||
|
||||
_Navigator.MoveToRoot();
|
||||
_Navigator.MoveToFirstChild();
|
||||
|
||||
while (_Navigator.Name != cast)
|
||||
_Navigator.MoveToNext();
|
||||
|
||||
_Navigator.MoveToFirstChild();
|
||||
|
||||
values.Add(_Navigator.LocalName);
|
||||
while (_Navigator.MoveToNext())
|
||||
values.Add(_Navigator.GetAttribute(attribute, ""));
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
public bool GetInnerValues(string cast, ref List<string> values)
|
||||
{
|
||||
_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);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool ItemExists(string cast)
|
||||
{
|
||||
int results = 0;
|
||||
|
||||
_Navigator.MoveToFirstChild();
|
||||
XPathNodeIterator iterator = _Navigator.Select(cast);
|
||||
|
||||
XPathNodeIterator iterator = _Navigator.Select(xPath);
|
||||
while (iterator.MoveNext())
|
||||
results++;
|
||||
values.Add(iterator.Current.LocalName);
|
||||
|
||||
if (results == 0)
|
||||
return false;
|
||||
return values;
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetAttributes(string xPath, string attribute)
|
||||
{
|
||||
var values = new List<string>();
|
||||
|
||||
_Navigator.MoveToRoot();
|
||||
XPathNodeIterator iterator = _Navigator.Select(xPath);
|
||||
while (iterator.MoveNext())
|
||||
values.Add(iterator.Current.GetAttribute(attribute, ""));
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
public bool GetValues(string xPath, ref List<string> values)
|
||||
{
|
||||
_Navigator.MoveToRoot();
|
||||
XPathNodeIterator iterator = _Navigator.Select(xPath);
|
||||
while (iterator.MoveNext())
|
||||
values.Add(iterator.Current.Value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool ItemExists(string xPath)
|
||||
{
|
||||
_Navigator.MoveToRoot();
|
||||
|
||||
return _Navigator.Select(xPath).MoveNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user