forked from Federerer/Notifications.Wpf
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95d81ac
commit c8cd121
Showing
19 changed files
with
401 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,8 +72,6 @@ public override void OnApplyTemplate() | |
|
||
#endregion | ||
|
||
|
||
|
||
#endregion | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Windows; | ||
using System.Windows.Threading; | ||
using MathCore.Annotations; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Notification.Wpf.Sample | ||
{ | ||
partial class App | ||
{ | ||
/// <summary>Обработчик неперехваченных исключений</summary> | ||
private static void OnDispatcherUnhandledException([CanBeNull] object Sender, [NotNull] DispatcherUnhandledExceptionEventArgs E) | ||
{ | ||
#if DEBUG | ||
var exception_text = E.Exception.ToString(); | ||
if (E.Exception is System.Windows.ResourceReferenceKeyNotFoundException) | ||
return; | ||
|
||
var logger = Services.GetRequiredService<ILogger<App>>(); | ||
logger?.LogCritical($"Unhandled exception!\n{E.Exception}"); | ||
var res = MessageBox.Show(exception_text, "Unhandled exception!", MessageBoxButton.OKCancel, E.Handled ? MessageBoxImage.Warning : MessageBoxImage.Error); | ||
if (res == MessageBoxResult.OK) | ||
E.Handled = true; | ||
|
||
if (Debugger.IsAttached) | ||
{ | ||
if (E.Exception is ResourceReferenceKeyNotFoundException) | ||
{ | ||
E.Handled = true; | ||
MessageBox.Show(exception_text, "Unhandled exception!", MessageBoxButton.OK, E.Handled ? MessageBoxImage.Warning : MessageBoxImage.Error); | ||
} | ||
else | ||
Debugger.Break(); | ||
} | ||
else | ||
{ | ||
MessageBox.Show(exception_text, "Unhandled exception!", MessageBoxButton.OK, E.Handled ? MessageBoxImage.Warning : MessageBoxImage.Error); | ||
} | ||
#endif | ||
} | ||
|
||
/// <summary>Обработчик неперехваченных исключений</summary> | ||
private static void OnExceptionUnhandled([CanBeNull] object Sender, [NotNull] UnhandledExceptionEventArgs E) | ||
{ | ||
var log = Services.GetRequiredService<ILogger<App>>(); | ||
log?.LogError("Exception:\r\n{0}", E.ExceptionObject); | ||
var exception_text = E.ExceptionObject.ToString(); | ||
#if DEBUG | ||
if (Debugger.IsAttached) Debugger.Break(); | ||
else | ||
MessageBox.Show(E.ExceptionObject.ToString(), "Unhandled exception!", MessageBoxButton.OK, E.IsTerminating ? MessageBoxImage.Error : MessageBoxImage.Warning); | ||
#endif | ||
Trace.Fail("Необработанное исключение", exception_text); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,96 @@ | ||
using System.Windows; | ||
using System; | ||
using System.ComponentModel; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Windows; | ||
using MathCore.Annotations; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using Notification.Wpf.Sample.Logger; | ||
using Notification.Wpf.Sample.Properties; | ||
using Notification.Wpf.Sample.Service; | ||
|
||
namespace Notification.Wpf.Sample | ||
{ | ||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App : Application | ||
/// <summary>Основной класс программы сборки</summary> | ||
public sealed partial class App | ||
{ | ||
/// <summary>Признак работы в режиме дизайнера</summary> | ||
public static bool IsInDesignMode => LicenseManager.UsageMode == LicenseUsageMode.Designtime; | ||
|
||
[NotNull] internal static Settings Settings => Settings.Default; | ||
|
||
[CanBeNull] public static Window ActiveWindow => Current.Windows.Cast<Window>().FirstOrDefault(w => w.IsActive); | ||
|
||
[CanBeNull] public static Window FocusedWindow => Current.Windows.Cast<Window>().FirstOrDefault(w => w.IsFocused); | ||
|
||
[CanBeNull] public static Window CurrentWindow => FocusedWindow ?? ActiveWindow; | ||
|
||
public static IServiceProvider Services => Hosting.Services; | ||
private static IHost __Hosting; | ||
|
||
public static IHost Hosting => __Hosting ??= | ||
CreateHostBuilder(Environment.GetCommandLineArgs()) | ||
.Build(); | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) => Host | ||
.CreateDefaultBuilder(args) | ||
.ConfigureServices(ConfigureServices); | ||
|
||
private static void ConfigureServices(HostBuilderContext host, IServiceCollection services) | ||
{ | ||
|
||
services.AddLogging(sp => sp.SetMinimumLevel(LogLevel.Information)); | ||
services.AddSingleton<INotificationManager, NotificationManager>(); | ||
|
||
|
||
services.RegisterViewModels(); | ||
services.AddSingleton(Settings.Default); | ||
|
||
} | ||
|
||
private static void RegisterBstoRepositories(IServiceCollection services) | ||
{ | ||
//services.RegisterBstoRepositories(); | ||
//services.RegisterBstoOverloadedRepository(); | ||
//services.RegisterBstoServices(); | ||
//services.AddTransient<BstoContextInitializer>(); | ||
|
||
} | ||
|
||
|
||
protected override async void OnStartup(StartupEventArgs e) | ||
{ | ||
var host = Hosting; | ||
|
||
var logger = Services.GetRequiredService<ILoggerFactory>(); | ||
logger.AddLog4Net(); | ||
|
||
base.OnStartup(e); | ||
await host.StartAsync(); | ||
} | ||
|
||
protected override async void OnExit(ExitEventArgs e) | ||
{ | ||
base.OnExit(e); | ||
|
||
using var host = Hosting; | ||
await host.StopAsync(); | ||
} | ||
|
||
public App() | ||
{ | ||
if (!Debugger.IsAttached) | ||
{ | ||
Debugger.Launch(); | ||
Debugger.Break(); | ||
} | ||
|
||
AppDomain.CurrentDomain.UnhandledException += OnExceptionUnhandled; | ||
DispatcherUnhandledException += OnDispatcherUnhandledException; | ||
|
||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.