diff --git a/AideDeJeu/AideDeJeu/App.xaml.cs b/AideDeJeu/AideDeJeu/App.xaml.cs index ec17936e..ae10b3d6 100644 --- a/AideDeJeu/AideDeJeu/App.xaml.cs +++ b/AideDeJeu/AideDeJeu/App.xaml.cs @@ -1,6 +1,8 @@ using AideDeJeu.ViewModels; using AideDeJeu.Views; using AideDeJeuLib; +using System.Linq; +using System.Threading.Tasks; using Xamarin.Forms; using Xamarin.Forms.Xaml; @@ -27,6 +29,7 @@ namespace AideDeJeu var navigationPage = tabbeddPage.MainNavigationPage; vm.Navigator = new Navigator(navigationPage.Navigation); MainPage = tabbeddPage; + } protected override void OnStart () diff --git a/AideDeJeu/AideDeJeu/ViewModels/BookmarksViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/BookmarksViewModel.cs index f7c25fed..a3019a88 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/BookmarksViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/BookmarksViewModel.cs @@ -265,7 +265,7 @@ namespace AideDeJeu.ViewModels public async Task> ToItems(string md) { - var item = Store.ToItem(null, md); + var item = Store.ToItem(null, md, null); //if(item is Items) //{ var items = item; // as Items; diff --git a/AideDeJeu/AideDeJeu/ViewModels/StoreViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/StoreViewModel.cs index 3f1809d8..128980de 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/StoreViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/StoreViewModel.cs @@ -18,7 +18,7 @@ namespace AideDeJeu.ViewModels { public class StoreViewModel : BaseViewModel { - public Item ToItem(string source, string md) + public Item ToItem(string source, string md, Dictionary allItems) { var pipeline = new MarkdownPipelineBuilder().UsePipeTables().Build(); var document = MarkdownParser.Parse(md, pipeline); @@ -35,7 +35,7 @@ namespace AideDeJeu.ViewModels { if (IsNewItem(block)) { - var item = ParseItem(source, ref enumerator); + var item = ParseItem(source, ref enumerator, allItems); return item; } } @@ -50,7 +50,7 @@ namespace AideDeJeu.ViewModels return null; } - public Item ParseItem(string source, ref ContainerBlock.Enumerator enumerator) + public Item ParseItem(string source, ref ContainerBlock.Enumerator enumerator, Dictionary allItems) { var currentItem = GetNewItem(enumerator.Current); @@ -65,16 +65,16 @@ namespace AideDeJeu.ViewModels { if (IsClosingItem(block)) { - currentItem.Id = GetNewAnchorId(source, currentItem.Name); - if (currentItem.Id != null) + currentItem.Id = GetNewAnchorId(source, currentItem.Name, allItems); + if (currentItem.Id != null && allItems != null) { - _AllItems[currentItem.Id] = currentItem; + allItems[currentItem.Id] = currentItem; } return currentItem; } else if (IsNewItem(block)) { - var subItem = ParseItem(source, ref enumerator); + var subItem = ParseItem(source, ref enumerator, allItems); var propertyName = subItem.GetType().Name; @@ -88,7 +88,7 @@ namespace AideDeJeu.ViewModels } else //if (currentItem is Items) { - if (currentItem.GetNewFilterViewModel() == null) + if (allItems != null && currentItem.GetNewFilterViewModel() == null) { var name = subItem.Name; var level = Math.Max(1, Math.Min(6, subItem.NameLevel)); @@ -123,8 +123,11 @@ namespace AideDeJeu.ViewModels enumerator.MoveNext(); } } - currentItem.Id = GetNewAnchorId(source, currentItem.Name); - _AllItems[currentItem.Id] = currentItem; + currentItem.Id = GetNewAnchorId(source, currentItem.Name, allItems); + if (allItems != null) + { + allItems[currentItem.Id] = currentItem; + } } return currentItem; @@ -273,7 +276,7 @@ namespace AideDeJeu.ViewModels - public string GetNewAnchorId(string source, string name) + public string GetNewAnchorId(string source, string name, Dictionary allItems) { if (name != null) { @@ -282,7 +285,7 @@ namespace AideDeJeu.ViewModels int index = 0; while (true) { - if (!_AllItems.ContainsKey(name)) + if (allItems == null || !allItems.ContainsKey(name)) { return id; } @@ -349,7 +352,7 @@ namespace AideDeJeu.ViewModels var md = await Tools.Helpers.GetResourceStringAsync(resourceName); if (md != null) { - var item = ToItem(source, md); + var item = ToItem(source, md, _AllItems); if (item != null) { var anchors = new Dictionary(); @@ -428,7 +431,7 @@ namespace AideDeJeu.ViewModels var md = await Tools.Helpers.GetResourceStringAsync($"AideDeJeu.Data.{source}.md"); if (md != null) { - var item = ToItem(source, md); + var item = ToItem(source, md, _AllItems); if (item != null) { var anchors = new Dictionary(); diff --git a/AideDeJeu/AideDeJeu/Views/ItemDetailPage.xaml.cs b/AideDeJeu/AideDeJeu/Views/ItemDetailPage.xaml.cs index 212cd66d..4f3c82ce 100644 --- a/AideDeJeu/AideDeJeu/Views/ItemDetailPage.xaml.cs +++ b/AideDeJeu/AideDeJeu/Views/ItemDetailPage.xaml.cs @@ -3,6 +3,8 @@ using AideDeJeu.ViewModels; using AideDeJeuLib; using SkiaSharp; using SkiaSharp.Views.Forms; +using System.Linq; +using System.Threading.Tasks; using Xamarin.Forms; using Xamarin.Forms.Xaml; @@ -42,6 +44,10 @@ namespace AideDeJeu.Views Markdown = AideDeJeu.Tools.Helpers.GetResourceString($"AideDeJeu.Data.index.md"), } ) { Title = "Bibliothèque" }; + + + //Task.Run(async () => await InitDBEngineAsync().ConfigureAwait(false)); + //var item = new Item //{ // Name = "", @@ -53,6 +59,16 @@ namespace AideDeJeu.Views //BindingContext = viewModel; } + async Task InitDBEngineAsync() + { + await Task.Delay(1000).ConfigureAwait(false); + using (var context = await StoreViewModel.GetDatabaseContextAsync().ConfigureAwait(false)) + { + var item = context.Items.FirstOrDefault(); + } + } + + void PaintHeaderBar(object sender, SKPaintSurfaceEventArgs args) { SKImageInfo info = args.Info; diff --git a/AideDeJeu/AideDeJeuUnitTest/UnitTest1.cs b/AideDeJeu/AideDeJeuUnitTest/UnitTest1.cs index f6b4e3e7..f5b1061a 100644 --- a/AideDeJeu/AideDeJeuUnitTest/UnitTest1.cs +++ b/AideDeJeu/AideDeJeuUnitTest/UnitTest1.cs @@ -1,6 +1,7 @@ using AideDeJeu.ViewModels; using AideDeJeuLib; using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Collections.Generic; using System.Threading.Tasks; namespace AideDeJeuUnitTest @@ -11,8 +12,9 @@ namespace AideDeJeuUnitTest [TestMethod] public async Task TestMethod1() { + var allItems = new Dictionary(); var store = new StoreViewModel(); - var item = store.ToItem(null, AideDeJeu.Tools.Helpers.GetResourceString($"AideDeJeu.Data.sandbox.md")); + var item = store.ToItem(null, AideDeJeu.Tools.Helpers.GetResourceString($"AideDeJeu.Data.sandbox.md"), allItems); var md = item.Markdown; var children = await item.GetChildrenAsync(); foreach(var iitem in children)