From c7c4975fd0010fc666c467105a39b1cd93cb818d Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 29 Aug 2018 11:49:53 +0300 Subject: Added restore to previous version support. --- .../Properties/AssemblyInfo.cs | 2 +- .../ViewModels/UpdateViewVM.cs | 160 ++++++++++++++++++++- .../Tango.MachineStudio.UI/Views/UpdateView.xaml | 74 ++++++++++ 3 files changed, 233 insertions(+), 3 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI') 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(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().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 @@ UPDATE + + @@ -177,6 +184,13 @@ Your version of Machine Studio is up to date! + + @@ -205,6 +219,66 @@ + + + + + + + Restoring previous version, please wait... + + + + + + + + + + + + + + Error restoring previous version + + An error occurred while restore the last version. + + press 'Try Again' to give it another try. + + + + + + + + + + + + + + + Machine studio has been restored to the previous version! + + + Please restart Machine Studio in order to apply the changes. + + + + + + + -- cgit v1.3.1 From 7171e1a3b7579420f2060798c649088d70565401 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 30 Aug 2018 12:35:00 +0300 Subject: Implemented In-Memory Transport Adapter. Implemented Embedded In-Memory Emulator. --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 15400960 -> 15400960 bytes Software/Graphics/external-bridge-emulator.png | Bin 0 -> 3554 bytes .../Build/Shortcuts/Machine Studio.lnk | Bin 1516 -> 1516 bytes .../ViewModels/MainViewVM.cs | 4 +- .../ViewModels/EventsViewVM.cs | 2 +- .../ViewModels/MachineTechViewVM.cs | 10 +- .../EventLogging/DefaultEventLogger.cs | 2 +- .../MachineStudioSettings.cs | 14 +++ .../StudioApplication/IStudioApplicationManager.cs | 14 ++- .../Images/external-bridge-emulator.png | Bin 0 -> 3554 bytes .../Properties/AssemblyInfo.cs | 2 +- .../DefaultStudioApplicationManager.cs | 35 +++++- .../TFS/TeamFoundationServiceExtendedClient.cs | 2 +- .../Tango.MachineStudio.UI.csproj | 7 +- .../ViewModels/MachineConnectionViewVM.cs | 19 +++ .../ViewModels/MainViewVM.cs | 12 +- .../Views/ConnectedMachineView.xaml | 38 ++++++ .../Views/MachineConnectionView.xaml | 20 +++ .../Tango.MachineStudio.UI/Views/MainView.xaml | 6 +- .../Tango.BL/EntitiesExtensions/BrushStop.cs | 5 + .../Tango.Core/SynchronizedObservableCollection.cs | 29 +++-- .../Tango.Emulations/Emulators/MachineEmulator.cs | 2 +- .../ExternalBridge/EmulatorExternalBridge.cs | 88 +++++++++++++ .../Tango.Emulations/Tango.Emulations.csproj | 3 +- .../ExternalBridge/ExternalBridgeTcpClient.cs | 16 ++- .../ExternalBridge/ExternalBridgeUsbClient.cs | 17 ++- .../ExternalBridge/IExternalBridgeClient.cs | 11 ++ .../Operation/IMachineOperator.cs | 5 - .../Tango.Integration/Operation/MachineOperator.cs | 14 --- .../Adapters/MemoryTransportAdapter.cs | 138 +++++++++++++++++++++ .../Tango.Transport/Tango.Transport.csproj | 3 +- .../Tango.Transport/TransportAdapterBase.cs | 2 +- 33 files changed, 452 insertions(+), 68 deletions(-) create mode 100644 Software/Graphics/external-bridge-emulator.png create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/external-bridge-emulator.png create mode 100644 Software/Visual_Studio/Tango.Emulations/ExternalBridge/EmulatorExternalBridge.cs create mode 100644 Software/Visual_Studio/Tango.Transport/Adapters/MemoryTransportAdapter.cs (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index ff50e2333..0774ec401 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 72cba010e..79cfb7a85 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Graphics/external-bridge-emulator.png b/Software/Graphics/external-bridge-emulator.png new file mode 100644 index 000000000..cb159d4a6 Binary files /dev/null and b/Software/Graphics/external-bridge-emulator.png differ diff --git a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk index afc922b97..35d97ffcc 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk and b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index 55dd370d1..0a9bba69e 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -461,7 +461,6 @@ namespace Tango.MachineStudio.Developer.ViewModels set { _segmentsCollectionView = value; - BindingOperations.EnableCollectionSynchronization(_segmentsCollectionView, _syncLock); RaisePropertyChangedAuto(); } } @@ -1230,7 +1229,8 @@ namespace Tango.MachineStudio.Developer.ViewModels if (status.Message != null) { - _eventLogger.Log(BL.Enumerations.EventTypes.JobStatus, status.Message); + // TODO: Write to db when shlomo is not sending test messages anymore. + _eventLogger.Log(BL.Enumerations.EventTypes.JobStatus, status.Message, false); } } }; diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs index 68094d91f..1f93a96dc 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs @@ -145,7 +145,7 @@ namespace Tango.MachineStudio.Logging.ViewModels DateTime now = DateTime.UtcNow.AddMonths(-1); - _history_events = _db.MachinesEvents.Where(x => x.MachineGuid == SelectedMachine.Guid && x.DateTime > now).ToList(); + _history_events = _db.MachinesEvents.Where(x => x.MachineGuid == SelectedMachine.Guid && x.DateTime > now).Include(x => x.User).Include(x => x.User.Contact).Include(x => x.Machine).ToList(); Dates = new ObservableCollection(); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs index a186d3039..9dd6c4b79 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs @@ -1571,13 +1571,13 @@ namespace Tango.MachineStudio.Technician.ViewModels public override void OnNavigatedTo() { base.OnNavigatedTo(); - _singleControllers.ToList().ForEach(x => x.Value.ChangeRenderMode(true)); + //_singleControllers.ToList().ForEach(x => x.Value.ChangeRenderMode(true)); } public override void OnNavigatedFrom() { base.OnNavigatedFrom(); - _singleControllers.ToList().ForEach(x => x.Value.ChangeRenderMode(false)); + //_singleControllers.ToList().ForEach(x => x.Value.ChangeRenderMode(false)); } public override void OnShuttingDown() @@ -1698,8 +1698,8 @@ namespace Tango.MachineStudio.Technician.ViewModels { using (ObservablesContext db = ObservablesContext.CreateDefault()) { - config = db.Adapter.GetConfiguration(x => x.Guid == ApplicationManager.ConnectedMachine.Machine.ConfigurationGuid).Clone(); - hw = db.Adapter.GetHardwareVersionByMachine(ApplicationManager.ConnectedMachine.Machine.Guid).Clone(); + config = db.Adapter.GetConfiguration(x => x.Guid == ApplicationManager.Machine.ConfigurationGuid).Clone(); + hw = db.Adapter.GetHardwareVersionByMachine(ApplicationManager.Machine.Guid).Clone(); } }); @@ -1795,7 +1795,7 @@ namespace Tango.MachineStudio.Technician.ViewModels await Task.Factory.StartNew(() => { - hw = adapter.GetHardwareVersionByMachine(ApplicationManager.ConnectedMachine.Machine.Guid); + hw = adapter.GetHardwareVersionByMachine(ApplicationManager.Machine.Guid); }); foreach (var motorConfig in hw.HardwareMotors) diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs index cb4611cad..3663eb093 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs @@ -220,7 +220,7 @@ namespace Tango.MachineStudio.Common.EventLogging } LogManager.Log("Logging event " + machineEvent.EventType.Name + " - " + machineEvent.Description); - machineEvent.MachineGuid = _application.ConnectedMachine.Machine.Guid; + machineEvent.MachineGuid = _application.Machine.Guid; machineEvent.UserGuid = _authentication.CurrentUser.Guid; machineEvent.User = _authentication.CurrentUser; _events.Enqueue(machineEvent); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs index 706f82774..f54611d9c 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs @@ -46,12 +46,26 @@ namespace Tango.MachineStudio.Common /// public Rect LastBounds { get; set; } + /// + /// Gets or sets the default issue report assign to. + /// public String DefaultIssueReportAssignTo { get; set; } + /// + /// Gets or sets the default issue report area. + /// public String DefaultIssueReportArea { get; set; } + /// + /// Gets or sets the default issue report tags. + /// public List DefaultIssueReportTags { get; set; } + /// + /// Gets or sets a value indicating whether add external bridge client emulator when scanning for connected machines. + /// + public bool UseExternalBridgeEmulator { get; set; } + /// /// Initializes a new instance of the class. /// diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IStudioApplicationManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IStudioApplicationManager.cs index 96de3eea0..1a0499f2c 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IStudioApplicationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IStudioApplicationManager.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; +using Tango.BL.Entities; using Tango.Integration.ExternalBridge; namespace Tango.MachineStudio.Common.StudioApplication @@ -32,7 +33,12 @@ namespace Tango.MachineStudio.Common.StudioApplication /// /// Gets or sets the currently connected machine if any. /// - IExternalBridgeClient ConnectedMachine { get; set; } + IExternalBridgeClient ConnectedMachine { get; } + + /// + /// Gets or sets the machine. + /// + Machine Machine { get; } /// /// Gets a value indicating whether the is valid. @@ -75,5 +81,11 @@ namespace Tango.MachineStudio.Common.StudioApplication /// Raises the application ready event. /// void NotifyApplicationReady(); + + /// + /// Sets the connected machine. + /// + /// The connected machine. + void SetConnectedMachine(IExternalBridgeClient connectedMachine); } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/external-bridge-emulator.png b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/external-bridge-emulator.png new file mode 100644 index 000000000..cb159d4a6 Binary files /dev/null and b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/external-bridge-emulator.png differ 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 224cd3199..1865bfb2f 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.39.18238")] +[assembly: AssemblyVersion("3.3.40.18238")] [assembly: ComVisible(false)] \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs index 17bf57f56..29bb459ee 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs @@ -19,6 +19,8 @@ using Tango.Integration.ExternalBridge; using Tango.MachineStudio.Common.EventLogging; using Tango.BL.Enumerations; using Tango.Core.DI; +using Tango.BL.Entities; +using Tango.BL; namespace Tango.MachineStudio.UI.StudioApplication { @@ -55,22 +57,23 @@ namespace Tango.MachineStudio.UI.StudioApplication public bool IsShuttingDown { get; private set; } /// - /// The connected machine + /// Occurs when the connected machine property has changed. /// - private IExternalBridgeClient _connectedMachine; + public event EventHandler ConnectedMachineChanged; /// - /// Occurs when the connected machine property has changed. + /// Gets or sets the machine. /// - public event EventHandler ConnectedMachineChanged; + public Machine Machine { get; private set; } + private IExternalBridgeClient _connectedMachine; /// /// Gets or sets the currently connected machine if any. /// public IExternalBridgeClient ConnectedMachine { get { return _connectedMachine; } - set + private set { _connectedMachine = value; RaisePropertyChangedAuto(); @@ -270,9 +273,31 @@ namespace Tango.MachineStudio.UI.StudioApplication } } + /// + /// Raises the application ready event. + /// public void NotifyApplicationReady() { TangoIOC.Default.GetAllInstancesByBase().ToList().ForEach(x => x.OnApplicationReady()); } + + /// + /// Sets the connected machine. + /// + /// The connected machine. + public void SetConnectedMachine(IExternalBridgeClient connectedMachine) + { + if (connectedMachine != null) + { + Machine = ObservablesStaticCollections.Instance.Machines.SingleOrDefault(x => x.SerialNumber == connectedMachine.SerialNumber); + ConnectedMachine = connectedMachine; + ConnectedMachine.SetMachine(Machine); + } + else + { + Machine = null; + ConnectedMachine = null; + } + } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/TFS/TeamFoundationServiceExtendedClient.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/TFS/TeamFoundationServiceExtendedClient.cs index 6225e1480..8f67a21c2 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/TFS/TeamFoundationServiceExtendedClient.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/TFS/TeamFoundationServiceExtendedClient.cs @@ -196,7 +196,7 @@ namespace Tango.MachineStudio.UI.TFS if (app.ConnectedMachine != null) { - Machine machine = app.ConnectedMachine.Machine; + Machine machine = app.Machine; sysModel.Machine = machine; sysModel.EmbeddedVersion = app.ConnectedMachine.DeviceInformation.Version; 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 ed3d0e5fc..3cab71602 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 @@ -369,6 +369,10 @@ {38197109-8610-4d3f-92b9-16d48df94d7c} Tango.DAL.Remote + + {63561e19-ff5a-414b-a5ef-e30711543e1d} + Tango.Emulations + {4206ac58-3b57-4699-8835-90bf6db01a61} Tango.Integration @@ -481,6 +485,7 @@ + ChangeLog.txt @@ -571,7 +576,7 @@ copy /Y "$(SolutionDir)Referenced Assemblies\Microsoft.WITDataStore32.dll" "$(Ta - + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineConnectionViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineConnectionViewVM.cs index 60447f37a..51b7168ed 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineConnectionViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineConnectionViewVM.cs @@ -4,8 +4,11 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.Core.Commands; +using Tango.Emulations.ExternalBridge; using Tango.Integration.ExternalBridge; +using Tango.MachineStudio.Common; using Tango.MachineStudio.Common.Notifications; +using Tango.Settings; using Tango.SharedUI; namespace Tango.MachineStudio.UI.ViewModels @@ -16,6 +19,8 @@ namespace Tango.MachineStudio.UI.ViewModels /// public class MachineConnectionViewVM : DialogViewVM { + private EmulatorExternalBridge _emulator; + private ExternalBridgeScanner _scanner; /// /// Gets or sets the machine scanner. @@ -63,6 +68,9 @@ namespace Tango.MachineStudio.UI.ViewModels } } + /// + /// Invokes the event. + /// protected override void Cancel() { Scanner.Stop(); @@ -76,6 +84,17 @@ namespace Tango.MachineStudio.UI.ViewModels { base.OnShow(); Scanner.AvailableMachines.Clear(); + + if (SettingsManager.Default.GetOrCreate().UseExternalBridgeEmulator) + { + if (_emulator != null) + { + _emulator.Disconnect(); + } + _emulator = new EmulatorExternalBridge(); + } + + Scanner.AvailableMachines.Add(_emulator); Scanner.Start(); } } 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 ee4435832..31b2181ea 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -388,7 +388,7 @@ namespace Tango.MachineStudio.UI.ViewModels InvalidateRelayCommands(); String serial = ApplicationManager.ConnectedMachine.SerialNumber; await ApplicationManager.ConnectedMachine.Disconnect(); - ApplicationManager.ConnectedMachine = null; + ApplicationManager.SetConnectedMachine(null); _eventLogger.Log("Disconnected from machine " + serial); PostMessage(new MachineConnectionChangedMessage() { Machine = null }); @@ -459,13 +459,13 @@ namespace Tango.MachineStudio.UI.ViewModels Intent = PMR.Integration.ExternalBridgeLoginIntent.Override, }); - ApplicationManager.ConnectedMachine = x.SelectedMachine; + ApplicationManager.SetConnectedMachine(x.SelectedMachine); (x.SelectedMachine as IExternalBridgeSecureClient).SessionClosed += (_, __) => { InvokeUI(() => { _notificationProvider.ShowError("The remote machine has closed the current session. Machine disconnected."); - ApplicationManager.ConnectedMachine = null; + ApplicationManager.SetConnectedMachine(null); }); }; PostMessage(new MachineConnectionChangedMessage() { Machine = x.SelectedMachine }); @@ -506,7 +506,7 @@ namespace Tango.MachineStudio.UI.ViewModels await x.SelectedMachine.Connect(); x.SelectedMachine.SerialNumber = vm.SelectedMachine.SerialNumber; - ApplicationManager.ConnectedMachine = x.SelectedMachine; + ApplicationManager.SetConnectedMachine(x.SelectedMachine); PostMessage(new MachineConnectionChangedMessage() { Machine = x.SelectedMachine }); _eventLogger.Log(String.Format("Successfully connected to machine {0} via USB", x.SelectedMachine.SerialNumber)); @@ -556,8 +556,8 @@ namespace Tango.MachineStudio.UI.ViewModels { using (ObservablesContext db = ObservablesContext.CreateDefault()) { - var config = db.Adapter.GetConfiguration(s => s.Guid == ApplicationManager.ConnectedMachine.Machine.ConfigurationGuid); - var hw = db.Adapter.GetHardwareVersionByMachine(ApplicationManager.ConnectedMachine.Machine.Guid); + var config = db.Adapter.GetConfiguration(s => s.Guid == ApplicationManager.Machine.ConfigurationGuid); + var hw = db.Adapter.GetHardwareVersionByMachine(ApplicationManager.Machine.Guid); await ApplicationManager.ConnectedMachine.UploadHardwareConfiguration(hw, config); } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ConnectedMachineView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ConnectedMachineView.xaml index 319fa3596..26790c67d 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ConnectedMachineView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ConnectedMachineView.xaml @@ -6,6 +6,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:integration="clr-namespace:Tango.Integration.ExternalBridge;assembly=Tango.Integration" xmlns:integ="clr-namespace:Tango.Integration.Operation;assembly=Tango.Integration" + xmlns:emulations="clr-namespace:Tango.Emulations.ExternalBridge;assembly=Tango.Emulations" xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" @@ -38,6 +39,10 @@ + + + + @@ -131,6 +136,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineConnectionView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineConnectionView.xaml index 5f8cca8fe..180a2a8e0 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineConnectionView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineConnectionView.xaml @@ -7,6 +7,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:integration="clr-namespace:Tango.Integration.ExternalBridge;assembly=Tango.Integration" xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" + xmlns:emulations="clr-namespace:Tango.Emulations.ExternalBridge;assembly=Tango.Emulations" xmlns:local="clr-namespace:Tango.MachineStudio.UI.Views" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" Width="600" Height="400" Background="White" DataContext="{Binding MachineConnectionViewVM, Source={StaticResource Locator}}"> @@ -95,6 +96,25 @@ + + + + + Diagnostics + + + + + + + + + Address: + + + + + 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 9a494f862..67bdf81ed 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml @@ -15,7 +15,7 @@ xmlns:local="clr-namespace:Tango.MachineStudio.UI.Views" xmlns:commonConverters="clr-namespace:Tango.MachineStudio.Common.Converters;assembly=Tango.MachineStudio.Common" mc:Ignorable="d" - d:DesignHeight="720" d:DesignWidth="1270" Background="Transparent" DataContext="{Binding MainViewVM, Source={StaticResource Locator}}"> + d:DesignHeight="720" d:DesignWidth="1270" Background="Transparent" DataContext="{Binding MainViewVM, Source={StaticResource Locator}}" x:Name="control"> @@ -161,7 +161,7 @@ - public event EventHandler SessionClosed; + + /// + /// Gets the database machine associated with this client. + /// + public Machine Machine { get; private set; } + + /// + /// Sets the database machine. + /// + /// The machine. + public void SetMachine(Machine machine) + { + Machine = machine; + } } } diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeUsbClient.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeUsbClient.cs index f610de206..0496c270e 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeUsbClient.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeUsbClient.cs @@ -34,9 +34,6 @@ namespace Tango.Integration.ExternalBridge { _serialNumber = value; RaisePropertyChangedAuto(); - - Machine = ObservablesStaticCollections.Instance.Machines.SingleOrDefault(x => x.SerialNumber == _serialNumber); - RaisePropertyChanged(nameof(Machine)); } } @@ -110,5 +107,19 @@ namespace Tango.Integration.ExternalBridge { return Device; } + + /// + /// Gets the database machine associated with this client. + /// + public Machine Machine { get; private set; } + + /// + /// Sets the database machine. + /// + /// The machine. + public void SetMachine(Machine machine) + { + Machine = machine; + } } } diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/IExternalBridgeClient.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/IExternalBridgeClient.cs index b1d084cfa..d336b6b70 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/IExternalBridgeClient.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/IExternalBridgeClient.cs @@ -26,5 +26,16 @@ namespace Tango.Integration.ExternalBridge /// Gets or sets the machine serial number. /// String SerialNumber { get; set; } + + /// + /// Gets the database machine associated with this client. + /// + Machine Machine { get; } + + /// + /// Sets the database machine. + /// + /// The machine. + void SetMachine(Machine machine); } } diff --git a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs index ce48ffa31..11b57fcc8 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs @@ -24,11 +24,6 @@ namespace Tango.Integration.Operation /// public interface IMachineOperator : ITransporter { - /// - /// Gets the machine database entity. - /// - Machine Machine { get; } - /// /// Gets or sets the job handling mode. /// diff --git a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs index 5e942fe36..332a2696c 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs @@ -317,20 +317,6 @@ namespace Tango.Integration.Operation set { _deviceInformation = value; RaisePropertyChangedAuto(); } } - private Machine _machine; - /// - /// Gets the machine database entity. - /// - public Machine Machine - { - get { return _machine; } - protected set - { - _machine = value; - RaisePropertyChangedAuto(); - } - } - #endregion #region Virtual Methods diff --git a/Software/Visual_Studio/Tango.Transport/Adapters/MemoryTransportAdapter.cs b/Software/Visual_Studio/Tango.Transport/Adapters/MemoryTransportAdapter.cs new file mode 100644 index 000000000..09b98527a --- /dev/null +++ b/Software/Visual_Studio/Tango.Transport/Adapters/MemoryTransportAdapter.cs @@ -0,0 +1,138 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Transport.Adapters +{ + /// + /// Represents an in-memory transport adapter. + /// + /// + public class MemoryTransportAdapter : TransportAdapterBase + { + #region Memory Transport Manager + + internal static class MemoryTransportManager + { + private static List _adapters; + + static MemoryTransportManager() + { + _adapters = new List(); + } + + internal static void Connect(MemoryTransportAdapter adapter) + { + if (adapter == null) + { + throw new NullReferenceException("Cannot connect null adapter."); + } + + if (String.IsNullOrWhiteSpace(adapter.Address)) + { + throw new InvalidOperationException("Cannot register a memory adapter with null address."); + } + + if (_adapters.Where(x => x.Address == adapter.Address).Count() > 1) + { + throw new InvalidOperationException("Cannot register more than two memory adapters with the same address."); + } + + if (_adapters.Contains(adapter)) + { + throw new InvalidOperationException("The specified memory adapter is already registered."); + } + + _adapters.Add(adapter); + } + + internal static void Disconnect(MemoryTransportAdapter adapter) + { + if (adapter == null) + { + throw new NullReferenceException("Cannot disconnect null adapter."); + } + + _adapters.Remove(adapter); + } + + internal static void Write(MemoryTransportAdapter adapter, byte[] data) + { + Task.Factory.StartNew(() => + { + var other_adapter = _adapters.ToList().SingleOrDefault(x => x.Address == adapter.Address && x != adapter); + + if (other_adapter != null) + { + other_adapter.EmulateDataAvailable(data); + } + }); + } + } + + #endregion + + /// + /// Initializes a new instance of the class. + /// + /// The address. + public MemoryTransportAdapter(String address) + { + Address = address; + } + + /// + /// Emulates in coming data. + /// + /// The data. + internal void EmulateDataAvailable(byte[] data) + { + OnDataAvailable(data); + } + + /// + /// Writes the specified data to the stream. + /// + /// The data. + public override void Write(byte[] data) + { + ThrowIfDisposed(); + + try + { + TotalBytesSent += data.Length; + _totalBytes += data.Length; + MemoryTransportManager.Write(this, data); + } + catch (Exception ex) + { + OnFailed(LogManager.Log(ex)); + } + } + + /// + /// Connects the transport component. + /// + /// + public override Task Connect() + { + MemoryTransportManager.Connect(this); + State = TransportComponentState.Connected; + return Task.FromResult(new object()); + } + + /// + /// Disconnects the transport component. + /// + /// + public override Task Disconnect() + { + MemoryTransportManager.Disconnect(this); + State = TransportComponentState.Disconnected; + return Task.FromResult(new object()); + } + } +} diff --git a/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj b/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj index c0d37b76c..837fd6549 100644 --- a/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj +++ b/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj @@ -66,6 +66,7 @@ GlobalVersionInfo.cs + @@ -129,7 +130,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Transport/TransportAdapterBase.cs b/Software/Visual_Studio/Tango.Transport/TransportAdapterBase.cs index 8a5ebda55..bcaf3aee8 100644 --- a/Software/Visual_Studio/Tango.Transport/TransportAdapterBase.cs +++ b/Software/Visual_Studio/Tango.Transport/TransportAdapterBase.cs @@ -16,7 +16,7 @@ namespace Tango.Transport /// public abstract class TransportAdapterBase : ExtendedObject, ITransportAdapter { - private long _totalBytes; + protected long _totalBytes; private long _transferRateTotalBytes; private Timer _transferRateTimer; -- cgit v1.3.1