1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-10-31 07:26:09 +00:00

Tests sérialization nouveaux bookmarks

This commit is contained in:
Yan Maniez 2019-07-21 00:27:23 +02:00
parent f5199f470b
commit da496a08a9
2 changed files with 93 additions and 55 deletions

View file

@ -312,17 +312,19 @@ namespace AideDeJeuLib
return post as Item; return post as Item;
} }
[YamlIgnore]
public virtual string CleanMarkdown public virtual string CleanMarkdown
{ {
get get
{ {
var md = Markdown; var md = Markdown ?? string.Empty;
var rx = new Regex("<!--.*?-->"); var rx = new Regex("<!--.*?-->");
md = rx.Replace(md, ""); md = rx.Replace(md, "");
return md; return md;
} }
} }
[YamlIgnore]
public virtual string NewId public virtual string NewId
{ {
get get
@ -412,6 +414,7 @@ namespace AideDeJeuLib
} }
} }
[YamlIgnore]
public virtual OrderedDictionary AttributesKeyValue public virtual OrderedDictionary AttributesKeyValue
{ {
get get

View file

@ -2,6 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.Serialization.Json; using System.Runtime.Serialization.Json;
@ -17,7 +18,8 @@ namespace AideDeJeu.ViewModels.Library
{ {
public BookmarksViewModel() public BookmarksViewModel()
{ {
LoadBookmarkCollectionAsync(BookmarkCollectionNames[BookmarkCollectionIndex]).ConfigureAwait(true); //LoadBookmarkCollectionAsync(BookmarkCollectionNames[BookmarkCollectionIndex]).ConfigureAwait(true);
LoadBookmarkCollectionsAsync().ConfigureAwait(true);
} }
public ObservableCollection<string> BookmarkCollectionNames { get; set; } = new ObservableCollection<string>() public ObservableCollection<string> BookmarkCollectionNames { get; set; } = new ObservableCollection<string>()
@ -42,6 +44,9 @@ namespace AideDeJeu.ViewModels.Library
//LoadBookmarkCollection(BookmarkCollectionNames[BookmarkCollectionIndex]); //LoadBookmarkCollection(BookmarkCollectionNames[BookmarkCollectionIndex]);
} }
} }
private Dictionary<string, ObservableCollection<Item>> _BookmarkCollections = new Dictionary<string, ObservableCollection<Item>>();
private ObservableCollection<Item> _BookmarkCollection = new ObservableCollection<Item>(); private ObservableCollection<Item> _BookmarkCollection = new ObservableCollection<Item>();
public ObservableCollection<Item> BookmarkCollection public ObservableCollection<Item> BookmarkCollection
{ {
@ -60,7 +65,7 @@ namespace AideDeJeu.ViewModels.Library
{ {
get get
{ {
return _SelectedIndexChangedCommand ?? (_SelectedIndexChangedCommand = new Command(async() => await ExecuteSelectedIndexChangedCommandAsync())); return _SelectedIndexChangedCommand ?? (_SelectedIndexChangedCommand = new Command(async () => await ExecuteSelectedIndexChangedCommandAsync()));
} }
} }
@ -70,10 +75,10 @@ namespace AideDeJeu.ViewModels.Library
{ {
await LoadBookmarkCollectionAsync(BookmarkCollectionNames[BookmarkCollectionIndex]); await LoadBookmarkCollectionAsync(BookmarkCollectionNames[BookmarkCollectionIndex]);
} }
else if(BookmarkCollectionIndex == BookmarkCollectionNames.Count - 1) else if (BookmarkCollectionIndex == BookmarkCollectionNames.Count - 1)
{ {
var result = await Main.Navigator.OpenCancellableTextInputAlertDialog(""); var result = await Main.Navigator.OpenCancellableTextInputAlertDialog("");
if(result.Item2 == Navigator.PopupResultEnum.Save) if (result.Item2 == Navigator.PopupResultEnum.Save)
{ {
var index = BookmarkCollectionNames.Count - 1; var index = BookmarkCollectionNames.Count - 1;
BookmarkCollectionNames.Insert(index, result.Item1); BookmarkCollectionNames.Insert(index, result.Item1);
@ -93,7 +98,7 @@ namespace AideDeJeu.ViewModels.Library
{ {
get get
{ {
return _GotoItemCommand ?? (_GotoItemCommand = new Command<Item>(async(item) => await ExecuteGotoItemCommandAsync(item))); return _GotoItemCommand ?? (_GotoItemCommand = new Command<Item>(async (item) => await ExecuteGotoItemCommandAsync(item)));
} }
} }
@ -110,7 +115,7 @@ namespace AideDeJeu.ViewModels.Library
{ {
get get
{ {
return _RemoveItemCommand ?? (_RemoveItemCommand = new Command<Item>(async(item) => await ExecuteRemoveItemCommandAsync(item))); return _RemoveItemCommand ?? (_RemoveItemCommand = new Command<Item>(async (item) => await ExecuteRemoveItemCommandAsync(item)));
} }
} }
@ -125,7 +130,7 @@ namespace AideDeJeu.ViewModels.Library
{ {
get get
{ {
return _MoveUpItemCommand ?? (_MoveUpItemCommand = new Command<Item>(async(item) => await ExecuteMoveUpItemCommandAsync(item))); return _MoveUpItemCommand ?? (_MoveUpItemCommand = new Command<Item>(async (item) => await ExecuteMoveUpItemCommandAsync(item)));
} }
} }
@ -144,7 +149,7 @@ namespace AideDeJeu.ViewModels.Library
{ {
get get
{ {
return _MoveDownItemCommand ?? (_MoveDownItemCommand = new Command<Item>(async(item) => await ExecuteMoveDownItemCommandAsync(item))); return _MoveDownItemCommand ?? (_MoveDownItemCommand = new Command<Item>(async (item) => await ExecuteMoveDownItemCommandAsync(item)));
} }
} }
@ -224,7 +229,7 @@ namespace AideDeJeu.ViewModels.Library
{ {
var linkItem = new LinkItem() { Name = item.Name, AltName = item.AltName, Link = item.Id }; var linkItem = new LinkItem() { Name = item.Name, AltName = item.AltName, Link = item.Id };
var items = await GetBookmarkCollectionAsync(key); var items = await GetBookmarkCollectionAsync(key);
if(items == null) if (items == null)
{ {
items = new List<Item>(); items = new List<Item>();
} }
@ -253,11 +258,41 @@ namespace AideDeJeu.ViewModels.Library
await App.Current.SavePropertiesAsync(); await App.Current.SavePropertiesAsync();
} }
public async Task InitBookmarkCollectionsAsync()
{
_BookmarkCollections = new Dictionary<string, ObservableCollection<Item>>()
{
{ "Général", new ObservableCollection<Item>() },
{ "Grimoire", new ObservableCollection<Item>() },
{ "Bestiaire", new ObservableCollection<Item>() },
{ "Sac", new ObservableCollection<Item>() },
};
}
public async Task LoadBookmarkCollectionsAsync()
{
if(true)
{
await InitBookmarkCollectionsAsync();
using (var context = await StoreViewModel.GetLibraryContextAsync())
{
var spells = context.Spells.ToList();
var spell = spells.Take(1).FirstOrDefault();
_BookmarkCollections["Grimoire"].Add(new Item() { Id = spell.Id, Name = spell.Name });
}
await SaveBookmarkCollectionsAsync();
}
}
public async Task SaveBookmarkCollectionsAsync()
{
var yaml = new YamlDotNet.Serialization.Serializer().Serialize(_BookmarkCollections);
Debug.WriteLine(yaml);
}
public string ToString(IEnumerable<Item> items) public string ToString(IEnumerable<Item> items)
{ {
string md = string.Empty; string md = string.Empty;
md += "\n<!--Items-->\n\n"; md += "\n<!--Items-->\n\n";
foreach(var item in items) foreach (var item in items)
{ {
md += item.Markdown; md += item.Markdown;
} }
@ -271,57 +306,57 @@ namespace AideDeJeu.ViewModels.Library
//if(item is Items) //if(item is Items)
//{ //{
var items = item; // as Items; var items = item; // as Items;
return await items.GetChildrenAsync(); return await items.GetChildrenAsync();
//} //}
//return new List<Item> { item }; //return new List<Item> { item };
} }
/* /*
public string ToString(List<Item> items) public string ToString(List<Item> items)
{
var serializer = ItemJsonSerializer;
using(var stream = new MemoryStream())
{ {
var serializer = ItemJsonSerializer; serializer.WriteObject(stream, items);
using(var stream = new MemoryStream()) stream.Seek(0, SeekOrigin.Begin);
using (StreamReader reader = new StreamReader(stream))
{ {
serializer.WriteObject(stream, items); return reader.ReadToEnd();
stream.Seek(0, SeekOrigin.Begin);
using (StreamReader reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
} }
} }
public List<Item> ToItems(string str)
{
var serializer = ItemJsonSerializer;
byte[] byteArray = Encoding.UTF8.GetBytes(str);
using (var stream = new MemoryStream(byteArray))
{
return serializer.ReadObject(stream) as List<Item>;
}
}
public DataContractJsonSerializer ItemJsonSerializer
{
get
{
var settings = new DataContractJsonSerializerSettings();
settings.KnownTypes = new List<Type>()
{
typeof(HomeItem),
typeof(Spell),
typeof(Monster),
//typeof(Items),
typeof(LinkItem),
typeof(Equipment),
//typeof(Spells),
//typeof(Monsters),
//typeof(Equipments),
typeof(PageItem),
};
return new DataContractJsonSerializer(typeof(List<Item>), settings);
}
}
*/
} }
public List<Item> ToItems(string str)
{
var serializer = ItemJsonSerializer;
byte[] byteArray = Encoding.UTF8.GetBytes(str);
using (var stream = new MemoryStream(byteArray))
{
return serializer.ReadObject(stream) as List<Item>;
}
}
public DataContractJsonSerializer ItemJsonSerializer
{
get
{
var settings = new DataContractJsonSerializerSettings();
settings.KnownTypes = new List<Type>()
{
typeof(HomeItem),
typeof(Spell),
typeof(Monster),
//typeof(Items),
typeof(LinkItem),
typeof(Equipment),
//typeof(Spells),
//typeof(Monsters),
//typeof(Equipments),
typeof(PageItem),
};
return new DataContractJsonSerializer(typeof(List<Item>), settings);
}
}
*/
} }
}