aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-08-07 19:26:57 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-08-07 19:26:57 +0300
commit6511527e4b576d29fc97aa80479b61d7d1abc079 (patch)
tree9734dc9bc5b6c347c7fc651702419afa37d0d3d9 /Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels
parent3bcad30c7eacb41c134631f79bb50957751f11c7 (diff)
downloadTango-6511527e4b576d29fc97aa80479b61d7d1abc079.tar.gz
Tango-6511527e4b576d29fc97aa80479b61d7d1abc079.zip
Working on PPC Machine Setup !
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs22
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs186
2 files changed, 205 insertions, 3 deletions
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 38616f39f..d5915eeb0 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs
@@ -27,6 +27,8 @@ namespace Tango.PPC.UI.ViewModels
/// <seealso cref="Tango.PPC.Common.PPCViewModel" />
public class LoadingViewVM : PPCViewModel
{
+ private bool _setup;
+
/// <summary>
/// Gets or sets the module loader.
/// </summary>
@@ -46,9 +48,19 @@ namespace Tango.PPC.UI.ViewModels
/// <summary>
/// Initializes a new instance of the <see cref="LoadingViewVM"/> class.
/// </summary>
- public LoadingViewVM()
+ public LoadingViewVM(IPPCApplicationManager applicationManager)
{
- Task.Delay(1000).ContinueWith((x) => { IsLoading = true; });
+ if (!DesignMode)
+ {
+ applicationManager.SetupRequired += ApplicationManager_SetupRequired;
+ Task.Delay(1000).ContinueWith((x) => { IsLoading = true; });
+ }
+ }
+
+ private void ApplicationManager_SetupRequired(object sender, SetupRequiredEventArgs e)
+ {
+ _setup = true;
+ NavigationManager.NavigateTo(NavigationView.MachineSetupView);
}
/// <summary>
@@ -56,8 +68,12 @@ namespace Tango.PPC.UI.ViewModels
/// </summary>
public override void OnApplicationStarted()
{
- NavigationManager.NavigateTo(NavigationView.LoginView);
IsLoading = false;
+
+ if (!_setup)
+ {
+ NavigationManager.NavigateTo(NavigationView.LoginView);
+ }
}
}
}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs
new file mode 100644
index 000000000..6be3d8ca0
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs
@@ -0,0 +1,186 @@
+using System;
+using System.Collections.Generic;
+using System.Data.SqlClient;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Core;
+using Tango.Core.Commands;
+using Tango.PPC.Common;
+using Tango.PPC.Common.Application;
+using Tango.Settings;
+using Tango.SQLExaminer;
+
+namespace Tango.PPC.UI.ViewModels
+{
+ public class MachineSetupViewVM : PPCViewModel
+ {
+ private bool _postSetp;
+
+ private SetupRequiredEventArgs _setupRequiredEventArgs;
+
+ private String _serialNumber;
+ public String SerialNumber
+ {
+ get { return _serialNumber; }
+ set { _serialNumber = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
+ }
+
+ private String _hostAddress;
+ public String HostAddress
+ {
+ get { return _hostAddress; }
+ set { _hostAddress = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
+ }
+
+ private String _log;
+ public String Log
+ {
+ get { return _log; }
+ set { _log = value; RaisePropertyChangedAuto(); }
+ }
+
+ private bool _isWorking;
+ public bool IsWorking
+ {
+ get { return _isWorking; }
+ set { _isWorking = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
+ }
+
+ public RelayCommand StartCommand { get; set; }
+
+ public MachineSetupViewVM(IPPCApplicationManager applicationManager)
+ {
+ HostAddress = "localhost\\SQLEXPRESS";
+ SerialNumber = "1111";
+
+ AppendLog("Ready to start...");
+ StartCommand = new RelayCommand(StartSetup, () => !String.IsNullOrWhiteSpace(HostAddress) && !String.IsNullOrWhiteSpace(SerialNumber) && !IsWorking);
+
+ applicationManager.SetupRequired += ApplicationManager_SetupRequired;
+ }
+
+ private void ApplicationManager_SetupRequired(object sender, SetupRequiredEventArgs e)
+ {
+ _setupRequiredEventArgs = e;
+ }
+
+ public override void OnApplicationStarted()
+ {
+ if (_postSetp)
+ {
+ NavigationManager.NavigateTo(Common.Navigation.NavigationView.LoginView);
+ }
+ }
+
+ public override void OnNavigatedTo()
+ {
+ base.OnNavigatedTo();
+ }
+
+ private void AppendLog(String msg)
+ {
+ Log += msg + Environment.NewLine;
+ }
+
+ private void StartSetup()
+ {
+ IsWorking = true;
+
+ Task.Factory.StartNew(() =>
+ {
+ 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.");
+ }
+
+ Settings.HasSetup = true;
+ _postSetp = true;
+ Settings.Save();
+ _setupRequiredEventArgs.Continue();
+ }
+ catch (Exception ex)
+ {
+ NotificationProvider.ShowError(ex.Message);
+ }
+ finally
+ {
+ IsWorking = false;
+ }
+ });
+ }
+ }
+}