aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio
diff options
context:
space:
mode:
authorRoy <roy.mail.net@gmail.com>2018-02-23 23:14:27 +0200
committerRoy <roy.mail.net@gmail.com>2018-02-23 23:14:27 +0200
commit2b781099f7cb08d6a5b9363b9079fab5be108541 (patch)
tree41cd2acfa8047cea0399bfc6f46ab851b484aaac /Software/Visual_Studio/MachineStudio
parentfadf83a50071ffba21db05eceff10c51c18f5fb3 (diff)
downloadTango-2b781099f7cb08d6a5b9363b9079fab5be108541.tar.gz
Tango-2b781099f7cb08d6a5b9363b9079fab5be108541.zip
Implemented machine studio periodical update checking.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio')
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs6
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs72
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs42
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/LoadingView.xaml10
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml40
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/UpdateView.xaml12
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UpdateService/MachineStudioUpdateService.svc.cs6
7 files changed, 163 insertions, 25 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs
index 1ea22c587..4dd17b500 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs
@@ -225,7 +225,7 @@ namespace Tango.MachineStudio.UI.Notifications
/// <param name="message">The message.</param>
public void ShowError(string message)
{
- ShowMessageBox(PackIconKind.Exclamation, Brushes.Red, message, false);
+ ShowMessageBox(PackIconKind.AlertOctagon, Brushes.Red, message, false);
}
/// <summary>
@@ -234,7 +234,7 @@ namespace Tango.MachineStudio.UI.Notifications
/// <param name="message">The message.</param>
public void ShowInfo(string message)
{
- ShowMessageBox(PackIconKind.Information, Brushes.Black, message, false);
+ ShowMessageBox(PackIconKind.CommentAlertOutline, Brushes.Black, message, false);
}
/// <summary>
@@ -253,7 +253,7 @@ namespace Tango.MachineStudio.UI.Notifications
/// <param name="message">The message.</param>
public void ShowWarning(string message)
{
- ShowMessageBox(PackIconKind.Exclamation, Brushes.DarkOrange, message, false);
+ ShowMessageBox(PackIconKind.AlertOutline, Brushes.DarkOrange, message, false);
}
/// <summary>
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs
index acd9e7925..fb2cd5c82 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs
@@ -6,6 +6,7 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
+using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
@@ -19,6 +20,7 @@ using Tango.MachineStudio.Common.Modules;
using Tango.MachineStudio.Common.Navigation;
using Tango.MachineStudio.Common.Notifications;
using Tango.MachineStudio.Common.StudioApplication;
+using Tango.MachineStudio.Common.Update;
using Tango.MachineStudio.UI.StudioApplication;
using Tango.MachineStudio.UI.SupervisingController;
using Tango.MachineStudio.UI.Views;
@@ -39,6 +41,7 @@ namespace Tango.MachineStudio.UI.ViewModels
private IStudioModule _currentModule;
private INavigationManager _navigation;
private bool _isDisconnecting;
+ private Thread _updateCheckThread;
/// <summary>
/// Gets or sets the current loaded module.
@@ -149,6 +152,38 @@ namespace Tango.MachineStudio.UI.ViewModels
set { _applicationManager = value; RaisePropertyChangedAuto(); }
}
+ private bool _isUpdateAvailable;
+ /// <summary>
+ /// Gets or sets a value indicating whether a new version update is available.
+ /// </summary>
+ public bool IsUpdateAvailable
+ {
+ get { return _isUpdateAvailable; }
+ set { _isUpdateAvailable = value; RaisePropertyChangedAuto(); }
+ }
+
+ private String _latestVersion;
+ /// <summary>
+ /// Gets or sets the latest version.
+ /// </summary>
+ public String LatestVersion
+ {
+ get { return _latestVersion; }
+ set { _latestVersion = value; RaisePropertyChangedAuto(); }
+ }
+
+
+ private bool _disableCheckForUpdates;
+ /// <summary>
+ /// Gets or sets a value indicating whether [disable check for updates].
+ /// </summary>
+ public bool DisableCheckForUpdates
+ {
+ get { return _disableCheckForUpdates; }
+ set { _disableCheckForUpdates = value; RaisePropertyChangedAuto(); }
+ }
+
+
/// <summary>
/// Initializes a new instance of the <see cref="MainViewVM"/> class.
/// </summary>
@@ -181,6 +216,43 @@ namespace Tango.MachineStudio.UI.ViewModels
OpenModuleInWindowCommand = new RelayCommand<IStudioModule>(OpenModuleInWindow);
ExitCommand = new RelayCommand(ExitApplication);
UpdateCenterCommand = new RelayCommand(NavigateToUpdateCenter);
+
+ _updateCheckThread = new Thread(UpdateCheckThreadMethod);
+ _updateCheckThread.IsBackground = true;
+ _updateCheckThread.Start();
+ }
+
+ private void UpdateCheckThreadMethod()
+ {
+ while (!DisableCheckForUpdates)
+ {
+ Thread.Sleep(TimeSpan.FromMinutes(1));
+
+ try
+ {
+ if (_authenticationProvider.CurrentUser != null)
+ {
+ var service = UpdateServiceHelper.GetUpdateServiceChannel();
+ var client = service.CreateChannel();
+
+ CheckForUpdatesResponse response = client.CheckForUpdates(new CheckForUpdatesRequest()
+ {
+ Email = _authenticationProvider.CurrentUser.Email,
+ Password = _authenticationProvider.CurrentUser.Password,
+ Version = _applicationManager.Version,
+ });
+
+ IsUpdateAvailable = response.IsUpdateAvailable;
+ LatestVersion = response.Version;
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error in version update periodic check...");
+ }
+
+ Thread.Sleep(TimeSpan.FromMinutes(4));
+ }
}
/// <summary>
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs
index c24204fb6..6be4ba4ca 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs
@@ -1,5 +1,6 @@
using FluentFTP;
using Ionic.Zip;
+using Microsoft.Practices.ServiceLocation;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -75,6 +76,14 @@ namespace Tango.MachineStudio.UI.ViewModels
set { _updateProgress = value; RaisePropertyChangedAuto(); }
}
+ private String _currentUpdateFile;
+
+ public String CurrentUpdateFile
+ {
+ get { return _currentUpdateFile; }
+ set { _currentUpdateFile = value; RaisePropertyChanged(nameof(CurrentUpdateFile)); }
+ }
+
public RelayCommand UpdateCommand { get; set; }
public RelayCommand BackCommand { get; set; }
@@ -95,7 +104,7 @@ namespace Tango.MachineStudio.UI.ViewModels
UpdateCommand = new RelayCommand(StartUpdate, () => Status == UpdateStatus.UpdateAvailable);
BackCommand = new RelayCommand(BackToApplication, () => Status != UpdateStatus.Updating);
RestartCommand = new RelayCommand(RestartApplication, () => Status == UpdateStatus.UpdateCompleted);
- TryAgainCommand = new RelayCommand(TryAgain, () => Status == UpdateStatus.CheckingForUpdate);
+ TryAgainCommand = new RelayCommand(TryAgain, () => Status == UpdateStatus.Error);
}
public void OnNavigatedInto()
@@ -174,10 +183,10 @@ namespace Tango.MachineStudio.UI.ViewModels
Task.Factory.StartNew(() =>
{
+ var tempFile = PathHelper.GetTempFilePath() + ".zip";
+
try
{
- var tempFile = PathHelper.GetTempFilePath() + ".zip";
-
LogManager.Log("Creating temporary file " + tempFile);
int fileSize = 0;
@@ -235,6 +244,7 @@ namespace Tango.MachineStudio.UI.ViewModels
}
else
{
+ CurrentUpdateFile = Path.GetFileName(entry.FileName);
entry.Extract(_newPackageTempFolder, ExtractExistingFileAction.OverwriteSilently);
}
}
@@ -245,6 +255,7 @@ namespace Tango.MachineStudio.UI.ViewModels
}
}
+ ServiceLocator.Current.GetInstance<MainViewVM>().DisableCheckForUpdates = true;
Status = UpdateStatus.UpdateCompleted;
}
catch (Exception ex)
@@ -252,6 +263,10 @@ namespace Tango.MachineStudio.UI.ViewModels
LogManager.Log(ex, "Error while extracting update package.");
Status = UpdateStatus.Error;
}
+ finally
+ {
+ PathHelper.TryDeleteFile(tempFile);
+ }
});
}
@@ -262,11 +277,22 @@ namespace Tango.MachineStudio.UI.ViewModels
private void RestartApplication()
{
- Process p = new Process();
- p.StartInfo.FileName = _appPath + "\\Tango.MachineStudio.Updater.exe";
- p.StartInfo.UseShellExecute = true;
- p.StartInfo.Arguments = _newPackageTempFolder;
- p.Start();
+ try
+ {
+ Process p = new Process();
+ p.StartInfo.FileName = _appPath + "\\Tango.MachineStudio.Updater.exe";
+ p.StartInfo.UseShellExecute = true;
+ p.StartInfo.Arguments = _newPackageTempFolder;
+ p.Start();
+ }
+ catch (Exception ex)
+ {
+ if (ex.Message == "The operation was canceled by the user")
+ {
+ _notification.ShowWarning("It seems like you refused to invoke our update utility. This prevents Machine Studio from completing the update process!");
+ return;
+ }
+ }
Environment.Exit(0);
}
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/LoadingView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/LoadingView.xaml
index aaf4accd4..5f65100df 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/LoadingView.xaml
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/LoadingView.xaml
@@ -13,15 +13,17 @@
<Image Source="/Images/machine-trans.png" RenderOptions.BitmapScalingMode="Fant" Width="100"></Image>
<StackPanel Orientation="Horizontal">
<TextBlock FontSize="70" Foreground="{StaticResource AccentColorBrush}">Machine Studio</TextBlock>
- <TextBlock Foreground="Gray" VerticalAlignment="Bottom" Margin="10 0 0 5" FontSize="16" FontWeight="SemiBold" FontStyle="Italic">
- <Run>v</Run>
- <Run Text="{Binding ApplicationManager.Version,Mode=OneWay}"></Run>
- </TextBlock>
</StackPanel>
<TextBlock HorizontalAlignment="Right" FontSize="18" Margin="0 0 -50 0" Foreground="{StaticResource AccentColorBrush}">Twine Solutions</TextBlock>
<mahapps:ProgressRing Margin="20 60 20 40" Width="80" Height="80"></mahapps:ProgressRing>
<TextBlock HorizontalAlignment="Center" FontSize="18" FontStyle="Italic">Loading, please wait...</TextBlock>
</StackPanel>
</Grid>
+
+
+ <TextBlock Foreground="Gray" VerticalAlignment="Bottom" HorizontalAlignment="Center" Margin="40" FontSize="20" FontWeight="SemiBold" FontStyle="Italic">
+ <Run>v</Run>
+ <Run Text="{Binding ApplicationManager.Version,Mode=OneWay}"></Run>
+ </TextBlock>
</Grid>
</UserControl>
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml
index 355bdc1fd..19c0c47df 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml
@@ -19,6 +19,7 @@
<converters:StringEllipsisConverter x:Key="StringEllipsisConverter" />
<converters:BooleanToVisibilityInverseConverter x:Key="BooleanToVisibilityInverseConverter" />
<converters:NullObjectToBooleanConverter x:Key="NullObjectToBooleanConverter" />
+ <converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
</UserControl.Resources>
<Grid>
@@ -153,14 +154,8 @@
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
-
+
<Button VerticalAlignment="Center" Margin="10 0 0 0" Style="{StaticResource MaterialDesignFlatButton}" FontSize="12" ToolTip="Connect to machine on the local network" BorderThickness="0" Command="{Binding ConnectCommand}">
- <!--<Button.Background>
- <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
- <GradientStop Color="White" Offset="0.4" />
- <GradientStop Color="#75E0FA" Offset="1"/>
- </LinearGradientBrush>
- </Button.Background>-->
<StackPanel Orientation="Horizontal">
<Grid>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
@@ -183,6 +178,37 @@
</Grid>
</StackPanel>
</Button>
+
+ <Button Style="{StaticResource emptyButton}" Cursor="Hand" Command="{Binding UpdateCenterCommand}" Visibility="{Binding IsUpdateAvailable,Converter={StaticResource BooleanToVisibilityConverter}}">
+ <Button.ToolTip>
+ <TextBlock>
+ <Run>Version</Run>
+ <Run Text="{Binding LatestVersion}"></Run>
+ <Run>is available !</Run>
+ </TextBlock>
+ </Button.ToolTip>
+ <Image Source="/Images/update.png" Width="32" RenderTransformOrigin="0.5,0.5" RenderOptions.BitmapScalingMode="Fant">
+ <Image.RenderTransform>
+ <ScaleTransform ScaleX="1" ScaleY="1" />
+ </Image.RenderTransform>
+ <Image.Style>
+ <Style TargetType="Image">
+ <Style.Triggers>
+ <EventTrigger RoutedEvent="Loaded">
+ <EventTrigger.Actions>
+ <BeginStoryboard>
+ <Storyboard>
+ <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX" From="0.9" To="1.1" Duration="00:00:0.5" RepeatBehavior="Forever" AutoReverse="True"></DoubleAnimation>
+ <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleY" From="0.9" To="1.1" Duration="00:00:0.5" RepeatBehavior="Forever" AutoReverse="True"></DoubleAnimation>
+ </Storyboard>
+ </BeginStoryboard>
+ </EventTrigger.Actions>
+ </EventTrigger>
+ </Style.Triggers>
+ </Style>
+ </Image.Style>
+ </Image>
+ </Button>
</StackPanel>
</Grid>
</Grid>
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/UpdateView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/UpdateView.xaml
index a08bcbddb..dabbaab94 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/UpdateView.xaml
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/UpdateView.xaml
@@ -17,7 +17,7 @@
<DockPanel>
<Grid DockPanel.Dock="Top" HorizontalAlignment="Center">
<Grid.Effect>
- <DropShadowEffect BlurRadius="100" ShadowDepth="0" Opacity="0.7" />
+ <DropShadowEffect BlurRadius="200" ShadowDepth="0" Opacity="0.5" />
</Grid.Effect>
<StackPanel Orientation="Horizontal">
<Image Source="/Images/update.png" Width="100" />
@@ -68,10 +68,14 @@
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<Image Source="/Images/new-version.png" Width="64"></Image>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
- <TextBlock VerticalAlignment="Center" Margin="0 20 0 0">New version is available!</TextBlock>
+ <TextBlock VerticalAlignment="Center" Margin="0 20 0 0">
+ <Run>Version</Run>
+ <Run Text="{Binding LatestVersion}" FontWeight="SemiBold" Foreground="{StaticResource AccentColorBrush}"></Run>
+ <Run>is available!</Run>
+ </TextBlock>
</StackPanel>
<TextBlock FontSize="12" TextAlignment="Center" Padding="20" Margin="0 0 0 40">
- <Run>A new version of Machine Studio is available to download</Run>
+ <Run>A new version of Machine Studio is available for download</Run>
<LineBreak/>
<Run>Click 'Update' to start the update process.</Run>
</TextBlock>
@@ -111,6 +115,8 @@
<Run>Updating Machine Studio, please wait...</Run>
</TextBlock>
<ProgressBar Height="10" Foreground="DimGray" Margin="0 20 0 0" Maximum="100" Value="{Binding UpdateProgress}"></ProgressBar>
+
+ <TextBlock TextTrimming="CharacterEllipsis" Text="{Binding CurrentUpdateFile}" FontSize="10" Margin="0 10 0 0" TextAlignment="Center" Foreground="DimGray"></TextBlock>
</StackPanel>
</Grid>
</Setter.Value>
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UpdateService/MachineStudioUpdateService.svc.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UpdateService/MachineStudioUpdateService.svc.cs
index bf737c7a9..2f001b281 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UpdateService/MachineStudioUpdateService.svc.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UpdateService/MachineStudioUpdateService.svc.cs
@@ -48,6 +48,12 @@ namespace Tango.MachineStudio.UpdateService
{
db.Configuration.LazyLoadingEnabled = false;
+ //Load relation first...
+ db.Roles.ToList();
+ db.Permissions.ToList();
+ db.UsersRoles.ToList();
+ db.RolesPermissions.ToList();
+
var user = db.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower() && x.Password == request.Password);
if (user != null && user.HasPermission(Permissions.RunMachineStudio))