diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2017-12-27 13:16:00 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2017-12-27 13:16:00 +0200 |
| commit | af8530c50d90c12ebe60383e67101920760c314f (patch) | |
| tree | 53e8f091a3cd8dc2235b38db527ef7798b9c347c /Software/Visual_Studio/MachineStudio | |
| parent | 9d12fd0ba222619dd5b42816ed004c7b762809dd (diff) | |
| download | Tango-af8530c50d90c12ebe60383e67101920760c314f.tar.gz Tango-af8530c50d90c12ebe60383e67101920760c314f.zip | |
Fixed issue with local sync SQL Logic error.
Added some missing columns to SQLite db.
Direct Remote Sync is fully working !!!
Diffstat (limited to 'Software/Visual_Studio/MachineStudio')
4 files changed, 45 insertions, 11 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/Tango.MachineStudio.Synchronization.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/Tango.MachineStudio.Synchronization.csproj index bc47bbb0b..3c03f1e48 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/Tango.MachineStudio.Synchronization.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/Tango.MachineStudio.Synchronization.csproj @@ -171,7 +171,7 @@ </EmbeddedResource> <Content Include="..\..\..\..\DB\Tango.db"> <Link>Tango.db</Link> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> <None Include="App.config" /> <None Include="packages.config" /> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/DirectSynchronizationViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/DirectSynchronizationViewVM.cs index f265fafe7..cfa21a416 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/DirectSynchronizationViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/DirectSynchronizationViewVM.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Data.Entity.Validation; using System.IO; using System.Linq; using System.Text; @@ -29,7 +30,7 @@ namespace Tango.MachineStudio.Synchronization.ViewModels private String _masterDBFile; private LocalDBComparer _comparer; private INotificationProvider _notification; - private bool _isWorking; + private String _comparedSerialNumber; public IStudioApplicationManager ApplicationManager { get; set; } @@ -44,8 +45,8 @@ namespace Tango.MachineStudio.Synchronization.ViewModels Differences = new ObservableCollection<Diff>(); - CompareCommand = new RelayCommand(Compare, (x) => !_isWorking && SelectedMachine != null); - CommitAllCommand = new RelayCommand(Synchronize, (x) => Differences.Count > 0 && !_isWorking && SelectedMachine != null); + CompareCommand = new RelayCommand(Compare, (x) => !IsWorking && SelectedMachine != null); + CommitAllCommand = new RelayCommand(Synchronize, (x) => Differences.Count > 0 && !IsWorking && SelectedMachine != null); } #region Commands @@ -89,6 +90,16 @@ namespace Tango.MachineStudio.Synchronization.ViewModels #region Properties + private bool _isWorking; + /// <summary> + /// Gets or sets a value indicating whether this instance is working. + /// </summary> + public bool IsWorking + { + get { return _isWorking; } + set { _isWorking = value; RaisePropertyChangedAuto(); } + } + private bool _isClearMachine; /// <summary> /// Gets or sets a value indicating whether this instance is clear machine. @@ -151,7 +162,7 @@ namespace Tango.MachineStudio.Synchronization.ViewModels { try { - _isWorking = true; + IsWorking = true; InvalidateRelayCommands(); Thread.Sleep(1500); @@ -176,6 +187,8 @@ namespace Tango.MachineStudio.Synchronization.ViewModels //Synchronize the SQL Server db with the new SQLite template. (Overwrite basically) RemoteDBSynchronizer.Synchronize(_masterDBFile, SelectedMachine.SerialNumber, true); + _comparedSerialNumber = SelectedMachine.SerialNumber; + using (_notification.PushTaskItem("Comparing database...")) { _comparer = new LocalDBComparer(new SQLiteDataBase(_masterDBFile), new SQLiteDataBase(_slaveDBFile)); @@ -194,13 +207,24 @@ namespace Tango.MachineStudio.Synchronization.ViewModels } } } + catch (DbEntityValidationException ex) + { + String message = "The following validation errors occurred." + Environment.NewLine + Environment.NewLine; + + foreach (var error in ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).ToList()) + { + message += error.ErrorMessage + Environment.NewLine; + } + + ShowError(message); + } catch (Exception ex) { ShowError(ex.Message); } finally { - _isWorking = false; + IsWorking = false; SelectedDifference = null; InvalidateRelayCommands(); } @@ -218,13 +242,19 @@ namespace Tango.MachineStudio.Synchronization.ViewModels } } + if (SelectedMachine.SerialNumber != _comparedSerialNumber) + { + _notification.ShowError("You have selected a different machine serial number after comparing. Please compare again if you wish to synchronize a different machine."); + return; + } + Task.Factory.StartNew(async () => { using (_notification.PushTaskItem("Synchronizing...")) { try { - _isWorking = true; + IsWorking = true; InvalidateRelayCommands(); Thread.Sleep(1500); @@ -252,6 +282,9 @@ namespace Tango.MachineStudio.Synchronization.ViewModels } else { + //Synchronize the SQL Server db with the synchronized master DB. + RemoteDBSynchronizer.Synchronize(_masterDBFile, _comparedSerialNumber, false); + PathHelper.TryDeleteFile(_slaveDBFile); PathHelper.TryDeleteFile(_masterDBFile); _slaveDBFile = null; @@ -265,7 +298,7 @@ namespace Tango.MachineStudio.Synchronization.ViewModels } finally { - _isWorking = false; + IsWorking = false; SelectedDifference = null; InvalidateRelayCommands(); } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/Views/DirectSynchronizationView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/Views/DirectSynchronizationView.xaml index 4c5a719b5..ba0530ca6 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/Views/DirectSynchronizationView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/Views/DirectSynchronizationView.xaml @@ -17,6 +17,7 @@ <UserControl.Resources> <converters:BooleanToVisibilityInverseConverter x:Key="BooleanToVisibilityInverseConverter"></converters:BooleanToVisibilityInverseConverter> + <converters:BooleanInverseConverter x:Key="BooleanInverseConverter"></converters:BooleanInverseConverter> <providers:MachinesProvider x:Key="MachinesProvider"></providers:MachinesProvider> @@ -80,7 +81,7 @@ <TextBlock Background="{StaticResource badgeBackground}" Padding="5" Width="200" FontSize="14" HorizontalAlignment="Left">Remote Database</TextBlock> <StackPanel Orientation="Horizontal" Margin="0 5 0 0"> <fa:ImageAwesome Icon="Key" Width="16" Height="16"></fa:ImageAwesome> - <autoComplete:AutoCompleteTextBox Margin="5 0 0 0" Width="170" materialDesign:HintAssist.Hint="Enter machine serial number" DisplayMember="SerialNumber" Provider="{StaticResource ResourceKey=MachinesProvider}" SelectedItem="{Binding SelectedMachine,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"> + <autoComplete:AutoCompleteTextBox Margin="5 0 0 0" IsEnabled="{Binding IsWorking,Converter={StaticResource BooleanInverseConverter}}" Width="170" materialDesign:HintAssist.Hint="Enter machine serial number" DisplayMember="SerialNumber" Provider="{StaticResource ResourceKey=MachinesProvider}" SelectedItem="{Binding SelectedMachine,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"> <autoComplete:AutoCompleteTextBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding SerialNumber}"></TextBlock> @@ -174,7 +175,7 @@ </GroupBox> </Grid> - <Grid Grid.Row="1" Visibility="Hidden"> + <Grid Grid.Row="1" Visibility="{Binding ApplicationManager.IsMachineConnected,Converter={StaticResource BooleanToVisibilityInverseConverter}}"> <Grid.Background> <SolidColorBrush Color="White" Opacity="0.8"></SolidColorBrush> </Grid.Background> 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 ede66dc19..d4d053eaf 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs @@ -103,7 +103,7 @@ namespace Tango.MachineStudio.UI.Notifications if (viewTypes == null) { - viewTypes = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes()).ToList(); + viewTypes = AppDomain.CurrentDomain.GetAssemblies().Where(x => x.FullName.Contains("MachineStudio")).SelectMany(x => x.GetTypes()).ToList(); } var viewType = viewTypes.SingleOrDefault(x => x.Name == viewName); |
