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/Tango.MachineStudio.UI/ViewModels | |
| 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/Tango.MachineStudio.UI/ViewModels')
2 files changed, 47 insertions, 1 deletions
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 { |
