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) { Music tmpM = Indexation.GetMusicByID(nM["MID"].InnerText); tmpM.FileBinary = null; tmp.Add(tmpM); } } } } return(tmp); }
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 (m != null) { if (VoteExist) { m.Rating--; } else { m.Rating++; Program.MyServer.Clients.TryGetValue(socket, out string uid); Program.MyServer.SendObject(new RequestAnswer(UsersInfos.GetLikedMusics(uid)), socket); } Program.MyServer.SendObject(new RateReport(true, temp.MusicRatedMID, m.Rating), socket); MusicsInfo.SaveMusicInfo(m); } } else { UsersInfos.RatePlaylist(temp.MusicRatedMID, !VoteExist); Program.MyServer.SendObject(new RateReport(true, temp.MusicRatedMID, UsersInfos.GetPlaylist(temp.MusicRatedMID).Rating), socket); } }
private static void TreatEditRequest(Socket socket, EditRequest editRequest) { switch (editRequest.TypeOfEdit) { case TypesEdit.Users: if (UsersInfos.GetRankOfUser(MyServer.Clients.GetUser(socket).UID) > editRequest.NewRankOfUser && UsersInfos.GetRankOfUser(MyServer.Clients.GetUser(socket).UID) > UsersInfos.GetRankOfUser(editRequest.UserToEdit)) { PromoteUser(editRequest.UserToEdit, editRequest.NewRankOfUser); List <User> tmpU = new List <User> { UsersInfos.GetUser(editRequest.UserToEdit) }; MyServer.SendObject(new RequestAnswer(tmpU, true), socket); MyServer.Log.Warn($"User promoted { editRequest.UserToEdit} to " + editRequest.NewRankOfUser.ToString()); } else { MyServer.Log.Warn($"Promoting the user {editRequest.UserToEdit} to {editRequest.NewRankOfUser.ToString()} failed !"); } break; case TypesEdit.Musics: if (MyServer.Clients.GetUser(socket).Rank > Rank.User) { Indexation.ModifyElement(editRequest.ObjectToEdit as Element, editRequest.NewName, editRequest.NewGenres); MyServer.Log.Warn($"The musics {editRequest.NewName} has been edited !"); } else { MyServer.Log.Warn($"The musics {editRequest.NewName } couldn't be edited"); } break; } }
private static void DoAuthor(RequestSearch requestSearch, Socket asker) { var result = Indexation.GetAuthors(x => Search.Find(requestSearch.Name, x.Name)); foreach (var a in result) { MyServer.Log.Info($" {a.Name}"); } (new RequestAnswer(result.Cast <IElement>().ToList(), ElementType.Author, requestSearch.Name)).Send(asker); }
public void GetMusicByIDTest() { //Author a = new Author("Author1", "TestPath1"); //a.Albums.Add(new Album(a, "Album1", "TestPath2")); //a.Albums[0].Add(new Music("Music1", a, a.Albums[0], "TestPath3")); //Indexation.ServerMusics.Add(a); var r = Indexation.GetMusicByID(Indexation.ServerMusics[0].Albums[0].Musics.First().MID); Assert.AreEqual(Indexation.ServerMusics[0].Albums[0].Musics.First(), r); }
private static void EditMusic(Socket socket, EditRequest editRequest) { if (Program.MyServer.Clients.GetUser(socket).Rank > Rank.User) { Indexation.ModifyElement(editRequest.ObjectToEdit as Element, editRequest.NewName, editRequest.NewGenres); Program.MyServer.Log.Warn($"The musics {editRequest.NewName} has been edited !"); } else { Program.MyServer.Log.Warn($"The musics {editRequest.NewName } couldn't be edited"); } }
private void TreatUploadMusic(Socket socket, UploadMusic uploadMusic) { if (Indexation.AddElement(uploadMusic) && (int)Program.MyServer.Clients.GetUser(socket).Rank > 1) { new UploadReport(null, true).Send(socket); Program.MyServer.Log.Warn($"The music { uploadMusic.MusicPart.Name } has been upload"); } else { new UploadReport(null, false).Send(socket); Program.MyServer.Log.Warn($"The music { uploadMusic.MusicPart.Name } has been upload"); Program.MyServer.Log.Warn("Upload completed with success"); } }
private static void DoMusic(RequestSearch requestSearch, Socket asker) { var result = Indexation.GetAllMusics() .Where(m => Search.Find(requestSearch.Name, m.Title)).OrderBy(x => Search.FindStrength(requestSearch.Name, x.Title)).OrderByDescending(x => x.Rating); foreach (var m in result) { MyServer.Log.Info(" " + m.Title); } requestSearch.SenderUID = MyServer.Clients.GetUser(asker).UID; //ServerCom.GlobalSend(requestSearch); (new RequestAnswer(result.Cast <IElement>().ToList(), ElementType.Music, requestSearch.Name)).Send(asker); }
private static void DoMusic(RequestSearch requestSearch, Socket asker) { var result = Indexation.GetAllMusics() .Where(m => Search.Find(requestSearch.Name, m.Title)); foreach (var m in result) { MyServer.Log.Info(" " + m.Title); } requestSearch.SenderUID = MyServer.Clients.GetUser(asker).UID; ServerCom.GlobalSend(requestSearch); MyServer.SendObject(new RequestAnswer(result.Cast <IElement>().ToList(), ElementType.Music), asker); }
static void Main(string[] args) { MyServer.Setup(); MyServer.AuthService.SetupAuth(); Indexation.InitRepository(); MyServer.Log.Info("Indexation of all musics.... "); MyServer.Log.Info(Indexation.Do(Properties.Settings.Default.UseMultiThreading) + "Musics"); MyServer.Log.Info("Indexation done."); Indexation.SaveAllInfos(); CommandLineInterpreter.Instance.Start(); MyServer.Log.Info("Saving music info ... "); Indexation.SaveAllInfos(); MyServer.Log.Info("Done."); }
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 GetElementPathTest() { string AuthorPathExpected = "TestPath1"; string AlbumPathExpected = "TestPath2"; string MusicPathExpected = "TestPath3"; Author a = new Author("Author1", AuthorPathExpected); a.Albums.Add(new Album(a, "Album1", AlbumPathExpected)); a.Albums[0].Add(new Music("Music1", a, a.Albums[0], MusicPathExpected)); Indexation.ServerMusics.Add(a); var result1 = Indexation.GetElementPath(a); var result2 = Indexation.GetElementPath(a.Albums[0]); var result3 = Indexation.GetElementPath(a.Albums[0].Musics.First()); Assert.AreEqual(AuthorPathExpected, result1); Assert.AreEqual(AlbumPathExpected, result2); Assert.AreEqual(MusicPathExpected, result3); }
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; } }
static void Main(string[] args) { MyServer.Setup(new System.Net.IPEndPoint(System.Net.IPAddress.Any, 2003)); Indexation.InitRepository(); MyServer.Log.Info("Indexation of all musics.... "); MyServer.Log.Info(Indexation.Do(Properties.Settings.Default.UseMultiThreading) + "Musics"); MyServer.Log.Info("Indexation done."); //Indexation.ServerMusics[0].Albums[0].Musics.First().Tags[0] = new Utility.Musics.Tags.Tag("test"); Indexation.SaveAllInfos(); AllServices = new Service(); AllServices.SetupServices(); TrackersClient.Init(); CommandLineInterpreter.Instance.Start(); MyServer.Log.Info("Saving music info ... "); Indexation.SaveAllInfos(); MyServer.Log.Info("Done."); }
public static Playlist GetPlaylist(string MID) { 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) { if (p.Attributes["MID"].InnerText == MID) { Playlist playlist = new Playlist(new User(n["Name"].InnerText), p.Attributes["Name"].InnerText); foreach (XmlNode m in p.SelectNodes("Music")) { playlist.musics.Add(Indexation.GetMusicByID(m.InnerText)); } playlist.Rating = Convert.ToInt32(p.Attributes["Rating"].InnerText); if (p.Attributes["Level"].InnerText == true.ToString()) { playlist.Private = true; return(playlist); } else { playlist.Private = false; return(playlist); } } } } return(null); }
public override void Execute(IEnumerable <string> args) => Indexation.SaveAllInfos();
public override void Execute(IEnumerable <string> args) => Indexation.InitRepository();
public override void Execute(IEnumerable <string> args) => Indexation.Do();
public void GetAuthorTest() { var r = Indexation.GetAuthor(Indexation.ServerMusics[0].MID); Assert.AreEqual(Indexation.ServerMusics[0], r); }
static public IEnumerable <Music> GetMostLikedMusic(int length) => Indexation.GetAllMusics() .OrderBy(m => m.Rating) .Take(length);
static public IEnumerable <Music> GetMostLikedMusicByGenre(string genre, int length) => Indexation.GetAllMusics() .Where(m => m.Genre.Contains(genre)) .OrderBy(m => m.Rating) .Take(length);