mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-31 01:42:02 +00:00
Core - Ensure application data folder exists
UI - Properly catch exceptions during exception display UI - Display fatal exceptions during Core creation, even before Core initialisation
This commit is contained in:
parent
0ccc1fed3d
commit
d009b11e97
@ -39,7 +39,14 @@ namespace Artemis.Core.Ninject
|
|||||||
.Configure(c => c.When(HasAccessToProtectedService).InSingletonScope());
|
.Configure(c => c.When(HasAccessToProtectedService).InSingletonScope());
|
||||||
});
|
});
|
||||||
|
|
||||||
Kernel.Bind<LiteRepository>().ToMethod(t => new LiteRepository(Constants.ConnectionString)).InSingletonScope();
|
Kernel.Bind<LiteRepository>().ToMethod(t =>
|
||||||
|
{
|
||||||
|
// Ensure the data folder exists
|
||||||
|
if (!Directory.Exists(Constants.DataFolder))
|
||||||
|
Directory.CreateDirectory(Constants.DataFolder);
|
||||||
|
|
||||||
|
return new LiteRepository(Constants.ConnectionString);
|
||||||
|
}).InSingletonScope();
|
||||||
|
|
||||||
// Bind all repositories as singletons
|
// Bind all repositories as singletons
|
||||||
Kernel.Bind(x =>
|
Kernel.Bind(x =>
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using Artemis.Core.Events;
|
using Artemis.Core.Events;
|
||||||
using Artemis.Core.Plugins.Abstract;
|
|
||||||
using Artemis.Core.Plugins.Models;
|
using Artemis.Core.Plugins.Models;
|
||||||
using Artemis.Core.RGB.NET;
|
using Artemis.Core.RGB.NET;
|
||||||
using Artemis.Core.Services.Interfaces;
|
using Artemis.Core.Services.Interfaces;
|
||||||
|
|||||||
@ -95,14 +95,18 @@ namespace Artemis.UI.Shared.Services.Dialog
|
|||||||
new ConstructorArgument("message", message),
|
new ConstructorArgument("message", message),
|
||||||
new ConstructorArgument("exception", exception)
|
new ConstructorArgument("exception", exception)
|
||||||
};
|
};
|
||||||
try
|
|
||||||
|
await Execute.OnUIThreadAsync(async () =>
|
||||||
{
|
{
|
||||||
await Execute.OnUIThreadAsync(async () => await ShowDialog<ExceptionDialogViewModel>(arguments));
|
try
|
||||||
}
|
{
|
||||||
catch (Exception)
|
await ShowDialog<ExceptionDialogViewModel>(arguments);
|
||||||
{
|
}
|
||||||
//ignored
|
catch (Exception)
|
||||||
}
|
{
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<object> ShowDialog(string identifier, DialogViewModelBase viewModel)
|
private async Task<object> ShowDialog(string identifier, DialogViewModelBase viewModel)
|
||||||
|
|||||||
@ -38,7 +38,15 @@ namespace Artemis.UI
|
|||||||
var viewManager = Kernel.Get<IViewManager>();
|
var viewManager = Kernel.Get<IViewManager>();
|
||||||
|
|
||||||
// Create the Artemis core
|
// Create the Artemis core
|
||||||
_core = Kernel.Get<ICoreService>();
|
try
|
||||||
|
{
|
||||||
|
_core = Kernel.Get<ICoreService>();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
HandleFatalException(e, logger);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
// Create and bind the root view, this is a tray icon so don't show it with the window manager
|
// Create and bind the root view, this is a tray icon so don't show it with the window manager
|
||||||
Execute.OnUIThread(() => viewManager.CreateAndBindViewForModelIfNecessary(RootViewModel));
|
Execute.OnUIThread(() => viewManager.CreateAndBindViewForModelIfNecessary(RootViewModel));
|
||||||
@ -58,19 +66,7 @@ namespace Artemis.UI
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
logger.Fatal(e, "Fatal exception during initialization, shutting down.");
|
HandleFatalException(e, logger);
|
||||||
|
|
||||||
// Can't use a pretty exception dialog here since the UI might not even be visible
|
|
||||||
Execute.OnUIThread(() =>
|
|
||||||
{
|
|
||||||
Kernel.Get<IWindowManager>().ShowMessageBox(e.Message + "\n\n Please refer the log file for more details.",
|
|
||||||
"Fatal exception during initialization",
|
|
||||||
MessageBoxButton.OK,
|
|
||||||
MessageBoxImage.Error
|
|
||||||
);
|
|
||||||
Environment.Exit(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -106,6 +102,22 @@ namespace Artemis.UI
|
|||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void HandleFatalException(Exception e, ILogger logger)
|
||||||
|
{
|
||||||
|
logger.Fatal(e, "Fatal exception during initialization, shutting down.");
|
||||||
|
|
||||||
|
// Can't use a pretty exception dialog here since the UI might not even be visible
|
||||||
|
Execute.OnUIThread(() =>
|
||||||
|
{
|
||||||
|
Kernel.Get<IWindowManager>().ShowMessageBox(e.Message + "\n\n Please refer the log file for more details.",
|
||||||
|
"Fatal exception during initialization",
|
||||||
|
MessageBoxButton.OK,
|
||||||
|
MessageBoxImage.Error
|
||||||
|
);
|
||||||
|
Environment.Exit(1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void ShowMainWindow(IWindowManager windowManager, SplashViewModel splashViewModel)
|
private void ShowMainWindow(IWindowManager windowManager, SplashViewModel splashViewModel)
|
||||||
{
|
{
|
||||||
Execute.OnUIThread(() =>
|
Execute.OnUIThread(() =>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user