Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic libraries #153

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions NToastNotify.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29009.5
# Visual Studio Version 17
VisualStudioVersion = 17.1.31911.260
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NToastNotify", "src\NToastNotify.csproj", "{70FC6753-E13C-4FF0-8FC1-914B9478A11F}"
EndProject
Expand All @@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Toastr", "samples\Toastr\To
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Noty", "samples\Noty\Noty.csproj", "{672B06FE-A2B8-49AF-9424-C4B942E54E8F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GenericDevExtreme", "samples\GenericDevExtreme\GenericDevExtreme.csproj", "{FB260842-43D1-46B6-B921-8A6C436BC526}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -71,13 +73,26 @@ Global
{672B06FE-A2B8-49AF-9424-C4B942E54E8F}.Release|x64.Build.0 = Release|Any CPU
{672B06FE-A2B8-49AF-9424-C4B942E54E8F}.Release|x86.ActiveCfg = Release|Any CPU
{672B06FE-A2B8-49AF-9424-C4B942E54E8F}.Release|x86.Build.0 = Release|Any CPU
{FB260842-43D1-46B6-B921-8A6C436BC526}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FB260842-43D1-46B6-B921-8A6C436BC526}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB260842-43D1-46B6-B921-8A6C436BC526}.Debug|x64.ActiveCfg = Debug|Any CPU
{FB260842-43D1-46B6-B921-8A6C436BC526}.Debug|x64.Build.0 = Debug|Any CPU
{FB260842-43D1-46B6-B921-8A6C436BC526}.Debug|x86.ActiveCfg = Debug|Any CPU
{FB260842-43D1-46B6-B921-8A6C436BC526}.Debug|x86.Build.0 = Debug|Any CPU
{FB260842-43D1-46B6-B921-8A6C436BC526}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB260842-43D1-46B6-B921-8A6C436BC526}.Release|Any CPU.Build.0 = Release|Any CPU
{FB260842-43D1-46B6-B921-8A6C436BC526}.Release|x64.ActiveCfg = Release|Any CPU
{FB260842-43D1-46B6-B921-8A6C436BC526}.Release|x64.Build.0 = Release|Any CPU
{FB260842-43D1-46B6-B921-8A6C436BC526}.Release|x86.ActiveCfg = Release|Any CPU
{FB260842-43D1-46B6-B921-8A6C436BC526}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{2325625E-C8BC-44DF-88FB-DF4FA0E41765} = {02286F62-91A5-4704-ABA3-F46D1B445717}
{672B06FE-A2B8-49AF-9424-C4B942E54E8F} = {02286F62-91A5-4704-ABA3-F46D1B445717}
{FB260842-43D1-46B6-B921-8A6C436BC526} = {02286F62-91A5-4704-ABA3-F46D1B445717}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D4720901-6BAC-48CE-A03E-85759AC6B66E}
Expand Down
12 changes: 12 additions & 0 deletions samples/GenericDevExtreme/DevExtremeToastOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using NToastNotify;
using NToastNotify.Helpers;

namespace GenericDevExtreme
{
public class DevExtremeToastOptions : GenericOptions
{
public int DisplayTime { get; set; }

public override string Json => this.ToJson();
}
}
19 changes: 19 additions & 0 deletions samples/GenericDevExtreme/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["GenericDevExtreme.csproj", "."]
RUN dotnet restore "GenericDevExtreme.csproj"
COPY . .
RUN dotnet build "GenericDevExtreme.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "GenericDevExtreme.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "GenericDevExtreme.dll"]
19 changes: 19 additions & 0 deletions samples/GenericDevExtreme/GenericDevExtreme.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<LangVersion>latest</LangVersion>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NToastNotify" Version="7.0.0" />
</ItemGroup>

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

</Project>
6 changes: 6 additions & 0 deletions samples/GenericDevExtreme/Pages/About.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@page
@model AboutModel
@{
ViewData["Title"] = "Privacy Policy";
}
<h2>Should simply be redirected to /privacy</h2>
21 changes: 21 additions & 0 deletions samples/GenericDevExtreme/Pages/About.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using NToastNotify;

namespace GenericDevExtreme.Pages
{
public class AboutModel : PageModel
{
private readonly IToastNotification _toastNotification;

public AboutModel(IToastNotification toastNotification)
{
_toastNotification = toastNotification;
}
public IActionResult OnGet()
{
_toastNotification.AddWarningToastMessage("This message is from About page before being redirected to Privacy page");
return RedirectToPage("/Privacy");
}
}
}
3 changes: 3 additions & 0 deletions samples/GenericDevExtreme/Pages/Ajax.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@page
@model AjaxModel

24 changes: 24 additions & 0 deletions samples/GenericDevExtreme/Pages/Ajax.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using NToastNotify;

namespace GenericDevExtreme.Pages
{
public class AjaxModel : PageModel
{
private readonly IToastNotification _toastNotification;

public AjaxModel(IToastNotification toastNotification)
{
_toastNotification = toastNotification;
}
public JsonResult OnGet(string type)
{
System.Threading.Thread.Sleep(2000);
_toastNotification.AddSuccessToastMessage($"This toast is shown on Ajax request. Type: {type} " + DateTime.Now.ToLongTimeString());
return new JsonResult(new { ok = true });
}

}
}
26 changes: 26 additions & 0 deletions samples/GenericDevExtreme/Pages/Error.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@page
@model ErrorModel
@{
ViewData["Title"] = "Error";
}

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
23 changes: 23 additions & 0 deletions samples/GenericDevExtreme/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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;

namespace GenericDevExtreme.Pages
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public class ErrorModel : PageModel
{
public string? RequestId { get; set; }

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

public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
}
19 changes: 19 additions & 0 deletions samples/GenericDevExtreme/Pages/FormPost.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@page
@model GenericDevExtreme.Pages.FormPostModel
@{
ViewData["Title"] = "FormPost";
Layout = "~/Pages/Shared/_Layout.cshtml";
}

<h1>FormPost</h1>
<form method="post">
<div>
<label>Input</label>
<input name="input" type="text" />
</div>
<div>
<label>Redirect after post</label>
<input name="redirect" type="checkbox" />
</div>
<button type="submit">Submit</button>
</form>
32 changes: 32 additions & 0 deletions samples/GenericDevExtreme/Pages/FormPost.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using NToastNotify;
using NToastNotify.Helpers;

namespace GenericDevExtreme.Pages
{
public class FormPostModel : PageModel
{
private readonly IToastNotification _toastNotification;

public FormPostModel(IToastNotification toastNotification)
{
_toastNotification = toastNotification;
}
public void OnGet()
{

}
public IActionResult OnPost(string input, string redirect)
{
_toastNotification.AddSuccessToastMessage("Input received: " + input, new DevExtremeToastOptions { DisplayTime = 3000 });
if (redirect == "on")
return RedirectToPage("/Privacy");
return Page();
}
}
}
10 changes: 10 additions & 0 deletions samples/GenericDevExtreme/Pages/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}

<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>
44 changes: 44 additions & 0 deletions samples/GenericDevExtreme/Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Reflection;
using Microsoft.AspNetCore.Mvc.RazorPages;
using NToastNotify;

namespace GenericDevExtreme.Pages
{
public class IndexModel : PageModel
{
private readonly string? _version;
private readonly IToastNotification _toastNotification;
//private readonly ToastrNotification _toastNotification;

public IndexModel(IToastNotification toastNotification)
{
_version = Assembly.GetAssembly(typeof(IToastNotification))?.GetName().Version?.ToString() ?? throw new Exception("Version not found");
_toastNotification = toastNotification;
//_toastNotification = toastNotification as ToastrNotification;
}
public void OnGet()
{
//Success
_toastNotification.AddSuccessToastMessage("Same for success message. Version: " + _version, new DevExtremeToastOptions()
{
DisplayTime = 6000
});
// Success with default options (taking into account the overwritten defaults when initializing in Startup.cs)
_toastNotification.AddSuccessToastMessage();

//Info
_toastNotification.AddInfoToastMessage();
_toastNotification.AddInfoToastMessage("This is an info toast. Version: " + _version, new DevExtremeToastOptions()
{
DisplayTime = 8000
});

//Warning
_toastNotification.AddWarningToastMessage();

//Error
_toastNotification.AddErrorToastMessage("Custom Error Message. Version: " + _version, new DevExtremeToastOptions() { DisplayTime = 3000 });
}
}
}
37 changes: 37 additions & 0 deletions samples/GenericDevExtreme/Pages/Privacy.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@page
@model PrivacyModel
@{
ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>

<p>Use this page to detail your site's privacy policy.</p>

<h4 id="message">AJAX Messages</h4>

<script>
window.addEventListener('load', function () {
setTimeout(function () {
$('#message').text('Making a native fetch request and show notification.');
fetch('/Ajax?type=fetch').then(function (response) {
var messages = nToastNotify.getMessagesFromFetchResponse(response);
nToastNotify.showMessages(messages);
$('#message').text('Making an XMLHTTPRequest (AJAX) and show notification.');
$.ajax({
url: '/Ajax?type=xmlhttp',
}).then(function () {
$('#message').text('Again : Making an XMLHTTPRequest (AJAX) and show notification.');
$.ajax({
url: '/Ajax?type=xmlhttp'
}).then(function () {
$('#message').text('Again : native fetch request and show notification.');
fetch('/Ajax?type=fetch').then(function (response) {
var messages = nToastNotify.getMessagesFromFetchResponse(response);
nToastNotify.showMessages(messages);
});
})
});
});
}, 2000)
})
</script>
24 changes: 24 additions & 0 deletions samples/GenericDevExtreme/Pages/Privacy.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using NToastNotify;

namespace GenericDevExtreme.Pages
{
public class PrivacyModel : PageModel
{
private readonly IToastNotification _toastNotification;

public PrivacyModel(IToastNotification toastNotification)
{
_toastNotification = toastNotification;
}
public void OnGet()
{
_toastNotification.AddInfoToastMessage("Privacy is important");
}
}
}
Loading