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/Modules/Tango.MachineStudio.Synchronization/ViewModels | |
| 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/Modules/Tango.MachineStudio.Synchronization/ViewModels')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/DirectSynchronizationViewVM.cs | 47 |
1 files changed, 40 insertions, 7 deletions
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(); } |
