/
RemotePlaylist.cs
80 lines (75 loc) · 2.43 KB
/
RemotePlaylist.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using BooBox;
namespace BooBoxClient {
public class RemotePlaylist {
public List<SongInfo> SongList = new List<SongInfo>();
public ConnectionInfo ConnectionInfo;
public String Name;
public int SongCount;
public String GUID;
/// <summary>
/// RemotePlaylist constructor. Sets various internal variables.
/// </summary>
/// <param name="iServerGUID">GUID of server hosting the playlist</param>
/// <param name="iPlaylistName">Name of the playlist</param>
/// <param name="iSongCount">Number of songs in the playlist</param>
/// <param name="PlaylistGUID">GUID of the playlist</param>
public RemotePlaylist(String iServerGUID, String iName, int iSongCount, String PlaylistGUID) {
Name = iName;
SongCount = iSongCount;
ConnectionInfo = Functions.ServerGUIDToConnectionInfo(Config.Instance.ConnectionInfoList, iServerGUID);
GUID = PlaylistGUID;
}
/// <summary>
/// Returns a string describing the playlist.
/// </summary>
/// <returns>[Server Name] Playlist Name (Song Count)</returns>
public override String ToString() {
return "[" + ConnectionInfo.Name + "] " + Name + " (" + SongCount.ToString() + ")";
}
/// <summary>
/// Parses an XML String and adds the appropriate songs to the playlist's SongList.
/// </summary>
/// <param name="XMLString">XML String to parse</param>
public void ImportXMLString(String XMLString) {
SongList.Clear();
XmlTextReader XmlReader = new XmlTextReader(new StringReader(XMLString));
SongInfo tempSI = new SongInfo();
String currentTag = "";
while (XmlReader.Read()) {
switch (XmlReader.NodeType) {
case XmlNodeType.Element:
currentTag = XmlReader.Name;
break;
case XmlNodeType.Text:
switch (currentTag) {
case "name":
Name = XmlReader.Value;
break;
case "songcount":
SongCount = Convert.ToInt32(XmlReader.Value);
break;
case "guid":
GUID = XmlReader.Value;
break;
case "song":
tempSI = Library.MD5ToSongInfo(XmlReader.Value);
if (tempSI.ServerGUID == ConnectionInfo.GUID) {
SongList.Add(tempSI);
}
break;
}
break;
case XmlNodeType.EndElement:
currentTag = "";
break;
}
}
}
}
}