aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels
diff options
context:
space:
mode:
authorShlomo Hecht <shlomo@twine-s.com>2019-09-16 17:48:16 +0300
committerShlomo Hecht <shlomo@twine-s.com>2019-09-16 17:48:16 +0300
commit161fe6f6d2b29ba3deb641cdc049ad0d8f58004e (patch)
tree20318bb7ea4a243b8c2e9757e4635e8d5f5cb728 /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels
parent30fcfa4100a9d00e887c6e17e32e427b05296ce7 (diff)
parentb674a2e7751daa80c0d74207968bf8e3d18d7faf (diff)
downloadTango-161fe6f6d2b29ba3deb641cdc049ad0d8f58004e.tar.gz
Tango-161fe6f6d2b29ba3deb641cdc049ad0d8f58004e.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels')
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs46
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs5
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineConnectionViewVM.cs22
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs31
4 files changed, 97 insertions, 7 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..c181d7b9d 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs
@@ -17,6 +17,7 @@ using Tango.MachineStudio.Common.EventLogging;
using Tango.MachineStudio.Common.Navigation;
using Tango.MachineStudio.Common.Notifications;
using Tango.MachineStudio.Common.Web;
+using Tango.MachineStudio.UI.Authentication;
using Tango.MachineStudio.UI.Messages;
using Tango.Settings;
using Tango.SharedUI;
@@ -157,7 +158,7 @@ namespace Tango.MachineStudio.UI.ViewModels
{
_settings.DeploymentSlot = DeploymentSlot;
- var result = _authenticationProvider.Login(Email, Password).Response;
+ LoginResponse result = _authenticationProvider.Login(Email, Password).Response;
if (result.VersionChangeRequired && !_settings.ByPassEnvironmentVersionCheck)
{
@@ -193,7 +194,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 log-in operation.\n{ex.FlattenMessage()}");
}
finally
{
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 ce49d805e..d1f3cc69e 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineConnectionViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineConnectionViewVM.cs
@@ -36,7 +36,7 @@ namespace Tango.MachineStudio.UI.ViewModels
public IExternalBridgeClient SelectedMachine
{
get { return _selectedMachine; }
- set { _selectedMachine = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
+ set { _selectedMachine = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(RequiresAuthentication)); InvalidateRelayCommands(); }
}
/// <summary>
@@ -57,6 +57,7 @@ namespace Tango.MachineStudio.UI.ViewModels
EnableDiagnostics = true;
UploadHardwareConfiguration = true;
+ EnableKeepAlive = true;
ConnectCommand = new RelayCommand(Connect, (x) => SelectedMachine != null);
}
@@ -130,6 +131,17 @@ namespace Tango.MachineStudio.UI.ViewModels
set { _uploadHardwareConfiguration = value; RaisePropertyChangedAuto(); }
}
+ private bool _enableApplicationLogs;
+ /// <summary>
+ /// Gets or sets a value indicating whether to enable application logs.
+ /// </summary>
+ public bool EnableApplicationLogs
+ {
+ get { return _enableApplicationLogs; }
+ set { _enableApplicationLogs = value; RaisePropertyChangedAuto(); }
+ }
+
+
private bool _enableKeepAlive;
/// <summary>
/// Gets or sets a value indicating whether to use the keep alive mechanism.
@@ -140,5 +152,13 @@ namespace Tango.MachineStudio.UI.ViewModels
set { _enableKeepAlive = value; RaisePropertyChangedAuto(); }
}
+ public bool RequiresAuthentication
+ {
+ get
+ {
+ return SelectedMachine != null && SelectedMachine is IExternalBridgeSecureClient;
+ }
+ }
+
}
}
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 3f69ff771..31ba4e57d 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs
@@ -5,6 +5,7 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
+using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
@@ -174,6 +175,11 @@ namespace Tango.MachineStudio.UI.ViewModels
/// </summary>
public RelayCommand AboutCommand { get; set; }
+ /// <summary>
+ /// Gets or sets the about command.
+ /// </summary>
+ public RelayCommand<MachineStudioTheme> ChangeAppThemeCommand { get; set; }
+
private IAuthenticationProvider _authenticationProvider;
/// <summary>
/// Gets or sets the authentication provider.
@@ -336,6 +342,8 @@ namespace Tango.MachineStudio.UI.ViewModels
TangoMessenger.Default.Register<Messages.ForcedUpdateMessage>((x) => DisableCheckForUpdates = true);
AboutCommand = new RelayCommand(ShowAboutDialog);
+
+ ChangeAppThemeCommand = new RelayCommand<MachineStudioTheme>(ChangeTheme);
}
private void MachineEventsStateProvider_EventsResolved(object sender, IEnumerable<MachinesEvent> e)
@@ -447,6 +455,11 @@ namespace Tango.MachineStudio.UI.ViewModels
x.SelectedMachine.EnableEventsNotification = x.EnableDiagnostics;
x.SelectedMachine.UseKeepAlive = x.EnableKeepAlive;
+ if (x.SelectedMachine is ExternalBridgeTcpClient)
+ {
+ x.SelectedMachine.As<ExternalBridgeTcpClient>().EnableApplicationLogs = x.EnableApplicationLogs;
+ }
+
if (x.SelectedMachine.RequiresAuthentication)
{
//Check machine exist on my database first
@@ -483,10 +496,10 @@ namespace Tango.MachineStudio.UI.ViewModels
PostMessage(new MachineConnectionChangedMessage() { Machine = x.SelectedMachine });
_eventLogger.Log(String.Format("Successfully connected to machine {0} via TCP", x.SelectedMachine.SerialNumber));
- if (x.UploadHardwareConfiguration)
- {
- UploadHardwareConfiguration(false);
- }
+ //if (x.UploadHardwareConfiguration)
+ //{
+ // UploadHardwareConfiguration(false);
+ //}
}
catch (ResponseErrorException ex)
@@ -921,5 +934,15 @@ namespace Tango.MachineStudio.UI.ViewModels
IsApplicationReady = true;
}
}
+
+ private void ChangeTheme(MachineStudioTheme theme)
+ {
+ var settings = SettingsManager.Default.GetOrCreate<MachineStudioSettings>();
+ //add current theme
+ settings.Theme = theme;
+ settings.Save();
+
+ _notificationProvider.ShowInfo("Changes will be applies after application restart.");
+ }
}
}