78 lines
3.3 KiB
C#
78 lines
3.3 KiB
C#
using System.Net.Http;
|
|
using System.Windows;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using UtopiaCanteenSystem;
|
|
using UtopiaCanteenSystem.Data;
|
|
using UtopiaCanteenSystem.Services;
|
|
using UtopiaCanteenSystem.Services.Logging;
|
|
using UtopiaCanteen.Client.ViewModels;
|
|
using UtopiaCanteenSystem.ViewModels;
|
|
|
|
namespace UtopiaCanteen.Client;
|
|
|
|
public partial class App : Application
|
|
{
|
|
private static Mutex _mutex = null!;
|
|
|
|
protected override void OnStartup(StartupEventArgs e)
|
|
{
|
|
base.OnStartup(e);
|
|
|
|
DatabasePath.UseClientStorage();
|
|
FileLogger.ConfigureClient();
|
|
FileLogger.Info("ClientApp", "Application started.");
|
|
|
|
bool isNewInstance;
|
|
_mutex = new Mutex(true, "UtopiaCanteenClientMutex", out isNewInstance);
|
|
|
|
if (!isNewInstance)
|
|
{
|
|
MessageBox.Show("Another instance of the scanner client is already running.", "Warning",
|
|
MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
Current.Shutdown();
|
|
return;
|
|
}
|
|
|
|
var configService = new ClientConfigService();
|
|
FileLogger.Info("ClientApp", $"BackendBaseUrl = {configService.GetBackendBaseUrl()}");
|
|
FileLogger.Info(
|
|
"ClientApp",
|
|
$"Device ID resolved. MachineName={Environment.MachineName}, DeviceId={configService.GetDeviceId()}");
|
|
FileLogger.Info("ClientApp", $"Logs directory={LogPaths.ClientLogsDirectory}");
|
|
|
|
var httpClient = new HttpClient { Timeout = TimeSpan.FromMinutes(5) };
|
|
var backendApiClient = new CanteenBackendApiClient(httpClient, configService);
|
|
|
|
var dbFactory = new DbContextFactory();
|
|
using (var db = dbFactory.CreateDbContext())
|
|
db.EnsureDatabaseCreated();
|
|
|
|
var employeeLookupService = new EmployeeLookupService(dbFactory, configService);
|
|
var menuLookupService = new EmptyMenuLookupService();
|
|
var employeePhotoService = new NoOpEmployeePhotoService();
|
|
var adminAuditService = new AdminAuditService(dbFactory);
|
|
var session = new AppSession();
|
|
var authService = new AuthService("https://portal.utopiaindustries.pk/uind/rest/auth/user/");
|
|
|
|
NavigationService navigationService = null!;
|
|
navigationService = new NavigationService(
|
|
session,
|
|
() => new AdminLoginViewModel(authService, session, navigationService, configService, adminAuditService, employeeLookupService, backendApiClient),
|
|
() => new ScannerDashboardViewModel(backendApiClient, navigationService, session, configService, menuLookupService, employeePhotoService),
|
|
() => new MainDashboardViewModel(navigationService, backendApiClient, configService, session),
|
|
() => new AdminSettingsAuthViewModel(authService, session, navigationService, configService, employeeLookupService, backendApiClient),
|
|
() => new ClientSettingsViewModel(configService, navigationService, backendApiClient, session),
|
|
() => new MealSchedulesViewModel(new BackendApiMealScheduleService(backendApiClient), navigationService, configService));
|
|
|
|
var mainWindow = new MainWindow { DataContext = new MainViewModel(navigationService) };
|
|
mainWindow.WindowState = WindowState.Maximized;
|
|
mainWindow.Show();
|
|
}
|
|
|
|
protected override void OnExit(ExitEventArgs e)
|
|
{
|
|
_mutex?.ReleaseMutex();
|
|
base.OnExit(e);
|
|
}
|
|
}
|