aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs158
1 files changed, 55 insertions, 103 deletions
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 6be3d8ca0..7b4016341 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs
@@ -8,17 +8,31 @@ using Tango.Core;
using Tango.Core.Commands;
using Tango.PPC.Common;
using Tango.PPC.Common.Application;
+using Tango.PPC.Common.MachineSetup;
+using Tango.PPC.Common.Navigation;
+using Tango.PPC.UI.ViewsContracts;
using Tango.Settings;
+using Tango.SharedUI.Helpers;
using Tango.SQLExaminer;
namespace Tango.PPC.UI.ViewModels
{
- public class MachineSetupViewVM : PPCViewModel
+ public class MachineSetupViewVM : PPCViewModel<IMachineSetupView>
{
+ public enum MachineSetupStates
+ {
+ None,
+ Working,
+ Completed,
+ Failed,
+ }
+
private bool _postSetp;
private SetupRequiredEventArgs _setupRequiredEventArgs;
+ public IMachineSetupManager MachineSetupManager { get; set; }
+
private String _serialNumber;
public String SerialNumber
{
@@ -40,22 +54,28 @@ namespace Tango.PPC.UI.ViewModels
set { _log = value; RaisePropertyChangedAuto(); }
}
- private bool _isWorking;
- public bool IsWorking
+ private MachineSetupStates _state;
+ public MachineSetupStates State
{
- get { return _isWorking; }
- set { _isWorking = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
+ get { return _state; }
+ set { _state = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
}
public RelayCommand StartCommand { get; set; }
- public MachineSetupViewVM(IPPCApplicationManager applicationManager)
+ public RelayCommand CompleteCommand { get; set; }
+
+ public MachineSetupViewVM(IPPCApplicationManager applicationManager, IMachineSetupManager machineSetupManager)
{
+ MachineSetupManager = machineSetupManager;
+ MachineSetupManager.ProgressLog += (x, msg) => AppendLog(msg);
+ MachineSetupManager.ProgressStep += (x, step) => AppendLog(Environment.NewLine + "-----------" + step.ToDescription().ToUpper() + "-----------" + Environment.NewLine);
+
HostAddress = "localhost\\SQLEXPRESS";
SerialNumber = "1111";
- AppendLog("Ready to start...");
- StartCommand = new RelayCommand(StartSetup, () => !String.IsNullOrWhiteSpace(HostAddress) && !String.IsNullOrWhiteSpace(SerialNumber) && !IsWorking);
+ StartCommand = new RelayCommand(StartSetup, () => !String.IsNullOrWhiteSpace(HostAddress) && !String.IsNullOrWhiteSpace(SerialNumber) && State == MachineSetupStates.None);
+ CompleteCommand = new RelayCommand(CompleteSetup, () => State == MachineSetupStates.Completed);
applicationManager.SetupRequired += ApplicationManager_SetupRequired;
}
@@ -67,6 +87,8 @@ namespace Tango.PPC.UI.ViewModels
public override void OnApplicationStarted()
{
+ base.OnApplicationStarted();
+
if (_postSetp)
{
NavigationManager.NavigateTo(Common.Navigation.NavigationView.LoginView);
@@ -80,107 +102,37 @@ namespace Tango.PPC.UI.ViewModels
private void AppendLog(String msg)
{
- Log += msg + Environment.NewLine;
+ if (msg != null && !msg.Contains("SQL Examiner"))
+ {
+ InvokeUI(() =>
+ {
+ View.AppendLog(msg + Environment.NewLine);
+ });
+ }
}
- private void StartSetup()
+ private async void StartSetup()
{
- IsWorking = true;
+ State = MachineSetupStates.Working;
- Task.Factory.StartNew(() =>
+ try
{
- try
- {
- String db_name = "Tango";
-
- String localAddress = SettingsManager.Default.GetOrCreate<CoreSettings>().DataBaseSource;
-
- var tempFolder = TemporaryManager.CreateFolder("Machine Setup");
- String report_file = tempFolder.CreateImaginaryFile(".xml");
- String config_file = tempFolder.CreateImaginaryFile(".xml");
-
- DbManager db = new DbManager(new SqlConnection(String.Format("Server={0};Integrated security=SSPI", localAddress)));
-
- if (!db.Exists("Tango"))
- {
- throw new InvalidProgramException("Database tango does not exists.");
- }
-
- //Create schema configuration
- ExaminerConfigurationBuilder builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.Schema);
-
- builder.
- SetSourceServer(HostAddress, db_name).
- SetTargetServer(localAddress, db_name).
- Synchronize();
-
- //Synchronize Source schema with Target schema
-
- var process = new ExaminerProcess(builder.Build(), ExaminerProcessType.Schema);
- process.Progress += (x, msg) =>
- {
- AppendLog(msg);
- };
- var result = process.Execute().Result;
-
- //Synchronization was successful
- if (result.ExitCode != ExaminerProcessExitCode.Success)
- {
- throw new InvalidProgramException("Error while trying to synchronize database schema.");
- }
-
- //Create override data configuration
- builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.OverrideData);
-
- builder.
- SetSourceServer(HostAddress, db_name).
- SetTargetServer(localAddress, db_name).
- Synchronize();
-
- process = new ExaminerProcess(builder.Build(), ExaminerProcessType.Data);
- process.Progress += (x, msg) =>
- {
- AppendLog(msg);
- };
- result = process.Execute().Result;
-
- //Synchronization was successful
- if (result.ExitCode != ExaminerProcessExitCode.Success)
- {
- throw new InvalidProgramException("Error while trying to synchronize database schema.");
- }
-
- //Provision Target
- builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.ProvisionMachine);
-
- builder.
- SetSourceServer(HostAddress, db_name).
- SetTargetServer(localAddress, db_name).
- SetMachineSerialNumber(SerialNumber).
- Synchronize();
-
- result = new ExaminerProcess(builder.Build(), ExaminerProcessType.Data).Execute().Result;
-
- //Synchronization was successful
- if (result.ExitCode != ExaminerProcessExitCode.Success)
- {
- throw new InvalidProgramException("Error while trying to synchronize database schema.");
- }
+ await MachineSetupManager.Setup(SerialNumber, HostAddress);
+ Settings.HasSetup = true;
+ _postSetp = true;
+ Settings.Save();
+ State = MachineSetupStates.Completed;
+ }
+ catch (Exception ex)
+ {
+ State = MachineSetupStates.Failed;
+ await NotificationProvider.ShowInfo(ex.Message);
+ }
+ }
- Settings.HasSetup = true;
- _postSetp = true;
- Settings.Save();
- _setupRequiredEventArgs.Continue();
- }
- catch (Exception ex)
- {
- NotificationProvider.ShowError(ex.Message);
- }
- finally
- {
- IsWorking = false;
- }
- });
+ private void CompleteSetup()
+ {
+ NavigationManager.NavigateWithObject(NavigationView.LoadingView, new MachineSetupResult() { Completed = true });
}
}
}