image bundled ok

pull/66/head
Alexandre AGOSTINHO 2 years ago
parent f955fd809f
commit 9536f0614e

@ -5,6 +5,7 @@ using Managers;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization.Json;
namespace Views
{
@ -20,7 +21,7 @@ namespace Views
Debug.WriteLine("Hello, World!\n\n");
string path = FileSystem.Current.AppDataDirectory; // - path to the save file
string strategy = "xml"; // - strategy is 'xml' or 'json' (/!\ this is case sensitive)
string strategy = "json"; // - strategy is 'xml' or 'json' (/!\ this is case sensitive)
// Initialize the data serializer
IDataSerializer dataSerializer = (strategy == "xml") ?
@ -31,7 +32,7 @@ namespace Views
IDataManager dataManager;
if (!File.Exists(Path.Combine(path, $"data.{strategy}")))
{
var data = LoadXMLBundledFilesAsync("data.xml");
var data = LoadJSONBundledFilesAsync("data.json");
dataManager = new DataDefaultManager(dataSerializer, data);
}
else
@ -72,6 +73,8 @@ namespace Views
base.OnSleep();
}
/// <summary>
/// Load XML raw assets from data.
/// </summary>
@ -79,9 +82,8 @@ namespace Views
/// <returns>A dictionary containing the data loaded.</returns>
private static IDictionary<string, List<object>> LoadXMLBundledFilesAsync(string path)
{
//using Stream stream = await FileSystem.Current.OpenAppPackageFileAsync(path);
DataContractSerializerSettings _dataContractSerializerSettings
= new DataContractSerializerSettings()
DataContractSerializerSettings _dataContractSerializerSettings =
new DataContractSerializerSettings()
{
KnownTypes = new Type[]
{
@ -97,5 +99,29 @@ namespace Views
return data;
}
/// <summary>
/// Load JSON raw assets from data.
/// </summary>
/// <param name="path">The path in the raw assets directory.</param>
/// <returns>A dictionary containing the data loaded.</returns>
private static IDictionary<string, List<object>> LoadJSONBundledFilesAsync(string path)
{
DataContractJsonSerializerSettings _dataContractJsonSerializerSettings =
new DataContractJsonSerializerSettings()
{
KnownTypes = new Type[]
{
typeof(Recipe), typeof(RecipeType), typeof(Priority), typeof(Review), typeof(User), typeof(Ingredient), typeof(Quantity)
}
};
var jsonSerializer = new DataContractJsonSerializer(typeof(Dictionary<string, List<object>>), _dataContractJsonSerializerSettings);
IDictionary<string, List<Object>> data;
using Stream stream = FileSystem.Current.OpenAppPackageFileAsync(path).Result;
data = jsonSerializer.ReadObject(stream) as IDictionary<string, List<Object>>;
return data;
}
}
}

@ -57,7 +57,7 @@ namespace Views
if (ImageSource != null)
{
// save the file into local storage
ImageSourcePath = Path.Combine(FileSystem.Current.AppDataDirectory, $"{TitleRecipe}.{ImageSource.FileName}");
ImageSourcePath = Path.Combine(FileSystem.Current.AppDataDirectory, $"{TitleRecipe.Replace(" ", "")}.{ImageSource.FileName}");
using Stream sourceStream = await ImageSource.OpenReadAsync();
using FileStream localFileStream = File.OpenWrite(ImageSourcePath);
@ -95,7 +95,7 @@ namespace Views
PreparationStepList.Clear();
IngredientList.Clear();
await Navigation.PopAsync();
await Navigation.PopModalAsync();
}
private void AddStepRecipe(object sender, EventArgs e)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

@ -0,0 +1,376 @@
[
{
"Key": "Recipe",
"Value": [
{
"__type": "recipe:#Model",
"authorMail": "admin@mctg.fr",
"id": 9806,
"image": "cookies1.jpg",
"ingredient": [
{
"id": "Patates",
"quantity": {
"digit": 23,
"unit": 0
}
},
{
"id": "Farine",
"quantity": {
"digit": 23,
"unit": 3
}
}
],
"preparation-steps": [
{
"description": "Faire cuire.",
"order": 1
},
{
"description": "Manger.",
"order": 2
}
],
"priority": 2,
"reviews": [
{
"authorMail": "admin@mctg.fr",
"content": "Bonne recette, je recommande !",
"id": 30967,
"stars": 4
},
{
"authorMail": "admin@mctg.fr",
"content": "Bof bof, mais mangeable...",
"id": 27370,
"stars": 3
}
],
"title": "Cookies classiques",
"type": 3
},
{
"__type": "recipe:#Model",
"authorMail": "admin@mctg.fr",
"id": 4678,
"image": "cookies2.jpg",
"ingredient": [
{
"id": "Farine",
"quantity": {
"digit": 200,
"unit": 3
}
}
],
"preparation-steps": [
{
"description": "Moulinez la pâte.",
"order": 1
},
{
"description": "Faire cuire pendant une bonne heure.",
"order": 2
},
{
"description": "Sortir du four et mettre dans un plat.",
"order": 3
}
],
"priority": 1,
"reviews": [],
"title": "Cookies au chocolat",
"type": 3
},
{
"__type": "recipe:#Model",
"authorMail": "admin@mctg.fr",
"id": 28213,
"image": "room_service_icon.png",
"ingredient": [
{
"id": "Farine",
"quantity": {
"digit": 200,
"unit": 3
}
},
{
"id": "Lait",
"quantity": {
"digit": 2,
"unit": 4
}
}
],
"preparation-steps": [
{
"description": "Achetez les ingrédients.",
"order": 1
},
{
"description": "Préparez le matériel. Ustensiles et tout.",
"order": 2
},
{
"description": "Pleurez.",
"order": 3
}
],
"priority": 4,
"reviews": [
{
"authorMail": "pedrosamigos@hotmail.com",
"content": "C'était vraiment IN-CROY-ABLE !!!",
"id": 5127,
"stars": 5
}
],
"title": "Gateau nature",
"type": 3
},
{
"__type": "recipe:#Model",
"authorMail": "admin@mctg.fr",
"id": 27448,
"image": "room_service_icon.png",
"ingredient": [ ],
"preparation-steps": [
{
"description": "Achetez les légumes.",
"order": 1
},
{
"description": "Préparez le plat. Ustensiles et préchauffez le four.",
"order": 2
},
{
"description": "Coupez les pommes en morceaux et disposez-les sur le plat.",
"order": 3
},
{
"description": "Mettez enfin le plat au four, puis une fois cuit, dégustez !",
"order": 4
}
],
"priority": 3,
"reviews": [ ],
"title": "Gateau au pommes",
"type": 3
},
{
"__type": "recipe:#Model",
"authorMail": "pedrosamigos@hotmail.com",
"id": 14217,
"image": "room_service_icon.png",
"ingredient": [
{
"id": "Mais",
"quantity": {
"digit": 2,
"unit": 1
}
},
{
"id": "Sachet pépites de chocolat",
"quantity": {
"digit": 1,
"unit": 0
}
},
{
"id": "Dinde",
"quantity": {
"digit": 2,
"unit": 3
}
}
],
"preparation-steps": [
{
"description": "Ajouter les oeufs.",
"order": 1
},
{
"description": "Ajouter la farine.",
"order": 2
},
{
"description": "Ajouter 100g de chocolat fondu.",
"order": 3
},
{
"description": "Mélanger le tout.",
"order": 4
},
{
"description": "Faire cuire 45h au four traditionnel.",
"order": 5
}
],
"priority": 0,
"reviews": [ ],
"title": "Gateau au chocolat",
"type": 3
},
{
"__type": "recipe:#Model",
"authorMail": "pedrosamigos@hotmail.com",
"id": 3856,
"image": "room_service_icon.png",
"ingredient": [
{
"id": "Morceaux de bois",
"quantity": {
"digit": 2,
"unit": 0
}
},
{
"id": "Sachet gélatine",
"quantity": {
"digit": 1,
"unit": 0
}
},
{
"id": "Jambon",
"quantity": {
"digit": 2,
"unit": 1
}
}
],
"preparation-steps": [
{
"description": "Faire une cuisson bien sec de la dinde à la poêle",
"order": 1
},
{
"description": "Mettre la dinde au frigo.",
"order": 2
},
{
"description": "Mettre le jambon dans le micro-onde.",
"order": 3
},
{
"description": "Faire chauffer 3min.",
"order": 4
},
{
"description": "Présentez sur un plat la dinde et le jambon : Miam !",
"order": 5
}
],
"priority": 2,
"reviews": [ ],
"title": "Dinde au jambon",
"type": 2
},
{
"__type": "recipe:#Model",
"authorMail": "pedrosamigos@hotmail.com",
"id": 29272,
"image": "room_service_icon.png",
"ingredient": [
{
"id": "Pissenlis",
"quantity": {
"digit": 200,
"unit": 0
}
},
{
"id": "Boule de pétanque",
"quantity": {
"digit": 10,
"unit": 0
}
},
{
"id": "Poivre",
"quantity": {
"digit": 4,
"unit": 2
}
}
],
"preparation-steps": [
{
"description": "Trouvez des épices de curry.",
"order": 1
},
{
"description": "Trouvez maintenant du poulet.",
"order": 2
},
{
"description": "Coupez la tête du poulet et posez-la dans un plat.",
"order": 3
},
{
"description": "Parsemez d'épices curry la tête de la poule.",
"order": 4
},
{
"description": "Mettre le tout au four traditionnel 30min.",
"order": 5
},
{
"description": "Dégustez en famille !",
"order": 6
}
],
"priority": 4,
"reviews": [
{
"authorMail": "admin@mctg.fr",
"content": "Meilleure recette que j'ai avalé de tout les temps !!!!!!!",
"id": 7846,
"stars": 5
}
],
"title": "Poulet au curry",
"type": 2
}
]
},
{
"Key": "User",
"Value": [
{
"__type": "user:#Model",
"hashedpass": "8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918",
"mail": "admin@mctg.fr",
"name": "Admin",
"priorities": [
4,
0,
1,
3,
2
],
"profilepic": "default_picture.png",
"surname": "Admin"
},
{
"__type": "user:#Model",
"hashedpass": "df7415f099b2e105822cb6052a0de0a4eb6a4c4060b5ea191bff1271e1c377fa",
"mail": "pedrosamigos@hotmail.com",
"name": "Pedros",
"priorities": [
4,
0,
1,
3,
2
],
"profilepic": "default_picture.png",
"surname": "Amigos"
}
]
}
]
Loading…
Cancel
Save