2024-07-14 11:24:10 +00:00
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
|
|
|
|
|
using Microsoft.UI.Xaml.Controls;
|
|
|
|
|
|
|
|
|
|
using RustTools.Contracts.Services;
|
|
|
|
|
using RustTools.ViewModels;
|
|
|
|
|
using RustTools.Views;
|
|
|
|
|
|
|
|
|
|
namespace RustTools.Services;
|
|
|
|
|
|
|
|
|
|
public class PageService : IPageService
|
|
|
|
|
{
|
|
|
|
|
private readonly Dictionary<string, Type> _pages = new();
|
|
|
|
|
|
|
|
|
|
public PageService()
|
|
|
|
|
{
|
2024-07-15 05:22:53 +00:00
|
|
|
|
//Configure<MainViewModel, MainPage>();
|
|
|
|
|
|
2024-07-14 11:24:10 +00:00
|
|
|
|
Configure<HomePageViewModel, HomePage>();
|
2024-08-03 11:49:28 +00:00
|
|
|
|
Configure<ConcernViewModel, ConcernPage>();
|
2024-07-15 05:22:53 +00:00
|
|
|
|
Configure<RankingViewModel, RankingPage>();
|
|
|
|
|
Configure<UserViewModel, UserPage>();
|
2024-08-07 02:31:13 +00:00
|
|
|
|
Configure<ModuleViewModel, ModulePage>();
|
2024-08-19 14:30:11 +00:00
|
|
|
|
Configure<CodeTableViewModel, CodeTablePage>();
|
|
|
|
|
Configure<CodeDataViewModel, CodeDataPage>();
|
2024-07-15 05:22:53 +00:00
|
|
|
|
|
2024-07-14 11:24:10 +00:00
|
|
|
|
Configure<SettingsViewModel, SettingsPage>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Type GetPageType(string key)
|
|
|
|
|
{
|
|
|
|
|
Type? pageType;
|
|
|
|
|
lock (_pages)
|
|
|
|
|
{
|
|
|
|
|
if (!_pages.TryGetValue(key, out pageType))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException($"Page not found: {key}. Did you forget to call PageService.Configure?");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pageType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Configure<VM, V>()
|
|
|
|
|
where VM : ObservableObject
|
|
|
|
|
where V : Page
|
|
|
|
|
{
|
|
|
|
|
lock (_pages)
|
|
|
|
|
{
|
|
|
|
|
var key = typeof(VM).FullName!;
|
|
|
|
|
if (_pages.ContainsKey(key))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException($"The key {key} is already configured in PageService");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var type = typeof(V);
|
|
|
|
|
if (_pages.ContainsValue(type))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException($"This type is already configured with key {_pages.First(p => p.Value == type).Key}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_pages.Add(key, type);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|