Skip to content

Commit

Permalink
v7
Browse files Browse the repository at this point in the history
  • Loading branch information
nabinked committed Jul 3, 2020
1 parent 5dde93e commit f7dd798
Show file tree
Hide file tree
Showing 37 changed files with 143 additions and 212 deletions.
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- task: UseDotNet@2
inputs:
packageType: "sdk"
version: "3.1.200"
version: "3.1.301"

- task: DotNetCoreCLI@2
displayName: "Restore"
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "3.1.200"
"version": "3.1.301"
}
}
7 changes: 5 additions & 2 deletions samples/Noty/Noty.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeFrameworkName>Microsoft.AspNetCore.App</RuntimeFrameworkName>
</PropertyGroup>
Expand All @@ -9,8 +11,9 @@
<PackageReference Include="NToastNotify" Version="6.1.3" />
</ItemGroup>

<!--<ItemGroup>
<!-- <ItemGroup>
// Comment out before pushing changes
<ProjectReference Include="..\..\src\NToastNotify.csproj" />
</ItemGroup>-->
</ItemGroup> -->

</Project>
6 changes: 1 addition & 5 deletions samples/Noty/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

Expand All @@ -11,7 +7,7 @@ namespace Noty.Pages
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public class ErrorModel : PageModel
{
public string RequestId { get; set; }
public string? RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

Expand Down
2 changes: 1 addition & 1 deletion samples/Toastr/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Toastr.Pages
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public class ErrorModel : PageModel
{
public string RequestId { get; set; }
public string? RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

Expand Down
7 changes: 5 additions & 2 deletions samples/Toastr/Toastr.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeFrameworkName>Microsoft.AspNetCore.App</RuntimeFrameworkName>
</PropertyGroup>
Expand All @@ -9,8 +11,9 @@
<PackageReference Include="NToastNotify" Version="6.1.3" />
</ItemGroup>

<!--<ItemGroup>
<!-- <ItemGroup>
// Comment out before pushing changes
<ProjectReference Include="..\..\src\NToastNotify.csproj" />
</ItemGroup>-->
</ItemGroup> -->

</Project>
8 changes: 4 additions & 4 deletions src/Attributes/ConcreteTypeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@

namespace NToastNotify.Attributes
{
internal class ConcreteTypeConverter<TConcrete> : JsonConverter
internal class ConcreteTypeConverter<TConcrete> : JsonConverter where TConcrete : new()
{
public override bool CanConvert(Type objectType)
{
//assume we can convert to anything for now
return true;
}

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
{
//explicitly specify the concrete type we want to create
return serializer.Deserialize<TConcrete>(reader);
return serializer.Deserialize<TConcrete>(reader) ?? new TConcrete();
}

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
{
//use the default serialization - it works fine
serializer.Serialize(writer, value);
Expand Down
19 changes: 9 additions & 10 deletions src/Components/NToastNotifyViewComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using NToastNotify.Components;
using NToastNotify.Helpers;

// ReSharper disable once CheckNamespace
namespace NToastNotify
{
[ViewComponent(Name = "NToastNotify")]
Expand All @@ -21,15 +20,15 @@ public NToastNotifyViewComponent(IToastNotification toastNotification, ILibrary

public IViewComponentResult Invoke()
{
var model = new ToastNotificationViewModel
{
ToastMessagesJson = JsonOrUndefined(_toastNotification.ReadAllMessages()),
ResponseHeaderKey = Constants.ResponseHeaderKey,
RequestHeaderKey = Constants.RequestHeaderKey,
LibraryDetails = _library,
DisableAjaxToasts = _nToastNotifyOption.DisableAjaxToasts,
LibraryJsPath = $"~/_content/{this.GetType().Assembly.GetName().Name}/{_library.VarName}.js?something"
};
var assemblyName = GetType().Assembly.GetName();
var model = new ToastNotificationViewModel(
toastMessagesJson: JsonOrUndefined(_toastNotification.ReadAllMessages()),
requestHeaderKey: Constants.RequestHeaderKey,
responseHeaderKey: Constants.ResponseHeaderKey,
libraryDetails: _library,
disableAjaxToasts: _nToastNotifyOption.DisableAjaxToasts,
libraryJsPath: $"~/_content/{assemblyName.Name}/{_library.VarName}.js?{assemblyName.Version}");

return View("Default", model);
}

Expand Down
19 changes: 12 additions & 7 deletions src/Components/ToastNotificationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,31 @@
{
public class ToastNotificationViewModel
{
public ToastNotificationViewModel(string toastMessagesJson, string requestHeaderKey, string responseHeaderKey, ILibrary libraryDetails, bool disableAjaxToasts, string libraryJsPath)
{
ToastMessagesJson = toastMessagesJson;
RequestHeaderKey = requestHeaderKey;
ResponseHeaderKey = responseHeaderKey;
LibraryDetails = libraryDetails;
DisableAjaxToasts = disableAjaxToasts;
LibraryJsPath = libraryJsPath;
}
/// <summary>
/// JSON string of arrays of message
/// </summary>
public string ToastMessagesJson { get; set; }
public string ToastMessagesJson { get; }
/// <summary>
/// Request header key used to show toast notification in AJAX calls
/// </summary>
public string RequestHeaderKey { get; set; }
public string RequestHeaderKey { get; }
/// <summary>
/// Response header key used to show toast notification in AJAX calls
/// </summary>
public string ResponseHeaderKey { get; set; }
public string ResponseHeaderKey { get; }
/// <summary>
/// Library details
/// </summary>
public ILibrary LibraryDetails { get; set; }
/// <summary>
/// This is used to get the hash of the javascript file using the last modified date. Used for cache busting.
/// </summary>
public string Hash { get; set; }

/// <summary>
/// If set to true, Ajax toasts will be disabled.
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/JsonSerialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class JsonSerialization

public static string ToJson(this object obj)
{
return obj != null ? JsonConvert.SerializeObject(obj, JsonSerializerSettings) : null;
return JsonConvert.SerializeObject(obj, JsonSerializerSettings);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Helpers/OptionMerger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public static T MergeWith<T>(this T primary, T secondary)
}
foreach (var pi in typeof(T).GetProperties())
{
var priValue = pi.GetGetMethod().Invoke(primary, null);
var secValue = pi.GetGetMethod().Invoke(secondary, null);
if (priValue == null)
var priValue = pi.GetGetMethod()?.Invoke(primary, null);
var secValue = pi.GetGetMethod()?.Invoke(secondary, null);
if (priValue is null)
{
pi.GetSetMethod()?.Invoke(primary, new[] { secValue });
}
Expand Down
12 changes: 6 additions & 6 deletions src/Helpers/OptionsHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ namespace NToastNotify.Helpers
{
internal class OptionsHelpers
{
public static T CastOptionTo<T>(LibraryOptions options) where T : LibraryOptions, new()
public static T CastOptionTo<T>(LibraryOptions? options) where T : LibraryOptions, new()
{
EnsureSameType<T>(options);
var opt = (options ?? new T()) as T;
var opt = options as T ?? new T();
return opt;
}
public static void EnsureSameType<T>(object obj) where T : new()
public static void EnsureSameType<T>(object? obj) where T : new()
{
if (obj != null)
{
Expand All @@ -21,17 +21,17 @@ public static void EnsureSameType<T>(object obj) where T : new()
}
}
}
public static NotyOptions PrepareOptionsNoty(LibraryOptions options, string message, NotificationTypesNoty type)
public static NotyOptions PrepareOptionsNoty(LibraryOptions? options, NotificationTypesNoty type)
{
var notyOptions = CastOptionTo<NotyOptions>(options);
notyOptions.Type = type;
return notyOptions;
}
public static ToastrOptions PrepareOptionsToastr(LibraryOptions toastrOptions, NotificationTypesToastr type, string defaultTitle)
public static ToastrOptions PrepareOptionsToastr(LibraryOptions? toastrOptions, NotificationTypesToastr type, string defaultTitle)
{
var options = CastOptionTo<ToastrOptions>(toastrOptions);
options.Type = type;
options.Title = options.Title ?? defaultTitle;
options.Title ??= defaultTitle;
return options;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static EmbeddedFileProvider GetEmbeddedFileProvider()
return new EmbeddedFileProvider(ThisAssembly, "NToastNotify");
}

public static ILibrary GetLibraryDetails<T>(NToastNotifyOption nToastNotifyOptions, LibraryOptions defaultOptions) where T : class, ILibrary, new()
public static ILibrary GetLibraryDetails<T>(NToastNotifyOption? nToastNotifyOptions, LibraryOptions? defaultOptions) where T : class, ILibrary, new()
{
var library = new T();
if (nToastNotifyOptions != null)
Expand Down
4 changes: 2 additions & 2 deletions src/ITempDataWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public interface ITempDataWrapper
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
T Get<T>(string key) where T : class
T? Get<T>(string key) where T : class
;
T Peek<T>(string key) where T : class
T? Peek<T>(string key) where T : class
;
void Add(string key, object value);
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/IToastMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
public interface IToastMessage
{
string Message { get; }
LibraryOptions Options { get; }
LibraryOptions? Options { get; }
}
}
10 changes: 5 additions & 5 deletions src/IToastNotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,39 @@ public interface IToastNotification
/// <param name="message">Messsage body</param>
/// <param name="title">Title of the message</param>
/// <param name="toastOptions">Custom option for the message being added. Please provide an instance of the relative options class for the js library that is being used which implements <see cref="LibraryOptions"/></param>
void AddSuccessToastMessage(string message = null, LibraryOptions toastOptions = null);
void AddSuccessToastMessage(string? message = null, LibraryOptions? toastOptions = null);

/// <summary>
/// Adds a toast message of type info"
/// </summary>
/// <param name="message">Messsage body</param>
/// <param name="title">Title of the message</param>
/// <param name="toastOptions">Custom option for the message being added. Please provide an instance of the relative options class for the js library that is being used which implements <see cref="LibraryOptions"/></param>
void AddInfoToastMessage(string message = null, LibraryOptions toastOptions = null);
void AddInfoToastMessage(string? message = null, LibraryOptions? toastOptions = null);

/// <summary>
/// Adds a toast message of type alert"
/// </summary>
/// <param name="message">Messsage body</param>
/// <param name="title">Title of the message</param>
/// <param name="toastOptions">Custom option for the message being added. Please provide an instance of the relative options class for the js library that is being used which implements <see cref="LibraryOptions"/></param>
void AddAlertToastMessage(string message = null, LibraryOptions toastOptions = null);
void AddAlertToastMessage(string? message = null, LibraryOptions? toastOptions = null);

/// <summary>
/// Adds a toast message of type warning"
/// </summary>
/// <param name="message">Messsage body</param>
/// <param name="title">Title of the message</param>
/// <param name="toastOptions">Custom option for the message being added. Please provide an instance of the relative options class for the js library that is being used which implements <see cref="LibraryOptions"/></param>
void AddWarningToastMessage(string message = null, LibraryOptions toastOptions = null);
void AddWarningToastMessage(string? message = null, LibraryOptions? toastOptions = null);

/// <summary>
/// Adds a toast message of type error
/// </summary>
/// <param name="message">Messsage body</param>
/// <param name="title">Title of the message</param>
/// <param name="toastOptions">Custom option for the message being added. Please provide an instance of the relative options class for the js library that is being used which implements <see cref="LibraryOptions"/></param>
void AddErrorToastMessage(string message = null, LibraryOptions toastOptions = null);
void AddErrorToastMessage(string? message = null, LibraryOptions? toastOptions = null);

/// <summary>
/// Gets the list of <see cref="IToastMessage"/> added so far.
Expand Down
2 changes: 1 addition & 1 deletion src/Libraries/ILibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public interface ILibrary
/// </summary>
string StyleHref { get; set; }

LibraryOptions Options { get; set; }
LibraryOptions? Options { get; set; }
}
}
22 changes: 0 additions & 22 deletions src/Libraries/Noty/INotyJsOptions.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Libraries/Noty/NotyLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ public class NotyLibrary : ILibrary
public string VarName { get; } = "noty";
public string ScriptSrc { get; set; } = "https://cdnjs.cloudflare.com/ajax/libs/noty/3.1.4/noty.min.js";
public string StyleHref { get; set; } = "https://cdnjs.cloudflare.com/ajax/libs/noty/3.1.4/noty.min.css";
public LibraryOptions Options { get; set; }
public LibraryOptions? Options { get; set; }
}
}
4 changes: 2 additions & 2 deletions src/Libraries/Noty/NotyMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace NToastNotify
{
public class NotyMessage : IToastMessage
{
public NotyMessage(string message, LibraryOptions options = null)
public NotyMessage(string message, LibraryOptions? options = null)
{
Message = message;
Options = options;
Expand All @@ -14,6 +14,6 @@ public NotyMessage(string message, LibraryOptions options = null)
public string Message { get; private set; }
[JsonProperty]
[JsonConverter(typeof(ConcreteTypeConverter<NotyOptions>))]
public LibraryOptions Options { get; private set; }
public LibraryOptions? Options { get; private set; }
}
}

0 comments on commit f7dd798

Please sign in to comment.