Added update handler.

This commit is contained in:
Patrick Fic
2020-12-01 20:10:35 -08:00
parent d75f6d414c
commit 9a59f02dec
6 changed files with 42 additions and 17 deletions

View File

@@ -13,5 +13,6 @@
</metadata>
<files>
<file src="*.*" target="lib\net45\" exclude="*.pdb;*.nupkg;*.vshost.*"/>
<file src="**\*.*" target="lib\net45\" exclude="*.pdb;*.nupkg;*.vshost.*"/>
</files>
</package>

View File

@@ -14,7 +14,7 @@ namespace BodyshopPartner.Utils
{
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
public const string UpdatePath = @"https://update.partner.imex.online";
public const string UpdatePath = @"http://partner.imex.online/";
public static async Task<bool> AreUpdatesAvailable()
{
@@ -55,6 +55,7 @@ namespace BodyshopPartner.Utils
{
var updateInfo = await updateManager.CheckForUpdate();
var releases = updateInfo.ReleasesToApply;
logger.Debug("Applying releases", releases.ToString());
await updateManager.DownloadReleases(releases, _ => { DownloadProgress = _; });
await updateManager.ApplyReleases(updateInfo, _ => { InstallProgress = _; });
}

View File

@@ -83,15 +83,24 @@ namespace BodyshopPartner.ViewModels
_callingThread.ReportProgress(80);
logger.Debug("VM Init Complete");
Task.Run(() => Utils.HTTPServer.InitHttpServer(AddHttpStatus));
Task.Run(() => updateCheck());
_callingThread.ReportProgress(100);
}
private async Task updateCheck()
{
logger.Debug("Checking if updates are available.");
if (await Utils.UpdateHandler.AreUpdatesAvailable())
{
logger.Debug("Updates are available! Installing.");
await Utils.UpdateHandler.ApplyUpdates(Progress, Progress);
}
}
private async void _updateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (await Utils.UpdateHandler.AreUpdatesAvailable())
{
await Utils.UpdateHandler.ApplyUpdates(Progress, Progress);
}
await updateCheck();
}
private void MonitoringPathsChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
@@ -206,7 +215,7 @@ namespace BodyshopPartner.ViewModels
IndeterminateLoading = true;
foreach (var s in ShopData)
{
if (s.Id == ActiveShop.Id) s.AssociationActive = true;
if (s.Id == ActiveShop?.Id) s.AssociationActive = true;
else s.AssociationActive = false;
var r = new GraphQLRequest
{
@@ -228,10 +237,10 @@ namespace BodyshopPartner.ViewModels
};
await Utils.GraphQL.ExecuteQuery(r);
}
Properties.Settings.Default.LastSelectedShop = ActiveShop.Id;
Properties.Settings.Default.LastSelectedShop = ActiveShop?.Id;
Properties.Settings.Default.Save();
Utils.AppMetaData.ActiveShopId = ActiveShop.Id;
Utils.AppMetaData.ShopRegion = ActiveShop.RegionConfig;
Utils.AppMetaData.ActiveShopId = ActiveShop?.Id;
Utils.AppMetaData.ShopRegion = ActiveShop?.RegionConfig;
IndeterminateLoading = false;
}

View File

@@ -6,6 +6,7 @@ using System.Text;
using System.Threading.Tasks;
using BodyshopPartner.Utils.Growls;
using BodyshopPartner.Models;
using System.Reflection;
namespace BodyshopPartner.ViewModels
{
@@ -55,5 +56,12 @@ namespace BodyshopPartner.ViewModels
get { return _httpServerLog; }
set { SetProperty(ref _httpServerLog, value); }
}
private string _appVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
public string AppVersion
{
get { return _appVersion; }
set { SetProperty(ref _appVersion, value); }
}
}
}

View File

@@ -11,7 +11,7 @@
xmlns:vm="clr-namespace:BodyshopPartner.ViewModels"
mc:Ignorable="d"
Title="{x:Static p:Resources.Title_Main}"
Height="450"
Height="489.819"
Width="800"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular"
@@ -149,6 +149,9 @@
Command="{Binding TestCommand}"
Background="Tomato"
Content="_TEST COMMAND" />
<Label DockPanel.Dock="Top"
Margin="8"
Content="{Binding AppVersion}" />
</StackPanel>
<Grid>
@@ -217,9 +220,11 @@
</DataGrid>
<DockPanel Grid.Row="1"
Height="Auto">
<TextBox DockPanel.Dock="Top" Text="{Binding Source={x:Static properties:Settings.Default},
<TextBox DockPanel.Dock="Top"
Text="{Binding Source={x:Static properties:Settings.Default},
Path=QuickBooksFilePath}"
materialDesign:HintAssist.Hint="{x:Static p:Resources.Label_QbFilePath}" TextChanged="TextBox_TextChanged"/>
materialDesign:HintAssist.Hint="{x:Static p:Resources.Label_QbFilePath}"
TextChanged="TextBox_TextChanged" />
<TextBox Height="Auto"
materialDesign:HintAssist.Hint="{x:Static p:Resources.Label_InteractionLog}"
Text="{Binding HttpServerLog}"

View File

@@ -13,5 +13,6 @@
</metadata>
<files>
<file src="*.*" target="lib\net45\" exclude="*.pdb;*.nupkg;*.vshost.*"/>
<file src="**\*.*" target="lib\net45\" exclude="*.pdb;*.nupkg;*.vshost.*"/>
</files>
</package>