From a20fd4bd769aeccd1fd1f20273f895c92a5b5bb8 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 14 Jan 2018 15:24:49 +0200 Subject: Added code comments for: MachineStudio.Common. --- .../Modules/IStudioModuleLoader.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Modules/IStudioModuleLoader.cs') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Modules/IStudioModuleLoader.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Modules/IStudioModuleLoader.cs index d67accbc1..cb9f1122f 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Modules/IStudioModuleLoader.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Modules/IStudioModuleLoader.cs @@ -7,12 +7,24 @@ using System.Threading.Tasks; namespace Tango.MachineStudio.Common.Modules { + /// + /// Represents a Machine Studio modules loading engine. + /// public interface IStudioModuleLoader { + /// + /// Gets all loaded modules. + /// ObservableCollection AllModules { get; } + /// + /// Gets all the user permitted modules. + /// ObservableCollection UserModules { get; } + /// + /// Loads all available Machine Studio modules. + /// void LoadModules(); } } -- cgit v1.3.1 From ee88fc31d9b1b8f4782c7103d91de2d1b11c211b Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 13 Feb 2018 19:41:19 +0200 Subject: Implemented StudioModuleBase. --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 8388608 -> 8388608 bytes .../TechnicianModule.cs | 39 ++------- .../ViewModels/SensorsViewVM.cs | 2 +- .../Modules/IStudioModuleLoader.cs | 7 ++ .../Tango.MachineStudio.Common/StudioModuleBase.cs | 92 +++++++++++++++++++++ .../Tango.MachineStudio.Common.csproj | 1 + .../Modules/DefaultStudioModuleLoader.cs | 27 +++++- 8 files changed, 133 insertions(+), 35 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioModuleBase.cs (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Modules/IStudioModuleLoader.cs') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 746556e9e..4354c3d3f 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index d98f40fca..54a54624a 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechnicianModule.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechnicianModule.cs index c75bcdf29..7e0fdd3a4 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechnicianModule.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechnicianModule.cs @@ -16,58 +16,37 @@ namespace Tango.MachineStudio.Technician /// Represents a machine studio technician module. /// /// - public class TechnicianModule : IStudioModule + public class TechnicianModule : StudioModuleBase { - private bool _isLoaded; - - /// - /// Occurs when the module IsLoaded property has changed. - /// - public event EventHandler IsLoadedChanged; - /// /// Gets the module name. /// - public string Name => "Technician"; + public override string Name => "Technician"; /// /// Gets the module description. /// - public string Description => "Provides access to low level machine components by exposing diagnostics and profiling tools."; + public override string Description => "Provides access to low level machine components by exposing diagnostics and profiling tools."; /// /// Gets the module cover image. /// - public BitmapSource Image => ResourceHelper.GetImageFromResources("Images/technician.jpg"); + public override BitmapSource Image => ResourceHelper.GetImageFromResources("Images/technician.jpg"); /// /// Gets the module entry point view. /// - public FrameworkElement MainView => new MachineTechView(); + public override FrameworkElement MainView => new MachineTechView(); /// /// Gets the permission required to see and load this module. /// - public Permissions Permission => Permissions.RunTechnicianModule; - - /// - /// Gets a value indicating whether this module has been initialized. - /// - public bool IsInitialized => true; - - /// - /// Sets a value indicating whether this module is loaded. - /// - public bool IsLoaded - { - get { return _isLoaded; } - set { _isLoaded = value; IsLoadedChanged?.Invoke(this, value); } - } + public override Permissions Permission => Permissions.RunTechnicianModule; /// /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// - public void Dispose() + public override void Dispose() { } @@ -75,9 +54,9 @@ namespace Tango.MachineStudio.Technician /// /// Perform any operations required to initialize this module. /// - public void Initialize() + public override void Initialize() { - + IsInitialized = true; } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/SensorsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/SensorsViewVM.cs index 5062f2584..4480e353b 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/SensorsViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/SensorsViewVM.cs @@ -88,7 +88,7 @@ namespace Tango.MachineStudio.Technician.ViewModels _controllers.Add(PressureController); _controllers.Add(VelocityController); - var module = moduleLoader.UserModules.SingleOrDefault(x => x is TechnicianModule) as TechnicianModule; + var module = moduleLoader.GetStudioModule(); if (module != null) { diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Modules/IStudioModuleLoader.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Modules/IStudioModuleLoader.cs index cb9f1122f..1fd72c53a 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Modules/IStudioModuleLoader.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Modules/IStudioModuleLoader.cs @@ -22,6 +22,13 @@ namespace Tango.MachineStudio.Common.Modules /// ObservableCollection UserModules { get; } + /// + /// Gets the studio module of type T if loaded. + /// + /// + /// + T GetStudioModule() where T : IStudioModule; + /// /// Loads all available Machine Studio modules. /// diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioModuleBase.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioModuleBase.cs new file mode 100644 index 000000000..a773adf8b --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioModuleBase.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media.Imaging; +using Tango.Integration.Observables; + +namespace Tango.MachineStudio.Common +{ + /// + /// Represents a base class for studio modules. + /// + /// + public abstract class StudioModuleBase : IStudioModule + { + private bool _isInitialized; + private bool _isLoaded; + + /// + /// Occurs when the user has navigated into or out of this module. + /// + public event EventHandler IsLoadedChanged; + + /// + /// Gets the module name. + /// + public abstract string Name { get; } + + /// + /// Gets the module description. + /// + public abstract string Description { get; } + + /// + /// Gets the module cover image. + /// + public abstract BitmapSource Image { get; } + + /// + /// Gets the module entry point view. + /// + public abstract FrameworkElement MainView { get; } + + /// + /// Gets the permission required to see and load this module. + /// + public abstract Permissions Permission { get; } + + /// + /// Gets a value indicating whether this module has been initialized. + /// + public bool IsInitialized + { + get + { + return _isInitialized; + } + protected set + { + _isInitialized = value; + } + } + + /// + /// Sets a value indicating whether this module is loaded. + /// + public bool IsLoaded + { + get + { + return _isLoaded; + } + set + { + _isLoaded = value; + IsLoadedChanged?.Invoke(this, value); + } + } + + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// + public abstract void Dispose(); + + /// + /// Perform any operations required to initialize this module. + /// + public abstract void Initialize(); + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj index 5d5df59b7..20079ff68 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj @@ -92,6 +92,7 @@ + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs index e08ee9b08..5951137e3 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs @@ -1,4 +1,5 @@ -using System; +using GalaSoft.MvvmLight.Ioc; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; @@ -8,6 +9,7 @@ using System.Text; using System.Threading.Tasks; using Tango.Core; using Tango.Integration.Observables; +using Tango.Logging; using Tango.MachineStudio.Common; using Tango.MachineStudio.Common.Authentication; using Tango.MachineStudio.Common.Modules; @@ -95,12 +97,19 @@ namespace Tango.MachineStudio.UI.Modules if (moduleAssembly != null) { - foreach (var moduleType in moduleAssembly.GetTypes().Where(x => !x.IsInterface && typeof(IStudioModule).IsAssignableFrom(x))) + foreach (var moduleType in moduleAssembly.GetTypes().Where(x => !x.IsInterface && typeof(IStudioModule).IsAssignableFrom(x) && !x.IsAbstract)) { if (!AllModules.ToList().Exists(x => x.GetType() == moduleType)) { - var module = Activator.CreateInstance(moduleType) as IStudioModule; - AllModules.Add(module); + try + { + var module = Activator.CreateInstance(moduleType) as IStudioModule; + AllModules.Add(module); + } + catch (Exception ex) + { + LogManager.Log(ex, "Could not load module " + moduleType.Name); + } } } } @@ -120,5 +129,15 @@ namespace Tango.MachineStudio.UI.Modules ModulesLoaded?.Invoke(this, new EventArgs()); } + + /// + /// Gets the studio module of type T if loaded. + /// + /// + /// + public T GetStudioModule() where T : IStudioModule + { + return UserModules.OfType().FirstOrDefault(); + } } } -- cgit v1.3.1