diff options
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs index 29b9f7823..6c2afb403 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs @@ -12,18 +12,14 @@ using Tango.Core.DI; using Tango.PPC.Common; using System.Windows; using Tango.Core; +using System.IO; +using Tango.Core.Helpers; namespace Tango.PPC.UI.PPCApplication { public class DefaultPPCApplicationManager : ExtendedObject, IPPCApplicationManager { - public bool IsShuttingDown - { - get - { - throw new NotImplementedException(); - } - } + public bool IsShuttingDown { get; private set; } public IMachineOperator ConnectedMachine { @@ -65,8 +61,35 @@ namespace Tango.PPC.UI.PPCApplication { if (!DesignMode) { - MainWindow.Instance.ContentRendered += (_, __) => + MainWindow.Instance.ContentRendered += async (_, __) => { + await Task.Factory.StartNew(() => + { + //TODO: Use this in the future. + + //#if DEBUG + // DataSource = "localhost\\SQLEXPRESS"; + //#else + // DataBaseSettings.DefaultDataSource = Path.Combine(PathHelper.GetUserTangoFolder(), "DB", "Tango.db"); + //#endif + + CoreSettings.DefaultDataBaseSource = Path.Combine(PathHelper.GetUserTangoFolder(), "DB", "Tango.db"); + + if (!File.Exists(CoreSettings.DefaultDataBaseSource)) + { + Directory.CreateDirectory(Path.GetDirectoryName(CoreSettings.DefaultDataBaseSource)); + File.Copy(Path.Combine(PathHelper.GetStartupPath(), "DB", "Tango.db"), CoreSettings.DefaultDataBaseSource); + } + + var settings = SettingsManager.Default.GetOrCreate<PPCSettings>(); ; + + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + Machine = db.Machines.SingleOrDefault(x => x.SerialNumber == settings.MachineSerialNumber); + } + + }); + foreach (var vm in TangoIOC.Default.GetAllInstancesByBase<PPCViewModel>()) { vm.OnApplicationStarted(); @@ -77,12 +100,12 @@ namespace Tango.PPC.UI.PPCApplication public void ShutDown() { - throw new NotImplementedException(); - } + IsShuttingDown = true; - public void SetMachine(Machine machine) - { - Machine = machine; + foreach (var vm in TangoIOC.Default.GetAllInstancesByBase<PPCViewModel>()) + { + vm.OnApplicationShuttingDown(); + } } } } |
