From 3234e33cc4ba354f0395bb514b8b2fa102cf38ec Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 21 Jan 2018 15:56:57 +0200 Subject: Started working on Developer module. --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 8388608 -> 8388608 bytes .../Converters/DbRmlViewToEntityConverter.cs | 38 +++ .../Tango.MachineStudio.Developer.csproj | 49 ++- .../UserControl1.xaml | 12 - .../UserControl1.xaml.cs | 28 -- .../ViewModelLocator.cs | 31 ++ .../ViewModels/DBViewContextWrapper.cs | 36 +++ .../ViewModels/MainViewVM.cs | 49 +++ .../Views/MainView.xaml | 135 ++++++++- .../Tango.MachineStudio.Developer/packages.config | 8 + .../MachineDesignerModule.cs | 2 +- .../Tango.MachineStudio.MachineDesigner.csproj | 7 + .../ViewModels/MainViewVM.cs | 21 +- .../Views/MachineView.xaml | 327 +++++++++++++++++++++ .../Views/MachineView.xaml.cs | 28 ++ .../Controls/TableGrid.cs | 58 ++++ .../StudioApplication/IModuleRequestListener.cs | 21 ++ .../StudioApplication/IStudioApplicationManager.cs | 11 +- .../Tango.MachineStudio.Common.csproj | 2 + .../DefaultStudioApplicationManager.cs | 34 ++- .../ViewModels/MainViewVM.cs | 2 +- 22 files changed, 839 insertions(+), 60 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/DbRmlViewToEntityConverter.cs delete mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/UserControl1.xaml delete mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/UserControl1.xaml.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModelLocator.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/DBViewContextWrapper.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/packages.config create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineView.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineView.xaml.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/TableGrid.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IModuleRequestListener.cs diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 51d4999ac..0190a6686 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 c011e8db7..eb56d926e 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.Developer/Converters/DbRmlViewToEntityConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/DbRmlViewToEntityConverter.cs new file mode 100644 index 000000000..a2f0023cc --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/DbRmlViewToEntityConverter.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using Tango.DAL.Observables; +using Tango.MachineStudio.Developer.ViewModels; + +namespace Tango.MachineStudio.Developer.Converters +{ + public class DbRmlViewToEntityConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value != null) + { + DBViewContextWrapper db = value as DBViewContextWrapper; + return db; + } + + return null; + + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value != null) + { + Rml entity = value as Rml; + return new DBViewContextWrapper(entity); + } + + return null; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj index 44b50b443..5c90f04bd 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj @@ -31,8 +31,32 @@ 4 + + ..\..\..\packages\MvvmLightLibs.5.3.0.0\lib\net45\GalaSoft.MvvmLight.dll + + + ..\..\..\packages\MvvmLightLibs.5.3.0.0\lib\net45\GalaSoft.MvvmLight.Extras.dll + + + ..\..\..\packages\MvvmLightLibs.5.3.0.0\lib\net45\GalaSoft.MvvmLight.Platform.dll + + + ..\..\..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll + + + ..\..\..\packages\MaterialDesignColors.1.1.2\lib\net45\MaterialDesignColors.dll + + + ..\..\..\packages\MaterialDesignThemes.2.3.1.953\lib\net45\MaterialDesignThemes.Wpf.dll + + + ..\..\..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll + + + ..\..\..\packages\MvvmLightLibs.5.3.0.0\lib\net45\System.Windows.Interactivity.dll + @@ -47,21 +71,17 @@ + + + + MainView.xaml - - MSBuild:Compile - Designer - GlobalVersionInfo.cs - - UserControl1.xaml - Code - Designer MSBuild:Compile @@ -86,6 +106,7 @@ Resources.Designer.cs + SettingsSingleFileGenerator Settings.Designer.cs @@ -100,6 +121,10 @@ {0ecd6da8-7aa6-48d9-8b65-279d176ad9af} Tango.DAL.Observables + + {38197109-8610-4d3f-92b9-16d48df94d7c} + Tango.DAL.Remote + {8491d07b-c1f6-4b62-a412-41b9fd2d6538} Tango.SharedUI @@ -108,6 +133,14 @@ {cb0b0aa2-bb24-4bca-a720-45e397684e12} Tango.MachineStudio.Common + + {94f7acf8-55e1-4a02-b9bc-a818413fdbbf} + Tango.MachineStudio.DB + + + {d0ce8122-077d-42a2-9490-028ae4769b52} + Tango.MachineStudio.MachineDesigner + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/UserControl1.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/UserControl1.xaml deleted file mode 100644 index 95416b906..000000000 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/UserControl1.xaml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/UserControl1.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/UserControl1.xaml.cs deleted file mode 100644 index e5519cb7e..000000000 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/UserControl1.xaml.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace Tango.MachineStudio.Developer -{ - /// - /// Interaction logic for UserControl1.xaml - /// - public partial class UserControl1 : UserControl - { - public UserControl1() - { - InitializeComponent(); - } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModelLocator.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModelLocator.cs new file mode 100644 index 000000000..f11cee8d0 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModelLocator.cs @@ -0,0 +1,31 @@ +using GalaSoft.MvvmLight; +using GalaSoft.MvvmLight.Ioc; +using Microsoft.Practices.ServiceLocation; +using Tango.MachineStudio.Developer.ViewModels; + +namespace Tango.MachineStudio.Developer +{ + /// + /// This class contains static references to all the view models in the + /// application and provides an entry point for the bindings. + /// + public static class ViewModelLocator + { + /// + /// Initializes a new instance of the ViewModelLocator class. + /// + static ViewModelLocator() + { + ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default); + SimpleIoc.Default.Register(); + } + + public static MainViewVM MainViewVM + { + get + { + return ServiceLocator.Current.GetInstance(); + } + } + } +} \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/DBViewContextWrapper.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/DBViewContextWrapper.cs new file mode 100644 index 000000000..231c27bf2 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/DBViewContextWrapper.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.DAL.Observables; + +namespace Tango.MachineStudio.Developer.ViewModels +{ + public class DBViewContextWrapper where T : class, IObservableEntity + { + public T EditEntity { get; set; } + + public ObservablesEntitiesAdapter Adapter { get; set; } + + public DBViewContextWrapper() + { + Adapter = ObservablesEntitiesAdapter.Instance; + } + + public DBViewContextWrapper(T entity) : this() + { + EditEntity = entity; + } + + public static implicit operator DBViewContextWrapper(T entity) + { + return new DBViewContextWrapper(entity); + } + + public static implicit operator T(DBViewContextWrapper instance) + { + return instance.EditEntity; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs new file mode 100644 index 000000000..e7e97097b --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.Commands; +using Tango.DAL.Observables; +using Tango.MachineStudio.Common.StudioApplication; +using Tango.SharedUI; + +namespace Tango.MachineStudio.Developer.ViewModels +{ + public class MainViewVM : ViewModel + { + public IStudioApplicationManager ApplicationManager { get; set; } + + public ObservablesEntitiesAdapter Adapter { get; set; } + + private Machine _selectedMachine; + + public Machine SelectedMachine + { + get { return _selectedMachine; } + set { _selectedMachine = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } + } + + private DBViewContextWrapper _selectedRML; + + public DBViewContextWrapper SelectedRML + { + get { return _selectedRML; } + set { _selectedRML = value; RaisePropertyChangedAuto(); } + } + + public RelayCommand EditMachineCommand { get; set; } + + public MainViewVM(IStudioApplicationManager applicationManager) + { + Adapter = ObservablesEntitiesAdapter.Instance; + EditMachineCommand = new RelayCommand(EditMachine, (x) => SelectedMachine != null); + ApplicationManager = applicationManager; + } + + private void EditMachine() + { + ApplicationManager.RequestModule("Machine Designer", SelectedMachine); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml index cd91b007f..5b26b7891 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml @@ -3,10 +3,139 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" + xmlns:global="clr-namespace:Tango.MachineStudio.Developer" + xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls" + xmlns:db="clr-namespace:Tango.MachineStudio.DB.Views.DBViews;assembly=Tango.MachineStudio.DB" + xmlns:commonControls="clr-namespace:Tango.MachineStudio.Common.Controls;assembly=Tango.MachineStudio.Common" + xmlns:designer="clr-namespace:Tango.MachineStudio.MachineDesigner.Views;assembly=Tango.MachineStudio.MachineDesigner" + xmlns:vm="clr-namespace:Tango.MachineStudio.Developer.ViewModels" + xmlns:localConverters="clr-namespace:Tango.MachineStudio.Developer.Converters" + xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" xmlns:local="clr-namespace:Tango.MachineStudio.Developer.Views" mc:Ignorable="d" - d:DesignHeight="300" d:DesignWidth="300" Background="#CBCBCB"> - - DEVLOPER MODULE + d:DesignHeight="720" d:DesignWidth="1280" Background="White" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/packages.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/packages.config new file mode 100644 index 000000000..4fd672b32 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/packages.config @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/MachineDesignerModule.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/MachineDesignerModule.cs index 8fbac790f..b0160abd5 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/MachineDesignerModule.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/MachineDesignerModule.cs @@ -48,7 +48,7 @@ namespace Tango.MachineStudio.MachineDesigner /// /// Gets the permission required to see and load this module. /// - public Permissions Permission => Permissions.RunDeveloperModule; + public Permissions Permission => Permissions.RunMachineDesignerModule; /// /// Gets a value indicating whether this module has been initialized. diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Tango.MachineStudio.MachineDesigner.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Tango.MachineStudio.MachineDesigner.csproj index ac1616401..64c54b357 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Tango.MachineStudio.MachineDesigner.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Tango.MachineStudio.MachineDesigner.csproj @@ -85,6 +85,9 @@ MachineVersionDialog.xaml + + MachineView.xaml + MainView.xaml @@ -96,6 +99,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs index 24f2f6d43..9f44bc270 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs @@ -13,10 +13,12 @@ using Tango.DAL.Observables; using Tango.MachineStudio.Common.Notifications; using Tango.SharedUI; using SimpleValidator.Extensions; +using Tango.MachineStudio.Common.StudioApplication; +using Tango.MachineStudio.Common; namespace Tango.MachineStudio.MachineDesigner.ViewModels { - public class MainViewVM : ViewModel + public class MainViewVM : ViewModel, IModuleRequestListener { private bool _isSaving; private INotificationProvider _notification; @@ -631,5 +633,22 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels } #endregion + + #region IModuleRequestListener + + /// + /// Called when the request has been made. + /// + /// The module instance. + /// The arguments. + public void OnRequestModule(IStudioModule module, object args) + { + if (module is MachineDesignerModule) + { + SelectedMachine = args as Machine; + } + } + + #endregion } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineView.xaml new file mode 100644 index 000000000..a54f9bbdc --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineView.xaml @@ -0,0 +1,327 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Hardware + + + + + + Add IDS + + + + + + Remove IDS + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + NO IDS PACKS + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Touch Panel + + + + + + Embedded Firmware + + + + + + Dispensers + + + + + + Mid Tanks + + + + + + Cartridges + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineView.xaml.cs new file mode 100644 index 000000000..67fa0d5bf --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.MachineStudio.MachineDesigner.Views +{ + /// + /// Interaction logic for MachineView.xaml + /// + public partial class MachineView : UserControl + { + public MachineView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/TableGrid.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/TableGrid.cs new file mode 100644 index 000000000..07fd0c446 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/TableGrid.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; + +namespace Tango.MachineStudio.Common.Controls +{ + public class TableGrid : Grid + { + public TableGrid() + { + ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) }); + ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); + this.Loaded += TableGrid_Loaded; + } + + private void TableGrid_Loaded(object sender, RoutedEventArgs e) + { + InvalidateGrid(); + } + + protected override void OnVisualChildrenChanged(DependencyObject visualAdded, DependencyObject visualRemoved) + { + base.OnVisualChildrenChanged(visualAdded, visualRemoved); + } + + protected override Size ArrangeOverride(Size arrangeSize) + { + return base.ArrangeOverride(arrangeSize); + } + + private void InvalidateGrid() + { + RowDefinitions.Clear(); + RowDefinitions.Add(new RowDefinition() { Height = new GridLength(50, GridUnitType.Pixel) }); + + int currentRow = 0; + + for (int i = 0; i < Children.Count; i++) + { + SetRow(Children[i], currentRow); + + if (i % 2 != 0) + { + SetColumn(Children[i], 1); + (Children[i] as FrameworkElement).Margin = new Thickness(20, 0, 0, 0); + currentRow++; + RowDefinitions.Add(new RowDefinition() { Height = new GridLength(50, GridUnitType.Pixel) }); + } + + (Children[i] as FrameworkElement).VerticalAlignment = VerticalAlignment.Bottom; + } + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IModuleRequestListener.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IModuleRequestListener.cs new file mode 100644 index 000000000..b950d7bcd --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IModuleRequestListener.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.Common.StudioApplication +{ + /// + /// Represents a type which will be notified when a new module request was made by + /// + public interface IModuleRequestListener + { + /// + /// Called when the request has been made. + /// + /// The module instance. + /// The arguments. + void OnRequestModule(IStudioModule module, Object args); + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IStudioApplicationManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IStudioApplicationManager.cs index a88a045a6..c67c34044 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IStudioApplicationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IStudioApplicationManager.cs @@ -20,7 +20,7 @@ namespace Tango.MachineStudio.Common.StudioApplication /// /// Gets a value indicating whether Machine Studio is shutting down. /// - bool IsShuttingDown { get;} + bool IsShuttingDown { get; } /// /// Shutdown the application. @@ -40,6 +40,13 @@ namespace Tango.MachineStudio.Common.StudioApplication /// /// Gets a value indicating whether the is valid and connected through TCP/IP. /// - bool IsMachineConnectedViaTCP { get; } + bool IsMachineConnectedViaTCP { get; } + + /// + /// Loads the specified module if permitted. + /// + /// Name of the module. + /// The arguments. + void RequestModule(String moduleName, Object args); } } 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 42eae3c1e..e16703cfa 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 @@ -71,7 +71,9 @@ + + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs index 06b4dca7c..a59ecf8e0 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs @@ -14,6 +14,8 @@ using System.Collections; using Tango.Integration.Services; using Tango.Core; using Tango.Logging; +using Tango.MachineStudio.Common.Modules; +using Tango.MachineStudio.Common; namespace Tango.MachineStudio.UI.StudioApplication { @@ -24,17 +26,16 @@ namespace Tango.MachineStudio.UI.StudioApplication /// public class DefaultStudioApplicationManager : ExtendedObject, IStudioApplicationManager { - /// - /// The navigation manager - /// private INavigationManager _navigationManager; + private IStudioModuleLoader _moduleLoader; /// /// Initializes a new instance of the class. /// /// The navigation manager. - public DefaultStudioApplicationManager(INavigationManager navigationManager) + public DefaultStudioApplicationManager(INavigationManager navigationManager, IStudioModuleLoader moduleLoader) { + _moduleLoader = moduleLoader; _navigationManager = navigationManager; } @@ -146,5 +147,30 @@ namespace Tango.MachineStudio.UI.StudioApplication }); } + + /// + /// Loads the specified module if permitted. + /// + /// Name of the module. + /// The arguments. + public void RequestModule(string moduleName, object args) + { + IStudioModule module = _moduleLoader.UserModules.SingleOrDefault(x => x.Name == moduleName); + + if (module != null) + { + ServiceLocator.Current.GetInstance().StartModule(module); + + //Notify request listeners. + foreach (var vm in ServiceLocator.Current.GetAllInstancesByBase()) + { + vm.OnRequestModule(module, args); + } + } + else + { + throw new InvalidOperationException("The module was not found or you do not have sufficient privileges."); + } + } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs index fdab1a93c..679ba5ff3 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -272,7 +272,7 @@ namespace Tango.MachineStudio.UI.ViewModels /// Starts the specified module. /// /// The module. - private void StartModule(IStudioModule module) + internal void StartModule(IStudioModule module) { IsMenuOpened = false; -- cgit v1.3.1