public static List <Music> GetLikedMusics(string UserID)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(@"users.xml");

            XmlNodeList nodes = doc.DocumentElement.SelectNodes("User");

            List <Music> tmp = new List <Music>();

            foreach (XmlNode n in nodes)
            {
                if (n["UID"].InnerText == UserID)
                {
                    XmlNodeList nodesMusics = n.SelectNodes("RatedMusics/Music");
                    foreach (XmlNode nM in nodesMusics)
                    {
                        if (GetPlaylist(nM["MID"].InnerText) == null)
                        {
                            if (Indexation.TryGetMusicByID(nM["MID"].InnerText, out Music tmpM))
                            {
                                tmpM.FileBinary = null;
                                tmp.Add(tmpM);
                            }
                        }
                    }
                }
            }
            return(tmp);
        }
Exemple #2
0
        public static void Handle(Rate temp, Socket socket)
        {
            bool VoteExist = UsersInfos.VoteExist(temp.MusicRatedMID, Program.MyServer.Clients[socket]);

            UsersInfos.AddVoteMusic(temp.MusicRatedMID, Program.MyServer.Clients[socket]);

            if (temp.Type == ElementType.Music)
            {
                //var m = Indexation.GetMusicByID(temp.MusicRatedMID);
                if (Indexation.TryGetMusicByID(temp.MusicRatedMID, out Music m))
                {
                    if (VoteExist)
                    {
                        m.Rating--;
                    }
                    else
                    {
                        m.Rating++;

                        Program.MyServer.Clients.TryGetValue(socket, out string uid);
                        new RequestAnswer(UsersInfos.GetLikedMusics(uid)).Send(socket);
                    }
                    new RateReport(true, temp.MusicRatedMID, m.Rating).Send(socket);
                    MusicsInfo.SaveMusicInfo(m);
                }
            }
            else
            {
                UsersInfos.RatePlaylist(temp.MusicRatedMID, !VoteExist);
                new RateReport(true, temp.MusicRatedMID, UsersInfos.GetPlaylist(temp.MusicRatedMID).Rating).Send(socket);
            }
        }
        public static IEnumerable <Playlist> GetPlaylists(string UID)
        {
            List <Playlist> playlists = new List <Playlist>();

            XmlDocument doc = new XmlDocument();

            doc.Load(@"users.xml");

            XmlNodeList nodes = doc.DocumentElement.SelectNodes("User");

            foreach (XmlNode n in nodes)
            {
                XmlNodeList PlaylistNode = n.SelectNodes("UserPlaylists/Playlist");

                foreach (XmlNode p in PlaylistNode)
                {
                    Playlist playlist = new Playlist(new User(n["Name"].InnerText), p.Attributes["Name"].InnerText);
                    foreach (XmlNode m in p.SelectNodes("Music"))
                    {
                        if (Indexation.TryGetMusicByID(m.InnerText, out Music mu))
                        {
                            mu.FileBinary = null;
                            playlist.musics.Add(mu);
                            mu.N = UInt32.Parse(m.Attributes["Number"].InnerText);
                        }
                    }
                    playlist.Rating = Convert.ToInt32(p.Attributes["Rating"].InnerText);
                    if (p.Attributes["Level"].InnerText == true.ToString())
                    {
                        if (n["UID"].InnerText == UID)
                        {
                            playlist.Private = true;
                            playlists.Add(playlist);
                        }
                    }
                    else
                    {
                        playlist.Private = false;
                        playlists.Add(playlist);
                    }
                }
            }
            return(playlists);
        }
        public void Handle(Request request, Socket socket)
        {
            switch (request.RequestsType)
            {
            case RequestsTypes.Search:
                Console.WriteLine("Request by client :" + (request as RequestSearch).Name);
                MusicsManagement.ClientSearch.SearchAnswer.Do(request as RequestSearch, socket);
                break;

            case RequestsTypes.MusicsBinaries:
                if (Indexation.TryGetMusicByID((request as RequestBinairies).RequestedBinaries.MID, out Music m))
                {
                    Music answer = new Music(m.Title, new Author(m.Author.Name), m.Album, Indexation.GetFileBinary(m))
                    {
                        Format = m.Format,
                        Rating = m.Rating
                    };
                    new RequestAnswer(answer).Send(socket);
                }
                break;

            case RequestsTypes.Favorites:
                List <Music> tmp = UsersInfos.GetLikedMusics((request as RequestFavorites).UserID);
                new RequestAnswer(tmp).Send(socket);
                break;

            case RequestsTypes.Users:
                if (Program.MyServer.Clients.GetUser(socket).Rank != Rank.Viewer)
                {
                    new RequestAnswer(UsersInfos.SearchUser((request as RequestUser).Username), true).Send(socket);
                }
                else
                {
                    new RequestAnswer(null, false).Send(socket);
                }
                break;
            }
        }