From 2b925a8ffadecb44f6a83c9c004c10674798cb19 Mon Sep 17 00:00:00 2001 From: alexhoang Date: Fri, 25 Oct 2024 04:53:49 +0000 Subject: [PATCH] feat/Log-Information (#1) Co-authored-by: drake.pham Co-authored-by: kwan.nguyen Reviewed-on: https://git.acaziasoft.com/alexhoang/pcut_uwp/pulls/1 --- PCUT/Http.Core/Constants/HttpConstants.cs | 1 + .../Handlers/AuthenticationHandler.cs | 5 +- PCUT/PCUT.Entities/Log.cs | 13 ++++ PCUT/PCUT/Converters/LogTimestampConverter.cs | 26 +++++++ PCUT/PCUT/PCUT.csproj | 9 +++ PCUT/PCUT/Pages/AdminCenterPage.xaml | 1 + PCUT/PCUT/Pages/AdminCenterPage.xaml.cs | 3 + PCUT/PCUT/Pages/Logs/LogInformationPage.xaml | 66 +++++++++++++++++ .../Pages/Logs/LogInformationPage.xaml.cs | 52 ++++++++++++++ PCUT/PCUT/ViewModels/LogViewModel.cs | 72 +++++++++++++++++++ 10 files changed, 245 insertions(+), 3 deletions(-) create mode 100644 PCUT/PCUT.Entities/Log.cs create mode 100644 PCUT/PCUT/Converters/LogTimestampConverter.cs create mode 100644 PCUT/PCUT/Pages/Logs/LogInformationPage.xaml create mode 100644 PCUT/PCUT/Pages/Logs/LogInformationPage.xaml.cs create mode 100644 PCUT/PCUT/ViewModels/LogViewModel.cs diff --git a/PCUT/Http.Core/Constants/HttpConstants.cs b/PCUT/Http.Core/Constants/HttpConstants.cs index da39201..27d3925 100644 --- a/PCUT/Http.Core/Constants/HttpConstants.cs +++ b/PCUT/Http.Core/Constants/HttpConstants.cs @@ -40,6 +40,7 @@ public const string Metadata = "api/metadata"; public const string MetadataById = "api/metadata/{0}"; + public const string Log = "api/logs"; } } } diff --git a/PCUT/Http.Core/Handlers/AuthenticationHandler.cs b/PCUT/Http.Core/Handlers/AuthenticationHandler.cs index e065fad..6dbd947 100644 --- a/PCUT/Http.Core/Handlers/AuthenticationHandler.cs +++ b/PCUT/Http.Core/Handlers/AuthenticationHandler.cs @@ -1,7 +1,6 @@ using Http.Core.Constants; using Http.Core.Contexts; using Http.Core.Extensions; -using Http.Core.Models; using System; using System.Net.Http; using System.Net.Http.Headers; @@ -31,13 +30,13 @@ namespace Http.Core.Handlers return false; var expiredTime = UserContext.Instance.ExpiredTime; - if (expiredTime != null || expiredTime - DateTime.UtcNow < _requiredRefreshTime) + if (expiredTime != null && expiredTime - DateTime.UtcNow < _requiredRefreshTime) { await _refreshSemaphore.WaitAsync(); bool refreshSuccess; { expiredTime = UserContext.Instance.ExpiredTime; - if (expiredTime != null || expiredTime - DateTime.UtcNow < _requiredRefreshTime) + if (expiredTime != null && expiredTime - DateTime.UtcNow < _requiredRefreshTime) refreshSuccess = await RefreshTokenAsync(); else refreshSuccess = true; // Some other thread already refreshed token diff --git a/PCUT/PCUT.Entities/Log.cs b/PCUT/PCUT.Entities/Log.cs new file mode 100644 index 0000000..b0446ac --- /dev/null +++ b/PCUT/PCUT.Entities/Log.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; +using System; + +namespace PCUT.Entities +{ + public class Log + { + [JsonProperty("datetime")] + public DateTime Timestamp { get; set; } + [JsonProperty("content")] + public string Content { get; set; } + } +} diff --git a/PCUT/PCUT/Converters/LogTimestampConverter.cs b/PCUT/PCUT/Converters/LogTimestampConverter.cs new file mode 100644 index 0000000..ae32870 --- /dev/null +++ b/PCUT/PCUT/Converters/LogTimestampConverter.cs @@ -0,0 +1,26 @@ +using System; +using Windows.UI.Xaml.Data; + +namespace PCUT.Converters +{ + internal class LogTimestampConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, string language) + { + switch (value) + { + case DateTime timeValue: + { + return $"[{timeValue.ToString("yyyy-MM-dd HH:mm:ss.fff K")}]"; + } + default: + return string.Empty; + } + } + + public object ConvertBack(object value, Type targetType, object parameter, string language) + { + throw new NotImplementedException(); + } + } +} diff --git a/PCUT/PCUT/PCUT.csproj b/PCUT/PCUT/PCUT.csproj index fb7e32a..b554cb5 100644 --- a/PCUT/PCUT/PCUT.csproj +++ b/PCUT/PCUT/PCUT.csproj @@ -137,6 +137,7 @@ + @@ -194,6 +195,9 @@ CategoriesViewPage.xaml + + LogInformationPage.xaml + UserGuidePage.xaml @@ -243,6 +247,7 @@ UserListPage.xaml + @@ -361,6 +366,10 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + MSBuild:Compile Designer diff --git a/PCUT/PCUT/Pages/AdminCenterPage.xaml b/PCUT/PCUT/Pages/AdminCenterPage.xaml index 55ea1c2..7fa2abf 100644 --- a/PCUT/PCUT/Pages/AdminCenterPage.xaml +++ b/PCUT/PCUT/Pages/AdminCenterPage.xaml @@ -29,6 +29,7 @@ + diff --git a/PCUT/PCUT/Pages/AdminCenterPage.xaml.cs b/PCUT/PCUT/Pages/AdminCenterPage.xaml.cs index 5318e06..0e7c6c2 100644 --- a/PCUT/PCUT/Pages/AdminCenterPage.xaml.cs +++ b/PCUT/PCUT/Pages/AdminCenterPage.xaml.cs @@ -53,6 +53,9 @@ namespace PCUT.Pages case "Users": ContentFrame.Navigate(typeof(UserListPage)); break; + case "Logs": + ContentFrame.Navigate(typeof(LogInformationPage)); + break; } sender.IsPaneOpen = true; } diff --git a/PCUT/PCUT/Pages/Logs/LogInformationPage.xaml b/PCUT/PCUT/Pages/Logs/LogInformationPage.xaml new file mode 100644 index 0000000..88d8273 --- /dev/null +++ b/PCUT/PCUT/Pages/Logs/LogInformationPage.xaml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + +