Skip to content

Commit

Permalink
fix constants for text content
Browse files Browse the repository at this point in the history
  • Loading branch information
Platonenkov committed Oct 25, 2021
1 parent 95d81ac commit c8cd121
Show file tree
Hide file tree
Showing 19 changed files with 401 additions and 47 deletions.
30 changes: 16 additions & 14 deletions Notification.Wpf/Base/NotificationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
using System.Windows;
using System.Windows.Media;
using System.Windows.Threading;

using Notification.Wpf.Base;
using Notification.Wpf.Base.Interfaces.Options;
using Notification.Wpf.Classes;
using Notification.Wpf.Constants;
using Notification.Wpf.Controls;

using Notifications.Wpf.Annotations;
using Notifications.Wpf.ViewModels;

Expand Down Expand Up @@ -44,7 +46,7 @@ public void Show(object content, string areaName = "", TimeSpan? expirationTime
if (!_dispatcher.CheckAccess())
{
_dispatcher.BeginInvoke(
new Action(() => Show(content, areaName, expirationTime, onClick, onClose, CloseOnClick,ShowXbtn)));
new Action(() => Show(content, areaName, expirationTime, onClick, onClose, CloseOnClick, ShowXbtn)));
return;
}

Expand Down Expand Up @@ -94,16 +96,16 @@ public void Show(string title, string message, NotificationType type = Notificat
Message = message,
Title = title,
CloseOnClick = CloseOnClick,
MessageTextSettings = MessageSettings,
TitleTextSettings = TitleSettings,
MessageTextSettings = MessageSettings ?? NotificationConstants.MessageSettings,
TitleTextSettings = TitleSettings ?? NotificationConstants.TitleSettings,
Icon = icon
};

ShowContent(content, expirationTime, areaName, onClick, onClose, CloseOnClick, ShowXbtn);
}
/// <inheritdoc />
public void Show(
string message, NotificationType type = NotificationType.None,
string message, NotificationType type = NotificationType.None,
string areaName = "", TimeSpan? expirationTime = null,
NotificationTextTrimType trim = NotificationTextTrimType.NoTrim, uint RowsCountWhenTrim = 1,
bool CloseOnClick = true,
Expand Down Expand Up @@ -135,11 +137,11 @@ public void Show(
RowsCount = RowsCountWhenTrim,
Message = message,
CloseOnClick = CloseOnClick,
MessageTextSettings = MessageSettings,
MessageTextSettings = MessageSettings ?? NotificationConstants.MessageSettings,
Icon = icon
};

ShowContent(content, expirationTime, areaName, null,null, CloseOnClick, ShowXbtn);
ShowContent(content, expirationTime, areaName, null, null, CloseOnClick, ShowXbtn);
}
/// <inheritdoc />
public void Show(
Expand All @@ -154,13 +156,13 @@ public void Show(
areaName,
expirationTime ?? TimeSpan.MaxValue,
NotificationTextTrimType.AttachIfMoreRows,
RowsCountWhenTrim, true, MessageSettings, ShowXbtn);
RowsCountWhenTrim, true, MessageSettings ?? NotificationConstants.MessageSettings, ShowXbtn);

/// <inheritdoc />
public void ShowCancellation(NotificationType type = NotificationType.Warning, string areaName = "",
TextContentSettings MessageSettings = null,
bool ShowXbtn = true)
=> Show(NotificationConstants.CancellationMessage, type, areaName, MessageSettings: MessageSettings, ShowXbtn: ShowXbtn);
=> Show(NotificationConstants.CancellationMessage, type, areaName, MessageSettings: MessageSettings ?? NotificationConstants.MessageSettings, ShowXbtn: ShowXbtn);

#endregion

Expand Down Expand Up @@ -190,7 +192,7 @@ public void ShowCancellation(NotificationType type = NotificationType.Warning, s
TrimText, DefaultRowsCount,
BaseWaitingMessage,
IsCollapse, TitleWhenCollapsed,
background, foreground, progressColor,
background, foreground, progressColor,
icon,
TitleSettings, MessageSettings,
ShowXbtn));
Expand All @@ -202,12 +204,12 @@ public void ShowCancellation(NotificationType type = NotificationType.Warning, s
BaseWaitingMessage,
IsCollapse, TitleWhenCollapsed,
background, foreground, progressColor, icon,
TitleSettings, MessageSettings);
TitleSettings ?? NotificationConstants.TitleSettings, MessageSettings ?? NotificationConstants.MessageSettings);

if (Title != null)
model.Title = Title;

ShowContent(model, areaName: areaName, ShowXbtn:ShowXbtn);
ShowContent(model, areaName: areaName, ShowXbtn: ShowXbtn);
return model.NotifierProgress;
}
/// <inheritdoc />
Expand Down Expand Up @@ -244,14 +246,14 @@ public void ShowCancellation(NotificationType type = NotificationType.Warning, s
TitleWhenCollapsed,
progressColor);

ShowContent(model, areaName: areaName,ShowXbtn:ShowXbtn);
ShowContent(model, areaName: areaName, ShowXbtn: ShowXbtn);
return model.NotifierProgress;
}

#endregion

#region Buttons

/// <inheritdoc />
public void ShowFilePopUpMessage(
string FilePath, bool ShowFile = true, bool ShowDirectory = true,
Expand Down Expand Up @@ -371,7 +373,7 @@ static void ShowContent(object content, TimeSpan? expirationTime = null, string
area.Show(progress, ShowXbtn);
break;
default:
area.Show(content, (TimeSpan)expirationTime, onClick, onClose, CloseOnClick,ShowXbtn);
area.Show(content, (TimeSpan)expirationTime, onClick, onClose, CloseOnClick, ShowXbtn);
break;
}
}
Expand Down
6 changes: 4 additions & 2 deletions Notification.Wpf/Base/Options/CustomizedOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public class CustomizedOptions : ICustomizedOptions
FontWeight = FontWeights.Bold,
TextAlignment = NotificationConstants.TitleTextAlignment,
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalTextAlignment = VerticalAlignment.Stretch
VerticalTextAlignment = VerticalAlignment.Stretch,
Opacity = 1
};
/// <inheritdoc />
public TextContentSettings MessageTextSettings { get; set; } = new()
Expand All @@ -44,7 +45,8 @@ public class CustomizedOptions : ICustomizedOptions
FontWeight = FontWeights.Normal,
TextAlignment = NotificationConstants.MessageTextAlignment,
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalTextAlignment = VerticalAlignment.Stretch
VerticalTextAlignment = VerticalAlignment.Stretch,
Opacity = 0.8
};


Expand Down
24 changes: 24 additions & 0 deletions Notification.Wpf/Constants/NotificationConstants.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Windows;
using System.Windows.Media;
using Notification.Wpf.Base;
using Notification.Wpf.Controls;

// ReSharper disable FieldCanBeMadeReadOnly.Global
Expand Down Expand Up @@ -80,6 +81,29 @@ public class NotificationConstants
public static TextAlignment TitleTextAlignment { get; set; } = TextAlignment.Left;
/// <summary> Default Message text alignment </summary>
public static TextAlignment MessageTextAlignment { get; set; } = TextAlignment.Left;

public static TextContentSettings TitleSettings => new ()
{
FontFamily = new FontFamily(FontName),
FontSize = TitleSize,
FontStyle = FontStyles.Normal,
FontWeight = FontWeights.Bold,
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalTextAlignment = VerticalAlignment.Stretch,
Opacity = 1,
TextAlignment = TextAlignment.Left
};
public static TextContentSettings MessageSettings => new ()
{
FontFamily = new FontFamily(FontName),
FontSize = TitleSize,
FontStyle = FontStyles.Normal,
FontWeight = FontWeights.Normal,
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalTextAlignment = VerticalAlignment.Stretch,
Opacity = 0.8,
TextAlignment = TextAlignment.Left
};
#endregion

#region Progress
Expand Down
2 changes: 0 additions & 2 deletions Notification.Wpf/Controls/Notifications/Notification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ public override void OnApplyTemplate()

#endregion



#endregion


Expand Down
2 changes: 1 addition & 1 deletion Notification.Wpf/Notification.Wpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net5.0-windows;netcoreapp3.1-windows;net4.6-windows;net4.6.1-windows;net4.7-windows;net4.8-windows</TargetFrameworks>
<UseWPF>true</UseWPF>
<LangVersion>latest</LangVersion>
<Version>5.7.1.0</Version>
<Version>5.7.1.1</Version>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>Notifications.Wpf.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
Expand Down
58 changes: 58 additions & 0 deletions Notifications.Wpf.Sample/App.Exceptions.cs
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);
}
}
}
2 changes: 2 additions & 0 deletions Notifications.Wpf.Sample/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:controls="clr-namespace:Notification.Wpf.Controls;assembly=Notification.Wpf"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:sample="clr-namespace:Notification.Wpf.Sample"
xmlns:service="clr-namespace:Notification.Wpf.Sample.Service"
ShutdownMode="OnMainWindowClose"
StartupUri="Views\SampleWindow.xaml">
<Application.Resources>
Expand All @@ -13,6 +14,7 @@
</ResourceDictionary>

</ResourceDictionary.MergedDictionaries>
<service:ServiceLocator x:Key="Locator"/>

<sample:CustomTemplateSelector x:Key="CustomTemplateSelector" />

Expand Down
95 changes: 90 additions & 5 deletions Notifications.Wpf.Sample/App.xaml.cs
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;

}

}
}
5 changes: 0 additions & 5 deletions Notifications.Wpf.Sample/Helpers/PositionConverter.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;
Expand Down Expand Up @@ -63,5 +59,4 @@ protected override object Convert(object v, Type t, object p, CultureInfo c)
protected override object ConvertBack(object v, Type t, object p, CultureInfo c) => throw new NotSupportedException();

}

}
Loading

0 comments on commit c8cd121

Please sign in to comment.