diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-07-23 13:13:25 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-07-23 13:13:25 +0300 |
| commit | 13cea5de4abfa38528ba74d9542734e133acaa81 (patch) | |
| tree | 1ceacae93d4099ec1168e7f0cc2cd9d8cd889d3e /Software/Visual_Studio/MachineStudio | |
| parent | 716eab37857a4565c0b1168b0f68dbc1ee8e7636 (diff) | |
| download | Tango-13cea5de4abfa38528ba74d9542734e133acaa81.tar.gz Tango-13cea5de4abfa38528ba74d9542734e133acaa81.zip | |
Improved user login errors.
Added machine counters to connected machine view.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio')
4 files changed, 78 insertions, 10 deletions
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<MachineStudioSettings>(); _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}}"> <UserControl.Resources> <converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"></converters:BooleanToVisibilityConverter> @@ -73,6 +73,10 @@ <TextBlock Text="{Binding Machine.Name}" /> <TextBlock FontWeight="SemiBold" Text="Organization:" /> <TextBlock Text="{Binding Machine.Organization.Name}" /> + <TextBlock FontWeight="SemiBold" Text="Total Dye Time:" /> + <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.TotalMachineWorkTime}" /> + <TextBlock FontWeight="SemiBold" Text="Total Dye Meters:" /> + <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.TotalMachineMeters}" /> <TextBlock FontWeight="SemiBold" Text="Embedded Software Version:" /> <TextBlock Text="{Binding DeviceInformation.Version}" /> <TextBlock FontWeight="SemiBold" Text="IP Address:" /> @@ -112,6 +116,10 @@ <TextBlock Text="{Binding Machine.Name}" /> <TextBlock FontWeight="SemiBold" Text="Organization:" /> <TextBlock Text="{Binding Machine.Organization.Name}" /> + <TextBlock FontWeight="SemiBold" Text="Total Dye Time:" /> + <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.TotalMachineWorkTime}" /> + <TextBlock FontWeight="SemiBold" Text="Total Dye Meters:" /> + <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.TotalMachineMeters}" /> <TextBlock FontWeight="SemiBold" Text="Embedded Software Version:" /> <TextBlock Text="{Binding DeviceInformation.Version}" /> <TextBlock FontWeight="SemiBold" Text="FPGA Version:" /> @@ -166,6 +174,10 @@ <TextBlock Text="{Binding Machine.Name}" /> <TextBlock FontWeight="SemiBold" Text="Organization:" /> <TextBlock Text="{Binding Machine.Organization.Name}" /> + <TextBlock FontWeight="SemiBold" Text="Total Dye Time:" /> + <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.TotalMachineWorkTime}" /> + <TextBlock FontWeight="SemiBold" Text="Total Dye Meters:" /> + <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.TotalMachineMeters}" /> <TextBlock FontWeight="SemiBold" Text="Embedded Software Version:" /> <TextBlock Text="{Binding DeviceInformation.Version}" /> <TextBlock FontWeight="SemiBold" Text="FPGA Version:" /> |
