parallelize some events and database mutating actions
continuous-integration/drone/push Build is passing Details

pull/55/head
maxime.BATISTA@etu.uca.fr 2 years ago
parent fdb27b6f2c
commit be38c91746

@ -0,0 +1,4 @@
[*.cs]
# CS1998: Async method lacks 'await' operators and will run synchronously
dotnet_diagnostic.CS1998.severity = none

@ -24,14 +24,14 @@ namespace ShoopNCook.Controllers
app.ForceLogin(); app.ForceLogin();
} }
public void GoToMyRecipesPage() public async void GoToMyRecipesPage()
{ {
Shell.Current.Navigation.PushAsync(new MyRecipesPage(account, endpoint.RecipesService, app.Notifier)); await Shell.Current.Navigation.PushAsync(new MyRecipesPage(account, endpoint.RecipesService, app.Notifier));
} }
public void GoToProfilePage() public async void GoToProfilePage()
{ {
Shell.Current.Navigation.PushAsync(new ProfilePage(account)); await Shell.Current.Navigation.PushAsync(new ProfilePage(account));
} }
} }
} }

@ -76,38 +76,38 @@ namespace LocalEndpoint.Data
return usersData[user].Rates[recipe]; return usersData[user].Rates[recipe];
} }
public void InsertInUserList(Guid userId, Guid recipeId, uint persAmount) public async void InsertInUserList(Guid userId, Guid recipeId, uint persAmount)
{ {
usersData[userId].RecipesList[recipeId] = persAmount; usersData[userId].RecipesList[recipeId] = persAmount;
Save(USERS_FILENAME, USERS_SERIALIZER, usersData); Save(USERS_FILENAME, USERS_SERIALIZER, usersData);
} }
public void RemoveFromUserList(Guid userId, Guid recipeId) public async void RemoveFromUserList(Guid userId, Guid recipeId)
{ {
usersData[userId].RecipesList.Remove(recipeId); usersData[userId].RecipesList.Remove(recipeId);
Save(USERS_FILENAME, USERS_SERIALIZER, usersData); Save(USERS_FILENAME, USERS_SERIALIZER, usersData);
} }
public void InsertRecipe(Recipe recipe) public async void InsertRecipe(Recipe recipe)
{ {
recipesData[recipe.Info.Id] = new RecipeData(recipe.Info, recipe.Owner.Id, recipe.Ingredients, recipe.Steps); recipesData[recipe.Info.Id] = new RecipeData(recipe.Info, recipe.Owner.Id, recipe.Ingredients, recipe.Steps);
Save(RECIPES_FILENAME, RECIPES_SERIALIZER, recipesData); Save(RECIPES_FILENAME, RECIPES_SERIALIZER, recipesData);
} }
public void InsertUser(User user) public async void InsertUser(User user)
{ {
usersData[user.Id] = new UserData(user, new Dictionary<Guid, RecipeRate>(), new Dictionary<Guid, uint>()); usersData[user.Id] = new UserData(user, new Dictionary<Guid, RecipeRate>(), new Dictionary<Guid, uint>());
Save(USERS_FILENAME, USERS_SERIALIZER, usersData); Save(USERS_FILENAME, USERS_SERIALIZER, usersData);
} }
public void InsertRate(Guid userId, Guid recipeId, RecipeRate rate) public async void InsertRate(Guid userId, Guid recipeId, RecipeRate rate)
{ {
usersData[userId].Rates[recipeId] = rate; usersData[userId].Rates[recipeId] = rate;
Save(USERS_FILENAME, USERS_SERIALIZER, usersData); Save(USERS_FILENAME, USERS_SERIALIZER, usersData);
} }
public void RemoveRecipe(Guid id) public async void RemoveRecipe(Guid id)
{ {
recipesData.Remove(id); recipesData.Remove(id);
Save(RECIPES_FILENAME, RECIPES_SERIALIZER, recipesData); Save(RECIPES_FILENAME, RECIPES_SERIALIZER, recipesData);
@ -151,7 +151,7 @@ namespace LocalEndpoint.Data
return JsonSerializer.Deserialize<Dictionary<K, V>>(text); return JsonSerializer.Deserialize<Dictionary<K, V>>(text);
} }
private void Save<K, T>(string fileName, DataContractSerializer serializer, Dictionary<K, T> dict) private async void Save<K, T>(string fileName, DataContractSerializer serializer, Dictionary<K, T> dict)
{ {
string json = JsonSerializer.Serialize(dict); string json = JsonSerializer.Serialize(dict);
File.WriteAllText(dbPath + "/" + fileName, json); File.WriteAllText(dbPath + "/" + fileName, json);

@ -37,11 +37,9 @@
<!-- Email entry --> <!-- Email entry -->
<Grid <Grid
Grid.Row="1" Grid.Row="1"
RowDefinitions="*, Auto, Auto" RowDefinitions="*, Auto, Auto">
>
<Label <Label
Grid.Row="0" Grid.Row="0"
FontSize="15" FontSize="15"
TextColor="{StaticResource TextColorSecondary}" TextColor="{StaticResource TextColorSecondary}"

@ -18,21 +18,21 @@ public partial class CreateRecipePage : ContentPage
this.notifier = notifier; this.notifier = notifier;
} }
private void OnAddIngredientTapped(object sender, TappedEventArgs e) private async void OnAddIngredientTapped(object sender, TappedEventArgs e)
{ {
IngredientList.Children.Add(new IngredientEntry()); IngredientList.Children.Add(new IngredientEntry());
} }
private void OnAddStepTapped(object sender, TappedEventArgs e) private async void OnAddStepTapped(object sender, TappedEventArgs e)
{ {
StepList.Children.Add(new StepEntry((uint) StepList.Children.Count() + 1)); StepList.Children.Add(new StepEntry((uint) StepList.Children.Count() + 1));
} }
private void OnBackButtonClicked(object sender, EventArgs e) private async void OnBackButtonClicked(object sender, EventArgs e)
{ {
Navigation.PopAsync(); Navigation.PopAsync();
} }
private void OnUploadRecipeClicked(object sender, EventArgs e) private async void OnUploadRecipeClicked(object sender, EventArgs e)
{ {
uint callPerPers; uint callPerPers;

@ -29,15 +29,15 @@ public partial class FavoritesPage : ContentPage
RecipeViewLayout.Children.Clear(); RecipeViewLayout.Children.Clear();
preferences.GetFavorites().ForEach(info => preferences.GetFavorites().ForEach(info =>
{ {
RecipeViewLayout.Children.Add(new RecipeView(info, () => RecipeViewLayout.Children.Add(new RecipeView(info, async () =>
{ {
Recipe? recipe = service.GetRecipe(info); Recipe? recipe = service.GetRecipe(info);
Shell.Current.Navigation.PushAsync(new RecipePage(recipe, notifier, preferences, 1)); await Shell.Current.Navigation.PushAsync(new RecipePage(recipe, notifier, preferences, 1));
})); }));
}); });
} }
private void ContentPage_NavigatedTo(object sender, NavigatedToEventArgs e) private async void ContentPage_NavigatedTo(object sender, NavigatedToEventArgs e)
{ {
UpdateFavorites(); UpdateFavorites();
} }

@ -1,47 +1,47 @@
namespace ShoopNCook.Pages; namespace ShoopNCook.Pages;
using Models; using Models;
using ShoopNCook.Views; using ShoopNCook.Views;
using Endpoint; using Endpoint;
using LocalEndpoint; using LocalEndpoint;
public partial class HomePage : ContentPage public partial class HomePage : ContentPage
{ {
public HomePage(Account account, IUserNotifier notifier, IEndpoint endpoint) public HomePage(Account account, IUserNotifier notifier, IEndpoint endpoint)
{ {
InitializeComponent(); InitializeComponent();
IRecipesService service = endpoint.RecipesService; IRecipesService service = endpoint.RecipesService;
IAccountRecipesPreferences preferences = service.GetPreferencesOf(account); IAccountRecipesPreferences preferences = service.GetPreferencesOf(account);
//TODO this code can be factorised //TODO this code can be factorised
void PushRecipe(Layout layout, RecipeInfo info) void PushRecipe(Layout layout, RecipeInfo info)
{ {
layout.Children.Add(new RecipeView(info, () => layout.Children.Add(new RecipeView(info, () =>
{ {
Recipe? recipe = service.GetRecipe(info); Recipe? recipe = service.GetRecipe(info);
if (recipe != null) if (recipe != null)
Shell.Current.Navigation.PushAsync(new RecipePage(recipe, notifier, preferences, 1)); Shell.Current.Navigation.PushAsync(new RecipePage(recipe, notifier, preferences, 1));
else else
{ {
notifier.Error("Could not find recipe"); notifier.Error("Could not find recipe");
} }
})); }));
} }
service.PopularRecipes().ForEach(recipe => PushRecipe(PopularsList, recipe)); service.PopularRecipes().ForEach(recipe => PushRecipe(PopularsList, recipe));
preferences.GetRecommendedRecipes().ForEach(recipe => PushRecipe(RecommendedList, recipe)); preferences.GetRecommendedRecipes().ForEach(recipe => PushRecipe(RecommendedList, recipe));
ProfilePictureImage.Source = ImageSource.FromUri(account.User.ProfilePicture); ProfilePictureImage.Source = ImageSource.FromUri(account.User.ProfilePicture);
ProfilePictureName.Text = account.User.Name; ProfilePictureName.Text = account.User.Name;
} }
private void OnSyncButtonClicked(object sender, EventArgs e) private async void OnSyncButtonClicked(object sender, EventArgs e)
{ {
Shell.Current.Navigation.PushAsync(new SearchPage()); await Shell.Current.Navigation.PushAsync(new SearchPage());
} }
} }

@ -37,7 +37,7 @@ public partial class MyListPage : ContentPage
}); });
} }
private void ContentPage_NavigatedTo(object sender, NavigatedToEventArgs e) private async void ContentPage_NavigatedTo(object sender, NavigatedToEventArgs e)
{ {
UpdateMyList(); UpdateMyList();
} }

@ -61,11 +61,11 @@ public partial class MyRecipesPage : ContentPage
notifier.Success("Recipe successfully removed"); notifier.Success("Recipe successfully removed");
} }
private void OnBackButtonClicked(object sender, EventArgs e) private async void OnBackButtonClicked(object sender, EventArgs e)
{ {
Navigation.PopAsync(); await Navigation.PopAsync();
} }
private void OnAddRecipeButtonClicked(object sender, EventArgs e) private async void OnAddRecipeButtonClicked(object sender, EventArgs e)
{ {
IAccountOwnedRecipes recipes = service.GetRecipesOf(account); IAccountOwnedRecipes recipes = service.GetRecipesOf(account);

@ -77,7 +77,7 @@ public partial class RecipePage : ContentPage
} }
} }
private void OnFavorite(object o, EventArgs e) private async void OnFavorite(object o, EventArgs e)
{ {
SetFavorite(!isFavorite); SetFavorite(!isFavorite);
if (isFavorite) if (isFavorite)
@ -86,13 +86,13 @@ public partial class RecipePage : ContentPage
preferences.RemoveFromFavorites(info); preferences.RemoveFromFavorites(info);
} }
private void OnSubmitReviewClicked(object o, EventArgs e) private async void OnSubmitReviewClicked(object o, EventArgs e)
{ {
preferences.SetReviewScore(info, note); preferences.SetReviewScore(info, note);
notifier.Success("Your review has been successfuly submited"); notifier.Success("Your review has been successfuly submited");
} }
private void OnAddToMyListClicked(object o, EventArgs e) private async void OnAddToMyListClicked(object o, EventArgs e)
{ {
if (!preferences.AddToWeeklyList(info, Counter.Count)) if (!preferences.AddToWeeklyList(info, Counter.Count))
notifier.Notice("You already added this recipe to you weekly list!"); notifier.Notice("You already added this recipe to you weekly list!");
@ -108,9 +108,9 @@ public partial class RecipePage : ContentPage
else else
Favorite.Source = ImageSource.FromFile("hearth_off.svg"); Favorite.Source = ImageSource.FromFile("hearth_off.svg");
} }
private void OnBackButtonClicked(object sender, EventArgs e) private async void OnBackButtonClicked(object sender, EventArgs e)
{ {
Navigation.PopAsync(); await Navigation.PopAsync();
} }
} }

@ -14,7 +14,7 @@ public partial class RegisterPage : ContentPage
{ {
await Shell.Current.GoToAsync("//Login"); await Shell.Current.GoToAsync("//Login");
} }
private void RegisterTapped(object sender, EventArgs e) private async void RegisterTapped(object sender, EventArgs e)
{ {
string email = EmailEntry.Text; string email = EmailEntry.Text;
string password = PasswordEntry.Text; string password = PasswordEntry.Text;

Loading…
Cancel
Save