From 535451e59b41598ca9a846301c3b2cf39e446831 Mon Sep 17 00:00:00 2001 From: "drake.pham" Date: Fri, 25 Oct 2024 09:08:01 +0700 Subject: [PATCH 1/2] Add loginformation page --- PCUT/PCUT/PCUT.csproj | 7 +++++++ PCUT/PCUT/Pages/AdminCenterPage.xaml | 1 + PCUT/PCUT/Pages/AdminCenterPage.xaml.cs | 6 +++++- PCUT/PCUT/Pages/Logs/LogInformationPage.xaml | 14 ++++++++++++++ PCUT/PCUT/Pages/Logs/LogInformationPage.xaml.cs | 17 +++++++++++++++++ 5 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 PCUT/PCUT/Pages/Logs/LogInformationPage.xaml create mode 100644 PCUT/PCUT/Pages/Logs/LogInformationPage.xaml.cs diff --git a/PCUT/PCUT/PCUT.csproj b/PCUT/PCUT/PCUT.csproj index fb7e32a..b784ee3 100644 --- a/PCUT/PCUT/PCUT.csproj +++ b/PCUT/PCUT/PCUT.csproj @@ -194,6 +194,9 @@ CategoriesViewPage.xaml + + LogInformationPage.xaml + UserGuidePage.xaml @@ -361,6 +364,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..3c908ce 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..47ecd00 100644 --- a/PCUT/PCUT/Pages/AdminCenterPage.xaml.cs +++ b/PCUT/PCUT/Pages/AdminCenterPage.xaml.cs @@ -1,4 +1,5 @@ -using System; +using PCUT.Pages.Logs; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -53,6 +54,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..6692088 --- /dev/null +++ b/PCUT/PCUT/Pages/Logs/LogInformationPage.xaml @@ -0,0 +1,14 @@ + + + + + + diff --git a/PCUT/PCUT/Pages/Logs/LogInformationPage.xaml.cs b/PCUT/PCUT/Pages/Logs/LogInformationPage.xaml.cs new file mode 100644 index 0000000..9da01ed --- /dev/null +++ b/PCUT/PCUT/Pages/Logs/LogInformationPage.xaml.cs @@ -0,0 +1,17 @@ +using Windows.UI.Xaml.Controls; + +// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 + +namespace PCUT.Pages.Logs +{ + /// + /// An empty page that can be used on its own or navigated to within a Frame. + /// + public sealed partial class LogInformationPage : Page + { + public LogInformationPage() + { + this.InitializeComponent(); + } + } +} -- 2.40.1 From d4d6cbd94d10bfc94a4b2055a8736624db047960 Mon Sep 17 00:00:00 2001 From: "kwan.nguyen" Date: Fri, 25 Oct 2024 11:49:33 +0700 Subject: [PATCH 2/2] integrate log api --- 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 | 2 + PCUT/PCUT/Pages/AdminCenterPage.xaml | 2 +- PCUT/PCUT/Pages/AdminCenterPage.xaml.cs | 3 +- PCUT/PCUT/Pages/Logs/LogInformationPage.xaml | 62 ++++++++++++++-- .../Pages/Logs/LogInformationPage.xaml.cs | 39 +++++++++- PCUT/PCUT/ViewModels/LogViewModel.cs | 72 +++++++++++++++++++ 10 files changed, 212 insertions(+), 13 deletions(-) create mode 100644 PCUT/PCUT.Entities/Log.cs create mode 100644 PCUT/PCUT/Converters/LogTimestampConverter.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 b784ee3..b554cb5 100644 --- a/PCUT/PCUT/PCUT.csproj +++ b/PCUT/PCUT/PCUT.csproj @@ -137,6 +137,7 @@ + @@ -246,6 +247,7 @@ UserListPage.xaml + diff --git a/PCUT/PCUT/Pages/AdminCenterPage.xaml b/PCUT/PCUT/Pages/AdminCenterPage.xaml index 3c908ce..7fa2abf 100644 --- a/PCUT/PCUT/Pages/AdminCenterPage.xaml +++ b/PCUT/PCUT/Pages/AdminCenterPage.xaml @@ -29,7 +29,7 @@ - + diff --git a/PCUT/PCUT/Pages/AdminCenterPage.xaml.cs b/PCUT/PCUT/Pages/AdminCenterPage.xaml.cs index 47ecd00..0e7c6c2 100644 --- a/PCUT/PCUT/Pages/AdminCenterPage.xaml.cs +++ b/PCUT/PCUT/Pages/AdminCenterPage.xaml.cs @@ -1,5 +1,4 @@ -using PCUT.Pages.Logs; -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; diff --git a/PCUT/PCUT/Pages/Logs/LogInformationPage.xaml b/PCUT/PCUT/Pages/Logs/LogInformationPage.xaml index 6692088..88d8273 100644 --- a/PCUT/PCUT/Pages/Logs/LogInformationPage.xaml +++ b/PCUT/PCUT/Pages/Logs/LogInformationPage.xaml @@ -1,14 +1,66 @@  + xmlns:viewmodels="using:PCUT.ViewModels" + mc:Ignorable="d"> + + + + + + + + + + + + + + + - + + + + + + +