/// <summary>
 /// Adds a song to the Active Playlist.
 /// </summary>
 /// <param name="SongInfo">MusicFile data to be added to the Playlist.</param>
 public Boolean AddSongToList(SongInfo SongInfo)
 {
     for (int i = 0; i < SongList.Count; i++) {
         if (SongList[i].MD5 == SongInfo.MD5) {
             return false;
         }
     }
     SongList.Add(SongInfo);
     return true;
 }
 /// <summary>
 /// Generates a MD5 Hash from a SongInfo object using information unique to the SongInfo object.
 /// </summary>
 /// <param name="inputSongInfo">SongInfo object.</param>
 /// <returns>String containing a MD5 hash.</returns>
 public static String CreateMD5FromSongInfo(SongInfo inputSongInfo)
 {
     String inputString;
     inputString = "|" + inputSongInfo.Album + "|";
     for (int i = 0; i < inputSongInfo.AlbumArtists.Length; i++) { inputString += inputSongInfo.AlbumArtists[i] + "|"; }
     inputString += inputSongInfo.BitRate + "|";
     for (int i = 0; i < inputSongInfo.Genres.Length; i++) { inputString += inputSongInfo.Genres[i] + "|"; }
     inputString += inputSongInfo.PlayLength + "|" + inputSongInfo.Title + "|";
     System.Security.Cryptography.MD5CryptoServiceProvider MD5Crypto = new System.Security.Cryptography.MD5CryptoServiceProvider();
     byte[] MD5Data = System.Text.Encoding.Unicode.GetBytes(inputString);
     MD5Data = MD5Crypto.ComputeHash(MD5Data);
     string MD5Output = "";
     for (int i = 0; i < MD5Data.Length; i++) {
         MD5Output += MD5Data[i].ToString("x2").ToUpper();
     }
     return MD5Output;
 }
 public static Boolean RequestSong(SongInfo inputSongInfo)
 {
     if (ServerOnline(inputSongInfo.ServerGUID)) {
         if (ActiveSong.Playing == true) {
             ActiveSong.EndSong();
             CommStream.CloseServerStreamConnection();
             ActiveSong.ClearSongData();
         }
         String[] inputStr = new String[1];
         inputStr[0] = inputSongInfo.MD5;
         Forms.MainFrm.UpdateStatusLabel("Requesting \"" + inputSongInfo.Title + "\" from \"" + Functions.ServerGUIDToConnectionInfo(Config.Instance.ConnectionInfoList, inputSongInfo.ServerGUID).Description + "\".");
         CommInfo.ConnectToServer(Functions.ServerGUIDToConnectionInfo(Config.Instance.ConnectionInfoList, inputSongInfo.ServerGUID), ConnectionMode.SongRequest, inputStr);
         return true;
     } else {
         Forms.MainFrm.UpdateStatusLabel("Server \"" + Functions.ServerGUIDToConnectionInfo(Config.Instance.ConnectionInfoList, inputSongInfo.ServerGUID).Description + "\" is offline. Song skipped.");
         return false;
     }
 }
 /// <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;
         }
     }
 }
 public static String AddSongRequest(SongInfo inputSongInfo)
 {
     String tempSIGUID = Guid.NewGuid().ToString();
     SongInfoDict.Add(tempSIGUID, inputSongInfo);
     return tempSIGUID;
 }
 /// <summary>
 /// Adds a XML String to the Client Library based on the XML String from the server and its GUID.
 /// </summary>
 /// <param name="XMLString">XML String containing the song metadata.</param>
 /// <param name="ServerGUID">GUID of the server which sent the XML String.</param>
 public static void AddXMLStringToLibrary(String XMLString, String ServerGUID)
 {
     XmlTextReader XmlReader = new XmlTextReader(new StringReader(XMLString));
     Boolean fileExistsInLibrary = false;
     SongInfo tempSI = new SongInfo();
     Boolean inSong = false;
     String currentTag = "";
     ArrayList artistList = new ArrayList();
     ArrayList genreList = new ArrayList();
     while (XmlReader.Read()) {
         switch (XmlReader.NodeType) {
             case XmlNodeType.Element:
                 if (XmlReader.Name == "song") { inSong = true; }
                 currentTag = XmlReader.Name;
                 break;
             case XmlNodeType.Text:
                 if (inSong) {
                     switch (currentTag) {
                         case "album":
                             tempSI.Album = XmlReader.Value;
                             break;
                         case "artist":
                             artistList.Add(XmlReader.Value);
                             break;
                         case "bitrate":
                             tempSI.BitRate = Convert.ToInt32(XmlReader.Value);
                             break;
                         case "comment":
                             tempSI.Comment = XmlReader.Value;
                             break;
                         case "endbyte":
                             tempSI.EndByte = Convert.ToInt64(XmlReader.Value);
                             break;
                         case "filelength":
                             tempSI.FileLength = Convert.ToInt64(XmlReader.Value);
                             break;
                         case "filename":
                             tempSI.FileName = XmlReader.Value;
                             break;
                         case "genre":
                             genreList.Add(XmlReader.Value);
                             break;
                         case "md5":
                             tempSI.MD5 = XmlReader.Value;
                             break;
                         //case "playcount":
                         //	tempSI.PlayCount = Convert.ToInt32(XmlReader.Value);
                         //	break;
                         case "playlength":
                             tempSI.PlayLength = Convert.ToInt64(XmlReader.Value);
                             break;
                         case "startbyte":
                             tempSI.StartByte = Convert.ToInt64(XmlReader.Value);
                             break;
                         case "title":
                             tempSI.Title = XmlReader.Value;
                             break;
                         case "track":
                             tempSI.Track = Convert.ToInt32(XmlReader.Value);
                             break;
                         case "trackcount":
                             tempSI.TrackCount = Convert.ToInt32(XmlReader.Value);
                             break;
                         case "year":
                             tempSI.Year = Convert.ToInt32(XmlReader.Value);
                             break;
                     }
                 }
                 break;
             case XmlNodeType.EndElement:
                 if (XmlReader.Name == "song") {
                     inSong = false;
                     currentTag = "";
                     tempSI.AlbumArtists = (String[])artistList.ToArray(typeof(String));
                     tempSI.Genres = (String[])genreList.ToArray(typeof(String));
                     tempSI.ServerGUID = ServerGUID;
                     artistList.Clear();
                     genreList.Clear();
                     Forms.MainFrm.UpdateStatusProgressBar("Increment", 1);
                     fileExistsInLibrary = false;
                     for (int x = 0; x < SongList.Count; x++) { if (SongList[x].MD5 == tempSI.MD5) { fileExistsInLibrary = true; break; } }
                     if (fileExistsInLibrary == false) { SongList.Add(tempSI); }
                 }
                 break;
         }
     }
     SaveSettings();
     UpdateMainFrmDGV();
 }
 private void MusicLibraryDGV_SelectionChanged(object sender, EventArgs e)
 {
     if (PlaylistMLComb.SelectedIndex != -1) {
         AddToPlaylistMLCmd.Enabled = true;
     }
     if (MusicLibraryDGV.SelectedRows.Count > 0) {
         if (MusicLibraryDGV.SelectedRows[0].Tag != null) {
             LastSelectedSong = (SongInfo)MusicLibraryDGV.SelectedRows[0].Tag;
             PlayCmd.Enabled = true;
             NextCmd.Enabled = true;
             PreviousCmd.Enabled = true;
             LastSelectedSongFromPlaylist = false;
         }
     }
 }
 private void ActivePlaylistDGV_SelectionChanged(object sender, EventArgs e)
 {
     if (ActivePlaylistDGV.SelectedRows.Count > 0) {
         if (ActivePlaylistDGV.SelectedRows[0].Tag != null) {
             LastSelectedSong = (SongInfo)ActivePlaylistDGV.SelectedRows[0].Tag;
             PlayCmd.Enabled = true;
             NextCmd.Enabled = true;
             PreviousCmd.Enabled = true;
             LastSelectedSongFromPlaylist = true;
         }
     }
     UpdatePlaylistButtons();
 }
 /// <summary>
 /// Converts a TagLib.File to a SongInfo object.
 /// </summary>
 /// <param name="ID3File">TagLib.File to Convert to SongInfo.</param>
 /// <param name="ServerGUID">GUID of the server who owns the file.</param>
 /// <returns>SongInfo containing data from TagLib.File</returns>
 public static SongInfo ID3ToSongInfo(TagLib.File ID3File, String ServerGUID)
 {
     SongInfo tempSongInfo = new SongInfo();
     String[] tempStr = new String[ID3File.Tag.AlbumArtists.Length];
     tempSongInfo.Album = RemoveNewLineChars(ID3File.Tag.Album);
     for (int i = 0; i < ID3File.Tag.AlbumArtists.Length; i++) { tempStr[i] = RemoveNewLineChars(ID3File.Tag.AlbumArtists[i]); }
     tempSongInfo.AlbumArtists = tempStr;
     tempSongInfo.BitRate = ID3File.Properties.AudioBitrate;
     tempSongInfo.Comment = RemoveNewLineChars(ID3File.Tag.Comment);
     tempSongInfo.EndByte = ID3File.InvariantEndPosition;
     tempSongInfo.FileLength = (new FileInfo(ID3File.Name)).Length;
     tempSongInfo.FileName = RemoveNewLineChars(ID3File.Name);
     tempStr = new String[ID3File.Tag.Genres.Length];
     for (int i = 0; i < ID3File.Tag.Genres.Length; i++) { tempStr[i] = RemoveNewLineChars(ID3File.Tag.Genres[i]); }
     tempSongInfo.Genres = tempStr;
     tempSongInfo.PlayCount = 0;
     tempSongInfo.PlayLength = ID3File.Properties.Duration.TotalMilliseconds;
     tempSongInfo.ServerGUID = ServerGUID;
     tempSongInfo.StartByte = ID3File.InvariantStartPosition;
     tempSongInfo.Title = RemoveNewLineChars(ID3File.Tag.Title);
     tempSongInfo.Track = (int)ID3File.Tag.Track;
     tempSongInfo.TrackCount = (int)ID3File.Tag.TrackCount;
     tempSongInfo.Year = (int)ID3File.Tag.Year;
     tempSongInfo.MD5 = CreateMD5FromSongInfo(tempSongInfo);
     return tempSongInfo;
 }