aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-08-13 16:12:45 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-08-13 16:12:45 +0300
commit998cc8d4d91a7f85389cd0918f127257576c2c13 (patch)
tree368ecd76f09b8ff1c4156a554b799cd231c42119 /Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs
parent4490b0a76d4188cb285d62b106e208803ceaa133 (diff)
downloadTango-998cc8d4d91a7f85389cd0918f127257576c2c13.tar.gz
Tango-998cc8d4d91a7f85389cd0918f127257576c2c13.zip
Logs and comments for PPC.UI !
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.cs161
1 files changed, 105 insertions, 56 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 f2fba05fe..e984b7452 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs
@@ -45,6 +45,21 @@ namespace Tango.PPC.UI.PPCApplication
public event EventHandler ModulesInitialized;
/// <summary>
+ /// Occurs when the all components are ready.
+ /// </summary>
+ public event EventHandler Ready;
+
+ /// <summary>
+ /// Occurs when machine setup is required.
+ /// </summary>
+ public event EventHandler SetupRequired;
+
+ /// <summary>
+ /// Occurs when the main window content has been rendered.
+ /// </summary>
+ public event EventHandler ContentRendered;
+
+ /// <summary>
/// Gets a value indicating whether the application is shutting down.
/// </summary>
public bool IsShuttingDown { get; private set; }
@@ -62,6 +77,17 @@ namespace Tango.PPC.UI.PPCApplication
}
/// <summary>
+ /// Gets the application build date.
+ /// </summary>
+ public String BuildDate
+ {
+ get
+ {
+ return AssemblyHelper.GetCurrentAssemblyBuildDate().ToShortDateString();
+ }
+ }
+
+ /// <summary>
/// Initializes a new instance of the <see cref="DefaultPPCApplicationManager"/> class.
/// </summary>
public DefaultPPCApplicationManager(IMachineProvider machineProvider)
@@ -72,78 +98,95 @@ namespace Tango.PPC.UI.PPCApplication
{
_notifiedViewModels = new List<PPCViewModel>();
- PPCSettings settings = null;
-
- MainWindow.Instance.ContentRendered += async (_, __) =>
+ MainWindow.Instance.ContentRendered += (_, __) =>
{
- ContentRendered?.Invoke(this, new EventArgs());
+ OnMainWindowContentRendered();
+ };
+ }
+ }
- await Task.Factory.StartNew(() =>
- {
- //TODO: Use this in the future.
+ /// <summary>
+ /// Called when the main window content has been rendered
+ /// </summary>
+ private async void OnMainWindowContentRendered()
+ {
+ LogManager.Log("Main window content rendered.");
- //#if DEBUG
- // DataSource = "localhost\\SQLEXPRESS";
- //#else
- // DataBaseSettings.DefaultDataSource = Path.Combine(PathHelper.GetUserTangoFolder(), "DB", "Tango.db");
- //#endif
+ PPCSettings settings = null;
- if (!File.Exists(CoreSettings.DefaultDataBaseSource))
- {
- Directory.CreateDirectory(Path.GetDirectoryName(CoreSettings.DefaultDataBaseSource));
- File.Copy(Path.Combine(PathHelper.GetStartupPath(), "DB", "Tango.mdf"), CoreSettings.DefaultDataBaseSource);
- }
+ ContentRendered?.Invoke(this, new EventArgs());
- settings = SettingsManager.Default.GetOrCreate<PPCSettings>();
- var coreSettings = SettingsManager.Default.GetOrCreate<CoreSettings>();
+ await Task.Factory.StartNew(() =>
+ {
+ LogManager.Log("Reading PPC settings...");
+ settings = SettingsManager.Default.GetOrCreate<PPCSettings>();
- if (!SettingsManager.Default.IsFileExists())
- {
- settings.Save();
- }
+ LogManager.Log(settings.ToJsonString());
- if (App.StartupArgs.Contains("-update_ok"))
- {
- settings.ApplicationState = ApplicationStates.Default;
- settings.Save();
- }
+ LogManager.Log("Reading Core settings...");
+ var coreSettings = SettingsManager.Default.GetOrCreate<CoreSettings>();
- if (settings.ApplicationState == ApplicationStates.Default)
- {
- ObservablesEntitiesAdapter.Instance.Initialize();
- }
- });
+ if (!SettingsManager.Default.IsFileExists())
+ {
+ LogManager.Log("Settings file does not exists. creating...");
+ settings.Save();
+ }
+ if (App.StartupArgs.Contains("-update_ok"))
+ {
+ LogManager.Log("Application started with '-update_ok' startup arguments. The application has been successfully updated.");
+ settings.ApplicationState = ApplicationStates.Default;
+ settings.Save();
+ }
- if (settings.ApplicationState == ApplicationStates.PreSetup || settings.ApplicationState == ApplicationStates.SemiSetup)
- {
- SetupRequired?.Invoke(this, new EventArgs());
- }
- else
- {
- PostSetup();
- }
- };
+ if (settings.ApplicationState == ApplicationStates.Default)
+ {
+ LogManager.Log("Initializing ObservablesEntitiesAdapter...");
+ ObservablesEntitiesAdapter.Instance.Initialize();
+ }
+ });
+
+
+ if (settings.ApplicationState == ApplicationStates.PreSetup || settings.ApplicationState == ApplicationStates.SemiSetup)
+ {
+ LogManager.Log($"The application is in {settings.ApplicationState} state. database initialization skipped. Invoking setup required event!");
+ SetupRequired?.Invoke(this, new EventArgs());
+ }
+ else
+ {
+ OnDbInitialized();
}
}
- private void PostSetup()
+ /// <summary>
+ /// Called when the database has been initialized
+ /// </summary>
+ private void OnDbInitialized()
{
+ LogManager.Log($"Raising {nameof(ApplicationStarted)} event...");
+
ApplicationStarted?.Invoke(this, new EventArgs());
+ LogManager.Log("Invoking PPC view models OnApplicationStarted methods...");
foreach (var vm in TangoIOC.Default.GetAllInstancesByBase<PPCViewModel>())
{
if (!_notifiedViewModels.Contains(vm))
{
+ LogManager.Log($"Invoking {vm.GetType().Name}.OnApplicationStarted...");
vm.OnApplicationStarted();
_notifiedViewModels.Add(vm);
}
}
+ LogManager.Log("Waiting for IPPCModuleLoader instance injection...");
TangoIOC.Default.GetInstanceWhenAvailable<IPPCModuleLoader>((loader) =>
{
+ LogManager.Log("Module loader instance has been registered. Registering for the ModulesLoaded event...");
+
loader.ModulesLoaded += (x, y) =>
{
+ LogManager.Log($"{loader.UserModules.Count} loaded. Waiting for last module initialization...");
+
if (loader.UserModules.Count > 0)
{
if (loader.UserModules.ToList().Exists(m => !m.IsInitialized))
@@ -162,19 +205,34 @@ namespace Tango.PPC.UI.PPCApplication
});
}
+ /// <summary>
+ /// Finalizes the module initialization.
+ /// </summary>
private void FinalizeModuleInitialization()
{
+ LogManager.Log("Finalizing application initialization...");
+
+ LogManager.Log("Checking for un-notified PPC view models...");
foreach (var vm in TangoIOC.Default.GetAllInstancesByBase<PPCViewModel>())
{
if (!_notifiedViewModels.Contains(vm))
{
+ LogManager.Log($"Invoking {vm.GetType().Name}.OnApplicationStarted...");
vm.OnApplicationStarted();
_notifiedViewModels.Add(vm);
}
}
+ LogManager.Log($"Invoking {nameof(ModulesInitialized)} event.");
+
ModulesInitialized?.Invoke(this, new EventArgs());
+
+ LogManager.Log("Initializing Machine Provider...");
_machineProvider.Init();
+
+ LogManager.Log("Applications initialization completed!");
+
+ LogManager.Log($"Invoking {nameof(Ready)} event.");
Ready?.Invoke(this, new EventArgs());
}
@@ -183,6 +241,10 @@ namespace Tango.PPC.UI.PPCApplication
/// </summary>
public void ShutDown()
{
+ //TODO: Needs some work on logging and shutdown procedures! Do I really need this?
+
+ LogManager.Log("Shutting down application...");
+
IsShuttingDown = true;
foreach (var vm in TangoIOC.Default.GetAllInstancesByBase<PPCViewModel>())
@@ -190,18 +252,5 @@ namespace Tango.PPC.UI.PPCApplication
vm.OnApplicationShuttingDown();
}
}
-
- public event EventHandler Ready;
- public event EventHandler SetupRequired;
- public event EventHandler ContentRendered;
-
- public String BuildDate
- {
- get
- {
- return AssemblyHelper.GetCurrentAssemblyBuildDate().ToShortDateString();
- }
- }
-
}
}