- Create Views/Dialogs/ProfileManagementDialog.xaml (modal Window with Name/TenantUrl/ClientId fields and TranslationSource bindings) - Create Views/Dialogs/ProfileManagementDialog.xaml.cs (DI constructor injection, LoadAsync on Loaded) - Add OpenProfileManagementDialog factory delegate to MainWindowViewModel - Wire ManageProfilesCommand to open dialog via factory, reload profiles after close - Register ProfileManagementDialog as Transient in DI (App.xaml.cs) - Inject IServiceProvider into MainWindow constructor for DI-resolved dialog factory
84 lines
3.0 KiB
C#
84 lines
3.0 KiB
C#
using System.IO;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using Serilog;
|
|
using SharepointToolbox.Infrastructure.Auth;
|
|
using SharepointToolbox.Infrastructure.Logging;
|
|
using SharepointToolbox.Services;
|
|
using SharepointToolbox.ViewModels;
|
|
using SharepointToolbox.ViewModels.Tabs;
|
|
using SharepointToolbox.Views.Dialogs;
|
|
using SharepointToolbox.Views.Tabs;
|
|
using System.Windows;
|
|
|
|
namespace SharepointToolbox;
|
|
|
|
public partial class App : Application
|
|
{
|
|
[STAThread]
|
|
public static void Main(string[] args)
|
|
{
|
|
using IHost host = Host.CreateDefaultBuilder(args)
|
|
.UseSerilog((ctx, cfg) => cfg
|
|
.WriteTo.File(
|
|
Path.Combine(
|
|
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
|
"SharepointToolbox", "logs", "app-.log"),
|
|
rollingInterval: RollingInterval.Day,
|
|
retainedFileCountLimit: 30))
|
|
.ConfigureServices(RegisterServices)
|
|
.Build();
|
|
|
|
host.Start();
|
|
App app = new();
|
|
app.InitializeComponent();
|
|
|
|
var mainWindow = host.Services.GetRequiredService<MainWindow>();
|
|
|
|
// Wire LogPanelSink now that we have the RichTextBox
|
|
Log.Logger = new LoggerConfiguration()
|
|
.WriteTo.File(
|
|
Path.Combine(
|
|
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
|
"SharepointToolbox", "logs", "app-.log"),
|
|
rollingInterval: RollingInterval.Day,
|
|
retainedFileCountLimit: 30)
|
|
.WriteTo.Sink(new LogPanelSink(mainWindow.GetLogPanel()))
|
|
.CreateLogger();
|
|
|
|
// Global exception handlers
|
|
app.DispatcherUnhandledException += (s, e) =>
|
|
{
|
|
Log.Fatal(e.Exception, "Unhandled UI exception");
|
|
MessageBox.Show(
|
|
$"A fatal error occurred:\n{e.Exception.Message}\n\nCheck log for details.",
|
|
"Fatal Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
e.Handled = true;
|
|
};
|
|
TaskScheduler.UnobservedTaskException += (s, e) =>
|
|
{
|
|
Log.Fatal(e.Exception, "Unobserved task exception");
|
|
e.SetObserved();
|
|
};
|
|
|
|
app.MainWindow = mainWindow;
|
|
app.MainWindow.Visibility = Visibility.Visible;
|
|
app.Run();
|
|
}
|
|
|
|
private static void RegisterServices(HostBuilderContext ctx, IServiceCollection services)
|
|
{
|
|
services.AddSingleton<MsalClientFactory>();
|
|
services.AddSingleton<SessionManager>();
|
|
services.AddSingleton<ProfileService>();
|
|
services.AddSingleton<SettingsService>();
|
|
services.AddSingleton<MainWindowViewModel>();
|
|
services.AddTransient<ProfileManagementViewModel>();
|
|
services.AddTransient<SettingsViewModel>();
|
|
services.AddTransient<ProfileManagementDialog>();
|
|
services.AddTransient<SettingsView>();
|
|
services.AddSingleton<MainWindow>();
|
|
}
|
|
}
|