|
|
@ -5,6 +5,8 @@ using System.Collections.Immutable;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Runtime.Serialization;
|
|
|
|
using System.Runtime.Serialization;
|
|
|
|
using System.Text;
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
|
|
|
using System.Text.Json.Serialization;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
namespace LocalEndpoint.Data
|
|
|
|
namespace LocalEndpoint.Data
|
|
|
@ -62,9 +64,11 @@ namespace LocalEndpoint.Data
|
|
|
|
Save(ACCOUNTS_FILENAME, ACCOUNTS_SERIALIZER, accountsData);
|
|
|
|
Save(ACCOUNTS_FILENAME, ACCOUNTS_SERIALIZER, accountsData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Recipe GetRecipe(Guid id)
|
|
|
|
public Recipe? GetRecipe(Guid id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return ConvertRecipeDataToRecipe(recipesData[id]);
|
|
|
|
if (recipesData.TryGetValue(id, out RecipeData? data))
|
|
|
|
|
|
|
|
return ConvertRecipeDataToRecipe(data);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public RecipeRate GetRecipeRate(Guid user, Guid recipe)
|
|
|
|
public RecipeRate GetRecipeRate(Guid user, Guid recipe)
|
|
|
@ -141,19 +145,16 @@ namespace LocalEndpoint.Data
|
|
|
|
|
|
|
|
|
|
|
|
if (fileInfo.Length == 0)
|
|
|
|
if (fileInfo.Length == 0)
|
|
|
|
return new Dictionary<K, V>(); //file is empty thus there is nothing to deserialize
|
|
|
|
return new Dictionary<K, V>(); //file is empty thus there is nothing to deserialize
|
|
|
|
Console.WriteLine(File.ReadAllText(file));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (var stream = File.OpenRead(file))
|
|
|
|
string text = File.ReadAllText(file);
|
|
|
|
return deserializer.ReadObject(stream) as Dictionary<K, V> ?? throw new Exception("object read from " + file + " is not a dictionnary");
|
|
|
|
|
|
|
|
|
|
|
|
return JsonSerializer.Deserialize<Dictionary<K, V>>(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Save<K, T>(string fileName, DataContractSerializer serializer, Dictionary<K, T> dict)
|
|
|
|
private void Save<K, T>(string fileName, DataContractSerializer serializer, Dictionary<K, T> dict)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using (var stream = File.OpenWrite(dbPath + "/" + fileName))
|
|
|
|
string json = JsonSerializer.Serialize(dict);
|
|
|
|
{
|
|
|
|
File.WriteAllText(dbPath + "/" + fileName, json);
|
|
|
|
serializer.WriteObject(stream, dict);
|
|
|
|
|
|
|
|
stream.Flush();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|