1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-10-30 23:16: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;
}
[YamlIgnore]
public virtual string CleanMarkdown
{
get
{
var md = Markdown;
var md = Markdown ?? string.Empty;
var rx = new Regex("<!--.*?-->");
md = rx.Replace(md, "");
return md;
}
}
[YamlIgnore]
public virtual string NewId
{
get
@ -412,6 +414,7 @@ namespace AideDeJeuLib
}
}
[YamlIgnore]
public virtual OrderedDictionary AttributesKeyValue
{
get

View file

@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Json;
@ -17,7 +18,8 @@ namespace AideDeJeu.ViewModels.Library
{
public BookmarksViewModel()
{
LoadBookmarkCollectionAsync(BookmarkCollectionNames[BookmarkCollectionIndex]).ConfigureAwait(true);
//LoadBookmarkCollectionAsync(BookmarkCollectionNames[BookmarkCollectionIndex]).ConfigureAwait(true);
LoadBookmarkCollectionsAsync().ConfigureAwait(true);
}
public ObservableCollection<string> BookmarkCollectionNames { get; set; } = new ObservableCollection<string>()
@ -42,6 +44,9 @@ namespace AideDeJeu.ViewModels.Library
//LoadBookmarkCollection(BookmarkCollectionNames[BookmarkCollectionIndex]);
}
}
private Dictionary<string, ObservableCollection<Item>> _BookmarkCollections = new Dictionary<string, ObservableCollection<Item>>();
private ObservableCollection<Item> _BookmarkCollection = new ObservableCollection<Item>();
public ObservableCollection<Item> BookmarkCollection
{
@ -60,7 +65,7 @@ namespace AideDeJeu.ViewModels.Library
{
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]);
}
else if(BookmarkCollectionIndex == BookmarkCollectionNames.Count - 1)
else if (BookmarkCollectionIndex == BookmarkCollectionNames.Count - 1)
{
var result = await Main.Navigator.OpenCancellableTextInputAlertDialog("");
if(result.Item2 == Navigator.PopupResultEnum.Save)
if (result.Item2 == Navigator.PopupResultEnum.Save)
{
var index = BookmarkCollectionNames.Count - 1;
BookmarkCollectionNames.Insert(index, result.Item1);
@ -93,7 +98,7 @@ namespace AideDeJeu.ViewModels.Library
{
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
{
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
{
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
{
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 items = await GetBookmarkCollectionAsync(key);
if(items == null)
if (items == null)
{
items = new List<Item>();
}
@ -253,11 +258,41 @@ namespace AideDeJeu.ViewModels.Library
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)
{
string md = string.Empty;
md += "\n<!--Items-->\n\n";
foreach(var item in items)
foreach (var item in items)
{
md += item.Markdown;
}
@ -324,4 +359,4 @@ namespace AideDeJeu.ViewModels.Library
}
*/
}
}
}