aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels
diff options
context:
space:
mode:
authorShlomo Hecht <shlomo@twine-s.com>2019-01-02 08:47:29 +0200
committerShlomo Hecht <shlomo@twine-s.com>2019-01-02 08:47:29 +0200
commit520e878bf98efcec9c75abcfe483175ff72620a2 (patch)
tree62a7221e3c22187821f6a5e399eca0f7bd31168a /Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels
parent30574fe4a6e1bb4f60a43e9000acaf919811689a (diff)
parent25f5e6ddef7ef2fa0a747305847eeb4ceee5a2c9 (diff)
downloadTango-520e878bf98efcec9c75abcfe483175ff72620a2.tar.gz
Tango-520e878bf98efcec9c75abcfe483175ff72620a2.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs2
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/FirmwareUpgradeViewVM.cs170
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs2
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoginViewVM.cs18
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs70
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs19
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/NoPermissionsViewVM.cs30
7 files changed, 131 insertions, 180 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs
index 3b672411d..a8faeea7b 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs
@@ -132,7 +132,7 @@ namespace Tango.PPC.UI.ViewModels
{
LogManager.Log($"External bridge connection request received.\n{e.ToJsonString()}");
- if (e.Request.Password == MachineProvider.Machine.ExternalBridgePassword)
+ if (e.Request.Password == Settings.ExternalBridgePassword)
{
e.Confirmed = true;
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/FirmwareUpgradeViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/FirmwareUpgradeViewVM.cs
deleted file mode 100644
index 1cde1fe1a..000000000
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/FirmwareUpgradeViewVM.cs
+++ /dev/null
@@ -1,170 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Tango.Core.Commands;
-using Tango.PPC.Common;
-using Tango.PPC.Common.Application;
-using Tango.PPC.Common.FirmwareUpgrade;
-using Tango.PPC.Common.Navigation;
-using Tango.PPC.UI.ViewsContracts;
-
-namespace Tango.PPC.UI.ViewModels
-{
- public class FirmwareUpgradeViewVM : PPCViewModel<IFirmwareUpgradeView>
- {
- public enum FirmUpgradeView
- {
- FirmwareProgressView,
- FirmwareCompletedView,
- FirmwareFailedView,
- }
-
-
- private IFirmwareUpgrader _firmwareUpgrader;
-
- private String _status;
- /// <summary>
- /// Gets or sets the firmware upgrade status.
- /// </summary>
- public String Status
- {
- get { return _status; }
- set { _status = value; RaisePropertyChangedAuto(); }
- }
-
- private long _maxProgress;
- /// <summary>
- /// Gets or sets the firmware upgrade maximum progress.
- /// </summary>
- public long MaxProgress
- {
- get { return _maxProgress; }
- set { _maxProgress = value; RaisePropertyChangedAuto(); }
- }
-
- private long _progress;
- /// <summary>
- /// Gets or sets the firmware upgrade progress.
- /// </summary>
- public long Progress
- {
- get { return _progress; }
- set { _progress = value; RaisePropertyChangedAuto(); }
- }
-
- private bool _isIntermediate;
- /// <summary>
- /// Gets or sets a value indicating whether firmware upgrade progress is intermediate.
- /// </summary>
- public bool IsIntermediate
- {
- get { return _isIntermediate; }
- set { _isIntermediate = value; RaisePropertyChangedAuto(); }
- }
-
- /// <summary>
- /// Gets or sets the complete command.
- /// </summary>
- public RelayCommand CompleteCommand { get; set; }
-
- public RelayCommand TryAgainCommand { get; set; }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="FirmwareUpgradeViewVM"/> class.
- /// </summary>
- /// <param name="applicationManager">The application manager.</param>
- /// <param name="firmwareUpgrader">The firmware upgrader.</param>
- public FirmwareUpgradeViewVM(IPPCApplicationManager applicationManager, IFirmwareUpgrader firmwareUpgrader)
- {
- _firmwareUpgrader = firmwareUpgrader;
- CompleteCommand = new RelayCommand(Complete);
- TryAgainCommand = new RelayCommand(TryAgain);
- }
-
- private async void Upgrade()
- {
- IsIntermediate = true;
- Progress = 0;
- Status = "Connecting to the embedded firmware device...";
- await Task.Delay(2000);
- await NavigateTo(FirmUpgradeView.FirmwareProgressView);
- try
- {
- var handler = await _firmwareUpgrader.PerformUpgrade();
- IsIntermediate = false;
-
- handler.Progress += (_, e) =>
- {
- MaxProgress = e.Total;
- Progress = e.Current;
- Status = e.Message;
-
- if (e.Status != Integration.Upgrade.FirmwareUpgradeStatus.Uploading)
- {
- IsIntermediate = true;
- }
- };
- handler.Canceled += (_, __) =>
- {
- NavigateTo(FirmUpgradeView.FirmwareFailedView);
- };
- handler.Failed += (_, ex) =>
- {
- Status = ex.FlattenMessage();
- NavigateTo(FirmUpgradeView.FirmwareFailedView);
- };
- handler.Completed += (_, __) =>
- {
- NavigateTo(FirmUpgradeView.FirmwareCompletedView);
- };
- }
- catch (Exception ex)
- {
- Status = ex.FlattenMessage();
- LogManager.Log(ex);
- await NavigateTo(FirmUpgradeView.FirmwareFailedView);
- }
- }
-
- private void Complete()
- {
- Restart();
- }
-
- private async void TryAgain()
- {
- await NavigateTo(FirmUpgradeView.FirmwareProgressView);
- Upgrade();
- }
-
- private async void ApplicationManager_FirmwareUpgradeRequired(object sender, EventArgs e)
- {
- LogManager.Log("SetupRequired event received. Navigating to FirmwareUpgradeView...");
- await NavigationManager.NavigateTo(NavigationView.FirmwareUpgradeView);
- Upgrade();
- }
-
- private void Restart()
- {
- Settings.ApplicationState = ApplicationStates.Ready;
- Settings.Save();
- ApplicationManager.Restart();
- }
-
- /// <summary>
- /// Navigates to the specified view.
- /// </summary>
- /// <param name="view">The view.</param>
- private Task NavigateTo(FirmUpgradeView view)
- {
- return View.NavigateTo(view);
- }
-
- public override void OnApplicationStarted()
- {
-
- }
- }
-}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs
index 281e54958..516349a18 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs
@@ -20,6 +20,7 @@ using Tango.PPC.Common.Notifications.NotificationItems;
using Tango.PPC.Jobs;
using Tango.SharedUI;
using System.Data.Entity;
+using Tango.BL.Enumerations;
namespace Tango.PPC.UI.ViewModels
{
@@ -79,6 +80,7 @@ namespace Tango.PPC.UI.ViewModels
if (db.Users.Count() == 1 || machine.AutoLogin)
{
var user = await db.Users.FirstAsync();
+
LogManager.Log($"Application started. Single user/Auto login detected ({user.Email}). Skipping LoginView...");
await AuthenticationProvider.Login(user.Email, user.Password, false);
IsLoading = false;
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoginViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoginViewVM.cs
index 9d17a4a76..aa9689ef3 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoginViewVM.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoginViewVM.cs
@@ -11,6 +11,8 @@ using System.ComponentModel.DataAnnotations;
using Tango.SharedUI.Helpers;
using Tango.PPC.Common.Authentication;
using Tango.BL.Entities;
+using Tango.BL.Enumerations;
+using Tango.Logging;
namespace Tango.PPC.UI.ViewModels
{
@@ -89,9 +91,19 @@ namespace Tango.PPC.UI.ViewModels
base.OnApplicationReady();
await Task.Delay(500);
- LogManager.Log("Application is ready! Navigating to home module...");
- await NavigationManager.NavigateTo(NavigationView.HomeModule);
- IsLoading = false;
+
+ if (AuthenticationProvider.CurrentUser != null && AuthenticationProvider.CurrentUser.HasPermission(Permissions.RunPPC))
+ {
+ LogManager.Log("Application is ready! Navigating to home module...");
+ await NavigationManager.NavigateTo(NavigationView.HomeModule);
+ IsLoading = false;
+ }
+ else
+ {
+ LogManager.Log("Application is ready! The logged in user does not have permission to run the application!", LogCategory.Warning);
+ await NavigationManager.NavigateTo(NavigationView.NoPermissionsView);
+ IsLoading = false;
+ }
}
#endregion
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs
index 16b1c05bc..f5c6f43b9 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs
@@ -17,11 +17,13 @@ using Tango.PPC.Common.Application;
using Tango.PPC.Common.Connection;
using Tango.PPC.Common.MachineSetup;
using Tango.PPC.Common.Navigation;
+using Tango.PPC.Common.OS;
using Tango.PPC.UI.ViewsContracts;
using Tango.Settings;
using Tango.SharedUI.Helpers;
using Tango.SQLExaminer;
using Tango.Transport.Adapters;
+using Tango.Web;
namespace Tango.PPC.UI.ViewModels
{
@@ -47,6 +49,8 @@ namespace Tango.PPC.UI.ViewModels
WelcomeView,
WiFiSelectionView,
WiFiTestView,
+ TimeZoneView,
+ EnvironmentView,
SetupWelcomeView,
SetupProgressView,
SetupCompletedView,
@@ -54,6 +58,7 @@ namespace Tango.PPC.UI.ViewModels
}
private MachineSetupResult _setup_result;
+ private IOperationSystemManager _operationSystemManager;
#region Properties
@@ -102,6 +107,41 @@ namespace Tango.PPC.UI.ViewModels
set { _state = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
}
+ private String _failedError;
+ /// <summary>
+ /// Gets or sets the setup failed error.
+ /// </summary>
+ public String FailedError
+ {
+ get { return _failedError; }
+ set { _failedError = value; RaisePropertyChangedAuto(); }
+ }
+
+ /// <summary>
+ /// Gets or sets the available time zones.
+ /// </summary>
+ public List<TimeZoneInfo> TimeZones { get; set; }
+
+ private TimeZoneInfo _selectedTimeZone;
+ /// <summary>
+ /// Gets or sets the selected time zone.
+ /// </summary>
+ public TimeZoneInfo SelectedTimeZone
+ {
+ get { return _selectedTimeZone; }
+ set { _selectedTimeZone = value; RaisePropertyChangedAuto(); }
+ }
+
+ private DeploymentSlot _deploymentSlot;
+ /// <summary>
+ /// Gets or sets the deployment slot.
+ /// </summary>
+ public DeploymentSlot DeploymentSlot
+ {
+ get { return _deploymentSlot; }
+ set { _deploymentSlot = value; RaisePropertyChangedAuto(); }
+ }
+
#endregion
#region Commands
@@ -126,6 +166,15 @@ namespace Tango.PPC.UI.ViewModels
/// </summary>
public RelayCommand RestartCommand { get; set; }
+ /// <summary>
+ /// Gets or sets the time zone selected command.
+ /// </summary>
+ public RelayCommand TimeZoneSelectedCommand { get; set; }
+
+ /// <summary>
+ /// Gets or sets the environment selected command.
+ /// </summary>
+ public RelayCommand EnvironmentSelectedCommand { get; set; }
#endregion
#region Constructors
@@ -135,11 +184,12 @@ namespace Tango.PPC.UI.ViewModels
/// </summary>
/// <param name="applicationManager">The application manager.</param>
/// <param name="machineSetupManager">The machine setup manager.</param>
- public MachineSetupViewVM(IPPCApplicationManager applicationManager, IMachineSetupManager machineSetupManager)
+ public MachineSetupViewVM(IPPCApplicationManager applicationManager, IMachineSetupManager machineSetupManager, IOperationSystemManager operationSystemManager)
{
MachineSetupManager = machineSetupManager;
- HostAddress = Settings.MachineServiceAddress;
+ DeploymentSlot = Settings.DeploymentSlot;
+
SerialNumber = "";
CompleteCommand = new RelayCommand(CompleteSetup, () => State == MachineSetupStates.Completed);
@@ -150,6 +200,18 @@ namespace Tango.PPC.UI.ViewModels
InstallCommand = new RelayCommand(Install);
RestartCommand = new RelayCommand(() => { NavigateTo(MachineSetupView.WelcomeView); });
+ TimeZoneSelectedCommand = new RelayCommand(() => { NavigateTo(MachineSetupView.EnvironmentView); });
+ EnvironmentSelectedCommand = new RelayCommand(() =>
+ {
+ NavigateTo(MachineSetupView.SetupWelcomeView);
+ Settings.DeploymentSlot = DeploymentSlot;
+ HostAddress = Settings.GetMachineServiceAddress();
+ });
+
+ _operationSystemManager = operationSystemManager;
+
+ TimeZones = _operationSystemManager.GetAvailableTimeZones().ToList();
+ SelectedTimeZone = TimeZones.SingleOrDefault(x => x.ToString() == "(UTC+02:00) Jerusalem");
}
#endregion
@@ -239,7 +301,7 @@ namespace Tango.PPC.UI.ViewModels
if (connected)
{
- await NavigateTo(MachineSetupView.SetupWelcomeView);
+ await NavigateTo(MachineSetupView.TimeZoneView);
}
else
{
@@ -273,6 +335,7 @@ namespace Tango.PPC.UI.ViewModels
try
{
+ await _operationSystemManager.ChangeTimeZone(SelectedTimeZone);
_setup_result = await MachineSetupManager.Setup(SerialNumber, HostAddress);
State = MachineSetupStates.Completed;
LogManager.Log("Machine setup completed.");
@@ -281,6 +344,7 @@ namespace Tango.PPC.UI.ViewModels
catch (Exception ex)
{
LogManager.Log(ex, "Machine setup failed.");
+ FailedError = ex.FlattenMessage();
State = MachineSetupStates.Failed;
await NavigateTo(MachineSetupView.SetupFailedView);
}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs
index c201bf555..a553f3a18 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs
@@ -61,6 +61,16 @@ namespace Tango.PPC.UI.ViewModels
set { _isDbUpdate = value; RaisePropertyChangedAuto(); }
}
+ private String _failedError;
+ /// <summary>
+ /// Gets or sets the setup failed error.
+ /// </summary>
+ public String FailedError
+ {
+ get { return _failedError; }
+ set { _failedError = value; RaisePropertyChangedAuto(); }
+ }
+
#endregion
#region Commands
@@ -126,7 +136,7 @@ namespace Tango.PPC.UI.ViewModels
{
IsDbUpdate = false;
- var response = await MachineUpdateManager.CheckForUpdate(MachineProvider.Machine.SerialNumber, Settings.MachineServiceAddress);
+ var response = await MachineUpdateManager.CheckForUpdate(MachineProvider.Machine.SerialNumber, Settings.GetMachineServiceAddress());
if (response.IsUpdateAvailable)
{
@@ -135,7 +145,7 @@ namespace Tango.PPC.UI.ViewModels
}
else
{
- _db_compare_result = await MachineUpdateManager.UpdateDBCheck(MachineProvider.Machine.SerialNumber, Settings.MachineServiceAddress);
+ _db_compare_result = await MachineUpdateManager.UpdateDBCheck(MachineProvider.Machine.SerialNumber, Settings.GetMachineServiceAddress());
if (_db_compare_result.RequiresUpdate)
{
@@ -150,6 +160,7 @@ namespace Tango.PPC.UI.ViewModels
}
catch (Exception ex)
{
+ FailedError = ex.FlattenMessage();
LogManager.Log(ex, "Error while trying to check for updates.");
await NavigateTo(MachineUpdateView.UpdateFailedView);
}
@@ -165,12 +176,13 @@ namespace Tango.PPC.UI.ViewModels
try
{
- _update_result = await MachineUpdateManager.Update(MachineProvider.Machine.SerialNumber, Settings.MachineServiceAddress);
+ _update_result = await MachineUpdateManager.Update(MachineProvider.Machine.SerialNumber, Settings.GetMachineServiceAddress());
LogManager.Log("Machine update completed.");
await NavigateTo(MachineUpdateView.UpdateCompletedView);
}
catch (Exception ex)
{
+ FailedError = ex.FlattenMessage();
LogManager.Log(ex, "Machine update failed.");
await NavigateTo(MachineUpdateView.UpdateFailedView);
}
@@ -188,6 +200,7 @@ namespace Tango.PPC.UI.ViewModels
}
catch (Exception ex)
{
+ FailedError = ex.FlattenMessage();
LogManager.Log(ex, "Database update failed.");
await NavigateTo(MachineUpdateView.UpdateFailedView);
}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/NoPermissionsViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/NoPermissionsViewVM.cs
new file mode 100644
index 000000000..cea8a7d63
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/NoPermissionsViewVM.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Core.Commands;
+using Tango.PPC.Common;
+
+namespace Tango.PPC.UI.ViewModels
+{
+ public class NoPermissionsViewVM : PPCViewModel
+ {
+ public RelayCommand RestartCommand { get; set; }
+
+ public NoPermissionsViewVM()
+ {
+ RestartCommand = new RelayCommand(Restart);
+ }
+
+ private void Restart()
+ {
+ ApplicationManager.Restart();
+ }
+
+ public override void OnApplicationStarted()
+ {
+
+ }
+ }
+}