update version control
This commit is contained in:
parent
850dc4c8a1
commit
f5d9cce2ea
|
@ -29,6 +29,7 @@ namespace Http.Core.Contexts
|
||||||
public string AccessToken { get; private set; }
|
public string AccessToken { get; private set; }
|
||||||
public string RefreshToken { get; private set; }
|
public string RefreshToken { get; private set; }
|
||||||
public string DeviceId { get; private set; }
|
public string DeviceId { get; private set; }
|
||||||
|
public string AppVersion { get; private set; }
|
||||||
public DateTime? ExpiredTime { get; private set; }
|
public DateTime? ExpiredTime { get; private set; }
|
||||||
|
|
||||||
public bool IsPermittedEdit => Profile.Role == "admin" || (Profile.IsPermittedEdit ?? false);
|
public bool IsPermittedEdit => Profile.Role == "admin" || (Profile.IsPermittedEdit ?? false);
|
||||||
|
@ -41,6 +42,14 @@ namespace Http.Core.Contexts
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetAppVersion(string appVersion)
|
||||||
|
{
|
||||||
|
if (AppVersion == null)
|
||||||
|
{
|
||||||
|
AppVersion = appVersion;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private readonly object _updateLock = new object();
|
private readonly object _updateLock = new object();
|
||||||
internal void SetValue(string accessToken, string refreshToken, string userName = null)
|
internal void SetValue(string accessToken, string refreshToken, string userName = null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Http.Core.Exceptions
|
||||||
|
{
|
||||||
|
public class AppOutdatedException : Exception
|
||||||
|
{
|
||||||
|
public AppOutdatedException() : base() { }
|
||||||
|
|
||||||
|
public AppOutdatedException(string message) : base(message) { }
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,7 @@
|
||||||
using Http.Core.Contexts;
|
using Http.Core.Contexts;
|
||||||
|
using Http.Core.Exceptions;
|
||||||
|
using Http.Core.Extensions;
|
||||||
|
using PCUT.Entities.ApiResponse;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
@ -10,10 +13,17 @@ namespace Http.Core.Handlers
|
||||||
{
|
{
|
||||||
public class DeviceAuthHandler : DelegatingHandler
|
public class DeviceAuthHandler : DelegatingHandler
|
||||||
{
|
{
|
||||||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
request.Headers.Add("x-device-id", $"{UserContext.Instance.DeviceId}");
|
request.Headers.Add("x-device-id", UserContext.Instance.DeviceId);
|
||||||
return base.SendAsync(request, cancellationToken);
|
request.Headers.Add("x-version-id", UserContext.Instance.AppVersion);
|
||||||
|
var response = await base.SendAsync(request, cancellationToken);
|
||||||
|
if (response.StatusCode == System.Net.HttpStatusCode.Conflict && response.Content.Headers.ContentLength > 0)
|
||||||
|
{
|
||||||
|
var content = await response.DeserializeObjectAsync<MessageResponse>(ensureSuccess: false);
|
||||||
|
throw new AppOutdatedException(content.ErrorMessage);
|
||||||
|
}
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
using Http.Core;
|
using Http.Core;
|
||||||
|
using Http.Core.Contexts;
|
||||||
|
using Http.Core.Exceptions;
|
||||||
using Http.Core.Handlers;
|
using Http.Core.Handlers;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using PCUT.Pages;
|
using PCUT.Pages;
|
||||||
|
@ -12,6 +14,7 @@ using Windows.ApplicationModel.Activation;
|
||||||
using Windows.Foundation;
|
using Windows.Foundation;
|
||||||
using Windows.Foundation.Collections;
|
using Windows.Foundation.Collections;
|
||||||
using Windows.UI.Core;
|
using Windows.UI.Core;
|
||||||
|
using Windows.UI.Popups;
|
||||||
using Windows.UI.ViewManagement;
|
using Windows.UI.ViewManagement;
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
|
@ -45,6 +48,7 @@ namespace PCUT
|
||||||
{
|
{
|
||||||
this.InitializeComponent();
|
this.InitializeComponent();
|
||||||
this.Suspending += OnSuspending;
|
this.Suspending += OnSuspending;
|
||||||
|
this.UnhandledException += HandleException;
|
||||||
AppContainer = ConfigDI();
|
AppContainer = ConfigDI();
|
||||||
HttpClientFactory
|
HttpClientFactory
|
||||||
.AddHttpClient(ClientNames.AuthClient)
|
.AddHttpClient(ClientNames.AuthClient)
|
||||||
|
@ -65,8 +69,9 @@ namespace PCUT
|
||||||
/// <param name="e">Details about the launch request and process.</param>
|
/// <param name="e">Details about the launch request and process.</param>
|
||||||
protected override void OnLaunched(LaunchActivatedEventArgs e)
|
protected override void OnLaunched(LaunchActivatedEventArgs e)
|
||||||
{
|
{
|
||||||
Frame rootFrame = Window.Current.Content as Frame;
|
UserContext.Instance.SetAppVersion(GetAppVersion());
|
||||||
ApplicationView.GetForCurrentView().IsScreenCaptureEnabled = false;
|
ApplicationView.GetForCurrentView().IsScreenCaptureEnabled = false;
|
||||||
|
Frame rootFrame = Window.Current.Content as Frame;
|
||||||
// Do not repeat app initialization when the Window already has content,
|
// Do not repeat app initialization when the Window already has content,
|
||||||
// just ensure that the window is active
|
// just ensure that the window is active
|
||||||
if (rootFrame == null)
|
if (rootFrame == null)
|
||||||
|
@ -124,10 +129,25 @@ namespace PCUT
|
||||||
deferral.Complete();
|
deferral.Complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void HandleException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Exception is AppOutdatedException outdatedException)
|
||||||
|
{
|
||||||
|
e.Handled = true;
|
||||||
|
await new MessageDialog(outdatedException.Message, "App Outdated!").ShowAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
IServiceProvider ConfigDI()
|
IServiceProvider ConfigDI()
|
||||||
{
|
{
|
||||||
var serviceCollection = new ServiceCollection();
|
var serviceCollection = new ServiceCollection();
|
||||||
return serviceCollection.BuildServiceProvider();
|
return serviceCollection.BuildServiceProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string GetAppVersion()
|
||||||
|
{
|
||||||
|
var packageVersion = Package.Current.Id.Version;
|
||||||
|
return $"{packageVersion.Major}.{packageVersion.Minor}.{packageVersion.Build}.{packageVersion.Revision}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
<Identity
|
<Identity
|
||||||
Name="ac171214-3336-4e02-845d-9bdc107cce71"
|
Name="ac171214-3336-4e02-845d-9bdc107cce71"
|
||||||
Publisher="CN=pcut, O=PCUT, L=HN, S=HN, C=VN"
|
Publisher="CN=pcut, O=PCUT, L=HN, S=HN, C=VN"
|
||||||
Version="1.3.4.4" />
|
Version="1.3.4.6" />
|
||||||
|
|
||||||
<mp:PhoneIdentity PhoneProductId="ac171214-3336-4e02-845d-9bdc107cce71" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
|
<mp:PhoneIdentity PhoneProductId="ac171214-3336-4e02-845d-9bdc107cce71" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,8 @@
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="0.35*"/>
|
<RowDefinition Height="0.35*"/>
|
||||||
<RowDefinition Height="0.25*"/>
|
<RowDefinition Height="0.25*"/>
|
||||||
<RowDefinition Height="0.4*"/>
|
<RowDefinition Height="0.1*"/>
|
||||||
|
<RowDefinition Height="0.3*"/>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<Grid Grid.Column="0" Grid.Row="1">
|
<Grid Grid.Column="0" Grid.Row="1">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
|
@ -96,6 +97,13 @@
|
||||||
IsEnabled="{x:Bind Path=LoginModel.LoginEnabled, Mode=OneWay}"
|
IsEnabled="{x:Bind Path=LoginModel.LoginEnabled, Mode=OneWay}"
|
||||||
Command="{x:Bind Path=LoginModel.NavigateMainCommand}"/>
|
Command="{x:Bind Path=LoginModel.NavigateMainCommand}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
<TextBlock
|
||||||
|
Grid.Row="2"
|
||||||
|
Grid.Column="0"
|
||||||
|
Text="{x:Bind LoginModel.VersionDisplay}"
|
||||||
|
VerticalAlignment="Bottom"
|
||||||
|
HorizontalAlignment="Left"
|
||||||
|
Margin="10 0 0 10"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
|
@ -71,9 +71,10 @@ namespace PCUT.ViewModels
|
||||||
SetProperty(ref _loginEnabled, value);
|
SetProperty(ref _loginEnabled, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#region Commands
|
|
||||||
|
public string VersionDisplay = $"Version {UserContext.Instance.AppVersion}";
|
||||||
|
|
||||||
public ICommand NavigateMainCommand { get; private set; }
|
public ICommand NavigateMainCommand { get; private set; }
|
||||||
#endregion
|
|
||||||
|
|
||||||
private bool _success = false;
|
private bool _success = false;
|
||||||
private async Task LoginAsync()
|
private async Task LoginAsync()
|
||||||
|
|
Loading…
Reference in New Issue