aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2019-12-09 16:19:41 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2019-12-09 16:19:41 +0200
commitc7fa53084c674586ceee773ccbdc6b4c0a2ec7d4 (patch)
tree1642092f35d6e02de502909c3db97131e66bfaca /Software/Visual_Studio/MachineStudio
parentaeabb681d16451e191a1620d4eebf40549771491 (diff)
downloadTango-c7fa53084c674586ceee773ccbdc6b4c0a2ec7d4.tar.gz
Tango-c7fa53084c674586ceee773ccbdc6b4c0a2ec7d4.zip
Implemented full TUP package update !!!
Diffstat (limited to 'Software/Visual_Studio/MachineStudio')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Tango.MachineStudio.MachineDesigner.csproj8
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs8
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/TupViewVM.cs129
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineDetailsView.xaml3
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/TupView.xaml60
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/TupView.xaml.cs28
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj17
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tup/TupFileBuilder.cs285
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tup/TupFileBuilderProgressEventArgs.cs16
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/DownloadLatestPPCVersionRequest.cs14
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/DownloadLatestPPCVersionResponse.cs21
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClientBase.cs9
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/packages.config1
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj6
14 files changed, 603 insertions, 2 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Tango.MachineStudio.MachineDesigner.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Tango.MachineStudio.MachineDesigner.csproj
index 6225bd7ad..69cc75461 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Tango.MachineStudio.MachineDesigner.csproj
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Tango.MachineStudio.MachineDesigner.csproj
@@ -93,6 +93,7 @@
<Compile Include="ViewModels\MachineUpdatesViewVM.cs" />
<Compile Include="ViewModels\MachineVersionDialogVM.cs" />
<Compile Include="ViewModels\MainViewVM.cs" />
+ <Compile Include="ViewModels\TupViewVM.cs" />
<Compile Include="Views\ColorCalibrationView.xaml.cs">
<DependentUpon>ColorCalibrationView.xaml</DependentUpon>
</Compile>
@@ -130,6 +131,9 @@
<Compile Include="Views\MachineUpdatesView.xaml.cs">
<DependentUpon>MachineUpdatesView.xaml</DependentUpon>
</Compile>
+ <Compile Include="Views\TupView.xaml.cs">
+ <DependentUpon>TupView.xaml</DependentUpon>
+ </Compile>
<Compile Include="Views\SpoolsView.xaml.cs">
<DependentUpon>SpoolsView.xaml</DependentUpon>
</Compile>
@@ -185,6 +189,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
+ <Page Include="Views\TupView.xaml">
+ <Generator>MSBuild:Compile</Generator>
+ <SubType>Designer</SubType>
+ </Page>
<Page Include="Views\SpoolsView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs
index 820950290..768f93de1 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs
@@ -140,6 +140,12 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
set { _machineUpdatesViewVM = value; RaisePropertyChangedAuto(); }
}
+ private TupViewVM _tupViewVM;
+ public TupViewVM TupViewVM
+ {
+ get { return _tupViewVM; }
+ set { _tupViewVM = value; RaisePropertyChangedAuto(); }
+ }
#endregion
@@ -233,6 +239,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
ResetDeviceRegistrationCommand = new RelayCommand(ResetDeviceRegistration);
MachineUpdatesViewVM = new MachineUpdatesViewVM(_notification);
+ TupViewVM = new TupViewVM(_notification);
}
#endregion
@@ -478,6 +485,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
HardwareConfigurationViewVM.Init(ActiveMachine.Configuration);
await MachineUpdatesViewVM.Init(ActiveMachine, ActiveMachineAdapter.Context);
+ TupViewVM.Init(ActiveMachine);
ActiveMachine.Configuration.HardwareVersionChanged += Configuration_HardwareVersionChanged;
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/TupViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/TupViewVM.cs
new file mode 100644
index 000000000..12ed09c75
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/TupViewVM.cs
@@ -0,0 +1,129 @@
+using Microsoft.Win32;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.BL.Entities;
+using Tango.Core.Commands;
+using Tango.MachineStudio.Common.Notifications;
+using Tango.MachineStudio.Common.Tup;
+using Tango.SharedUI;
+
+namespace Tango.MachineStudio.MachineDesigner.ViewModels
+{
+ public class TupViewVM : ViewModel
+ {
+ private INotificationProvider _notification;
+
+ private String _latestVersion;
+ public String LatestVersion
+ {
+ get { return _latestVersion; }
+ set { _latestVersion = value; RaisePropertyChangedAuto(); }
+ }
+
+ private Machine _machine;
+ public Machine Machine
+ {
+ get { return _machine; }
+ set { _machine = value; RaisePropertyChangedAuto(); }
+ }
+
+ private String _filePath;
+ public String FilePath
+ {
+ get { return _filePath; }
+ set { _filePath = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
+ }
+
+ private TupFileBuilderProgressEventArgs _progress;
+ public TupFileBuilderProgressEventArgs Progress
+ {
+ get { return _progress; }
+ set { _progress = value; RaisePropertyChangedAuto(); }
+ }
+
+ public RelayCommand CreateTupFileCommand { get; set; }
+
+ public RelayCommand SelectFileCommand { get; set; }
+
+ public TupViewVM()
+ {
+
+ }
+
+ public TupViewVM(INotificationProvider notification) : this()
+ {
+ _notification = notification;
+ CreateTupFileCommand = new RelayCommand(CreateTupFile, () => FilePath != null && IsFree);
+ SelectFileCommand = new RelayCommand(SelectFile);
+ }
+
+ public void Init(Machine machine)
+ {
+ Machine = machine;
+ DisplayLatestPPCVersion();
+ }
+
+ private async void DisplayLatestPPCVersion()
+ {
+ TupFileBuilder builder = new TupFileBuilder();
+
+ try
+ {
+ LatestVersion = await builder.GetLatestPPCVersion(Machine.SerialNumber);
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error retrieving latest PPC version.");
+ await Task.Delay(5000);
+ DisplayLatestPPCVersion();
+ }
+ }
+
+ private void SelectFile()
+ {
+ SaveFileDialog dlg = new SaveFileDialog();
+ dlg.Title = "Select package location";
+ dlg.Filter = "Tango Update Package Files|*.tup";
+ dlg.DefaultExt = ".tup";
+ dlg.FileName = LatestVersion == null ? $"{Machine.SerialNumber}_Update.tup" : $"{Machine.SerialNumber}_Update_v{LatestVersion}.tup";
+
+ if (dlg.ShowDialog().Value)
+ {
+ FilePath = dlg.FileName;
+ }
+ }
+
+ private async void CreateTupFile()
+ {
+ try
+ {
+ LogManager.Log($"Generating TUP file to '{FilePath}'...");
+
+ IsFree = false;
+ TupFileBuilder builder = new TupFileBuilder();
+ builder.Progress += Builder_Progress;
+ await builder.Build(Machine.SerialNumber, FilePath);
+
+ LogManager.Log("TUP file generated successfully.");
+ _notification.ShowInfo("Tango update package created successfuly.");
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error generating tup file.");
+ _notification.ShowError($"An error occurred while generating the .tup file.\n{ex.FlattenMessage()}");
+ }
+ finally
+ {
+ IsFree = true;
+ }
+ }
+
+ private void Builder_Progress(object sender, TupFileBuilderProgressEventArgs e)
+ {
+ Progress = e;
+ }
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineDetailsView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineDetailsView.xaml
index 666a4ee4a..bcca83ca5 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineDetailsView.xaml
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineDetailsView.xaml
@@ -64,6 +64,9 @@
<TabItem Header="UPDATES">
<local:MachineUpdatesView/>
</TabItem>
+ <TabItem Header="TUP">
+ <local:TupView/>
+ </TabItem>
</TabControl>
</Grid>
</DockPanel>
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/TupView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/TupView.xaml
new file mode 100644
index 000000000..895a26ca0
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/TupView.xaml
@@ -0,0 +1,60 @@
+<UserControl x:Class="Tango.MachineStudio.MachineDesigner.Views.TupView"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:vm="clr-namespace:Tango.MachineStudio.MachineDesigner.ViewModels"
+ xmlns:global="clr-namespace:Tango.MachineStudio.MachineDesigner"
+ xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls"
+ xmlns:material="http://materialdesigninxaml.net/winfx/xaml/themes"
+ xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI"
+ xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
+ xmlns:local="clr-namespace:Tango.MachineStudio.MachineDesigner.Views"
+ mc:Ignorable="d"
+ d:DesignHeight="720" d:DesignWidth="1280" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}" Background="Transparent">
+
+ <Grid Margin="20" DataContext="{Binding TupViewVM}">
+ <DockPanel IsEnabled="{Binding IsFree}">
+ <Grid DockPanel.Dock="Bottom">
+
+ </Grid>
+
+ <Grid Margin="0 20">
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="38*"/>
+ <ColumnDefinition Width="117*"/>
+ </Grid.ColumnDefinitions>
+
+ <local:MachineView Margin="30 80 0 0" DataContext="{Binding Machine}" IsHitTestVisible="False" VerticalAlignment="Top" Height="241" />
+
+ <DockPanel Grid.Column="1" Margin="50 100 300 100">
+ <TextBlock DockPanel.Dock="Top">
+ <Run>Create a complete update package (.tup) in order to update this machine offline using a removable storage device.</Run>
+ <LineBreak/>
+ <Run>The latest PPC version is </Run>
+ <Run Foreground="{StaticResource AccentColorBrush}" FontWeight="SemiBold" Text="{Binding LatestVersion,FallbackValue='loading...',TargetNullValue='loading...'}"></Run>
+ </TextBlock>
+ <Grid Margin="0 20 0 0">
+ <Border Background="{StaticResource Transparent200}" CornerRadius="5" Padding="60" BorderThickness="1" BorderBrush="Silver">
+ <DockPanel>
+ <DockPanel DockPanel.Dock="Top" Height="40">
+ <Button Command="{Binding SelectFileCommand}" DockPanel.Dock="Right" BorderBrush="Silver" BorderThickness="1" Padding="0" Height="Auto" Width="40" Margin="5 0 0 0" Style="{StaticResource MaterialDesignFlatButton}">
+ <material:PackIcon Kind="Folder" />
+ </Button>
+ <TextBox materialDesign:HintAssist.Hint="Select package location" BorderBrush="Silver" BorderThickness="1" Text="{Binding FilePath}" IsReadOnly="True" VerticalContentAlignment="Center" Padding="10 0 0 0"></TextBox>
+ </DockPanel>
+ <StackPanel DockPanel.Dock="Bottom">
+ <TextBlock HorizontalAlignment="Center" Text="{Binding Progress.Message,FallbackValue='Ready',TargetNullValue='Ready'}"></TextBlock>
+ <ProgressBar Margin="0 10 0 0" Height="15" IsIndeterminate="{Binding Progress.IsIntermediate}" Value="{Binding Progress.Progress}" Maximum="{Binding Progress.Total}"></ProgressBar>
+ </StackPanel>
+ <Grid>
+ <Button Command="{Binding CreateTupFileCommand}" HorizontalAlignment="Center" VerticalAlignment="Center" Padding="20 10" Height="60" Width="300">GENERATE UPDATE PACKAGE</Button>
+ </Grid>
+ </DockPanel>
+ </Border>
+ </Grid>
+ </DockPanel>
+ </Grid>
+ </DockPanel>
+ </Grid>
+</UserControl>
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/TupView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/TupView.xaml.cs
new file mode 100644
index 000000000..fe01296d8
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/TupView.xaml.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace Tango.MachineStudio.MachineDesigner.Views
+{
+ /// <summary>
+ /// Interaction logic for SpoolsView.xaml
+ /// </summary>
+ public partial class TupView : UserControl
+ {
+ public TupView()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj
index 7c0851d01..3ce667afe 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj
@@ -59,6 +59,9 @@
<HintPath>..\..\Referenced Assemblies\SMO\Microsoft.SqlServer.AzureStorageEnum.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Storage, Version=4.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
+ <Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+ <HintPath>..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Data" />
@@ -83,6 +86,9 @@
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="..\..\PPC\Tango.PPC.Common\Publish\PublishInfo.cs">
+ <Link>Tup\PublishInfo.cs</Link>
+ </Compile>
<Compile Include="..\..\Versioning\GlobalVersionInfo.cs">
<Link>GlobalVersionInfo.cs</Link>
</Compile>
@@ -95,6 +101,10 @@
<Compile Include="Converters\UserRoleToVisibilityConverter.cs" />
<Compile Include="MachineStudioTheme.cs" />
<Compile Include="Resources\SharedResourceDictionary.cs" />
+ <Compile Include="Tup\TupFileBuilder.cs" />
+ <Compile Include="Tup\TupFileBuilderProgressEventArgs.cs" />
+ <Compile Include="Web\DownloadLatestPPCVersionRequest.cs" />
+ <Compile Include="Web\DownloadLatestPPCVersionResponse.cs" />
<Compile Include="Web\LoginRequest.cs" />
<Compile Include="Web\LoginResponse.cs" />
<Compile Include="AutoComplete\MachinesProvider.cs" />
@@ -291,6 +301,10 @@
<Project>{8491d07b-c1f6-4b62-a412-41b9fd2d6538}</Project>
<Name>Tango.SharedUI</Name>
</ProjectReference>
+ <ProjectReference Include="..\..\Tango.SQLExaminer\Tango.SQLExaminer.csproj">
+ <Project>{e1e66ed9-597d-45fa-8048-de90a6930484}</Project>
+ <Name>Tango.SQLExaminer</Name>
+ </ProjectReference>
<ProjectReference Include="..\..\Tango.Transport\Tango.Transport.csproj">
<Project>{74e700b0-1156-4126-be40-ee450d3c3026}</Project>
<Name>Tango.Transport</Name>
@@ -387,10 +401,11 @@
<ItemGroup>
<Resource Include="Images\ti-tm4c129x.png" />
</ItemGroup>
+ <ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
- <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" />
+ <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" />
</VisualStudio>
</ProjectExtensions>
</Project> \ No newline at end of file
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tup/TupFileBuilder.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tup/TupFileBuilder.cs
new file mode 100644
index 000000000..6dd8b82f7
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tup/TupFileBuilder.cs
@@ -0,0 +1,285 @@
+using Ionic.Zip;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using Tango.BL;
+using Tango.Core;
+using Tango.Core.DB;
+using Tango.Core.DI;
+using Tango.MachineStudio.Common.Web;
+using Tango.SQLExaminer;
+using Tango.Transport.Web;
+using Tango.Core.ExtensionMethods;
+using Tango.PPC.Common.Publish;
+using Tango.Settings;
+using Tango.Core.Components;
+using System.Text.RegularExpressions;
+
+namespace Tango.MachineStudio.Common.Tup
+{
+ public class TupFileBuilder : ExtendedObject
+ {
+ public event EventHandler<TupFileBuilderProgressEventArgs> Progress;
+
+ public Task Build(String serialNumber, String filePath)
+ {
+ return Task.Factory.StartNew(() =>
+ {
+ String tempDbName = "Tango_TUP";
+ var tempPackageFolder = TemporaryManager.CreateFolder();
+ String tempBackupFolder = "C:\\MachineStudioTUP";
+ String tempBackupFile = Path.Combine(tempBackupFolder, tempDbName + ".bak");
+ var tempZipFile = TemporaryManager.CreateImaginaryFile();
+ DbManager dbManager = null;
+
+ LogManager.Log("Generating tup file...");
+ LogManager.Log($"Tup file: '{filePath}.'");
+ LogManager.Log($"Temporary db name: '{tempDbName}'.");
+ LogManager.Log($"Temporary package folder: '{tempPackageFolder}'.");
+ LogManager.Log($"Temporary db backup folder: '{tempBackupFolder}'.");
+ LogManager.Log($"Temporary db backup file: '{tempBackupFile}'.");
+ LogManager.Log($"Temporary zip file: '{tempZipFile}'.");
+
+ try
+ {
+ LogManager.Log("Initializing...");
+
+ OnProgress("Initializing...");
+
+ Core.DataSource localDataSource = new Core.DataSource()
+ {
+ Address = "localhost\\SQLEXPRESS",
+ IntegratedSecurity = true,
+ Type = DataSourceType.SQLServer,
+ Catalog = null,
+ };
+
+ try
+ {
+ LogManager.Log($"Trying to connect via SQLEXPRESS:\n{localDataSource.ToJsonString()}");
+ dbManager = DbManager.FromDataSource(localDataSource);
+ }
+ catch (Exception ex)
+ {
+ try
+ {
+ LogManager.Log(ex, "Could not connect using SQLEXPRESS. Trying local DB...");
+
+ CmdCommand command = new CmdCommand("sqllocaldb", "info \"MSSQLLocalDB\"");
+ var result = command.Run().Result;
+
+ String pattern = "np:.+";
+ Regex reg = new Regex(pattern);
+ var match = reg.Match(result.StandardOutput);
+ String address = match.ToString();
+ if (address.Contains("np:"))
+ {
+ localDataSource.Address = address;
+ address = address.Trim().Replace("\r", "");
+ }
+ else
+ {
+ throw new ArgumentException("Could not parse LocalDB address string.");
+ }
+
+ LogManager.Log($"Trying to connect via LocalDB:\n{localDataSource.ToJsonString()}");
+ dbManager = DbManager.FromDataSource(localDataSource);
+ }
+ catch (Exception x)
+ {
+ LogManager.Log(x, "Could not find any database service for this operation.");
+ throw x;
+ }
+ }
+
+
+
+ OnProgress("Downloading latest PPC version...");
+
+ LogManager.Log("Connecting to machine service...");
+ MachineStudioWebClient client = TangoIOC.Default.GetInstance<MachineStudioWebClient>();
+
+ LogManager.Log("Requesting latest PPC version from machine service...");
+ var response = client.DownloadLatestPPCVersion(new DownloadLatestPPCVersionRequest() { SerialNumber = serialNumber }).Result;
+
+ LogManager.Log($"Machine service response:\n{response.ToJsonString()}");
+
+ var remoteDataSource = response.DataSource;
+
+ using (AutoFileDownloader downloader = new AutoFileDownloader(response.BlobAddress, response.CdnAddress, tempZipFile))
+ {
+ downloader.Progress += (x, e) =>
+ {
+ OnProgress($"Downloading latest PPC version '{response.Version}'...", false, e.Current, e.Total);
+ };
+
+ downloader.ResolveMode().GetAwaiter().GetResult();
+
+ LogManager.Log($"Downloading latest PPC version from: '{downloader.Address}'");
+
+ downloader.Download().Wait();
+ }
+
+ LogManager.Log("Extracting PPC version package...");
+
+ OnProgress("Extracting PPC package...");
+
+ using (ZipFile zip = new ZipFile(tempZipFile))
+ {
+ int currentEntry = 0;
+
+ zip.ExtractProgress += (x, args) =>
+ {
+ if (args.EventType == ZipProgressEventType.Extracting_AfterExtractEntry)
+ {
+ OnProgress("Extracting PPC package...", false, currentEntry++, zip.Entries.Count);
+ }
+ };
+
+ zip.ExtractAll(tempPackageFolder);
+ }
+
+ OnProgress("Extracting version information...");
+ LogManager.Log("Extracting publish information...");
+ PublishInfo publishInfo = PublishInfo.FromJson(File.ReadAllText(Path.Combine(tempPackageFolder, "version.json")));
+ LogManager.Log($"Publish Information:\n{publishInfo}");
+
+ LogManager.Log("Modifying publish information to custom tup file...");
+ publishInfo.IsMachineTupPackage = true;
+ publishInfo.MachineSerialNumber = serialNumber;
+ publishInfo.MachineDeploymentSlot = SettingsManager.Default.GetOrCreate<MachineStudioSettings>().DeploymentSlot;
+
+ OnProgress("Creating temporary database...");
+
+ LogManager.Log($"Creating temporary db backup directory '{tempBackupFolder}'");
+
+ Directory.CreateDirectory(tempBackupFolder);
+
+ LogManager.Log($"Creating new database: '{tempDbName}'");
+
+ //Create temp db
+ dbManager.Create(tempDbName, Path.Combine(tempBackupFolder, tempDbName + ".mdf"));
+
+ OnProgress("Generating database snapshot...");
+
+ LogManager.Log("Starting database synchronization...");
+
+ Thread.Sleep(2000);
+
+ localDataSource.Catalog = tempDbName;
+
+ ExaminerSequenceConfigurationRunner runner = new ExaminerSequenceConfigurationRunner(
+ Path.Combine(tempPackageFolder, "Provision Scripts", "config.xml"),
+ Path.Combine(tempPackageFolder, "Provision Scripts"),
+ remoteDataSource,
+ localDataSource,
+ serialNumber);
+
+ runner.ScriptExecuting += (x, item) =>
+ {
+ LogManager.Log($"Executing script '{item.FileName}'...");
+ OnProgress($"{item.Name}...");
+ };
+
+ runner.Log += (x, log) =>
+ {
+ LogManager.Log(log);
+ };
+
+ runner.Run().GetAwaiter().GetResult();
+
+ OnProgress("Generating database snapshot...");
+
+ if (File.Exists(tempBackupFile))
+ {
+ LogManager.Log($"Deleting file '{tempBackupFile}'");
+ File.Delete(tempBackupFile);
+ }
+
+ LogManager.Log($"Generating backup for '{tempDbName}' to '{tempBackupFile}'...");
+
+ dbManager.Backup(tempDbName, tempBackupFile);
+
+ OnProgress("Injecting database snapshot to PPC package...");
+
+ using (ZipFile zip = new ZipFile(tempZipFile))
+ {
+ LogManager.Log($"Injecting file '{tempBackupFile}' to original package at '{tempZipFile}'...");
+ zip.AddFile(tempBackupFile, "/");
+
+ LogManager.Log($"Injecting modified publish information...");
+ zip.UpdateEntry("version.json", publishInfo.ToJson());
+
+ zip.Save();
+ }
+
+ LogManager.Log($"Copying '{tempZipFile}' to '{filePath}'...");
+
+ File.Copy(tempZipFile, filePath, true);
+
+ OnProgress("Completed", false, 100, 100);
+
+ LogManager.Log("TUP file generation completed successfully.");
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "TUP file generation failed.");
+ OnProgress("Failed", false, 0, 100);
+ throw ex;
+ }
+ finally
+ {
+ LogManager.Log($"Removing '{tempZipFile}'.");
+ tempZipFile.Delete();
+ LogManager.Log($"Removing '{tempPackageFolder}'.");
+ tempPackageFolder.Delete();
+
+ try
+ {
+ LogManager.Log($"Removing database '{tempDbName}'.");
+ dbManager.SetOffline(tempDbName);
+ dbManager.SetOnline(tempDbName);
+ dbManager.Delete(tempDbName);
+ dbManager.Dispose();
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, $"Error removing temp database '{tempDbName}'.");
+ }
+
+ try
+ {
+ LogManager.Log($"Removing '{tempBackupFolder}'.");
+ Directory.Delete(tempBackupFolder, true);
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, $"Error removing folder '{tempBackupFolder}'.");
+ }
+ }
+ });
+ }
+
+ public async Task<String> GetLatestPPCVersion(String serialNumber)
+ {
+ MachineStudioWebClient client = TangoIOC.Default.GetInstance<MachineStudioWebClient>();
+ var response = await client.DownloadLatestPPCVersion(new DownloadLatestPPCVersionRequest() { SerialNumber = serialNumber });
+ return response.Version;
+ }
+
+ private void OnProgress(String message, bool isIntermediate = true, double progress = 0, double total = 100)
+ {
+ Progress?.Invoke(this, new TupFileBuilderProgressEventArgs()
+ {
+ Message = message,
+ IsIntermediate = isIntermediate,
+ Progress = progress,
+ Total = total,
+ });
+ }
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tup/TupFileBuilderProgressEventArgs.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tup/TupFileBuilderProgressEventArgs.cs
new file mode 100644
index 000000000..ada69dd40
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tup/TupFileBuilderProgressEventArgs.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.MachineStudio.Common.Tup
+{
+ public class TupFileBuilderProgressEventArgs
+ {
+ public double Progress { get; set; }
+ public double Total { get; set; }
+ public bool IsIntermediate { get; set; }
+ public String Message { get; set; }
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/DownloadLatestPPCVersionRequest.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/DownloadLatestPPCVersionRequest.cs
new file mode 100644
index 000000000..24d465e69
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/DownloadLatestPPCVersionRequest.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Transport.Web;
+
+namespace Tango.MachineStudio.Common.Web
+{
+ public class DownloadLatestPPCVersionRequest : WebRequestMessage
+ {
+ public String SerialNumber { get; set; }
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/DownloadLatestPPCVersionResponse.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/DownloadLatestPPCVersionResponse.cs
new file mode 100644
index 000000000..2cc6b731a
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/DownloadLatestPPCVersionResponse.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Core;
+using Tango.Transport.Web;
+
+namespace Tango.MachineStudio.Common.Web
+{
+ public class DownloadLatestPPCVersionResponse : WebResponseMessage
+ {
+ public String Version { get; set; }
+
+ public String BlobAddress { get; set; }
+
+ public String CdnAddress { get; set; }
+
+ public DataSource DataSource { get; set; }
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClientBase.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClientBase.cs
index 131f89515..c2d0dd3e6 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClientBase.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClientBase.cs
@@ -94,5 +94,14 @@ namespace Tango.MachineStudio.Common.Web
return Post<Tango.MachineStudio.Common.Web.RefreshTokenRequest, Tango.MachineStudio.Common.Web.RefreshTokenResponse>("RefreshToken", request);
}
+ /// <summary>
+ /// Executes the DownloadLatestPPCVersion action and returns Tango.MachineStudio.Common.Web.DownloadLatestPPCVersionResponse.
+ /// </summary>
+ /// <returns></returns>
+ public Task<Tango.MachineStudio.Common.Web.DownloadLatestPPCVersionResponse> DownloadLatestPPCVersion(Tango.MachineStudio.Common.Web.DownloadLatestPPCVersionRequest request)
+ {
+ return Post<Tango.MachineStudio.Common.Web.DownloadLatestPPCVersionRequest, Tango.MachineStudio.Common.Web.DownloadLatestPPCVersionResponse>("DownloadLatestPPCVersion", request);
+ }
+
}
}
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/packages.config b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/packages.config
index f871776f5..6fd5091a8 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/packages.config
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/packages.config
@@ -9,4 +9,5 @@
<package id="MahApps.Metro" version="1.5.0" targetFramework="net46" />
<package id="MaterialDesignColors" version="1.1.2" targetFramework="net46" />
<package id="MaterialDesignThemes" version="2.3.1.953" targetFramework="net46" />
+ <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net461" />
</packages> \ No newline at end of file
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj
index 991eb9da6..c6cf624b3 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj
@@ -448,6 +448,10 @@
<Project>{8491d07b-c1f6-4b62-a412-41b9fd2d6538}</Project>
<Name>Tango.SharedUI</Name>
</ProjectReference>
+ <ProjectReference Include="..\..\Tango.SQLExaminer\Tango.SQLExaminer.csproj">
+ <Project>{e1e66ed9-597d-45fa-8048-de90a6930484}</Project>
+ <Name>Tango.SQLExaminer</Name>
+ </ProjectReference>
<ProjectReference Include="..\..\Tango.TFS\Tango.TFS.csproj">
<Project>{998f8471-dc1b-41b6-9d96-354e1b4e7a32}</Project>
<Name>Tango.TFS</Name>
@@ -661,7 +665,7 @@ if $(ConfigurationName) == Release RD /S /Q "$(TargetDir)ProtoCompilers\"</PostB
</Target>
<ProjectExtensions>
<VisualStudio>
- <UserProperties BuildVersion_UseGlobalSettings="False" BuildVersion_DetectChanges="True" BuildVersion_UpdateFileVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.DeltaBaseYearDayOfYear" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_StartDate="2000/1/1" />
+ <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_BuildVersioningStyle="None.None.Increment.DeltaBaseYearDayOfYear" BuildVersion_UpdateFileVersion="True" BuildVersion_DetectChanges="True" BuildVersion_UseGlobalSettings="False" />
</VisualStudio>
</ProjectExtensions>
</Project> \ No newline at end of file