Skip to content

Commit

Permalink
add RegisterPage
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-YousefiTelori committed Dec 22, 2023
1 parent baaa521 commit 00a04fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.IO;
using EasyMicroservices.UI.Cores.Interfaces;
using System;
using System.Collections.Concurrent;
using System.IO;
using System.Threading.Tasks;

namespace EasyMicroservices.UI.Cores;
Expand All @@ -11,6 +14,10 @@ public abstract class NavigationManagerBase
///
/// </summary>
public static NavigationManagerBase Current { get; set; }
/// <summary>
///
/// </summary>
protected ConcurrentDictionary<string, Type> Pages { get; set; } = new ConcurrentDictionary<string, Type>();

/// <summary>
///
Expand Down Expand Up @@ -62,4 +69,13 @@ public abstract class NavigationManagerBase
/// <param name="url"></param>
/// <returns></returns>
public abstract Task<bool> OpenBrowser(string url);
/// <summary>
///
/// </summary>
/// <param name="pageName"></param>
public void RegisterPage<T>(string pageName)
where T : IPage, new()
{
Pages.TryAdd(pageName, typeof(T));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public DefaultNavigationManager(INavigation navigation)
_navigation = navigation;
}

ConcurrentDictionary<string, IPage> Pages { get; set; } = new ConcurrentDictionary<string, IPage>();
public override Task PopAsync()
{
return _navigation.PopAsync();
Expand All @@ -24,8 +23,9 @@ public override Task<TResponseData> PushAsync<TResponseData>(string pageName, bo

public override async Task<TResponseData> PushDataAsync<TData, TResponseData>(TData data, string pageName, bool doClear = false)
{
if (!Pages.TryGetValue(pageName, out IPage findPage))
if (!Pages.TryGetValue(pageName, out Type pageTpe))
throw new Exception($"Page {pageName} not found, did you register it?");
var findPage = Activator.CreateInstance(pageTpe);
Page page = findPage as Page;
if (page == null)
throw new NotImplementedException($"Page {pageName} is not inherit Page!");
Expand Down

0 comments on commit 00a04fb

Please sign in to comment.