init
This commit is contained in:
315
Common/DTS.Common/RegionManager/DTSRegionManager.cs
Normal file
315
Common/DTS.Common/RegionManager/DTSRegionManager.cs
Normal file
@@ -0,0 +1,315 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Runtime.Remoting.Lifetime;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using DTS.Common.Classes;
|
||||
using DTS.Common.Events;
|
||||
using DTS.Common.Interface;
|
||||
using DTS.Common.Base;
|
||||
using Prism.Regions;
|
||||
using Prism.Events;
|
||||
using Unity;
|
||||
namespace DTS.Common
|
||||
{
|
||||
public class DTSRegionManager : IDTSRegionManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Injected unity container
|
||||
/// </summary>
|
||||
private readonly IUnityContainer _unityContainer;
|
||||
|
||||
/// <summary>
|
||||
/// Injected region manager
|
||||
/// </summary>
|
||||
private readonly IRegionManager _regionManager;
|
||||
|
||||
/// <summary>
|
||||
/// Injected event aggregator
|
||||
/// </summary>
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="DTSRegionManager"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unityContainer">Obtained reference of the unity container by using dependency injection.</param>
|
||||
/// <param name="regionManager">Obtained reference of the region manager by using dependency injection.</param>
|
||||
/// <param name="eventAggregator">Obtained reference of the event aggregator by using dependency injection.</param>
|
||||
public DTSRegionManager(IUnityContainer unityContainer, IRegionManager regionManager, IEventAggregator eventAggregator)
|
||||
{
|
||||
_unityContainer = unityContainer;
|
||||
_regionManager = regionManager;
|
||||
_eventAggregator = eventAggregator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds View to the Main Region.
|
||||
/// </summary>
|
||||
/// <param name="viewDefinition">The View definition.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
public void AddView(ViewDefinition viewDefinition, object parameter)
|
||||
{
|
||||
AddView(viewDefinition, parameter, false);
|
||||
}
|
||||
|
||||
private IShellViewModel GetShellViewModelByRegionName(string regionName)
|
||||
{
|
||||
IShellViewModel shellVm = null;
|
||||
|
||||
shellVm = _unityContainer.Resolve<IShellViewModel>();
|
||||
//TODO: Add more stuff
|
||||
return shellVm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds View to the Main Region.
|
||||
/// </summary>
|
||||
/// <param name="viewDefinition">The View definition.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
/// <param name="allowMultipleInstances">A value indicating whether to allow to create the multiple views.</param>
|
||||
public void AddView(ViewDefinition viewDefinition, object parameter, bool allowMultipleInstances)
|
||||
{
|
||||
var shell = _unityContainer.Resolve<IShellViewModel>();
|
||||
|
||||
var viewModel = (IBaseViewModel)_unityContainer.Resolve(viewDefinition.ViewModelInterfaceType);
|
||||
var view = (IBaseView)_unityContainer.Resolve(viewDefinition.ViewInterfaceType);
|
||||
view.DataContext = viewModel;
|
||||
|
||||
_regionManager.AddViewToRegion(viewDefinition.RegionName, view);
|
||||
_regionManager.ActivateViewIfExists(viewDefinition.RegionName, viewDefinition.ViewInterfaceType);
|
||||
|
||||
if (parameter == null)
|
||||
viewModel.Initialize();
|
||||
else
|
||||
viewModel.Initialize(parameter);
|
||||
|
||||
switch (viewDefinition.RegionName)
|
||||
{
|
||||
case RegionNames.MainRegion:
|
||||
shell.ContextMainRegion = view;
|
||||
break;
|
||||
}
|
||||
|
||||
//IShellViewModel shellVm = GetShellViewModelByRegionName(viewDefinition.RegionName);
|
||||
//if (shellVm != null)
|
||||
//{
|
||||
// shellVm.ContextMainRegion = view;
|
||||
//}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds View to the Main Region asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="viewDefinition">The View definition.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
public async Task AddViewAsync(ViewDefinition viewDefinition, object parameter)
|
||||
{
|
||||
await AddViewAsync(viewDefinition, parameter, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds View to the Main Region asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="viewDefinition">The View definition.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
/// <param name="allowMultipleInstances">A value indicating whether to allow to create the multiple views.</param>
|
||||
public async Task AddViewAsync(ViewDefinition viewDefinition, object parameter, bool allowMultipleInstances)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!allowMultipleInstances)
|
||||
{
|
||||
if (_regionManager.ActivateViewIfExists(viewDefinition.RegionName, viewDefinition.ViewInterfaceType))
|
||||
return;
|
||||
}
|
||||
|
||||
var viewModel = (IBaseViewModel)_unityContainer.Resolve(viewDefinition.ViewModelInterfaceType);
|
||||
var view = (IBaseView)_unityContainer.Resolve(viewDefinition.ViewInterfaceType);
|
||||
view.DataContext = viewModel;
|
||||
|
||||
_regionManager.AddViewToRegion(viewDefinition.RegionName, view);
|
||||
_regionManager.ActivateViewIfExists(viewDefinition.RegionName, viewDefinition.ViewInterfaceType);
|
||||
|
||||
if (parameter == null)
|
||||
await viewModel.InitializeAsync();
|
||||
else
|
||||
await viewModel.InitializeAsync(parameter);
|
||||
|
||||
var shellVm = GetShellViewModelByRegionName(viewDefinition.RegionName);
|
||||
|
||||
if (shellVm != null)
|
||||
{
|
||||
shellVm.ContextMainRegion = view;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_eventAggregator.GetEvent<RaiseNotification>()
|
||||
.Publish(new NotificationContentEventArgs(Utility.GetAllErrorMessages(ex)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes View from the Main Region asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="viewModel">The View-model.</param>
|
||||
public void RemoveView(IBaseViewModel viewModel)
|
||||
{
|
||||
// Jtacc is composed of three regions(three shells)
|
||||
foreach (var region in _regionManager.Regions)
|
||||
{
|
||||
var view =
|
||||
region.Views.FirstOrDefault(
|
||||
v => v is IBaseView && ReferenceEquals(((IBaseView)v).DataContext, viewModel));
|
||||
|
||||
if (view != null)
|
||||
{
|
||||
viewModel.Cleanup();
|
||||
region.Deactivate(view);
|
||||
region.Remove(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveViewByRegionName(string regionName)
|
||||
{
|
||||
_regionManager.ClearRegion(regionName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reloads data for the specified View.
|
||||
/// </summary>
|
||||
/// <param name="interfaceForView">Type of the View's interface.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
public void RefreshView(Type interfaceForView, object parameter)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var region in _regionManager.Regions)
|
||||
{
|
||||
var existingView = _regionManager.GetView(region.Name, interfaceForView) as IBaseView;
|
||||
|
||||
if (existingView != null)
|
||||
{
|
||||
var viewModel = existingView.DataContext as IBaseViewModel;
|
||||
if (viewModel != null)
|
||||
{
|
||||
viewModel.Cleanup();
|
||||
|
||||
if (parameter == null)
|
||||
viewModel.Initialize();
|
||||
else
|
||||
viewModel.Initialize(parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_eventAggregator.GetEvent<RaiseNotification>().Publish(new NotificationContentEventArgs(Utility.GetAllErrorMessages(ex)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reloads data for the specified View asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="interfaceForView">Type of the View's interface.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
public async Task RefreshViewAsync(Type interfaceForView, object parameter)
|
||||
{
|
||||
//TODO: fix so that it finds view in right view.
|
||||
try
|
||||
{
|
||||
foreach (var region in _regionManager.Regions)
|
||||
{
|
||||
var existingView =
|
||||
_regionManager.GetView(region.Name, interfaceForView) as IBaseView;
|
||||
if (existingView == null) continue;
|
||||
var viewModel = existingView.DataContext as IBaseViewModel;
|
||||
if (viewModel == null) continue;
|
||||
await viewModel.CleanupAsync();
|
||||
|
||||
if (parameter == null)
|
||||
await viewModel.InitializeAsync();
|
||||
else
|
||||
await viewModel.InitializeAsync(parameter);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_eventAggregator.GetEvent<RaiseNotification>().Publish(new NotificationContentEventArgs(Utility.GetAllErrorMessages(ex)));
|
||||
}
|
||||
}
|
||||
|
||||
public IRegionCollection Regions { get; private set; }
|
||||
public IRegionManager CreateRegionManager()
|
||||
{
|
||||
return new RegionManager();
|
||||
}
|
||||
|
||||
public IRegionManager AddToRegion(string regionName, object view)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IRegionManager AddToRegion(string regionName, string viewName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IRegionManager RegisterViewWithRegion(string regionName, string viewName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IRegionManager RegisterViewWithRegion(string regionName, Type viewType)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IRegionManager RegisterViewWithRegion(string regionName, Func<object> getContentDelegate)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void RequestNavigate(string regionName, Uri source, Action<NavigationResult> navigationCallback)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void RequestNavigate(string regionName, Uri source)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void RequestNavigate(string regionName, string source, Action<NavigationResult> navigationCallback)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void RequestNavigate(string regionName, string source)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void RequestNavigate(string regionName, Uri target, Action<NavigationResult> navigationCallback, NavigationParameters navigationParameters)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void RequestNavigate(string regionName, string target, Action<NavigationResult> navigationCallback, NavigationParameters navigationParameters)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void RequestNavigate(string regionName, Uri target, NavigationParameters navigationParameters)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void RequestNavigate(string regionName, string target, NavigationParameters navigationParameters)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
315
Common/DTS.Common/RegionManager/DTSViewRegionManager.cs
Normal file
315
Common/DTS.Common/RegionManager/DTSViewRegionManager.cs
Normal file
@@ -0,0 +1,315 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Runtime.Remoting.Lifetime;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using DTS.Common.Classes;
|
||||
using DTS.Common.Events;
|
||||
using DTS.Common.Interface;
|
||||
using DTS.Common.Base;
|
||||
using Prism.Regions;
|
||||
using Prism.Events;
|
||||
using Unity;
|
||||
// ReSharper disable InconsistentNaming
|
||||
// ReSharper disable CheckNamespace
|
||||
namespace DTS.Common
|
||||
{
|
||||
public class DTSViewRegionManager : IDTSViewRegionManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Injected unity container
|
||||
/// </summary>
|
||||
private readonly IUnityContainer _unityContainer;
|
||||
|
||||
/// <summary>
|
||||
/// Injected region manager
|
||||
/// </summary>
|
||||
private readonly IRegionManager _regionManager;
|
||||
|
||||
/// <summary>
|
||||
/// Injected event aggregator
|
||||
/// </summary>
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="DTSRegionManager"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unityContainer">Obtained reference of the unity container by using dependency injection.</param>
|
||||
/// <param name="regionManager">Obtained reference of the region manager by using dependency injection.</param>
|
||||
/// <param name="eventAggregator">Obtained reference of the event aggregator by using dependency injection.</param>
|
||||
public DTSViewRegionManager(IUnityContainer unityContainer, IRegionManager regionManager, IEventAggregator eventAggregator)
|
||||
{
|
||||
_unityContainer = unityContainer;
|
||||
_regionManager = regionManager;
|
||||
_eventAggregator = eventAggregator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds View to the Main Region.
|
||||
/// </summary>
|
||||
/// <param name="viewDefinition">The View definition.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
public void AddView(ViewDefinition viewDefinition, object parameter)
|
||||
{
|
||||
AddView(viewDefinition, parameter, false);
|
||||
}
|
||||
|
||||
private IShellViewModel GetShellViewModelByRegionName(string regionName)
|
||||
{
|
||||
IShellViewModel shellVm = null;
|
||||
shellVm = _unityContainer.Resolve<IShellViewModel>();
|
||||
return shellVm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds View to the Main Region.
|
||||
/// </summary>
|
||||
/// <param name="viewDefinition">The View definition.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
/// <param name="allowMultipleInstances">A value indicating whether to allow to create the multiple views.</param>
|
||||
public void AddView(ViewDefinition viewDefinition, object parameter, bool allowMultipleInstances)
|
||||
{
|
||||
var shell = _unityContainer.Resolve<IShellViewModel>();
|
||||
|
||||
var viewModel = (IBaseViewModel)_unityContainer.Resolve(viewDefinition.ViewModelInterfaceType);
|
||||
var view = (IBaseView)_unityContainer.Resolve(viewDefinition.ViewInterfaceType);
|
||||
view.DataContext = viewModel;
|
||||
|
||||
_regionManager.AddViewToRegion(viewDefinition.RegionName, view);
|
||||
_regionManager.ActivateViewIfExists(viewDefinition.RegionName, viewDefinition.ViewInterfaceType);
|
||||
|
||||
if (parameter == null)
|
||||
viewModel.Initialize();
|
||||
else
|
||||
viewModel.Initialize(parameter);
|
||||
|
||||
switch (viewDefinition.RegionName)
|
||||
{
|
||||
case RegionNames.MainRegion:
|
||||
shell.ContextMainRegion = view;
|
||||
break;
|
||||
}
|
||||
|
||||
//IShellViewModel shellVm = GetShellViewModelByRegionName(viewDefinition.RegionName);
|
||||
//if (shellVm != null)
|
||||
//{
|
||||
// shellVm.ContextMainRegion = view;
|
||||
//}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds View to the Main Region asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="viewDefinition">The View definition.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
public async Task AddViewAsync(ViewDefinition viewDefinition, object parameter)
|
||||
{
|
||||
await AddViewAsync(viewDefinition, parameter, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds View to the Main Region asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="viewDefinition">The View definition.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
/// <param name="allowMultipleInstances">A value indicating whether to allow to create the multiple views.</param>
|
||||
public async Task AddViewAsync(ViewDefinition viewDefinition, object parameter, bool allowMultipleInstances)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!allowMultipleInstances)
|
||||
{
|
||||
if (_regionManager.ActivateViewIfExists(viewDefinition.RegionName, viewDefinition.ViewInterfaceType))
|
||||
return;
|
||||
}
|
||||
|
||||
var viewModel = (IBaseViewModel)_unityContainer.Resolve(viewDefinition.ViewModelInterfaceType);
|
||||
var view = (IBaseView)_unityContainer.Resolve(viewDefinition.ViewInterfaceType);
|
||||
view.DataContext = viewModel;
|
||||
|
||||
_regionManager.AddViewToRegion(viewDefinition.RegionName, view);
|
||||
_regionManager.ActivateViewIfExists(viewDefinition.RegionName, viewDefinition.ViewInterfaceType);
|
||||
|
||||
if (parameter == null)
|
||||
await viewModel.InitializeAsync();
|
||||
else
|
||||
await viewModel.InitializeAsync(parameter);
|
||||
|
||||
var shellVm = GetShellViewModelByRegionName(viewDefinition.RegionName);
|
||||
|
||||
if (shellVm != null)
|
||||
{
|
||||
shellVm.ContextMainRegion = view;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_eventAggregator.GetEvent<RaiseNotification>()
|
||||
.Publish(new NotificationContentEventArgs(Utility.GetAllErrorMessages(ex)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes View from the Main Region asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="viewModel">The View-model.</param>
|
||||
public void RemoveView(IBaseViewModel viewModel)
|
||||
{
|
||||
// Jtacc is composed of three regions(three shells)
|
||||
foreach (var region in _regionManager.Regions)
|
||||
{
|
||||
var view =
|
||||
region.Views.FirstOrDefault(
|
||||
v => v is IBaseView && ReferenceEquals(((IBaseView)v).DataContext, viewModel));
|
||||
|
||||
if (view != null)
|
||||
{
|
||||
viewModel.Cleanup();
|
||||
region.Deactivate(view);
|
||||
region.Remove(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveViewByRegionName(string regionName)
|
||||
{
|
||||
_regionManager.ClearRegion(regionName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reloads data for the specified View.
|
||||
/// </summary>
|
||||
/// <param name="interfaceForView">Type of the View's interface.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
public void RefreshView(Type interfaceForView, object parameter)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var region in _regionManager.Regions)
|
||||
{
|
||||
var existingView = _regionManager.GetView(region.Name, interfaceForView) as IBaseView;
|
||||
|
||||
if (existingView != null)
|
||||
{
|
||||
var viewModel = existingView.DataContext as IBaseViewModel;
|
||||
if (viewModel != null)
|
||||
{
|
||||
viewModel.Cleanup();
|
||||
|
||||
if (parameter == null)
|
||||
viewModel.Initialize();
|
||||
else
|
||||
viewModel.Initialize(parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_eventAggregator.GetEvent<RaiseNotification>().Publish(new NotificationContentEventArgs(Utility.GetAllErrorMessages(ex)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reloads data for the specified View asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="interfaceForView">Type of the View's interface.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
public async Task RefreshViewAsync(Type interfaceForView, object parameter)
|
||||
{
|
||||
//TODO: fix so that it finds view in right view.
|
||||
try
|
||||
{
|
||||
foreach (var region in _regionManager.Regions)
|
||||
{
|
||||
var existingView =
|
||||
_regionManager.GetView(region.Name, interfaceForView) as IBaseView;
|
||||
if (existingView == null) continue;
|
||||
var viewModel = existingView.DataContext as IBaseViewModel;
|
||||
if (viewModel == null) continue;
|
||||
await viewModel.CleanupAsync();
|
||||
|
||||
if (parameter == null)
|
||||
await viewModel.InitializeAsync();
|
||||
else
|
||||
await viewModel.InitializeAsync(parameter);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_eventAggregator.GetEvent<RaiseNotification>().Publish(new NotificationContentEventArgs(Utility.GetAllErrorMessages(ex)));
|
||||
}
|
||||
}
|
||||
|
||||
public IRegionCollection Regions { get; private set; }
|
||||
public IRegionManager CreateRegionManager()
|
||||
{
|
||||
return new RegionManager();
|
||||
}
|
||||
|
||||
public IRegionManager AddToRegion(string regionName, object view)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IRegionManager AddToRegion(string regionName, string viewName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IRegionManager RegisterViewWithRegion(string regionName, string viewName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IRegionManager RegisterViewWithRegion(string regionName, Type viewType)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IRegionManager RegisterViewWithRegion(string regionName, Func<object> getContentDelegate)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void RequestNavigate(string regionName, Uri source, Action<NavigationResult> navigationCallback)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void RequestNavigate(string regionName, Uri source)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void RequestNavigate(string regionName, string source, Action<NavigationResult> navigationCallback)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void RequestNavigate(string regionName, string source)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void RequestNavigate(string regionName, Uri target, Action<NavigationResult> navigationCallback, NavigationParameters navigationParameters)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void RequestNavigate(string regionName, string target, Action<NavigationResult> navigationCallback, NavigationParameters navigationParameters)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void RequestNavigate(string regionName, Uri target, NavigationParameters navigationParameters)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void RequestNavigate(string regionName, string target, NavigationParameters navigationParameters)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
273
Common/DTS.Common/RegionManager/DataProRegionManager.cs
Normal file
273
Common/DTS.Common/RegionManager/DataProRegionManager.cs
Normal file
@@ -0,0 +1,273 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Runtime.Remoting.Lifetime;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using DTS.Common.Classes;
|
||||
using DTS.Common.Events;
|
||||
using DTS.Common.Interface;
|
||||
using DTS.Common.Base;
|
||||
using Microsoft.Practices.Prism.Regions;
|
||||
using Microsoft.Practices.Prism.Events;
|
||||
using Microsoft.Practices.Unity;
|
||||
namespace DTS.Common
|
||||
{
|
||||
public class DataProRegionManager : IDataProRegionManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Injected unity container
|
||||
/// </summary>
|
||||
private readonly IUnityContainer _unityContainer;
|
||||
|
||||
/// <summary>
|
||||
/// Injected region manager
|
||||
/// </summary>
|
||||
private readonly IRegionManager _regionManager;
|
||||
|
||||
/// <summary>
|
||||
/// Injected event aggregator
|
||||
/// </summary>
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="DataProRegionManager"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unityContainer">Obtained reference of the unity container by using dependency injection.</param>
|
||||
/// <param name="regionManager">Obtained reference of the region manager by using dependency injection.</param>
|
||||
/// <param name="eventAggregator">Obtained reference of the event aggregator by using dependency injection.</param>
|
||||
public DataProRegionManager(IUnityContainer unityContainer, IRegionManager regionManager,
|
||||
IEventAggregator eventAggregator)
|
||||
{
|
||||
_unityContainer = unityContainer;
|
||||
_regionManager = regionManager;
|
||||
_eventAggregator = eventAggregator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds View to the Main Region.
|
||||
/// </summary>
|
||||
/// <param name="viewDefinition">The View definition.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
public void AddView(ViewDefinition viewDefinition, object parameter)
|
||||
{
|
||||
AddView(viewDefinition, parameter, false);
|
||||
}
|
||||
|
||||
private IShellViewModel GetShellViewModelByRegionName(string regionName)
|
||||
{
|
||||
IShellViewModel shellVm = null;
|
||||
|
||||
if (regionName == RegionNames.MainRegion)
|
||||
{
|
||||
shellVm = _unityContainer.Resolve<IShellViewModel>();
|
||||
}
|
||||
//TODO: Add more stuff
|
||||
/*
|
||||
else if (regionName == RegionNames.BottomRegion)
|
||||
{
|
||||
shellVm = _unityContainer.Resolve<IShellViewModel2>();
|
||||
}
|
||||
else if (regionName == RegionNames.RightRegion)
|
||||
{
|
||||
shellVm = _unityContainer.Resolve<IShellViewModel3>();
|
||||
}
|
||||
*/
|
||||
return shellVm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds View to the Main Region.
|
||||
/// </summary>
|
||||
/// <param name="viewDefinition">The View definition.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
/// <param name="allowMultipleInstances">A value indicating whether to allow to create the multiple views.</param>
|
||||
public void AddView(ViewDefinition viewDefinition, object parameter, bool allowMultipleInstances)
|
||||
{
|
||||
IShellViewModel shell = _unityContainer.Resolve<IShellViewModel>();
|
||||
|
||||
var viewModel = (IBaseViewModel)_unityContainer.Resolve(viewDefinition.ViewModelInterfaceType);
|
||||
var view = (IBaseView)_unityContainer.Resolve(viewDefinition.ViewInterfaceType);
|
||||
view.DataContext = viewModel;
|
||||
|
||||
_regionManager.AddViewToRegion(viewDefinition.RegionName, view);
|
||||
_regionManager.ActivateViewIfExists(viewDefinition.RegionName, viewDefinition.ViewInterfaceType);
|
||||
|
||||
if (parameter == null)
|
||||
viewModel.Initialize();
|
||||
else
|
||||
viewModel.Initialize(parameter);
|
||||
|
||||
switch (viewDefinition.RegionName)
|
||||
{
|
||||
case RegionNames.NavigationRegion:
|
||||
shell.ContextNavigationRegion = view;
|
||||
break;
|
||||
case RegionNames.MainRegion:
|
||||
shell.ContextMainRegion = view;
|
||||
break;
|
||||
}
|
||||
|
||||
//IShellViewModel shellVm = GetShellViewModelByRegionName(viewDefinition.RegionName);
|
||||
//if (shellVm != null)
|
||||
//{
|
||||
// shellVm.ContextMainRegion = view;
|
||||
//}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds View to the Main Region asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="viewDefinition">The View definition.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
public async Task AddViewAsync(ViewDefinition viewDefinition, object parameter)
|
||||
{
|
||||
await AddViewAsync(viewDefinition, parameter, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds View to the Main Region asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="viewDefinition">The View definition.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
/// <param name="allowMultipleInstances">A value indicating whether to allow to create the multiple views.</param>
|
||||
public async Task AddViewAsync(ViewDefinition viewDefinition, object parameter, bool allowMultipleInstances)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!allowMultipleInstances)
|
||||
{
|
||||
if (_regionManager.ActivateViewIfExists(viewDefinition.RegionName, viewDefinition.ViewInterfaceType))
|
||||
return;
|
||||
}
|
||||
|
||||
var viewModel = (IBaseViewModel)_unityContainer.Resolve(viewDefinition.ViewModelInterfaceType);
|
||||
var view = (IBaseView)_unityContainer.Resolve(viewDefinition.ViewInterfaceType);
|
||||
view.DataContext = viewModel;
|
||||
|
||||
_regionManager.AddViewToRegion(viewDefinition.RegionName, view);
|
||||
_regionManager.ActivateViewIfExists(viewDefinition.RegionName, viewDefinition.ViewInterfaceType);
|
||||
|
||||
if (parameter == null)
|
||||
await viewModel.InitializeAsync();
|
||||
else
|
||||
await viewModel.InitializeAsync(parameter);
|
||||
|
||||
IShellViewModel shellVm = GetShellViewModelByRegionName(viewDefinition.RegionName);
|
||||
|
||||
if (shellVm != null)
|
||||
{
|
||||
shellVm.ContextMainRegion = view;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_eventAggregator.GetEvent<RaiseNotification>()
|
||||
.Publish(new NotificationContentEventArgs(Utility.GetAllErrorMessages(ex)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes View from the Main Region asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="viewModel">The View-model.</param>
|
||||
public void RemoveView(IBaseViewModel viewModel)
|
||||
{
|
||||
// Jtacc is composed of three regions(three shells)
|
||||
foreach (var region in _regionManager.Regions)
|
||||
{
|
||||
var view =
|
||||
region.Views.FirstOrDefault(
|
||||
v => v is IBaseView && ReferenceEquals(((IBaseView)v).DataContext, viewModel));
|
||||
|
||||
if (view != null)
|
||||
{
|
||||
viewModel.Cleanup();
|
||||
region.Deactivate(view);
|
||||
region.Remove(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveViewByRegionName(string regionName)
|
||||
{
|
||||
_regionManager.ClearRegion(regionName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reloads data for the specified View.
|
||||
/// </summary>
|
||||
/// <param name="interfaceForView">Type of the View's interface.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
public void RefreshView(Type interfaceForView, object parameter)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var region in _regionManager.Regions)
|
||||
{
|
||||
var existingView = _regionManager.GetView(region.Name, interfaceForView) as IBaseView;
|
||||
|
||||
if (existingView != null)
|
||||
{
|
||||
var viewModel = existingView.DataContext as IBaseViewModel;
|
||||
if (viewModel != null)
|
||||
{
|
||||
viewModel.Cleanup();
|
||||
|
||||
if (parameter == null)
|
||||
viewModel.Initialize();
|
||||
else
|
||||
viewModel.Initialize(parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_eventAggregator.GetEvent<RaiseNotification>()
|
||||
.Publish(new NotificationContentEventArgs(Utility.GetAllErrorMessages(ex)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reloads data for the specified View asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="interfaceForView">Type of the View's interface.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
public async Task RefreshViewAsync(Type interfaceForView, object parameter)
|
||||
{
|
||||
//TODO: fix so that it finds view in right view.
|
||||
try
|
||||
{
|
||||
foreach (var region in _regionManager.Regions)
|
||||
{
|
||||
var existingView =
|
||||
_regionManager.GetView(region.Name, interfaceForView) as IBaseView;
|
||||
if (existingView != null)
|
||||
{
|
||||
var viewModel = existingView.DataContext as IBaseViewModel;
|
||||
if (viewModel != null)
|
||||
{
|
||||
await viewModel.CleanupAsync();
|
||||
|
||||
if (parameter == null)
|
||||
await viewModel.InitializeAsync();
|
||||
else
|
||||
await viewModel.InitializeAsync(parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_eventAggregator.GetEvent<RaiseNotification>()
|
||||
.Publish(new NotificationContentEventArgs(Utility.GetAllErrorMessages(ex)));
|
||||
}
|
||||
}
|
||||
|
||||
public IRegionCollection Regions { get; private set; }
|
||||
public IRegionManager CreateRegionManager()
|
||||
{
|
||||
return new RegionManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
68
Common/DTS.Common/RegionManager/IDTSRegionManager.cs
Normal file
68
Common/DTS.Common/RegionManager/IDTSRegionManager.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using DTS.Common.Base;
|
||||
using Prism.Regions;
|
||||
// ReSharper disable InconsistentNaming
|
||||
// ReSharper disable CheckNamespace
|
||||
|
||||
namespace DTS.Common
|
||||
{
|
||||
public interface IDTSRegionManager : IRegionManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds View to the Main Region.
|
||||
/// </summary>
|
||||
/// <param name="viewDefinition">The View definition.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
void AddView(ViewDefinition viewDefinition, object parameter);
|
||||
|
||||
/// <summary>
|
||||
/// Adds View to the Main Region.
|
||||
/// </summary>
|
||||
/// <param name="viewDefinition">The View definition.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
/// <param name="allowMultipleInstances">A value indicating whether to allow to create the multiple views.</param>
|
||||
void AddView(ViewDefinition viewDefinition, object parameter, bool allowMultipleInstances);
|
||||
|
||||
/// <summary>
|
||||
/// Adds View to the Main Region asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="viewDefinition">The View definition.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the service.</param>
|
||||
Task AddViewAsync(ViewDefinition viewDefinition, object parameter);
|
||||
|
||||
/// <summary>
|
||||
/// Adds View to the Main Region asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="viewDefinition">The View definition.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
/// <param name="allowMultipleInstances">A value indicating whether to allow to create the multiple views.</param>
|
||||
Task AddViewAsync(ViewDefinition viewDefinition, object parameter, bool allowMultipleInstances);
|
||||
|
||||
/// <summary>
|
||||
/// Removes View from the Main Region.
|
||||
/// </summary>
|
||||
/// <param name="viewModel">The View-model.</param>
|
||||
void RemoveView(IBaseViewModel viewModel);
|
||||
|
||||
/// <summary>
|
||||
/// Removes View from the specified region by name
|
||||
/// </summary>
|
||||
/// <param name="regionName"></param>
|
||||
void RemoveViewByRegionName(string regionName);
|
||||
|
||||
/// <summary>
|
||||
/// Reloads data for the specified View.
|
||||
/// </summary>
|
||||
/// <param name="interfaceForView">Type of the View's interface.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
void RefreshView(Type interfaceForView, object parameter);
|
||||
|
||||
/// <summary>
|
||||
/// Reloads data for the specified View asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="interfaceForView">Type of the View's interface.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
Task RefreshViewAsync(Type interfaceForView, object parameter);
|
||||
}
|
||||
}
|
||||
68
Common/DTS.Common/RegionManager/IDTSViewRegionManager.cs
Normal file
68
Common/DTS.Common/RegionManager/IDTSViewRegionManager.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using DTS.Common.Base;
|
||||
using Prism.Regions;
|
||||
// ReSharper disable InconsistentNaming
|
||||
// ReSharper disable CheckNamespace
|
||||
|
||||
namespace DTS.Common
|
||||
{
|
||||
public interface IDTSViewRegionManager : IRegionManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds View to the Main Region.
|
||||
/// </summary>
|
||||
/// <param name="viewDefinition">The View definition.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
void AddView(ViewDefinition viewDefinition, object parameter);
|
||||
|
||||
/// <summary>
|
||||
/// Adds View to the Main Region.
|
||||
/// </summary>
|
||||
/// <param name="viewDefinition">The View definition.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
/// <param name="allowMultipleInstances">A value indicating whether to allow to create the multiple views.</param>
|
||||
void AddView(ViewDefinition viewDefinition, object parameter, bool allowMultipleInstances);
|
||||
|
||||
/// <summary>
|
||||
/// Adds View to the Main Region asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="viewDefinition">The View definition.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the service.</param>
|
||||
Task AddViewAsync(ViewDefinition viewDefinition, object parameter);
|
||||
|
||||
/// <summary>
|
||||
/// Adds View to the Main Region asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="viewDefinition">The View definition.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
/// <param name="allowMultipleInstances">A value indicating whether to allow to create the multiple views.</param>
|
||||
Task AddViewAsync(ViewDefinition viewDefinition, object parameter, bool allowMultipleInstances);
|
||||
|
||||
/// <summary>
|
||||
/// Removes View from the Main Region.
|
||||
/// </summary>
|
||||
/// <param name="viewModel">The View-model.</param>
|
||||
void RemoveView(IBaseViewModel viewModel);
|
||||
|
||||
/// <summary>
|
||||
/// Removes View from the specified region by name
|
||||
/// </summary>
|
||||
/// <param name="regionName"></param>
|
||||
void RemoveViewByRegionName(string regionName);
|
||||
|
||||
/// <summary>
|
||||
/// Reloads data for the specified View.
|
||||
/// </summary>
|
||||
/// <param name="interfaceForView">Type of the View's interface.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
void RefreshView(Type interfaceForView, object parameter);
|
||||
|
||||
/// <summary>
|
||||
/// Reloads data for the specified View asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="interfaceForView">Type of the View's interface.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
Task RefreshViewAsync(Type interfaceForView, object parameter);
|
||||
}
|
||||
}
|
||||
66
Common/DTS.Common/RegionManager/IDataProRegionManager.cs
Normal file
66
Common/DTS.Common/RegionManager/IDataProRegionManager.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using DTS.Common.Base;
|
||||
using Microsoft.Practices.Prism.Regions;
|
||||
|
||||
namespace DTS.Common
|
||||
{
|
||||
public interface IDataProRegionManager : IRegionManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds View to the Main Region.
|
||||
/// </summary>
|
||||
/// <param name="viewDefinition">The View definition.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
void AddView(ViewDefinition viewDefinition, object parameter);
|
||||
|
||||
/// <summary>
|
||||
/// Adds View to the Main Region.
|
||||
/// </summary>
|
||||
/// <param name="viewDefinition">The View definition.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
/// <param name="allowMultipleInstances">A value indicating whether to allow to create the multiple views.</param>
|
||||
void AddView(ViewDefinition viewDefinition, object parameter, bool allowMultipleInstances);
|
||||
|
||||
/// <summary>
|
||||
/// Adds View to the Main Region asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="viewDefinition">The View definition.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the service.</param>
|
||||
Task AddViewAsync(ViewDefinition viewDefinition, object parameter);
|
||||
|
||||
/// <summary>
|
||||
/// Adds View to the Main Region asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="viewDefinition">The View definition.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
/// <param name="allowMultipleInstances">A value indicating whether to allow to create the multiple views.</param>
|
||||
Task AddViewAsync(ViewDefinition viewDefinition, object parameter, bool allowMultipleInstances);
|
||||
|
||||
/// <summary>
|
||||
/// Removes View from the Main Region.
|
||||
/// </summary>
|
||||
/// <param name="viewModel">The View-model.</param>
|
||||
void RemoveView(IBaseViewModel viewModel);
|
||||
|
||||
/// <summary>
|
||||
/// Removes View from the specified region by name
|
||||
/// </summary>
|
||||
/// <param name="regionName"></param>
|
||||
void RemoveViewByRegionName(string regionName);
|
||||
|
||||
/// <summary>
|
||||
/// Reloads data for the specified View.
|
||||
/// </summary>
|
||||
/// <param name="interfaceForView">Type of the View's interface.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
void RefreshView(Type interfaceForView, object parameter);
|
||||
|
||||
/// <summary>
|
||||
/// Reloads data for the specified View asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="interfaceForView">Type of the View's interface.</param>
|
||||
/// <param name="parameter">The parameter which uses to initialize the View.</param>
|
||||
Task RefreshViewAsync(Type interfaceForView, object parameter);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Prism.Regions;
|
||||
|
||||
namespace DTS.Common
|
||||
{
|
||||
public class StackPanelRegionAdapter : RegionAdapterBase<StackPanel>
|
||||
{
|
||||
|
||||
public StackPanelRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)
|
||||
: base(regionBehaviorFactory)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Adapt(IRegion region, StackPanel regionTarget)
|
||||
{
|
||||
if (region == null) return;
|
||||
|
||||
region.Views.CollectionChanged += (sender, e) =>
|
||||
{
|
||||
switch (e.Action)
|
||||
{
|
||||
case NotifyCollectionChangedAction.Add:
|
||||
|
||||
foreach (UIElement element in e.NewItems)
|
||||
{
|
||||
regionTarget.Children.Add(element);
|
||||
}
|
||||
break;
|
||||
|
||||
case NotifyCollectionChangedAction.Remove:
|
||||
|
||||
foreach (UIElement elementLoopVariable in e.OldItems)
|
||||
{
|
||||
var element = elementLoopVariable;
|
||||
|
||||
if (regionTarget.Children.Contains(element))
|
||||
{
|
||||
regionTarget.Children.Remove(element);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected override IRegion CreateRegion()
|
||||
{
|
||||
return new AllActiveRegion();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Prism.Regions;
|
||||
|
||||
namespace DTS.Common
|
||||
{
|
||||
public class ViewerStackPanelRegionAdapter : RegionAdapterBase<StackPanel>
|
||||
{
|
||||
|
||||
public ViewerStackPanelRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)
|
||||
: base(regionBehaviorFactory)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Adapt(IRegion region, StackPanel regionTarget)
|
||||
{
|
||||
if (region == null) return;
|
||||
|
||||
region.Views.CollectionChanged += (sender, e) =>
|
||||
{
|
||||
switch (e.Action)
|
||||
{
|
||||
case NotifyCollectionChangedAction.Add:
|
||||
|
||||
foreach (UIElement element in e.NewItems)
|
||||
{
|
||||
regionTarget.Children.Add(element);
|
||||
}
|
||||
break;
|
||||
|
||||
case NotifyCollectionChangedAction.Remove:
|
||||
|
||||
foreach (UIElement elementLoopVariable in e.OldItems)
|
||||
{
|
||||
var element = elementLoopVariable;
|
||||
|
||||
if (regionTarget.Children.Contains(element))
|
||||
{
|
||||
regionTarget.Children.Remove(element);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected override IRegion CreateRegion()
|
||||
{
|
||||
return new AllActiveRegion();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
203
Common/DTS.Common/RegionManager/RegionManagerExtensions.cs
Normal file
203
Common/DTS.Common/RegionManager/RegionManagerExtensions.cs
Normal file
@@ -0,0 +1,203 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DTS.Common.Base;
|
||||
using Prism.Regions;
|
||||
|
||||
namespace DTS.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides extention for the RegionManager .
|
||||
/// </summary>
|
||||
public static class RegionManagerExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Clears the specified region.
|
||||
/// </summary>
|
||||
/// <param name="regionManager">The logical placeholder defined within the application's UI (in the shell or within views) into which views are displayed.</param>
|
||||
/// <param name="regionName">The region name.</param>
|
||||
public static void ClearRegion(this IRegionManager regionManager, string regionName)
|
||||
{
|
||||
regionManager.Regions[regionName].Views.ToList()
|
||||
.ForEach(view => RemoveView(regionManager, view));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of views from the specified region.
|
||||
/// </summary>
|
||||
/// <param name="regionManager">The logical placeholder defined within the application's UI (in the shell or within views) into which views are displayed.</param>
|
||||
/// <param name="regionName">The region name.</param>
|
||||
/// <param name="interfaceForView">Type of the views' interface.</param>
|
||||
/// <returns>A list of views.</returns>
|
||||
public static IList<object> GetViews(this IRegionManager regionManager, string regionName, Type interfaceForView)
|
||||
{
|
||||
var views = new List<object>();
|
||||
|
||||
regionManager.Regions[regionName].Views.ToList()
|
||||
.ForEach(view =>
|
||||
{
|
||||
if (interfaceForView.IsInstanceOfType(view))
|
||||
views.Add(view);
|
||||
});
|
||||
|
||||
return views;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a View from the specified region.
|
||||
/// </summary>
|
||||
/// <param name="regionManager">The logical placeholder defined within the application's UI (in the shell or within views) into which views are displayed.</param>
|
||||
/// <param name="regionName">The region name.</param>
|
||||
/// <param name="interfaceForView">Type of the View's interface.</param>
|
||||
/// <returns>A View.</returns>
|
||||
public static object GetView(this IRegionManager regionManager, string regionName, Type interfaceForView)
|
||||
{
|
||||
object view = null;
|
||||
regionManager.Regions[regionName].Views.ToList()
|
||||
.ForEach(aView =>
|
||||
{
|
||||
if (interfaceForView.IsInstanceOfType(aView))
|
||||
view = aView;
|
||||
});
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Activates a View in the specified region in case View exists.
|
||||
/// </summary>
|
||||
/// <param name="regionManager">The logical placeholder defined within the application's UI (in the shell or within views) into which views are displayed.</param>
|
||||
/// <param name="regionName">The region name.</param>
|
||||
/// <param name="viewType">Type of the View.</param>
|
||||
/// <returns></returns>
|
||||
public static bool ActivateViewIfExists(this IRegionManager regionManager, string regionName, Type viewType)
|
||||
{
|
||||
var returnValue = false;
|
||||
var existingView = regionManager.GetView(regionName, viewType) as IBaseView;
|
||||
if (existingView != null)
|
||||
{
|
||||
returnValue = true;
|
||||
regionManager.ActivateSingleView(regionName, existingView);
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
private static void ActivateSingleView(this IRegionManager regionManager, string regionName, IBaseView existingView)
|
||||
{
|
||||
regionManager.Regions[regionName].Activate(existingView);
|
||||
var viewModel = existingView.DataContext as IBaseViewModel;
|
||||
if (viewModel != null)
|
||||
{
|
||||
viewModel.Activated();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deactivates views in the specified region.
|
||||
/// </summary>
|
||||
/// <param name="regionManager">The logical placeholder defined within the application's UI (in the shell or within views) into which views are displayed.</param>
|
||||
/// <param name="regionName">The region name.</param>
|
||||
public static void DeactivateViews(this IRegionManager regionManager, string regionName)
|
||||
{
|
||||
var activeViews = regionManager.Regions[regionName].ActiveViews.ToList();
|
||||
if (activeViews.Count > 0)
|
||||
{
|
||||
activeViews.ForEach(one => regionManager.Regions[regionName].Deactivate(one));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes views from the specified region.
|
||||
/// </summary>
|
||||
/// <param name="regionManager">The logical placeholder defined within the application's UI (in the shell or within views) into which views are displayed.</param>
|
||||
/// <param name="regionName">The region name.</param>
|
||||
public static void RemoveViews(this IRegionManager regionManager, string regionName)
|
||||
{
|
||||
var activeViews = regionManager.Regions[regionName].ActiveViews.ToList();
|
||||
if (activeViews.Count > 0)
|
||||
{
|
||||
activeViews.ForEach(one => regionManager.Regions[regionName].Remove(one));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Activates a single View in the specified region.
|
||||
/// </summary>
|
||||
/// <param name="regionManager">The logical placeholder defined within the application's UI (in the shell or within views) into which views are displayed.</param>
|
||||
/// <param name="regionName">The region name.</param>
|
||||
public static void ActivateLastView(this IRegionManager regionManager, string regionName)
|
||||
{
|
||||
var activeViews = regionManager.Regions[regionName].ActiveViews.ToList();
|
||||
if (activeViews.Count > 0)
|
||||
{
|
||||
var existingView = activeViews.Last() as IBaseView;
|
||||
if (existingView != null)
|
||||
{
|
||||
regionManager.ActivateSingleView(regionName, existingView);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
activeViews = regionManager.Regions[regionName].Views.ToList();
|
||||
if (activeViews.Count > 0)
|
||||
{
|
||||
var existingView = activeViews.Last() as IBaseView;
|
||||
if (existingView != null)
|
||||
{
|
||||
regionManager.ActivateSingleView(regionName, existingView);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a View to the specified region.
|
||||
/// </summary>
|
||||
/// <param name="regionManager">The logical placeholder defined within the application's UI (in the shell or within views) into which views are displayed.</param>
|
||||
/// <param name="regionName">The region name.</param>
|
||||
/// <param name="view">A View.</param>
|
||||
public static void AddViewToRegion(this IRegionManager regionManager, string regionName, object view)
|
||||
{
|
||||
regionManager.Regions[regionName].Add(view);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a View to the specified region and activates it.
|
||||
/// </summary>
|
||||
/// <param name="regionManager">The logical placeholder defined within the application's UI (in the shell or within views) into which views are displayed.</param>
|
||||
/// <param name="regionName">The region name.</param>
|
||||
/// <param name="view">A View.</param>
|
||||
public static void AddViewToRegionActivate(this IRegionManager regionManager, string regionName, object view)
|
||||
{
|
||||
regionManager.Regions[regionName].Add(view);
|
||||
regionManager.Regions[regionName].Activate(view);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a specified View from all regions.
|
||||
/// </summary>
|
||||
/// <param name="regionManager">The logical placeholder defined within the application's UI (in the shell or within views) into which views are displayed.</param>
|
||||
/// <param name="view">A View to be removed.</param>
|
||||
public static void RemoveView(this IRegionManager regionManager, object view)
|
||||
{
|
||||
foreach (var region in regionManager.Regions)
|
||||
{
|
||||
if (region.Views.Contains(view))
|
||||
region.Remove(view);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a specified View from the specified region.
|
||||
/// </summary>
|
||||
/// <param name="regionManager">The logical placeholder defined within the application's UI (in the shell or within views) into which views are displayed.</param>
|
||||
/// <param name="regionName">The region name.</param>
|
||||
/// <param name="view">A View to be removed.</param>
|
||||
public static void RemoveView(this IRegionManager regionManager, string regionName, object view)
|
||||
{
|
||||
var region = regionManager.Regions[regionName];
|
||||
region.Deactivate(view);
|
||||
region.Remove(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
64
Common/DTS.Common/RegionManager/ViewDefinition.cs
Normal file
64
Common/DTS.Common/RegionManager/ViewDefinition.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DTS.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// The object definition which is adding to the Main Region.
|
||||
/// </summary>
|
||||
public class ViewDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the region name in which a view is displayed.
|
||||
/// </summary>
|
||||
public string RegionName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type the View's interface.
|
||||
/// </summary>
|
||||
public Type ViewInterfaceType { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type the View.
|
||||
/// </summary>
|
||||
// public Type ViewType { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the viewmodel's interface.
|
||||
/// </summary>
|
||||
public Type ViewModelInterfaceType { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the viewmodel.
|
||||
/// </summary>
|
||||
/// <param name="regionName">Region name</param>
|
||||
/// <param name="viewInterfaceType">Type of the View's interface to be registered.</param>
|
||||
/// <param name="viewModelInterfaceType">Type of the View Model to be registered.</param>
|
||||
public ViewDefinition(string regionName, Type viewInterfaceType, Type viewModelInterfaceType)
|
||||
{
|
||||
RegionName = regionName;
|
||||
ViewInterfaceType = viewInterfaceType;
|
||||
ViewModelInterfaceType = viewModelInterfaceType;
|
||||
}
|
||||
///// <summary>
|
||||
///// Creates a new instance of the object.
|
||||
///// Creates a new instance of the object.
|
||||
///// </summary>
|
||||
///// <param name="viewInterfaceType">Type of the View's interface to be registered.</param>
|
||||
///// <param name="viewType">Type of the View to be registered.</param>
|
||||
///// <param name="viewModelInterfaceType">Type of the viewmodel's interface to be registered.</param>
|
||||
///// <param name="viewModelType">Type of the viewmodel to be registered.</param>
|
||||
////public ViewDefinition(Type viewInterfaceType, Type viewType, Type viewModelInterfaceType, Type viewModelType)
|
||||
//{
|
||||
// ViewInterfaceType = viewInterfaceType;
|
||||
// ViewType = viewType;
|
||||
// ViewModelInterfaceType = viewModelInterfaceType;
|
||||
// ViewModelType = viewModelType;
|
||||
//}
|
||||
|
||||
private ViewDefinition() { }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user