aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-08-29 11:49:53 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-08-29 11:49:53 +0300
commitc7c4975fd0010fc666c467105a39b1cd93cb818d (patch)
treed1c2a9e2cc67826c029570a4fd746abe3ce0b88c /Software/Visual_Studio/MachineStudio
parent33a2d098936cad4e7a8ca0c16187023a78fc4e43 (diff)
downloadTango-c7c4975fd0010fc666c467105a39b1cd93cb818d.tar.gz
Tango-c7c4975fd0010fc666c467105a39b1cd93cb818d.zip
Added restore to previous version support.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio')
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Properties/AssemblyInfo.cs2
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs160
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/UpdateView.xaml74
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/MainWindow.xaml2
4 files changed, 234 insertions, 4 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Properties/AssemblyInfo.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Properties/AssemblyInfo.cs
index 2c31c002f..224cd3199 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Properties/AssemblyInfo.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Properties/AssemblyInfo.cs
@@ -4,5 +4,5 @@ using System.Runtime.InteropServices;
[assembly: System.Windows.ThemeInfo(System.Windows.ResourceDictionaryLocation.None, System.Windows.ResourceDictionaryLocation.SourceAssembly)]
[assembly: AssemblyTitle("Tango - Machine Studio")]
-[assembly: AssemblyVersion("3.3.38.18238")]
+[assembly: AssemblyVersion("3.3.39.18238")]
[assembly: ComVisible(false)] \ No newline at end of file
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 c5831f701..55f585626 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs
@@ -35,6 +35,9 @@ namespace Tango.MachineStudio.UI.ViewModels
Updating,
UpdateCompleted,
Error,
+ RollingBack,
+ RollbackCompleted,
+ RollbackError,
}
public class UpdateViewVM : ViewModel
@@ -48,6 +51,7 @@ namespace Tango.MachineStudio.UI.ViewModels
private IAuthenticationProvider _authentication;
private CheckForUpdatesResponse _updateInfo;
private TemporaryFolder _newPackageTempFolder;
+ private TemporaryFolder _previousPackageTempFolder;
private bool _forcedUpdate;
public bool ForcedUpdate
@@ -88,6 +92,14 @@ namespace Tango.MachineStudio.UI.ViewModels
set { _downloadProgress = value; RaisePropertyChangedAuto(); }
}
+ private double _rollbackProgress;
+
+ public double RollbackProgress
+ {
+ get { return _rollbackProgress; }
+ set { _rollbackProgress = value; RaisePropertyChangedAuto(); }
+ }
+
private double _updateProgress;
public double UpdateProgress
@@ -104,6 +116,14 @@ namespace Tango.MachineStudio.UI.ViewModels
set { _currentUpdateFile = value; RaisePropertyChanged(nameof(CurrentUpdateFile)); }
}
+ private bool _isRollbackAvailable;
+
+ public bool IsRollbackAvailable
+ {
+ get { return _isRollbackAvailable; }
+ set { _isRollbackAvailable = value; RaisePropertyChangedAuto(); }
+ }
+
public RelayCommand UpdateCommand { get; set; }
public RelayCommand BackCommand { get; set; }
@@ -112,6 +132,10 @@ namespace Tango.MachineStudio.UI.ViewModels
public RelayCommand TryAgainCommand { get; set; }
+ public RelayCommand RollbackCommand { get; set; }
+
+ public RelayCommand TryRollbackAgainCommand { get; set; }
+
public UpdateViewVM(INotificationProvider notification, IAuthenticationProvider authentication, INavigationManager navigation, IStudioApplicationManager application)
{
_notification = notification;
@@ -123,8 +147,12 @@ namespace Tango.MachineStudio.UI.ViewModels
Status = UpdateStatus.CheckingForUpdate;
UpdateCommand = new RelayCommand(StartUpdate, () => Status == UpdateStatus.UpdateAvailable);
BackCommand = new RelayCommand(BackToApplication, () => Status != UpdateStatus.Updating && !ForcedUpdate);
- RestartCommand = new RelayCommand(RestartApplication, () => Status == UpdateStatus.UpdateCompleted);
+ RestartCommand = new RelayCommand(RestartApplication, () => Status == UpdateStatus.UpdateCompleted || Status == UpdateStatus.RollbackCompleted);
TryAgainCommand = new RelayCommand(TryAgain, () => Status == UpdateStatus.Error);
+ RollbackCommand = new RelayCommand(Rollback, () => Status != UpdateStatus.RollingBack && !ForcedUpdate);
+ TryRollbackAgainCommand = new RelayCommand(TryRollbackAgain, () => Status == UpdateStatus.RollbackError);
+
+ IsRollbackAvailable = File.Exists(GetRollbackFile());
TangoMessenger.Default.Register<Messages.ForcedUpdateMessage>(HandleForcedUpdateMessage);
}
@@ -294,6 +322,41 @@ namespace Tango.MachineStudio.UI.ViewModels
}
}
+ try
+ {
+ LogManager.Log("Backing up current version...");
+ CurrentUpdateFile = "Backing up current version...";
+
+ String rollbackFolder = GetRollbackFolder();
+ Directory.CreateDirectory(rollbackFolder);
+
+ String backFile = GetRollbackFile();
+
+ if (File.Exists(backFile))
+ {
+ File.Delete(backFile);
+ }
+
+ using (ZipFile backZip = new ZipFile(backFile))
+ {
+ int currentEntry = 0;
+
+ backZip.SaveProgress += (_, e) =>
+ {
+ UpdateProgress = ((double)(currentEntry++) / (double)backZip.Entries.Count) * 100d;
+ };
+
+ backZip.Password = "Aa123456";
+ backZip.AddDirectory(_appPath);
+ backZip.Save();
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Could not construct rollback.");
+ _notification.ShowWarning("Update center has failed to construct a rollback point for the current version. Version rollback will not be available.");
+ }
+
TangoIOC.Default.GetInstance<MainViewVM>().DisableCheckForUpdates = true;
Status = UpdateStatus.UpdateCompleted;
}
@@ -319,7 +382,16 @@ namespace Tango.MachineStudio.UI.ViewModels
try
{
Process p = new Process();
- p.StartInfo.FileName = _newPackageTempFolder + "\\Tango.MachineStudio.Updater.exe";
+
+ if (Status == UpdateStatus.UpdateCompleted)
+ {
+ p.StartInfo.FileName = _newPackageTempFolder + "\\Tango.MachineStudio.Updater.exe";
+ }
+ else if (Status == UpdateStatus.RollbackCompleted)
+ {
+ p.StartInfo.FileName = _previousPackageTempFolder + "\\Tango.MachineStudio.Updater.exe";
+ }
+
p.StartInfo.UseShellExecute = true;
p.StartInfo.Arguments = _appPath;
p.Start();
@@ -335,6 +407,90 @@ namespace Tango.MachineStudio.UI.ViewModels
Environment.Exit(0);
}
+ private void Rollback()
+ {
+ if (_notification.ShowQuestion("Are you sure you want to restore the previous version?"))
+ {
+ Status = UpdateStatus.RollingBack;
+
+ try
+ {
+ Task.Factory.StartNew(() =>
+ {
+ _previousPackageTempFolder = TemporaryManager.CreateFolder();
+ _previousPackageTempFolder.Persist = true;
+
+ using (ZipFile zip = new ZipFile(GetRollbackFile()))
+ {
+ zip.Password = "Aa123456";
+
+ int currentEntry = 0;
+
+ zip.ExtractProgress += (x, args) =>
+ {
+ if (args.EventType == ZipProgressEventType.Extracting_AfterExtractEntry)
+ {
+ logManager.Log("Extracting " + Path.GetFileName(args.CurrentEntry.FileName));
+ RollbackProgress = ((double)(currentEntry++) / (double)zip.Entries.Count) * 100d;
+ }
+ };
+
+ foreach (ZipEntry entry in zip)
+ {
+ Thread.Sleep(10);
+
+ string newPath = Path.Combine(_previousPackageTempFolder.Path, entry.FileName);
+
+ try
+ {
+ if (entry.IsDirectory)
+ {
+ Directory.CreateDirectory(newPath);
+ }
+ else
+ {
+ entry.Extract(_previousPackageTempFolder.Path, ExtractExistingFileAction.OverwriteSilently);
+ }
+ }
+ catch
+ {
+ logManager.Log("Could not extract file " + entry.FileName);
+ }
+ }
+
+ }
+
+ File.Delete(GetRollbackFile());
+
+ Status = UpdateStatus.RollbackCompleted;
+ });
+ }
+ catch (Exception ex)
+ {
+ Status = UpdateStatus.Error;
+ LogManager.Log(ex, "Error while trying to restore version.");
+ _notification.ShowError("An error occurred while trying to restore the previous version.");
+ }
+ }
+ }
+
+ private void TryRollbackAgain()
+ {
+ CheckForUpdates();
+ }
+
+ private String GetRollbackFolder()
+ {
+ String rollbackFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Twine", "Tango", "Rollback");
+ return rollbackFolder;
+ }
+
+ private String GetRollbackFile()
+ {
+ String backFile = Path.Combine(GetRollbackFolder(), Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.FriendlyName) + ".rollback");
+ return backFile;
+ }
+
protected override void RaisePropertyChangedAuto([CallerMemberName] string caller = null)
{
base.RaisePropertyChangedAuto(caller);
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 52ba9ee18..6818d13cc 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/UpdateView.xaml
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/UpdateView.xaml
@@ -108,6 +108,13 @@
<TextBlock Margin="5 0 0 0" VerticalAlignment="Center">UPDATE</TextBlock>
</StackPanel>
</Button>
+
+ <Button Visibility="{Binding IsRollbackAvailable,Converter={StaticResource BoolToVisConverter}}" MinWidth="140" Height="40" Style="{StaticResource MaterialDesignFlatButton}" ToolTip="Restore Machine Studio to the previous version." Margin="0 40 0 0" Command="{Binding RollbackCommand}" Foreground="#FF5F5F">
+ <StackPanel Orientation="Horizontal">
+ <materialDesign:PackIcon Kind="BackupRestore" Width="24" Height="24" />
+ <TextBlock Margin="5 0 0 0" VerticalAlignment="Center">Restore previous version</TextBlock>
+ </StackPanel>
+ </Button>
</StackPanel>
</Grid>
</Setter.Value>
@@ -177,6 +184,13 @@
<StackPanel Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" Margin="0 20 0 0">Your version of Machine Studio is up to date!</TextBlock>
</StackPanel>
+
+ <Button Visibility="{Binding IsRollbackAvailable,Converter={StaticResource BoolToVisConverter}}" MinWidth="140" Height="40" Style="{StaticResource MaterialDesignFlatButton}" ToolTip="Restore Machine Studio to the previous version." Margin="0 40 0 0" Command="{Binding RollbackCommand}" Foreground="#FF5F5F">
+ <StackPanel Orientation="Horizontal">
+ <materialDesign:PackIcon Kind="BackupRestore" Width="24" Height="24" />
+ <TextBlock Margin="5 0 0 0" VerticalAlignment="Center">Restore previous version</TextBlock>
+ </StackPanel>
+ </Button>
</StackPanel>
</Grid>
</Setter.Value>
@@ -205,6 +219,66 @@
</Setter.Value>
</Setter>
</DataTrigger>
+ <DataTrigger Binding="{Binding Status}" Value="{x:Static vm:UpdateStatus.RollingBack}">
+ <Setter Property="Content">
+ <Setter.Value>
+ <Grid>
+ <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
+ <TextBlock HorizontalAlignment="Center">
+ <Run>Restoring previous version, please wait...</Run>
+ </TextBlock>
+ <ProgressBar Height="10" Foreground="DimGray" Margin="0 20 0 0" Maximum="100" Value="{Binding RollbackProgress}"></ProgressBar>
+ </StackPanel>
+ </Grid>
+ </Setter.Value>
+ </Setter>
+ </DataTrigger>
+ <DataTrigger Binding="{Binding Status}" Value="{x:Static vm:UpdateStatus.RollbackError}">
+ <Setter Property="Content">
+ <Setter.Value>
+ <Grid>
+ <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
+ <materialDesign:PackIcon Kind="Alert" Width="100" Height="100" Foreground="#FF5F5F" HorizontalAlignment="Center" />
+ <TextBlock VerticalAlignment="Center" Margin="0 20 0 0" HorizontalAlignment="Center">Error restoring previous version</TextBlock>
+ <TextBlock HorizontalAlignment="Center" Margin="0 10 0 0" FontSize="12" TextAlignment="Center">
+ <Run>An error occurred while restore the last version.</Run>
+ <LineBreak/>
+ <Run>press 'Try Again' to give it another try.</Run>
+ </TextBlock>
+ <Button MinWidth="140" Height="40" Margin="0 50 0 0" Width="200" Command="{Binding TryRollbackAgainCommand}">
+ <StackPanel Orientation="Horizontal">
+ <materialDesign:PackIcon Kind="BackupRestore" Width="24" Height="24" />
+ <TextBlock Margin="5 0 0 0" VerticalAlignment="Center">TRY AGAIN</TextBlock>
+ </StackPanel>
+ </Button>
+ </StackPanel>
+ </Grid>
+ </Setter.Value>
+ </Setter>
+ </DataTrigger>
+ <DataTrigger Binding="{Binding Status}" Value="{x:Static vm:UpdateStatus.RollbackCompleted}">
+ <Setter Property="Content">
+ <Setter.Value>
+ <Grid>
+ <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
+ <materialDesign:PackIcon Kind="Check" Width="100" Height="100" Foreground="#1CBB1C" HorizontalAlignment="Center" />
+ <StackPanel Orientation="Horizontal">
+ <TextBlock VerticalAlignment="Center" Margin="0 20 0 0">Machine studio has been restored to the previous version!</TextBlock>
+ </StackPanel>
+
+ <TextBlock HorizontalAlignment="Center" Margin="0 10 0 0" FontSize="12">Please restart Machine Studio in order to apply the changes.</TextBlock>
+
+ <Button MinWidth="140" Height="40" Margin="0 50 0 0" Width="200" Command="{Binding RestartCommand}">
+ <StackPanel Orientation="Horizontal">
+ <materialDesign:PackIcon Kind="BackupRestore" Width="24" Height="24" />
+ <TextBlock Margin="5 0 0 0" VerticalAlignment="Center">RESTART</TextBlock>
+ </StackPanel>
+ </Button>
+ </StackPanel>
+ </Grid>
+ </Setter.Value>
+ </Setter>
+ </DataTrigger>
</Style.Triggers>
</Style>
</ContentControl.Style>
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/MainWindow.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/MainWindow.xaml
index e254d289b..f78749fe2 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/MainWindow.xaml
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/MainWindow.xaml
@@ -28,7 +28,7 @@
<Grid Grid.Row="1">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<Image Source="/Images/update.png" Width="100" />
- <TextBlock x:Name="txtStatus" Margin="0 20 0 0" FontSize="16" Text="Updating Machine Studio..." HorizontalAlignment="Center"></TextBlock>
+ <TextBlock x:Name="txtStatus" Margin="0 20 0 0" FontSize="14" Text="Updating Machine Studio..." HorizontalAlignment="Center"></TextBlock>
<ProgressBar x:Name="prog" Margin="0 30 0 0" Width="500" Height="10" Maximum="100" Value="0" Foreground="#0288D1"></ProgressBar>
</StackPanel>
</Grid>