aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-06-12 19:04:09 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-06-12 19:04:09 +0300
commitca50e0c8fc88acd06d6e1932e9412464bff95edb (patch)
treeaaafb06deca983c1e80c8c34508d23a452e4a235 /Software/Visual_Studio/PPC/Tango.PPC.UI
parent8a59643571080bfff715f0b0e4bb03e2dee4961a (diff)
downloadTango-ca50e0c8fc88acd06d6e1932e9412464bff95edb.tar.gz
Tango-ca50e0c8fc88acd06d6e1932e9412464bff95edb.zip
Working on PPC modules and loading.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Modules/DefaultStudioModuleLoader.cs146
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs8
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs43
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj17
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs23
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/JobsViewVM.cs130
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs23
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs15
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs2
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Views/JobsView.xaml155
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Views/JobsView.xaml.cs66
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml2
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs28
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewsContracts/ILayoutView.cs14
14 files changed, 296 insertions, 376 deletions
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);
+ }
+}