fix onpropertychange + références
continuous-integration/drone/push Build is passing Details

master
Anthony RICHARD 2 years ago
parent c13f44e63e
commit 0ef51c3fe3

@ -1,10 +1,7 @@
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
using System.Xml;
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.FileIO;
using Model;
using System.Runtime.InteropServices;
using System.Diagnostics.CodeAnalysis;
namespace StimPersistance
@ -26,7 +23,7 @@ namespace StimPersistance
public void SaveGame(List<Game> games)
{
XmlWriterSettings settings = new() { Indent = true };
DataContractSerializer serializer = new(typeof(List<Game>));
DataContractSerializer serializer = new(typeof(List<Game>), new DataContractSerializerSettings() { PreserveObjectReferences = true });
using (TextWriter tw = File.CreateText(fullGamePath))
using (XmlWriter writer = XmlWriter.Create(tw, settings)) serializer.WriteObject(writer, games);
@ -35,7 +32,7 @@ namespace StimPersistance
public void SaveUser(HashSet<User> users)
{
XmlWriterSettings settings = new() { Indent = true };
DataContractSerializer serializer = new(typeof(HashSet<User>));
DataContractSerializer serializer = new(typeof(HashSet<User>), new DataContractSerializerSettings() { PreserveObjectReferences = true});
using (TextWriter tw = File.CreateText(fullUserPath))
using (XmlWriter writer = XmlWriter.Create(tw, settings)) serializer.WriteObject(writer, users);
@ -45,7 +42,7 @@ namespace StimPersistance
{
if (File.Exists(fullGamePath))
{
DataContractSerializer serializer = new(typeof(List<Game>));
DataContractSerializer serializer = new(typeof(List<Game>), new DataContractSerializerSettings() { PreserveObjectReferences = true });
using (Stream stream = File.OpenRead(fullGamePath)) return serializer.ReadObject(stream) as List<Game> ?? new();
}
return new();
@ -55,10 +52,10 @@ namespace StimPersistance
{
if (File.Exists(fullUserPath))
{
DataContractSerializer serializer = new(typeof(HashSet<User>));
DataContractSerializer serializer = new(typeof(HashSet<User>), new DataContractSerializerSettings() { PreserveObjectReferences = true });
using (Stream stream = File.OpenRead(fullUserPath)) return serializer.ReadObject(stream) as HashSet<User> ?? new();
}
return new();
}
}
}
}

@ -71,5 +71,19 @@ namespace Model
{
mgrpersistance.SaveUser(Users);
}
[ExcludeFromCodeCoverage]
public void UpdateReferences()
{
if (CurrentUser != null && CurrentUser.Followed_Games.Count != 0)
{
foreach (var game in CurrentUser.Followed_Games.ToList())
{
CurrentUser.RemoveAGame(game);
if (GameList.Contains(game)) CurrentUser.FollowAGame(gameList.Where(g => g.Name == game.Name).First());
}
}
SaveUser();
}
}
}

@ -142,11 +142,13 @@ namespace Model
{
if (Followed_Games.Contains(game)) return;
followed_Games.Add(game);
NotifyPropertyChanged(nameof(Followed_Games));
}
public void RemoveAGame(Game game)
{
if (!Followed_Games.Contains(game)) return;
followed_Games.Remove(game);
NotifyPropertyChanged(nameof(Followed_Games));
}
public override string ToString()

@ -74,9 +74,17 @@ public partial class DetailledPage : ContentPage
var res = await this.ShowPopupAsync(new ConfirmationPopup("Voulez-vous vraiment supprimer " + (App.Current as App).Manager.SelectedGame.Name + " ?"));
if (res != null && res is bool && (bool)res)
{
(App.Current as App).Manager.CurrentUser.RemoveAGame((App.Current as App).Manager.SelectedGame);
(App.Current as App).Manager.RemoveGameFromGamesList((App.Current as App).Manager.SelectedGame);
(App.Current as App).Manager.SaveUser();
await Navigation.PopAsync();
await this.ShowPopupAsync(new MessagePopup("Jeu supprimé !"));
}
}
protected override void OnDisappearing()
{
Navigation.PopAsync();
base.OnDisappearing();
}
}

@ -21,8 +21,9 @@ public partial class LoginPage : ContentPage
if (user.Password == Pswd.Text)
{
((App)App.Current).Manager.CurrentUser = user;
((App)App.Current).Manager.UpdateReferences();
Application.Current.MainPage = new AppShell();
await Navigation.PushModalAsync(new MainPage());//Shell.Current.GoToAsync("//MainPage");
await Navigation.PushModalAsync(new MainPage());
}
else Error.Children.Add(new Label { Text = "Mot de passe incorrect",
TextColor = Colors.Red,

@ -174,12 +174,14 @@ namespace Test
Game game2 = new("name2", "description", 2020, new List<String> { "1" }, "cover2", "www.link.com");
Game? game3 = null;
string game4 = "";
Game game5 = new("name", "description2", 2012, new List<String> { "1", "2", "3" }, "cover", "www.link.com");
Assert.False(game.Equals(game2 as Game));
Assert.False(game.Equals(game3 as object));
Assert.True(game.Equals(game as object));
Assert.False(game.Equals(game4 as object));
Assert.False(game.Equals(game2 as object));
Assert.True(game.Equals(game5 as Game));
}
[Fact]

Loading…
Cancel
Save