From db1b58e499a6a3902eca13324875ace12338de57 Mon Sep 17 00:00:00 2001 From: "kwan.nguyen" Date: Fri, 1 Nov 2024 15:59:02 +0700 Subject: [PATCH] Add download button in dialog when app outdated --- PCUT/Http.Core/Extensions/CategoryExtensions.cs | 3 ++- PCUT/Http.Core/Extensions/HttpExtensions.cs | 4 +++- PCUT/Http.Core/Handlers/AuthenticationHandler.cs | 3 ++- PCUT/PCUT/App.xaml.cs | 12 +++++++++++- PCUT/PCUT/Factories/FileFactory.cs | 3 ++- PCUT/PCUT/Package.appxmanifest | 2 +- .../CategoriesManagement/CategoriesViewPage.xaml.cs | 5 +++-- .../Pages/FileManagement/FileManagerPage.xaml.cs | 3 ++- PCUT/PCUT/Pages/UserManagement/UserListPage.xaml.cs | 5 +++-- PCUT/PCUT/ViewModels/CategoriesViewModel.cs | 5 +++-- PCUT/PCUT/ViewModels/ChangePasswordViewModel.cs | 7 ++++--- PCUT/PCUT/ViewModels/DesignCenterViewModel.cs | 3 ++- PCUT/PCUT/ViewModels/FileAddViewModel.cs | 5 +++-- PCUT/PCUT/ViewModels/FileEditViewModel.cs | 7 ++++--- PCUT/PCUT/ViewModels/FileListViewModel.cs | 3 ++- PCUT/PCUT/ViewModels/LogViewModel.cs | 5 +++-- PCUT/PCUT/ViewModels/LoginViewModel.cs | 5 +++-- PCUT/PCUT/ViewModels/MetadataViewModel.cs | 3 ++- PCUT/PCUT/ViewModels/UpsertCategoryViewModel.cs | 7 ++++--- PCUT/PCUT/ViewModels/UpsertMetadataViewModel.cs | 7 ++++--- PCUT/PCUT/ViewModels/UpsertUserViewModel.cs | 5 +++-- PCUT/PCUT/ViewModels/UserViewModel.cs | 3 ++- 22 files changed, 68 insertions(+), 37 deletions(-) diff --git a/PCUT/Http.Core/Extensions/CategoryExtensions.cs b/PCUT/Http.Core/Extensions/CategoryExtensions.cs index 1d3a778..c741b39 100644 --- a/PCUT/Http.Core/Extensions/CategoryExtensions.cs +++ b/PCUT/Http.Core/Extensions/CategoryExtensions.cs @@ -1,4 +1,5 @@ using Http.Core.Contexts; +using Http.Core.Exceptions; using PCUT.Entities; using PCUT.Entities.ApiResponse; using System; @@ -28,7 +29,7 @@ namespace Http.Core.Extensions return permittedCategories; } } - catch + catch (Exception ex) when (!(ex is AppOutdatedException)) { } return Enumerable.Empty(); diff --git a/PCUT/Http.Core/Extensions/HttpExtensions.cs b/PCUT/Http.Core/Extensions/HttpExtensions.cs index a2a69c8..72be853 100644 --- a/PCUT/Http.Core/Extensions/HttpExtensions.cs +++ b/PCUT/Http.Core/Extensions/HttpExtensions.cs @@ -9,6 +9,8 @@ using Newtonsoft.Json; using Newtonsoft.Json.Serialization; using PCUT.Entities.ApiResponse; using PCUT.Entities; +using Http.Core.Exceptions; +using System; namespace Http.Core.Extensions { @@ -68,7 +70,7 @@ namespace Http.Core.Extensions response.EnsureSuccessStatusCode(); await response.Content.CopyToAsync(outputStream); } - catch + catch (Exception ex) when (!(ex is AppOutdatedException)) { isSuccess = false; } diff --git a/PCUT/Http.Core/Handlers/AuthenticationHandler.cs b/PCUT/Http.Core/Handlers/AuthenticationHandler.cs index 6dbd947..fcd52c4 100644 --- a/PCUT/Http.Core/Handlers/AuthenticationHandler.cs +++ b/PCUT/Http.Core/Handlers/AuthenticationHandler.cs @@ -1,5 +1,6 @@ using Http.Core.Constants; using Http.Core.Contexts; +using Http.Core.Exceptions; using Http.Core.Extensions; using System; using System.Net.Http; @@ -60,7 +61,7 @@ namespace Http.Core.Handlers return await client.RefreshTokenAsync(); } } - catch { } + catch (Exception ex) when (!(ex is AppOutdatedException)) { } return false; } } diff --git a/PCUT/PCUT/App.xaml.cs b/PCUT/PCUT/App.xaml.cs index ab00b05..4b74c99 100644 --- a/PCUT/PCUT/App.xaml.cs +++ b/PCUT/PCUT/App.xaml.cs @@ -135,7 +135,17 @@ namespace PCUT if (e.Exception is AppOutdatedException outdatedException) { e.Handled = true; - await new MessageDialog(outdatedException.Message, "App Outdated!").ShowAsync(); + var dialog = new MessageDialog(outdatedException.Message); + dialog.Commands.Add(new UICommand("Download", async (command) => + { + var _ = await Windows.System.Launcher.LaunchUriAsync( + new Uri("https://pcut.vn/download"), + new Windows.System.LauncherOptions { TreatAsUntrusted = false }); + })); + dialog.Commands.Add(new UICommand("Close")); + dialog.DefaultCommandIndex = 0; + dialog.CancelCommandIndex = 1; + await dialog.ShowAsync(); } } diff --git a/PCUT/PCUT/Factories/FileFactory.cs b/PCUT/PCUT/Factories/FileFactory.cs index f6390f9..890d91e 100644 --- a/PCUT/PCUT/Factories/FileFactory.cs +++ b/PCUT/PCUT/Factories/FileFactory.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading.Tasks; using System.Xml.Linq; using Http.Core; +using Http.Core.Exceptions; using Http.Core.Extensions; using PCUT.Extensions; using Windows.Security.Cryptography.Certificates; @@ -102,7 +103,7 @@ namespace PCUT.Factories stream.Dispose(); } } - catch (Exception ex) + catch (Exception ex) when (!(ex is AppOutdatedException)) { } } diff --git a/PCUT/PCUT/Package.appxmanifest b/PCUT/PCUT/Package.appxmanifest index e332ccb..4e1b42e 100644 --- a/PCUT/PCUT/Package.appxmanifest +++ b/PCUT/PCUT/Package.appxmanifest @@ -9,7 +9,7 @@ + Version="1.3.4.10" /> diff --git a/PCUT/PCUT/Pages/CategoriesManagement/CategoriesViewPage.xaml.cs b/PCUT/PCUT/Pages/CategoriesManagement/CategoriesViewPage.xaml.cs index af982fa..4ccaf72 100644 --- a/PCUT/PCUT/Pages/CategoriesManagement/CategoriesViewPage.xaml.cs +++ b/PCUT/PCUT/Pages/CategoriesManagement/CategoriesViewPage.xaml.cs @@ -12,6 +12,7 @@ using PCUT.Models.Categories; using System.Linq; using Windows.UI.Popups; using System.Reflection; +using Http.Core.Exceptions; // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 @@ -108,7 +109,7 @@ namespace PCUT.Pages await ShowDialog("Error!", "Cant delete category"); } } - catch (Exception ex) + catch (Exception ex) when (!(ex is AppOutdatedException)) { await ShowDialog("Error!", $"Got exception: {ex.Message}"); } @@ -218,7 +219,7 @@ namespace PCUT.Pages await messegaDialog.ShowAsync(); } } - catch + catch (Exception ex) when (!(ex is AppOutdatedException)) { } diff --git a/PCUT/PCUT/Pages/FileManagement/FileManagerPage.xaml.cs b/PCUT/PCUT/Pages/FileManagement/FileManagerPage.xaml.cs index a63de8c..6ad9ba3 100644 --- a/PCUT/PCUT/Pages/FileManagement/FileManagerPage.xaml.cs +++ b/PCUT/PCUT/Pages/FileManagement/FileManagerPage.xaml.cs @@ -25,6 +25,7 @@ using static PCUT.App; using Windows.UI.Core; using System.Threading; using PCUT.Models; +using Http.Core.Exceptions; // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 @@ -174,7 +175,7 @@ namespace PCUT.Pages await ShowDialog("Error!", "Cant delete file"); } } - catch (Exception ex) + catch (Exception ex) when (!(ex is AppOutdatedException)) { await ShowDialog("Error!", $"Got exception: {ex.Message}"); } diff --git a/PCUT/PCUT/Pages/UserManagement/UserListPage.xaml.cs b/PCUT/PCUT/Pages/UserManagement/UserListPage.xaml.cs index 6049743..4debc19 100644 --- a/PCUT/PCUT/Pages/UserManagement/UserListPage.xaml.cs +++ b/PCUT/PCUT/Pages/UserManagement/UserListPage.xaml.cs @@ -7,6 +7,7 @@ using Windows.UI.Xaml.Navigation; using Http.Core; using Http.Core.Extensions; using static Http.Core.Constants.HttpConstants; +using Http.Core.Exceptions; // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 @@ -107,7 +108,7 @@ namespace PCUT.Pages await ShowDialog("Error!", "Cant delete user"); } } - catch (Exception ex) + catch (Exception ex) when (!(ex is AppOutdatedException)) { await ShowDialog("Error!", $"Got exception: {ex.Message}"); } @@ -132,7 +133,7 @@ namespace PCUT.Pages await ShowDialog("Error!", "Failed to unlock user's device"); } } - catch (Exception ex) + catch (Exception ex) when (!(ex is AppOutdatedException)) { await ShowDialog("Error!", $"Got exception: {ex.Message}"); } diff --git a/PCUT/PCUT/ViewModels/CategoriesViewModel.cs b/PCUT/PCUT/ViewModels/CategoriesViewModel.cs index 8e07dd1..c68e8a2 100644 --- a/PCUT/PCUT/ViewModels/CategoriesViewModel.cs +++ b/PCUT/PCUT/ViewModels/CategoriesViewModel.cs @@ -11,6 +11,7 @@ using static Http.Core.Constants.HttpConstants; using PCUT.Entities.ApiResponse; using PCUT.Models.Categories; using Windows.ApplicationModel.Core; +using Http.Core.Exceptions; namespace PCUT.ViewModels { @@ -70,7 +71,7 @@ namespace PCUT.ViewModels FilteredCategories.Load(categories); } } - catch (Exception ex) + catch (Exception ex) when (!(ex is AppOutdatedException)) { } @@ -104,7 +105,7 @@ namespace PCUT.ViewModels } } } - catch + catch (Exception ex) when (!(ex is AppOutdatedException)) { } } diff --git a/PCUT/PCUT/ViewModels/ChangePasswordViewModel.cs b/PCUT/PCUT/ViewModels/ChangePasswordViewModel.cs index 3d68a06..3acbad6 100644 --- a/PCUT/PCUT/ViewModels/ChangePasswordViewModel.cs +++ b/PCUT/PCUT/ViewModels/ChangePasswordViewModel.cs @@ -19,6 +19,7 @@ using Http.Core.Extensions; using static Http.Core.Constants.HttpConstants; using Microsoft.IdentityModel.Tokens; using PCUT.Models.Users; +using Http.Core.Exceptions; namespace PCUT.ViewModels { @@ -102,7 +103,7 @@ namespace PCUT.ViewModels }; await ChangePasswordAsync(UserId, passwordChange); } - catch (Exception ex) + catch (Exception ex) when (!(ex is AppOutdatedException)) { var failDialog = new MessageDialog(ex.Message.ToString()); await failDialog.ShowAsync(); @@ -120,7 +121,7 @@ namespace PCUT.ViewModels }; await ChangePasswordAsync(UserId, passwordChange); } - catch (Exception ex) + catch (Exception ex) when (!(ex is AppOutdatedException)) { var failDialog = new MessageDialog(ex.Message.ToString()); await failDialog.ShowAsync(); @@ -145,7 +146,7 @@ namespace PCUT.ViewModels await failDialog.ShowAsync(); } } - catch (Exception ex) + catch (Exception ex) when (!(ex is AppOutdatedException)) { var errorDialog = new MessageDialog($"error: {ex.Message}"); await errorDialog.ShowAsync(); diff --git a/PCUT/PCUT/ViewModels/DesignCenterViewModel.cs b/PCUT/PCUT/ViewModels/DesignCenterViewModel.cs index 5466b25..33bb71d 100644 --- a/PCUT/PCUT/ViewModels/DesignCenterViewModel.cs +++ b/PCUT/PCUT/ViewModels/DesignCenterViewModel.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Http.Core; +using Http.Core.Exceptions; using Http.Core.Extensions; using Newtonsoft.Json; using PCUT.Entities; @@ -162,7 +163,7 @@ namespace PCUT.ViewModels } } } - catch + catch (Exception ex) when (!(ex is AppOutdatedException)) { } diff --git a/PCUT/PCUT/ViewModels/FileAddViewModel.cs b/PCUT/PCUT/ViewModels/FileAddViewModel.cs index 402632f..0485171 100644 --- a/PCUT/PCUT/ViewModels/FileAddViewModel.cs +++ b/PCUT/PCUT/ViewModels/FileAddViewModel.cs @@ -23,6 +23,7 @@ using Http.Core; using Http.Core.Extensions; using static Http.Core.Constants.HttpConstants; using PCUT.Entities.ApiResponse; +using Http.Core.Exceptions; namespace PCUT.ViewModels { @@ -137,7 +138,7 @@ namespace PCUT.ViewModels } } } - catch (Exception ex) + catch (Exception ex) when (!(ex is AppOutdatedException)) { var errorDialog = new MessageDialog($"Error: {ex.Message}"); await errorDialog.ShowAsync(); @@ -176,7 +177,7 @@ namespace PCUT.ViewModels } } } - catch (Exception ex) + catch (Exception ex) when (!(ex is AppOutdatedException)) { var exceptionDialog = new MessageDialog($"Error: {ex.Message}"); await exceptionDialog.ShowAsync(); diff --git a/PCUT/PCUT/ViewModels/FileEditViewModel.cs b/PCUT/PCUT/ViewModels/FileEditViewModel.cs index b65e25f..6913afe 100644 --- a/PCUT/PCUT/ViewModels/FileEditViewModel.cs +++ b/PCUT/PCUT/ViewModels/FileEditViewModel.cs @@ -26,6 +26,7 @@ using static Http.Core.Constants.HttpConstants; using Windows.Graphics.Imaging; using Windows.UI.Xaml.Media.Imaging; using Windows.UI.Xaml.Media; +using Http.Core.Exceptions; namespace PCUT.ViewModels { @@ -116,7 +117,7 @@ namespace PCUT.ViewModels } } } - catch (Exception ex) + catch (Exception ex) when (!(ex is AppOutdatedException)) { } } @@ -199,7 +200,7 @@ namespace PCUT.ViewModels } } } - catch (Exception ex) + catch (Exception ex) when (!(ex is AppOutdatedException)) { var errorDialog = new MessageDialog($"Error: {ex.Message}"); await errorDialog.ShowAsync(); @@ -238,7 +239,7 @@ namespace PCUT.ViewModels } } } - catch (Exception ex) + catch (Exception ex) when (!(ex is AppOutdatedException)) { var exceptionDialog = new MessageDialog($"Error: {ex.Message}"); await exceptionDialog.ShowAsync(); diff --git a/PCUT/PCUT/ViewModels/FileListViewModel.cs b/PCUT/PCUT/ViewModels/FileListViewModel.cs index 5be7c61..4ea3a7e 100644 --- a/PCUT/PCUT/ViewModels/FileListViewModel.cs +++ b/PCUT/PCUT/ViewModels/FileListViewModel.cs @@ -19,6 +19,7 @@ using Http.Core.Extensions; using static Http.Core.Constants.HttpConstants; using System.ComponentModel; using Windows.ApplicationModel.Core; +using Http.Core.Exceptions; namespace PCUT.ViewModels { @@ -168,7 +169,7 @@ namespace PCUT.ViewModels FilteredFiles.Load(files); } } - catch (Exception ex) + catch (Exception ex) when (!(ex is AppOutdatedException)) { } diff --git a/PCUT/PCUT/ViewModels/LogViewModel.cs b/PCUT/PCUT/ViewModels/LogViewModel.cs index 6f74897..2db2409 100644 --- a/PCUT/PCUT/ViewModels/LogViewModel.cs +++ b/PCUT/PCUT/ViewModels/LogViewModel.cs @@ -1,4 +1,5 @@ using Http.Core; +using Http.Core.Exceptions; using Http.Core.Extensions; using PCUT.Entities; using PCUT.Entities.ApiResponse; @@ -48,7 +49,7 @@ namespace PCUT.ViewModels Users.Load(data); } } - catch + catch (Exception ex) when (!(ex is AppOutdatedException)) { } } @@ -83,7 +84,7 @@ namespace PCUT.ViewModels Logs.Add(log); } } - catch (Exception ex) + catch (Exception ex) when (!(ex is AppOutdatedException)) { } diff --git a/PCUT/PCUT/ViewModels/LoginViewModel.cs b/PCUT/PCUT/ViewModels/LoginViewModel.cs index 2f672c0..4f41087 100644 --- a/PCUT/PCUT/ViewModels/LoginViewModel.cs +++ b/PCUT/PCUT/ViewModels/LoginViewModel.cs @@ -1,5 +1,6 @@ using Http.Core; using Http.Core.Contexts; +using Http.Core.Exceptions; using Http.Core.Extensions; using Http.Core.Models; using PCUT.Extensions; @@ -96,7 +97,7 @@ namespace PCUT.ViewModels if (!loginSuccess) errorMessage = loginResult.Message; } - catch (Exception ex) + catch (Exception ex) when (!(ex is AppOutdatedException)) { errorMessage = ex.Message; } @@ -114,7 +115,7 @@ namespace PCUT.ViewModels { await client.LoadUserProfileAsync(); } - catch { } + catch (Exception ex) when (!(ex is AppOutdatedException)) { } } if (RememberMe) diff --git a/PCUT/PCUT/ViewModels/MetadataViewModel.cs b/PCUT/PCUT/ViewModels/MetadataViewModel.cs index 4ee07e4..d723444 100644 --- a/PCUT/PCUT/ViewModels/MetadataViewModel.cs +++ b/PCUT/PCUT/ViewModels/MetadataViewModel.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using Http.Core.Extensions; using Windows.UI.Xaml.Controls.Primitives; using static Http.Core.Constants.HttpConstants; +using Http.Core.Exceptions; namespace PCUT.ViewModels { @@ -194,7 +195,7 @@ namespace PCUT.ViewModels return content.Data; } } - catch + catch (Exception ex) when (!(ex is AppOutdatedException)) { } } diff --git a/PCUT/PCUT/ViewModels/UpsertCategoryViewModel.cs b/PCUT/PCUT/ViewModels/UpsertCategoryViewModel.cs index 386ffe3..6b1f958 100644 --- a/PCUT/PCUT/ViewModels/UpsertCategoryViewModel.cs +++ b/PCUT/PCUT/ViewModels/UpsertCategoryViewModel.cs @@ -12,6 +12,7 @@ using PCUT.Models; using PCUT.Helpers; using System.Windows.Input; using PCUT.Entities.ApiResponse; +using Http.Core.Exceptions; namespace PCUT.ViewModels { @@ -63,7 +64,7 @@ namespace PCUT.ViewModels Description = categoryData.Data.Description; } } - catch { } + catch (Exception ex) when (!(ex is AppOutdatedException)) { } } } @@ -96,7 +97,7 @@ namespace PCUT.ViewModels else return "Failed to add the category!"; } - catch(Exception ex) + catch (Exception ex) when (!(ex is AppOutdatedException)) { return $"error: {ex.Message}"; } @@ -117,7 +118,7 @@ namespace PCUT.ViewModels else return "Failed to edit the category!"; } - catch (Exception ex) + catch (Exception ex) when (!(ex is AppOutdatedException)) { return $"error: {ex.Message}"; } diff --git a/PCUT/PCUT/ViewModels/UpsertMetadataViewModel.cs b/PCUT/PCUT/ViewModels/UpsertMetadataViewModel.cs index 9d0fd1f..ec5a005 100644 --- a/PCUT/PCUT/ViewModels/UpsertMetadataViewModel.cs +++ b/PCUT/PCUT/ViewModels/UpsertMetadataViewModel.cs @@ -11,6 +11,7 @@ using PCUT.Models.Categories; using System.Collections.Generic; using System.Linq; using System.Net.Http; +using Http.Core.Exceptions; namespace PCUT.ViewModels { @@ -72,7 +73,7 @@ namespace PCUT.ViewModels var response = await client.PostAsJsonAsync(Api.Metadata, request); return response.IsSuccessStatusCode ? "Metadata added successfully!" : "Failed to add the metadata!"; } - catch (Exception ex) + catch (Exception ex) when (!(ex is AppOutdatedException)) { return $"error: {ex.Message}"; } @@ -89,7 +90,7 @@ namespace PCUT.ViewModels var response = await client.PutAsJsonAsync(Api.MetadataById.FormatRoute(Id), request); return response.IsSuccessStatusCode ? "Metadata edited successfully!" : "Failed to edit the metadata!"; } - catch (Exception ex) + catch (Exception ex) when (!(ex is AppOutdatedException)) { return $"error: {ex.Message}"; } @@ -113,7 +114,7 @@ namespace PCUT.ViewModels } } } - catch { } + catch (Exception ex) when (!(ex is AppOutdatedException)) { } } } diff --git a/PCUT/PCUT/ViewModels/UpsertUserViewModel.cs b/PCUT/PCUT/ViewModels/UpsertUserViewModel.cs index 08a3c43..c8c6fda 100644 --- a/PCUT/PCUT/ViewModels/UpsertUserViewModel.cs +++ b/PCUT/PCUT/ViewModels/UpsertUserViewModel.cs @@ -18,6 +18,7 @@ using Windows.UI.Xaml.Controls; using Windows.UI.Xaml; using System.ComponentModel; using Newtonsoft.Json.Linq; +using Http.Core.Exceptions; namespace PCUT.ViewModels { @@ -209,7 +210,7 @@ namespace PCUT.ViewModels Description = _profile.Description; } } - catch (Exception ex) + catch (Exception ex) when (!(ex is AppOutdatedException)) { } } @@ -286,7 +287,7 @@ namespace PCUT.ViewModels return false; } } - catch (Exception ex) + catch (Exception ex) when (!(ex is AppOutdatedException)) { await ShowDialogAsync(ex.Message); return false; diff --git a/PCUT/PCUT/ViewModels/UserViewModel.cs b/PCUT/PCUT/ViewModels/UserViewModel.cs index 3b9991f..2387c79 100644 --- a/PCUT/PCUT/ViewModels/UserViewModel.cs +++ b/PCUT/PCUT/ViewModels/UserViewModel.cs @@ -1,4 +1,5 @@ using Http.Core; +using Http.Core.Exceptions; using Http.Core.Extensions; using PCUT.Entities.ApiResponse; using PCUT.Extensions; @@ -71,7 +72,7 @@ namespace PCUT.ViewModels FilteredUsers.Load(users); } } - catch (Exception ex) + catch (Exception ex) when (!(ex is AppOutdatedException)) { }