From 13cea5de4abfa38528ba74d9542734e133acaa81 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 23 Jul 2019 13:13:25 +0300 Subject: Improved user login errors. Added machine counters to connected machine view. --- .../DefaultAuthenticationProvider.cs | 26 ++++++++---- .../ViewModels/ConnectedMachineViewVM.cs | 46 ++++++++++++++++++++++ .../ViewModels/LoginViewVM.cs | 2 +- .../Views/ConnectedMachineView.xaml | 14 ++++++- 4 files changed, 78 insertions(+), 10 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs index 7aa9ae890..951a40870 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs @@ -17,6 +17,7 @@ using Tango.MachineStudio.Common.StudioApplication; using Tango.Core.Helpers; using Tango.MachineStudio.Common.Web; using Tango.BL.Builders; +using System.Data.Entity.Core; namespace Tango.MachineStudio.UI.Authentication { @@ -70,14 +71,24 @@ namespace Tango.MachineStudio.UI.Authentication var settings = SettingsManager.Default.GetOrCreate(); _client.Environment = settings.DeploymentSlot; - var response = _client.Login(new LoginRequest() + + LoginResponse response = null; + + try { + response = _client.Login(new LoginRequest() + { - Email = email, - Password = password, - Version = AssemblyHelper.GetCurrentAssemblyVersion().ToString(), + Email = email, + Password = password, + Version = AssemblyHelper.GetCurrentAssemblyVersion().ToString(), - }).Result; + }).Result; + } + catch (Exception ex) + { + throw new AggregateException(new AuthenticationException("Error logging in to machine service."), ex); + } if (settings.Environment == MachineStudioSettings.WorkingEnvironment.Remote) { @@ -88,10 +99,9 @@ namespace Tango.MachineStudio.UI.Authentication { ObservablesStaticCollections.Instance.Initialize(); } - catch (System.Data.Entity.Core.MetadataException) + catch (Exception ex) { - ObservablesContext.ClearModelStore(); - ObservablesStaticCollections.Instance.Initialize(); + throw new AggregateException(new MetadataException("Error initializing database connection."), ex); } using (ObservablesContext db = ObservablesContext.CreateDefault()) diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs index 5467c53a0..16f6938a0 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs @@ -3,12 +3,14 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.BL; using Tango.BL.Entities; using Tango.Core.Commands; using Tango.MachineStudio.Common.Diagnostics; using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.Common.StudioApplication; using Tango.SharedUI; +using System.Data.Entity; namespace Tango.MachineStudio.UI.ViewModels { @@ -39,6 +41,19 @@ namespace Tango.MachineStudio.UI.ViewModels set { _diagnosticsFrameProvider = value; RaisePropertyChangedAuto(); } } + private String _totalMachineWorkTime; + public String TotalMachineWorkTime + { + get { return _totalMachineWorkTime; } + set { _totalMachineWorkTime = value; RaisePropertyChangedAuto(); } + } + + private String _totalMachineMeters; + public String TotalMachineMeters + { + get { return _totalMachineMeters; } + set { _totalMachineMeters = value; RaisePropertyChangedAuto(); } + } public RelayCommand DisconnectCommand { get; set; } @@ -64,5 +79,36 @@ namespace Tango.MachineStudio.UI.ViewModels Result = result; Accept(); } + + public override void OnShow() + { + base.OnShow(); + LoadMachineCounters(); + } + + private async void LoadMachineCounters() + { + try + { + TotalMachineMeters = "loading..."; + TotalMachineWorkTime = "loading..."; + + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + var jobs = await db.Jobs.Include(x => x.JobRuns).Where(x => x.MachineGuid == ApplicationManager.Machine.Guid).ToListAsync(); + + TotalMachineWorkTime = TimeSpan.FromHours(jobs.SelectMany(x => x.JobRuns).Select(x => x.EndDate - x.StartDate).Sum(x => x.TotalHours)).ToString(@"hh\:mm\:ss"); + + int meters = (int)jobs.SelectMany(x => x.JobRuns).Select(x => x.EndPosition).Sum(); + TotalMachineMeters = $"{meters.ToString("N0")} meters"; + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error loading machine counters."); + TotalMachineMeters = "error!"; + TotalMachineWorkTime = "error!"; + } + } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs index 1165c0920..b9cd82979 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs @@ -193,7 +193,7 @@ namespace Tango.MachineStudio.UI.ViewModels catch (Exception ex) { LogManager.Log(ex, "Login Error."); - _notificationProvider.ShowError($"The specified email or password was incorrect, or you don't have a permission to run this application.\nError: {ex.FlattenMessage()}"); + _notificationProvider.ShowError($"An error occurred while trying to perform the logging operation.\n{ex.FlattenMessage()}"); } finally { 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 338cb2d22..5e49cf9de 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ConnectedMachineView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ConnectedMachineView.xaml @@ -12,7 +12,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Tango.MachineStudio.UI.Views" mc:Ignorable="d" - d:DesignHeight="300" d:DesignWidth="300" Width="600" Height="480" Background="White" DataContext="{Binding ConnectedMachineViewVM, Source={StaticResource Locator}}"> + d:DesignHeight="300" d:DesignWidth="300" Width="640" Height="500" Background="White" DataContext="{Binding ConnectedMachineViewVM, Source={StaticResource Locator}}"> @@ -73,6 +73,10 @@ + + + + @@ -112,6 +116,10 @@ + + + + @@ -166,6 +174,10 @@ + + + + -- cgit v1.3.1