1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2026-05-15 09:00:28 +00:00

Liens améliorés

This commit is contained in:
Yan Maniez 2018-07-18 13:18:11 +02:00
parent 958e9332a6
commit 43d536c213
5 changed files with 77 additions and 45 deletions

View file

@ -28,10 +28,14 @@ namespace AideDeJeu.Tools
var assembly = typeof(Helpers).GetTypeInfo().Assembly;
using (var stream = assembly.GetManifestResourceStream(resourceName))
{
using (var sr = new StreamReader(stream))
if (stream != null)
{
return await sr.ReadToEndAsync();
using (var sr = new StreamReader(stream))
{
return await sr.ReadToEndAsync();
}
}
return null;
}
}

View file

@ -18,24 +18,32 @@ namespace AideDeJeu.ViewModels
set => SetProperty(ref _isLoading, value);
}
private Dictionary<string, Items> _AllItems = new Dictionary<string, Items>();
public async Task<Items> GetAllItemsAsync(string source)
private Dictionary<string, Item> _AllItems = new Dictionary<string, Item>();
public async Task<Item> GetItemFromDataAsync(string source)
{
if (!_AllItems.ContainsKey(source))
{
//var md = await Tools.Helpers.GetStringFromUrl($"https://raw.githubusercontent.com/Nioux/AideDeJeu/master/Data/{source}.md");
var md = await Tools.Helpers.GetResourceStringAsync($"AideDeJeu.Data.{source}.md");
_AllItems[source] = Tools.MarkdownExtensions.ToItem(md) as Items;
//return Tools.MarkdownExtensions.ToItem(md);
if (md != null)
{
_AllItems[source] = Tools.MarkdownExtensions.ToItem(md);
}
else
{
return null;
}
}
return _AllItems[source];
}
public async Task<ItemsViewModel> GetItemsViewModelAsync(string source)
{
var itemsViewModel = new ItemsViewModel();
itemsViewModel.AllItems = await GetAllItemsAsync(source);
return itemsViewModel;
}
//public async Task<ItemsViewModel> GetItemsViewModelAsync(string source)
//{
// var itemsViewModel = new ItemsViewModel();
// itemsViewModel.AllItems = await GetAllItemsAsync(source);
// return itemsViewModel;
//}
public Command LoadItemsCommand { get; private set; }
public Command AboutCommand { get; private set; }
@ -51,27 +59,39 @@ namespace AideDeJeu.ViewModels
{
if (s != null)
{
if (s.Contains("#"))
var regex = new Regex("/(?<file>.*)\\.md(#(?<anchor>.*))?");
var match = regex.Match(s);
var file = match.Groups["file"].Value;
var anchor = match.Groups["anchor"].Value;
var item = await GetItemFromDataAsync(file);
if (item != null)
{
var regex = new Regex("/(?<file>.*)\\.md#(?<anchor>.*)");
var match = regex.Match(s);
var file = match.Groups["file"].Value;
var anchor = match.Groups["anchor"].Value;
var items = await GetAllItemsAsync(file);
var item = items.Where(i => Tools.Helpers.IdFromName(i.Name) == anchor).FirstOrDefault();
if (item != null)
if (item is Items)
{
var items = item as Items;
if (!string.IsNullOrEmpty(anchor))
{
var subitem = items.Where(i => Tools.Helpers.IdFromName(i.Name) == anchor).FirstOrDefault();
if (subitem != null)
{
await Navigator.GotoItemDetailPageAsync(subitem);
}
}
else
{
var itemsViewModel = new ItemsViewModel() { AllItems = items };
itemsViewModel.LoadItemsCommand.Execute(null);
await Navigator.GotoItemsPageAsync(itemsViewModel);
}
}
else
{
await Navigator.GotoItemDetailPageAsync(item);
}
}
else
{
var regex = new Regex("/(?<file>.*)\\.md");
var match = regex.Match(s);
var file = match.Groups["file"].Value;
var items = await GetItemsViewModelAsync(file);
items.LoadItemsCommand.Execute(null);
await Navigator.GotoItemsPageAsync(items);
await App.Current.MainPage.DisplayAlert("Lien invalide", s, "OK");
}
}
}