diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-06-12 19:04:09 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-06-12 19:04:09 +0300 |
| commit | ca50e0c8fc88acd06d6e1932e9412464bff95edb (patch) | |
| tree | aaafb06deca983c1e80c8c34508d23a452e4a235 | |
| parent | 8a59643571080bfff715f0b0e4bb03e2dee4961a (diff) | |
| download | Tango-ca50e0c8fc88acd06d6e1932e9412464bff95edb.tar.gz Tango-ca50e0c8fc88acd06d6e1932e9412464bff95edb.zip | |
Working on PPC modules and loading.
32 files changed, 443 insertions, 435 deletions
diff --git a/Software/DB/Tango-old.db b/Software/DB/Tango-old.db Binary files differdeleted file mode 100644 index 0693a2623..000000000 --- a/Software/DB/Tango-old.db +++ /dev/null diff --git a/Software/DB/Tango.db b/Software/DB/Tango.db Binary files differindex 336f96dcf..59973a131 100644 --- a/Software/DB/Tango.db +++ b/Software/DB/Tango.db diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf Binary files differindex 446be806b..435076d96 100644 --- a/Software/DB/Tango.mdf +++ b/Software/DB/Tango.mdf diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf Binary files differindex a7ce079a0..c4bde6923 100644 --- a/Software/DB/Tango_log.ldf +++ b/Software/DB/Tango_log.ldf diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/JobsModule.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/JobsModule.cs index de4b89c22..7414a5b7a 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/JobsModule.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/JobsModule.cs @@ -11,6 +11,7 @@ using Tango.SharedUI.Helpers; namespace Tango.PPC.Jobs { + [PPCModule(1)] public class JobsModule : PPCModuleBase { public override string Name diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModelLocator.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModelLocator.cs index 479490486..e9f636b80 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModelLocator.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModelLocator.cs @@ -16,6 +16,7 @@ namespace Tango.PPC.Jobs static ViewModelLocator() { TangoIOC.Default.Register<MainViewVM>(); + TangoIOC.Default.Register<JobsViewVM>(); } /// <summary> @@ -28,5 +29,16 @@ namespace Tango.PPC.Jobs return TangoIOC.Default.GetInstance<MainViewVM>(); } } + + /// <summary> + /// Gets the main view VM. + /// </summary> + public static JobsViewVM JobsViewVM + { + get + { + return TangoIOC.Default.GetInstance<JobsViewVM>(); + } + } } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobsView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobsView.xaml index 8da6012bf..4f9b2db1d 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobsView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobsView.xaml @@ -13,8 +13,10 @@ xmlns:entities="clr-namespace:Tango.BL.Entities;assembly=Tango.BL" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:sharedConverters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" + xmlns:views="clr-namespace:Tango.PPC.Jobs.Views" + xmlns:global="clr-namespace:Tango.PPC.Jobs" mc:Ignorable="d" - d:DesignHeight="1280" d:DesignWidth="800"> + d:DesignHeight="1280" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=vm:JobsViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.JobsViewVM}"> <UserControl.Resources> <converters:SegmentsToPieConverter x:Key="SegmentsToPieConverter" /> diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Synchronization/MyModule.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Synchronization/MyModule.cs index e53b902e0..5de78a7f0 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Synchronization/MyModule.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Synchronization/MyModule.cs @@ -15,6 +15,7 @@ namespace Tango.PPC.Synchronization /// Represents a PPC <see cref="MyModule"/>. /// </summary> /// <seealso cref="Tango.PPC.Common.PPCModuleBase" /> + [PPCModule(2)] public class MyModule : PPCModuleBase { /// <summary> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs index 2a9ca212d..62a8d4d05 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs @@ -16,6 +16,16 @@ namespace Tango.PPC.Common.Application public interface IPPCApplicationManager { /// <summary> + /// Occurs when the application has started. + /// </summary> + event EventHandler ApplicationStarted; + + /// <summary> + /// Occurs when all PPC modules are ready and initialized. + /// </summary> + event EventHandler ModulesInitialized; + + /// <summary> /// Gets or sets the DAL machine. /// </summary> Machine Machine { get; } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Authentication/DefaultAuthenticationProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Authentication/DefaultAuthenticationProvider.cs index c8e89ac2f..f49beb32d 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Authentication/DefaultAuthenticationProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Authentication/DefaultAuthenticationProvider.cs @@ -3,30 +3,42 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.BL; using Tango.BL.Entities; +using Tango.Core; namespace Tango.PPC.Common.Authentication { - public class DefaultAuthenticationProvider : IAuthenticationProvider + public class DefaultAuthenticationProvider : ExtendedObject, IAuthenticationProvider { + private User _currentUser; + public User CurrentUser { - get + get { return _currentUser; } + private set { - throw new NotImplementedException(); + _currentUser = value; + RaisePropertyChangedAuto(); } } public event EventHandler<User> CurrentUserChanged; - public User Login(string email, string password) + public Task<User> Login(string email, string password) { - throw new NotImplementedException(); + return Task.Factory.StartNew(() => + { + CurrentUser = ObservablesEntitiesAdapter.Instance.Users.SingleOrDefault(x => x.Email.ToLower() == email && x.Password == password); + CurrentUserChanged?.Invoke(this, CurrentUser); + return CurrentUser; + }); } public void Logout() { - throw new NotImplementedException(); + CurrentUser = null; + CurrentUserChanged?.Invoke(this, CurrentUser); } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Authentication/IAuthenticationProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Authentication/IAuthenticationProvider.cs index 0892932a8..0fca03d49 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Authentication/IAuthenticationProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Authentication/IAuthenticationProvider.cs @@ -28,7 +28,7 @@ namespace Tango.PPC.Common.Authentication /// <param name="email">The email.</param> /// <param name="password">The password.</param> /// <returns></returns> - User Login(String email, String password); + Task<User> Login(String email, String password); /// <summary> /// Logs-out the current logged-in user. diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/IPPCModule.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/IPPCModule.cs index 6c9bf3892..4226e7aad 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/IPPCModule.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/IPPCModule.cs @@ -17,6 +17,11 @@ namespace Tango.PPC.Common public interface IPPCModule : IDisposable { /// <summary> + /// Occurs when the module has been initialized. + /// </summary> + event EventHandler Initialized; + + /// <summary> /// Gets the module name. /// </summary> String Name { get; } @@ -37,11 +42,6 @@ namespace Tango.PPC.Common Type MainViewType { get; } /// <summary> - /// Gets or sets a value indicating whether this module is shown under a new window. - /// </summary> - bool InNewWindow { get; set; } - - /// <summary> /// Gets the permission required to see and load this module. /// </summary> Permissions Permission { get; } @@ -55,10 +55,5 @@ namespace Tango.PPC.Common /// Perform any operations required to initialize this module. /// </summary> void Initialize(); - - /// <summary> - /// Sets a value indicating whether this module is loaded. - /// </summary> - bool IsLoaded { set; get; } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/IPPCView.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/IPPCView.cs new file mode 100644 index 000000000..35018a922 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/IPPCView.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Common +{ + public interface IPPCView + { + + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Modules/IPPCModuleLoader.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Modules/IPPCModuleLoader.cs new file mode 100644 index 000000000..52527fb33 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Modules/IPPCModuleLoader.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Common.Modules +{ + /// <summary> + /// Represents a PPC <see cref="IPPCModule"/> modules loading engine. + /// </summary> + public interface IPPCModuleLoader + { + /// <summary> + /// Occurs when the user has logged in and user modules are loaded. + /// </summary> + event EventHandler ModulesLoaded; + + /// <summary> + /// Gets all loaded modules. + /// </summary> + ObservableCollection<IPPCModule> AllModules { get; } + + /// <summary> + /// Gets all the user permitted modules. + /// </summary> + ObservableCollection<IPPCModule> UserModules { get; } + + /// <summary> + /// Gets the PPC module of type T if loaded. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> + T GetPPCModule<T>() where T : IPPCModule; + + /// <summary> + /// Loads all available PPC modules. + /// </summary> + void LoadModules(); + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Navigation/INavigationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Navigation/INavigationManager.cs index f29476631..60ca12530 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Navigation/INavigationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Navigation/INavigationManager.cs @@ -16,5 +16,11 @@ namespace Tango.PPC.Common.Navigation /// </summary> /// <param name="view">The view.</param> void NavigateTo(NavigationView view); + + /// <summary> + /// Navigates to the specified module. + /// </summary> + /// <typeparam name="T"></typeparam> + void NavigateTo<T>() where T : IPPCModule; } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCModuleBase.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCModuleBase.cs index 31c3218db..d4d00064c 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCModuleBase.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCModuleBase.cs @@ -18,12 +18,11 @@ namespace Tango.PPC.Common public abstract class PPCModuleBase : ExtendedObject, IPPCModule { private bool _isInitialized; - private bool _isLoaded; /// <summary> - /// Occurs when the user has navigated into or out of this module. + /// Occurs when the module has been initialized. /// </summary> - public event EventHandler<bool> IsLoadedChanged; + public event EventHandler Initialized; /// <summary> /// Gets the module name. @@ -66,32 +65,6 @@ namespace Tango.PPC.Common } /// <summary> - /// Sets a value indicating whether this module is loaded. - /// </summary> - public bool IsLoaded - { - get - { - return _isLoaded; - } - set - { - _isLoaded = value; - IsLoadedChanged?.Invoke(this, value); - } - } - - private bool _inNewWindow; - /// <summary> - /// Gets or sets a value indicating whether this module is shown under a new window. - /// </summary> - public bool InNewWindow - { - get { return _inNewWindow; } - set { _inNewWindow = value; RaisePropertyChangedAuto(); } - } - - /// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public abstract void Dispose(); @@ -101,8 +74,11 @@ namespace Tango.PPC.Common /// </summary> public void Initialize() { - OnInitialized(); - IsInitialized = true; + if (!IsInitialized) + { + OnInitialized(); + IsInitialized = true; + } } /// <summary> @@ -110,16 +86,7 @@ namespace Tango.PPC.Common /// </summary> protected virtual void OnInitialized() { - - } - - /// <summary> - /// Raises the <see cref="IsLoadedChanged"/> event. - /// </summary> - /// <param name="loaded">if set to <c>true</c> the module is loaded.</param> - protected virtual void OnLoadedChanged(bool loaded) - { - + Initialized?.Invoke(this, new EventArgs()); } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs index d9d7097e0..ffe5c9a4f 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.BL; using Tango.Core.DI; using Tango.PPC.Common.Application; using Tango.PPC.Common.Authentication; @@ -15,6 +16,11 @@ namespace Tango.PPC.Common { public abstract class PPCViewModel : ViewModel { + public ObservablesEntitiesAdapter Adapter + { + get { return ObservablesEntitiesAdapter.Instance; } + } + [TangoInject] public IPPCApplicationManager ApplicationManager { get; set; } @@ -54,4 +60,23 @@ namespace Tango.PPC.Common } } + + public abstract class PPCViewModel<T> : PPCViewModel where T : IPPCView + { + public T View { get; private set; } + + public bool ViewAttached { get; private set; } + + public override void OnApplicationStarted() + { + TangoIOC.Default.GetInstanceWhenAvailable<T>((view) => + { + ViewAttached = true; + View = view; + OnViewAttached(); + }); + } + + public abstract void OnViewAttached(); + } }
\ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj index 6fad5887f..348f7ed26 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj @@ -92,6 +92,8 @@ <Compile Include="..\..\Versioning\PPCVersionInfo.cs"> <Link>PPCVersionInfo.cs</Link> </Compile> + <Compile Include="IPPCView.cs" /> + <Compile Include="Modules\IPPCModuleLoader.cs" /> <Compile Include="PPCModuleAttribute.cs" /> <Compile Include="PPCModuleBase.cs" /> <Page Include="Controls\MultiPieChart.xaml"> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Modules/DefaultStudioModuleLoader.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Modules/DefaultStudioModuleLoader.cs new file mode 100644 index 000000000..bb68f05cd --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Modules/DefaultStudioModuleLoader.cs @@ -0,0 +1,146 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; +using Tango.BL.Entities; +using Tango.Logging; +using Tango.PPC.Common.Authentication; +using Tango.PPC.Common.Modules; +using Tango.PPC.Common; +using Tango.PPC.Jobs; + +namespace Tango.PPC.UI.Modules +{ + /// <summary> + /// Represents the default PPC <see cref="IPPCModuleLoader"></see>. + /// </summary> + /// <seealso cref="Tango.Core.ExtendedObject" /> + /// <seealso cref="Tango.PPC.Common.Modules.IPPCModuleLoader" /> + public class DefaultPPCModuleLoader : ExtendedObject, IPPCModuleLoader + { + private IAuthenticationProvider _authenticationProvider; + private bool _loaded; + + /// <summary> + /// Occurs when the user has logged in and user modules are loaded. + /// </summary> + public event EventHandler ModulesLoaded; + + /// <summary> + /// Initializes a new instance of the <see cref="DefaultPPCModuleLoader"/> class. + /// </summary> + /// <param name="authenticationProvider">The authentication provider.</param> + public DefaultPPCModuleLoader(IAuthenticationProvider authenticationProvider) + { + _authenticationProvider = authenticationProvider; + AllModules = new ObservableCollection<IPPCModule>(); + UserModules = new ObservableCollection<IPPCModule>(); + _authenticationProvider.CurrentUserChanged += _authenticationProvider_CurrentUserChanged; + } + + /// <summary> + /// Handles the authentication provider user changed event. + /// </summary> + /// <param name="sender">The sender.</param> + /// <param name="e">The e.</param> + private void _authenticationProvider_CurrentUserChanged(object sender, User e) + { + LoadModules(); + } + + private ObservableCollection<IPPCModule> _allModules; + /// <summary> + /// Gets all loaded modules. + /// </summary> + public ObservableCollection<IPPCModule> AllModules + { + get { return _allModules; } + private set { _allModules = value; RaisePropertyChangedAuto(); } + } + + private ObservableCollection<IPPCModule> _userModules; + /// <summary> + /// Gets all the user permitted modules. + /// </summary> + public ObservableCollection<IPPCModule> UserModules + { + get { return _userModules; } + private set { _userModules = value; RaisePropertyChangedAuto(); } + } + + /// <summary> + /// Loads all available PPC modules. + /// </summary> + public void LoadModules() + { + if (!_loaded) + { + //Preloaded + LogManager.Log(String.Format("Loading module '{0}'...", nameof(JobsModule))); + AllModules.Add(new JobsModule()); + //Preloaded + + AllModules.Clear(); + string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + + foreach (var file in Directory.GetFiles(assemblyFolder, "*.dll").Where(x => x.Contains("Tango.PPC"))) + { + try + { + Assembly moduleAssembly = null; + moduleAssembly = Assembly.LoadFrom(file); + + if (moduleAssembly != null) + { + foreach (var moduleType in moduleAssembly.GetTypes().Where(x => !x.IsInterface && typeof(IPPCModule).IsAssignableFrom(x) && !x.IsAbstract)) + { + if (!AllModules.ToList().Exists(x => x.GetType() == moduleType)) + { + try + { + LogManager.Log(String.Format("Loading module '{0}'...", moduleType.Name)); + var module = Activator.CreateInstance(moduleType) as IPPCModule; + AllModules.Add(module); + } + catch (Exception ex) + { + LogManager.Log(ex, "Could not load module " + moduleType.Name); + } + } + } + } + } + catch { } + } + + _loaded = true; + } + + AllModules = AllModules.OrderBy(x => x.GetType().GetCustomAttribute<PPCModuleAttribute>().Index).ToObservableCollection(); + + UserModules.Clear(); + + if (_authenticationProvider.CurrentUser != null) + { + UserModules = AllModules.Where(x => _authenticationProvider.CurrentUser.HasPermission(x.Permission)).ToObservableCollection(); + } + + ModulesLoaded?.Invoke(this, new EventArgs()); + } + + /// <summary> + /// Gets the PPC module of type T if loaded. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> + public T GetPPCModule<T>() where T : IPPCModule + { + return UserModules.OfType<T>().FirstOrDefault(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs index 83cf92f11..12c759c1a 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.PPC.Common; using Tango.PPC.Common.Navigation; using Tango.PPC.UI.Views; using Tango.SharedUI.Controls; @@ -22,5 +23,12 @@ namespace Tango.PPC.UI.Navigation var control = controls.Where(x => x.Elements.ToList().Exists(y => NavigationControl.GetNavigationName(y) == view.ToString())).SingleOrDefault(); control.NavigateTo(view.ToString()); } + + public void NavigateTo<T>() where T : IPPCModule + { + var navigationControl = LayoutView.Instance.NavigationControl; + + + } } } 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 6c2afb403..8b772b8bc 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs @@ -14,11 +14,14 @@ using System.Windows; using Tango.Core; using System.IO; using Tango.Core.Helpers; +using Tango.PPC.Common.Modules; namespace Tango.PPC.UI.PPCApplication { public class DefaultPPCApplicationManager : ExtendedObject, IPPCApplicationManager { + private List<PPCViewModel> _notifiedViewModels; + public bool IsShuttingDown { get; private set; } public IMachineOperator ConnectedMachine @@ -61,6 +64,8 @@ namespace Tango.PPC.UI.PPCApplication { if (!DesignMode) { + _notifiedViewModels = new List<PPCViewModel>(); + MainWindow.Instance.ContentRendered += async (_, __) => { await Task.Factory.StartNew(() => @@ -87,13 +92,41 @@ namespace Tango.PPC.UI.PPCApplication { Machine = db.Machines.SingleOrDefault(x => x.SerialNumber == settings.MachineSerialNumber); } - }); + ApplicationStarted?.Invoke(this, new EventArgs()); + foreach (var vm in TangoIOC.Default.GetAllInstancesByBase<PPCViewModel>()) { - vm.OnApplicationStarted(); + if (!_notifiedViewModels.Contains(vm)) + { + vm.OnApplicationStarted(); + _notifiedViewModels.Add(vm); + } } + + TangoIOC.Default.GetInstanceWhenAvailable<IPPCModuleLoader>((loader) => + { + loader.ModulesLoaded += (x, y) => + { + if (loader.UserModules.Count > 0) + { + loader.UserModules.LastOrDefault().Initialized += (e, f) => + { + foreach (var vm in TangoIOC.Default.GetAllInstancesByBase<PPCViewModel>()) + { + if (!_notifiedViewModels.Contains(vm)) + { + vm.OnApplicationStarted(); + _notifiedViewModels.Add(vm); + } + } + + ModulesInitialized?.Invoke(this, new EventArgs()); + }; + } + }; + }); }; } } @@ -107,5 +140,11 @@ namespace Tango.PPC.UI.PPCApplication vm.OnApplicationShuttingDown(); } } + + /// <summary> + /// Occurs when the application has started. + /// </summary> + public event EventHandler ApplicationStarted; + public event EventHandler ModulesInitialized; } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj index 12b53248e..8d7a35301 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj @@ -92,6 +92,7 @@ <Compile Include="..\..\Versioning\PPCVersionInfo.cs"> <Link>PPCVersionInfo.cs</Link> </Compile> + <Compile Include="Modules\DefaultStudioModuleLoader.cs" /> <Compile Include="Navigation\DefaultNavigationManager.cs" /> <Compile Include="Notifications\DefaultNotificationProvider.cs" /> <Compile Include="Notifications\MessageBox.xaml.cs"> @@ -99,13 +100,10 @@ </Compile> <Compile Include="PPCApplication\DefaultPPCApplicationManager.cs" /> <Compile Include="ViewModelLocator.cs" /> - <Compile Include="ViewModels\JobsViewVM.cs" /> <Compile Include="ViewModels\LayoutViewVM.cs" /> <Compile Include="ViewModels\LoadingViewVM.cs" /> <Compile Include="ViewModels\MainViewVM.cs" /> - <Compile Include="Views\JobsView.xaml.cs"> - <DependentUpon>JobsView.xaml</DependentUpon> - </Compile> + <Compile Include="ViewsContracts\ILayoutView.cs" /> <Compile Include="Views\LayoutView.xaml.cs"> <DependentUpon>LayoutView.xaml</DependentUpon> </Compile> @@ -143,10 +141,6 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> - <Page Include="Views\JobsView.xaml"> - <SubType>Designer</SubType> - <Generator>MSBuild:Compile</Generator> - </Page> <Page Include="Views\LayoutView.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> @@ -178,6 +172,10 @@ <Generator>ResXFileCodeGenerator</Generator> <LastGenOutput>Resources.Designer.cs</LastGenOutput> </EmbeddedResource> + <Content Include="..\..\..\DB\Tango.db"> + <Link>DB\Tango.db</Link> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> <None Include="packages.config" /> <None Include="Properties\Settings.settings"> <Generator>SettingsSingleFileGenerator</Generator> @@ -263,6 +261,9 @@ <ItemGroup> <Resource Include="Images\MessageBox Icons\information.png" /> </ItemGroup> + <ItemGroup> + <Folder Include="Messages\" /> + </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="..\..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('..\..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets')" /> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs index 3a37fe452..b3f2268e4 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs @@ -1,4 +1,5 @@ using System; +using System.Windows; using Tango.Core.DI; using Tango.Integration.Services; using Tango.Logging; @@ -6,12 +7,16 @@ using Tango.PPC.Common.Application; using Tango.PPC.Common.Authentication; using Tango.PPC.Common.Diagnostics; using Tango.PPC.Common.EventLogging; +using Tango.PPC.Common.Modules; using Tango.PPC.Common.Navigation; using Tango.PPC.Common.Notifications; +using Tango.PPC.UI.Modules; using Tango.PPC.UI.Navigation; using Tango.PPC.UI.Notifications; using Tango.PPC.UI.PPCApplication; using Tango.PPC.UI.ViewModels; +using Tango.PPC.UI.Views; +using Tango.PPC.UI.ViewsContracts; using Tango.TFS; namespace Tango.PPC.UI @@ -29,6 +34,7 @@ namespace Tango.PPC.UI { TangoIOC.Default.Unregister<INotificationProvider>(); TangoIOC.Default.Unregister<IAuthenticationProvider>(); + TangoIOC.Default.Unregister<IPPCModuleLoader>(); TangoIOC.Default.Unregister<INavigationManager>(); TangoIOC.Default.Unregister<IPPCApplicationManager>(); TangoIOC.Default.Unregister<ExternalBridgeScanner>(); @@ -38,6 +44,7 @@ namespace Tango.PPC.UI TangoIOC.Default.Register<INotificationProvider, DefaultNotificationProvider>(); TangoIOC.Default.Register<IAuthenticationProvider, DefaultAuthenticationProvider>(); + TangoIOC.Default.Register<IPPCModuleLoader, DefaultPPCModuleLoader>(); TangoIOC.Default.Register<INavigationManager, DefaultNavigationManager>(); TangoIOC.Default.Register<IPPCApplicationManager, DefaultPPCApplicationManager>(); TangoIOC.Default.Register<ExternalBridgeScanner, ExternalBridgeScanner>(); @@ -48,7 +55,13 @@ namespace Tango.PPC.UI TangoIOC.Default.Register<LoadingViewVM>(); TangoIOC.Default.Register<MainViewVM>(); TangoIOC.Default.Register<LayoutViewVM>(); - TangoIOC.Default.Register<JobsViewVM>(); + + + TangoIOC.Default.GetInstance<IPPCApplicationManager>().ApplicationStarted += (_, __) => + { + TangoIOC.Default.Register<ILayoutView, LayoutView>(LayoutView.Instance); + }; + //TangoIOC.Default.Register<LoadingViewVM>(); //TangoIOC.Default.Register<ShutdownViewVM>(); //TangoIOC.Default.Register<LoginViewVM>(); @@ -81,13 +94,5 @@ namespace Tango.PPC.UI return TangoIOC.Default.GetInstance<LayoutViewVM>(); } } - - public static JobsViewVM JobsViewVM - { - get - { - return TangoIOC.Default.GetInstance<JobsViewVM>(); - } - } } }
\ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/JobsViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/JobsViewVM.cs deleted file mode 100644 index 75ef7a2ac..000000000 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/JobsViewVM.cs +++ /dev/null @@ -1,130 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using System.Windows.Data; -using Tango.BL; -using Tango.BL.Entities; -using Tango.Core.Commands; -using Tango.DragAndDrop; -using Tango.PPC.Common; -using Tango.PPC.Common.Application; -using Tango.PPC.Common.Authentication; -using Tango.PPC.Common.Navigation; -using Tango.PPC.Common.Notifications; -using Tango.Settings; -using Tango.SharedUI; - -namespace Tango.PPC.UI.ViewModels -{ - public class JobsViewVM : PPCViewModel - { - private ObservablesContext _jobsContext; - - private ObservableCollection<Job> _jobs; - public ObservableCollection<Job> Jobs - { - get { return _jobs; } - set { _jobs = value; RaisePropertyChangedAuto(); } - } - - private ICollectionView _jobsCollectionView; - /// <summary> - /// Gets or sets the jobs collection view. - /// </summary> - public ICollectionView JobsCollectionView - { - get { return _jobsCollectionView; } - set - { - _jobsCollectionView = value; - RaisePropertyChangedAuto(); - } - } - - public RelayCommand JobSelectedCommand { get; set; } - - public RelayCommand<DropEventArgs> OnDragAndDropCommand { get; set; } - - public RelayCommand<Job> RemoveJobCommand { get; set; } - - private void OnDragAndDropJobs(Job draggedJob, Job droppedJob) - { - Debug.WriteLine(draggedJob.Name + " Dragged on to " + droppedJob.Name); - - if (draggedJob.JobIndex > droppedJob.JobIndex) - { - draggedJob.JobIndex = droppedJob.JobIndex - 1; - } - else - { - draggedJob.JobIndex = droppedJob.JobIndex + 1; - } - - int index = 1; - - foreach (var job in Jobs.OrderBy(x => x.JobIndex)) - { - job.JobIndex = index++; - } - - JobsCollectionView.Refresh(); - } - - private async void JobSelected(Job job) - { - Debug.WriteLine(job.Name); - await NotificationProvider.ShowInfo("Job details not yet implemented..."); - } - - public JobsViewVM() - { - Jobs = new ObservableCollection<Job>(); - - JobSelectedCommand = new RelayCommand((x) => JobSelected(x as Job)); - OnDragAndDropCommand = new RelayCommand<DropEventArgs>((e) => - { - Job draggedJob = e.Draggable.DataContext as Job; - Job droppedJob = e.Droppable.DataContext as Job; - - OnDragAndDropJobs(draggedJob, droppedJob); - }); - - RemoveJobCommand = new RelayCommand<Job>(RemoveJob); - } - - private void RemoveJob(Job job) - { - NotificationProvider.ShowQuestion("Are you sure you want to remove " + job.Name); - } - - public override void OnApplicationStarted() - { - LoadJobs(); - } - - private void LoadJobs() - { - Task.Factory.StartNew(() => - { - Thread.Sleep(500); - - if (_jobsContext != null) - { - _jobsContext.Dispose(); - } - - _jobsContext = ObservablesContext.CreateDefault(); - - Jobs = _jobsContext.Jobs.Where(x => x.Machine.SerialNumber == Settings.MachineSerialNumber).ToObservableCollection(); - JobsCollectionView = CollectionViewSource.GetDefaultView(Jobs); - JobsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Job.LastUpdated), ListSortDirection.Descending)); - }); - } - } -} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs index cc64f82f5..168df019a 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs @@ -3,12 +3,33 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.Core.DI; +using Tango.PPC.Common; +using Tango.PPC.Common.Modules; +using Tango.PPC.UI.ViewsContracts; using Tango.SharedUI; namespace Tango.PPC.UI.ViewModels { - public class LayoutViewVM : ViewModel + public class LayoutViewVM : PPCViewModel<ILayoutView> { + [TangoInject] + public IPPCModuleLoader ModuleLoader { get; set; } + public override void OnApplicationStarted() + { + base.OnApplicationStarted(); + ModuleLoader.ModulesLoaded += ModuleLoader_ModulesLoaded; + } + + private void ModuleLoader_ModulesLoaded(object sender, EventArgs e) + { + View.ApplyModules(ModuleLoader.UserModules); + } + + public override void OnViewAttached() + { + + } } } 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 a33dc25d7..20752ac71 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.BL; using Tango.Core; using Tango.Core.Helpers; using Tango.PPC.Common; @@ -19,9 +20,17 @@ namespace Tango.PPC.UI.ViewModels { public async override void OnApplicationStarted() { - await Task.Delay(500); - NavigationManager.NavigateTo(NavigationView.LayoutView); - NavigationManager.NavigateTo(NavigationView.JobsView); + await Task.Factory.StartNew(() => + { + ObservablesEntitiesAdapter.Instance.Initialize(); + }); + + ApplicationManager.ModulesInitialized += (_, __) => + { + NavigationManager.NavigateTo(NavigationView.LayoutView); + }; + + await AuthenticationProvider.Login("roy@twine-s.com", "1234"); } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs index d1fc4c015..deea33a0d 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs @@ -3,9 +3,11 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.Core.DI; using Tango.PPC.Common; using Tango.PPC.Common.Application; using Tango.PPC.Common.Authentication; +using Tango.PPC.Common.Modules; using Tango.PPC.Common.Navigation; using Tango.PPC.Common.Notifications; using Tango.SharedUI; diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/JobsView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/JobsView.xaml deleted file mode 100644 index 37c768a0f..000000000 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/JobsView.xaml +++ /dev/null @@ -1,155 +0,0 @@ -<UserControl x:Class="Tango.PPC.UI.Views.JobsView" - xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" - 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:vm="clr-namespace:Tango.PPC.UI.ViewModels" - xmlns:global="clr-namespace:Tango.PPC.UI" - xmlns:dragAndDrop="clr-namespace:Tango.DragAndDrop;assembly=Tango.DragAndDrop" - xmlns:keyboard="clr-namespace:Tango.Touch.Keyboard;assembly=Tango.Touch" - xmlns:converters="clr-namespace:Tango.PPC.Common.Converters;assembly=Tango.PPC.Common" - xmlns:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch" - xmlns:touchComponents="clr-namespace:Tango.Touch.Components;assembly=Tango.Touch" - xmlns:fa="http://schemas.fontawesome.io/icons/" - xmlns:entities="clr-namespace:Tango.BL.Entities;assembly=Tango.BL" - xmlns:sys="clr-namespace:System;assembly=mscorlib" - xmlns:sharedConverters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" - xmlns:local="clr-namespace:Tango.PPC.UI.Views" - mc:Ignorable="d" - d:DesignHeight="1280" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=vm:JobsViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.JobsViewVM}"> - - <UserControl.Resources> - <converters:SegmentsToPieConverter x:Key="SegmentsToPieConverter" /> - <sharedConverters:DateTimeUTCToShortDateConverter x:Key="DateTimeUTCToShortDateConverter" /> - <sharedConverters:EnumToDescriptionConverter x:Key="EnumToDescriptionConverter" /> - </UserControl.Resources> - - <Grid Background="{StaticResource TangoMidBackgroundBrush}"> - <Grid.RowDefinitions> - <RowDefinition Height="Auto"/> - <RowDefinition Height="1*"/> - </Grid.RowDefinitions> - - <Border Padding="20" Background="{StaticResource TangoPrimaryBackgroundBrush}" BorderThickness="0 0 0 1" BorderBrush="{StaticResource TangoDividerBrush}"> - <Border.Effect> - <DropShadowEffect Color="Silver" ShadowDepth="0" BlurRadius="20" Opacity="1" /> - </Border.Effect> - <TextBlock VerticalAlignment="Center" FontSize="{StaticResource TangoHeaderFontSize}" FontWeight="SemiBold">Jobs</TextBlock> - </Border> - - <Grid Grid.Row="1"> - <Grid.RowDefinitions> - <RowDefinition Height="100"/> - <RowDefinition Height="1*"/> - </Grid.RowDefinitions> - - <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top" Height="57" Margin="0 -28 30 0"> - <touch:TouchIconButton Margin="0 0 30 0" Padding="20" Icon="Plus" Style="{StaticResource TangoRoundTouchIconButton}"></touch:TouchIconButton> - <touch:TouchIconButton Margin="0 0 30 0" Padding="20" Icon="Copy" Style="{StaticResource TangoRoundTouchIconButton}"></touch:TouchIconButton> - <touch:TouchIconButton Padding="20" Icon="Refresh" Style="{StaticResource TangoRoundTouchIconButton}"></touch:TouchIconButton> - </StackPanel> - - <touch:TouchNavigationLinks VerticalAlignment="Bottom" Margin="20" FontSize="{StaticResource TangoNavigationLinksFontSize}"> - <sys:String>READY TO DYE</sys:String> - <sys:String>NOT READY</sys:String> - <sys:String>ALL</sys:String> - </touch:TouchNavigationLinks> - - <Grid Grid.Row="1"> - <touch:LightTouchDataGrid x:Name="dataGridJobs" OnDragAndDropCommand="{Binding OnDragAndDropCommand}" ItemsSource="{Binding JobsCollectionView}" Margin="10"> - <touch:LightTouchDataGrid.Columns> - <touch:LightTouchDataGridColumn> - <touch:LightTouchDataGridColumn.Header> - <Image Source="/Images/warning.png" Width="24" /> - </touch:LightTouchDataGridColumn.Header> - <touch:LightTouchDataGridColumn.CellTemplate> - <DataTemplate> - <Image Source="/Images/Job Issues/cyan.png" Width="38" /> - </DataTemplate> - </touch:LightTouchDataGridColumn.CellTemplate> - </touch:LightTouchDataGridColumn> - <touch:LightTouchDataGridColumn Width="90" Header="Status" SortMember="JobStatus"> - <touch:LightTouchDataGridColumn.CellTemplate> - <DataTemplate> - <TextBlock IsHitTestVisible="False" Text="{Binding JobStatus,Converter={StaticResource EnumToDescriptionConverter}}"></TextBlock> - </DataTemplate> - </touch:LightTouchDataGridColumn.CellTemplate> - </touch:LightTouchDataGridColumn> - <touch:LightTouchDataGridColumn Width="240" Header="Name" SortMember="Name"> - <touch:LightTouchDataGridColumn.CellTemplate> - <DataTemplate> - <TextBlock IsHitTestVisible="False" Text="{Binding Name}"></TextBlock> - </DataTemplate> - </touch:LightTouchDataGridColumn.CellTemplate> - </touch:LightTouchDataGridColumn> - <touch:LightTouchDataGridColumn Width="117" Header="Length (m)" SortMember="Length"> - <touch:LightTouchDataGridColumn.CellTemplate> - <DataTemplate> - <TextBlock IsHitTestVisible="False" Text="{Binding Length,StringFormat=0.0}"></TextBlock> - </DataTemplate> - </touch:LightTouchDataGridColumn.CellTemplate> - </touch:LightTouchDataGridColumn> - <touch:LightTouchDataGridColumn Header="Colors" SortMember="Segments.Count" Width="85"> - <touch:LightTouchDataGridColumn.CellTemplate> - <DataTemplate> - <ContentControl IsHitTestVisible="False" Content="{Binding Segments,Converter={StaticResource SegmentsToPieConverter}}" Width="23" Height="23" HorizontalAlignment="Left"></ContentControl> - </DataTemplate> - </touch:LightTouchDataGridColumn.CellTemplate> - </touch:LightTouchDataGridColumn> - <touch:LightTouchDataGridColumn Width="100" Header="Updated" SortMember="LastUpdated"> - <touch:LightTouchDataGridColumn.CellTemplate> - <DataTemplate> - <TextBlock IsHitTestVisible="False" Text="{Binding LastUpdated,Converter={StaticResource DateTimeUTCToShortDateConverter}}"></TextBlock> - </DataTemplate> - </touch:LightTouchDataGridColumn.CellTemplate> - </touch:LightTouchDataGridColumn> - <touch:LightTouchDataGridColumn x:Name="userSortColumn" SortMember="JobIndex" SortDirection="{x:Null}" Width="78" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" DisplayChevron="False" ForcedSortDirection="Ascending"> - <touch:LightTouchDataGridColumn.HeaderTemplate> - <DataTemplate> - <Border CornerRadius="0 5 5 0" x:Name="userSortColumnBorder"> - <Border.Style> - <Style TargetType="Border"> - <Setter Property="Background" Value="{StaticResource TangoMidAccentBrush}"></Setter> - <Style.Triggers> - <DataTrigger Binding="{Binding SortDirection}" Value="Ascending"> - <Setter Property="Background" Value="{StaticResource TangoLowAccentBrush}"></Setter> - </DataTrigger> - </Style.Triggers> - </Style> - </Border.Style> - <Grid> - <Rectangle HorizontalAlignment="Left" StrokeThickness="2" Stroke="{StaticResource TangoColumnDividerBrush}" /> - <Image Source="/Images/arrows.png" Width="28" /> - </Grid> - </Border> - </DataTemplate> - </touch:LightTouchDataGridColumn.HeaderTemplate> - <touch:LightTouchDataGridColumn.CellTemplate> - <DataTemplate> - <dragAndDrop:DragThumb Background="Transparent" touchComponents:Ripple.PreventRipple="True" touchComponents:TransformationHelper.PreventTransform="True"> - <dragAndDrop:DragThumb.Style> - <Style TargetType="dragAndDrop:DragThumb"> - <Setter Property="Visibility" Value="Collapsed"></Setter> - <Style.Triggers> - <DataTrigger Binding="{Binding Source={x:Reference userSortColumn},Path=SortDirection}" Value="Ascending"> - <Setter Property="Visibility" Value="Visible"></Setter> - </DataTrigger> - </Style.Triggers> - </Style> - </dragAndDrop:DragThumb.Style> - <StackPanel Width="30" IsHitTestVisible="False" VerticalAlignment="Center"> - <Rectangle StrokeThickness="2" Stroke="{StaticResource TangoDarkForegroundBrush}" /> - <Rectangle StrokeThickness="2" Stroke="{StaticResource TangoDarkForegroundBrush}" Margin="0 5 0 0" /> - </StackPanel> - </dragAndDrop:DragThumb> - </DataTemplate> - </touch:LightTouchDataGridColumn.CellTemplate> - </touch:LightTouchDataGridColumn> - </touch:LightTouchDataGrid.Columns> - </touch:LightTouchDataGrid> - - <TextBox VerticalAlignment="Bottom" HorizontalAlignment="Center" Margin="100" Width="200" keyboard:KeyboardView.Mode="Alpha"></TextBox> - </Grid> - </Grid> - </Grid> -</UserControl> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/JobsView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/JobsView.xaml.cs deleted file mode 100644 index 66f104511..000000000 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/JobsView.xaml.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -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.PPC.UI.Views -{ - /// <summary> - /// Interaction logic for JobsView.xaml - /// </summary> - public partial class JobsView : UserControl - { - public JobsView() - { - InitializeComponent(); - - //dataGridJobs.Sorting += DataGridJobs_Sorting; - } - - private void DataGridJobs_Sorting(object sender, DataGridSortingEventArgs e) - { - //if (e.Column != userSortColumn) - //{ - // userSortColumnBorder.Background = Application.Current.Resources["TangoMidAccentBrush"] as Brush; - //} - } - - private void OnJobIndexColumnClick(object sender, MouseButtonEventArgs e) - { - //SortDataGrid(dataGridJobs, dataGridJobs.Columns.Count - 1, ListSortDirection.Ascending); - //userSortColumnBorder.Background = Application.Current.Resources["TangoLowAccentBrush"] as Brush; - } - - private static void SortDataGrid(DataGrid dataGrid, int columnIndex = 0, ListSortDirection sortDirection = ListSortDirection.Ascending) - { - var column = dataGrid.Columns[columnIndex]; - - // Clear current sort descriptions - dataGrid.Items.SortDescriptions.Clear(); - - // Add the new sort description - dataGrid.Items.SortDescriptions.Add(new SortDescription(column.SortMemberPath, sortDirection)); - - // Apply sort - foreach (var col in dataGrid.Columns) - { - col.SortDirection = null; - } - column.SortDirection = sortDirection; - - // Refresh items to display sort - dataGrid.Items.Refresh(); - } - } -} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml index fb5cb4f8b..46e104627 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml @@ -98,7 +98,7 @@ <Grid> <keyboard:KeyboardView> <controls:NavigationControl x:Name="NavigationControl" x:FieldModifier="public" TransitionAlwaysFades="False" TransitionType="Slide"> - <local:JobsView controls:NavigationControl.NavigationName="JobsView"></local:JobsView> + </controls:NavigationControl> </keyboard:KeyboardView> </Grid> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs index e6c778a92..8ab602f2c 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs @@ -12,13 +12,16 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using Tango.Logging; +using Tango.PPC.Common; +using Tango.PPC.UI.ViewsContracts; namespace Tango.PPC.UI.Views { /// <summary> /// Interaction logic for LayoutView.xaml /// </summary> - public partial class LayoutView : UserControl + public partial class LayoutView : UserControl, ILayoutView { public static LayoutView Instance { get; private set; } @@ -27,5 +30,28 @@ namespace Tango.PPC.UI.Views InitializeComponent(); Instance = this; } + + public void ApplyModules(IEnumerable<IPPCModule> modules) + { + this.BeginInvoke(() => + { + foreach (var module in modules) + { + if (!NavigationControl.Elements.ToList().Exists(x => x.GetType() == module.MainViewType)) + { + LogManager.Default.Log("Loading module " + module.Name + "..."); + FrameworkElement view = Activator.CreateInstance(module.MainViewType) as FrameworkElement; + SharedUI.Controls.NavigationControl.SetNavigationName(view, module.Name); + NavigationControl.Elements.Add(view); + module.Initialize(); + } + } + + if (modules.Count() > 0) + { + NavigationControl.NavigateTo(modules.First().Name); + } + }); + } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewsContracts/ILayoutView.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewsContracts/ILayoutView.cs new file mode 100644 index 000000000..f79c790ff --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewsContracts/ILayoutView.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.PPC.Common; + +namespace Tango.PPC.UI.ViewsContracts +{ + public interface ILayoutView : IPPCView + { + void ApplyModules(IEnumerable<IPPCModule> modules); + } +} |
