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)
|
if (xmlReader != null)
|
||||||
{
|
{
|
||||||
_Covers.Clear();
|
_Covers.Clear();
|
||||||
List<string> cover = xmlReader.GetValues("Cover");
|
List<string> cover = xmlReader.GetNames("//root/Cover/*");
|
||||||
foreach (string coverName in cover)
|
foreach (string coverName in cover)
|
||||||
{
|
{
|
||||||
string name;
|
string name;
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ namespace Vocaluxe.Base
|
|||||||
private static bool _LoadLanguageEntries(CXMLReader xmlReader, out Dictionary<string, string> texts)
|
private static bool _LoadLanguageEntries(CXMLReader xmlReader, out Dictionary<string, string> texts)
|
||||||
{
|
{
|
||||||
texts = new Dictionary<string, string>();
|
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)
|
foreach (string name in names)
|
||||||
{
|
{
|
||||||
string value;
|
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/Author", out pm.Author, "ERROR Author");
|
||||||
loaded &= xmlReader.GetValue("//root/Info/Folder", out pm.Folder, "ERROR Folder");
|
loaded &= xmlReader.GetValue("//root/Info/Folder", out pm.Folder, "ERROR Folder");
|
||||||
loaded &= xmlReader.GetValue("//root/Info/PartyModeFile", out pm.PartyModeFile, "ERROR PartyModeFile");
|
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/PartyModeVersionMajor", ref pm.PartyModeVersionMajor);
|
||||||
loaded &= xmlReader.TryGetIntValue("//root/Info/PartyModeVersionMinor", ref pm.PartyModeVersionMinor);
|
loaded &= xmlReader.TryGetIntValue("//root/Info/PartyModeVersionMinor", ref pm.PartyModeVersionMinor);
|
||||||
loaded &= xmlReader.GetValue("//root/Info/TargetAudience", out pm.TargetAudience, "ERROR TargetAudience");
|
loaded &= xmlReader.GetValue("//root/Info/TargetAudience", out pm.TargetAudience, "ERROR TargetAudience");
|
||||||
|
loaded &= xmlReader.GetValues("//root/PartyScreens/*", ref pm.ScreenFiles);
|
||||||
|
|
||||||
if (!loaded)
|
if (!loaded)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -485,12 +485,12 @@ namespace Vocaluxe.Base
|
|||||||
skin.PartyModeID = theme.PartyModeID;
|
skin.PartyModeID = theme.PartyModeID;
|
||||||
|
|
||||||
skin.SkinList = new Dictionary<string, CSkinElement>();
|
skin.SkinList = new Dictionary<string, CSkinElement>();
|
||||||
List<string> names = xmlReader.GetValues("Skins");
|
List<string> names = xmlReader.GetNames("//root/Skins/*");
|
||||||
foreach (string str in names)
|
foreach (string str in names)
|
||||||
skin.SkinList[str] = new CSkinElement();
|
skin.SkinList[str] = new CSkinElement();
|
||||||
|
|
||||||
skin.VideoList = new Dictionary<string, CVideoSkinElement>();
|
skin.VideoList = new Dictionary<string, CVideoSkinElement>();
|
||||||
names = xmlReader.GetValues("Videos");
|
names = xmlReader.GetNames("//root/Videos/*");
|
||||||
foreach (string str in names)
|
foreach (string str in names)
|
||||||
skin.VideoList[str] = new CVideoSkinElement();
|
skin.VideoList[str] = new CVideoSkinElement();
|
||||||
_Skins.Add(skin);
|
_Skins.Add(skin);
|
||||||
@@ -665,7 +665,7 @@ namespace Vocaluxe.Base
|
|||||||
}
|
}
|
||||||
|
|
||||||
var colorScheme = new List<SColorScheme>();
|
var colorScheme = new List<SColorScheme>();
|
||||||
List<string> names = xmlReader.GetValues("ColorSchemes");
|
List<string> names = xmlReader.GetNames("//root/ColorSchemes/*");
|
||||||
foreach (string str in names)
|
foreach (string str in names)
|
||||||
{
|
{
|
||||||
var scheme = new SColorScheme {Name = str};
|
var scheme = new SColorScheme {Name = str};
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ namespace Vocaluxe.Lib.Playlist
|
|||||||
|
|
||||||
Songs = new List<CPlaylistSong>();
|
Songs = new List<CPlaylistSong>();
|
||||||
|
|
||||||
List<string> songs = xmlReader.GetValues("Songs");
|
List<string> songs = xmlReader.GetNames("//root/Songs/*");
|
||||||
|
|
||||||
foreach (string songEntry in 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
|
where T : struct
|
||||||
{
|
{
|
||||||
string val;
|
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 CHelper.TryParse(val, out value, true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryGetIntValue(string cast, ref int value)
|
public bool TryGetIntValue(string xPath, ref int value)
|
||||||
{
|
{
|
||||||
string val;
|
string val;
|
||||||
if (GetValue(cast, out val, value.ToString()))
|
if (GetValue(xPath, out val, value.ToString()))
|
||||||
return int.TryParse(val, out value);
|
return int.TryParse(val, out value);
|
||||||
return false;
|
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 (result)
|
||||||
{
|
value = value.Clamp(min, max);
|
||||||
if (value < min)
|
|
||||||
value = min;
|
|
||||||
else if (value > max)
|
|
||||||
value = max;
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryGetFloatValue(string cast, ref float value)
|
public bool TryGetFloatValue(string xPath, ref float value)
|
||||||
{
|
{
|
||||||
string val;
|
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;
|
int resultCt = 0;
|
||||||
string val = string.Empty;
|
string val = string.Empty;
|
||||||
|
|
||||||
_Navigator.MoveToFirstChild();
|
_Navigator.MoveToRoot();
|
||||||
XPathNodeIterator iterator = _Navigator.Select(cast);
|
XPathNodeIterator iterator = _Navigator.Select(xPath);
|
||||||
|
|
||||||
while (iterator.MoveNext())
|
while (iterator.MoveNext())
|
||||||
{
|
{
|
||||||
@@ -116,77 +111,45 @@ namespace VocaluxeLib
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<string> GetValues(string cast)
|
public List<string> GetNames(string xPath)
|
||||||
{
|
{
|
||||||
var values = new List<string>();
|
var values = new List<string>();
|
||||||
|
|
||||||
_Navigator.MoveToRoot();
|
_Navigator.MoveToRoot();
|
||||||
_Navigator.MoveToFirstChild();
|
XPathNodeIterator iterator = _Navigator.Select(xPath);
|
||||||
_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);
|
|
||||||
|
|
||||||
while (iterator.MoveNext())
|
while (iterator.MoveNext())
|
||||||
results++;
|
values.Add(iterator.Current.LocalName);
|
||||||
|
|
||||||
if (results == 0)
|
return values;
|
||||||
return false;
|
}
|
||||||
|
|
||||||
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool ItemExists(string xPath)
|
||||||
|
{
|
||||||
|
_Navigator.MoveToRoot();
|
||||||
|
|
||||||
|
return _Navigator.Select(xPath).MoveNext();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user