init
This commit is contained in:
@@ -0,0 +1,210 @@
|
||||
using System.ComponentModel;
|
||||
using DTS.Common.Base;
|
||||
using DTS.Common.Events;
|
||||
using DTS.Common.Interface;
|
||||
using Microsoft.Practices.Prism.Events;
|
||||
using Microsoft.Practices.Prism.Interactivity.InteractionRequest;
|
||||
using Microsoft.Practices.Prism.Regions;
|
||||
using Microsoft.Practices.Unity;
|
||||
|
||||
namespace DTS.Viewer
|
||||
{
|
||||
public class MainViewModel : BaseViewModel<IMainViewModel>, IMainViewModel
|
||||
{
|
||||
public IMainView View { get; private set; }
|
||||
private IViewerShellViewModel Parent { get; set; }
|
||||
private IEventAggregator _eventAggregator { get; set; }
|
||||
private IRegionManager _regionManager;
|
||||
private IUnityContainer _unityContainer { get; set; }
|
||||
|
||||
public InteractionRequest<Notification> NotificationRequest { get; private set; }
|
||||
public InteractionRequest<Confirmation> ConfirmationRequest { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the MainViewModel.
|
||||
/// </summary>
|
||||
/// <param name="view">The MainView View.</param>
|
||||
/// <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="eventAggregator">The EventAggregator which allows different components to publish/subscribe to events without being coupled to each other.</param>
|
||||
/// <param name="unityContainer">The Unity container.</param>
|
||||
public MainViewModel(IMainView view, IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer unityContainer)
|
||||
: base(regionManager, eventAggregator, unityContainer)
|
||||
{
|
||||
View = view;
|
||||
View.DataContext = this;
|
||||
NotificationRequest = new InteractionRequest<Notification>();
|
||||
ConfirmationRequest = new InteractionRequest<Confirmation>();
|
||||
|
||||
_eventAggregator = eventAggregator;
|
||||
_unityContainer = unityContainer;
|
||||
_regionManager = regionManager;
|
||||
_eventAggregator.GetEvent<RaiseNotification>().Subscribe(OnRaiseNotification);
|
||||
|
||||
|
||||
_unityContainer.RegisterType<IMenuView, MenuView>();
|
||||
_unityContainer.RegisterType<IMenuViewModel, MenuViewModel>();
|
||||
|
||||
_unityContainer.RegisterType<INavigationView, NavigationView>();
|
||||
_unityContainer.RegisterType<INavigationViewModel, NavigationViewModel>();
|
||||
}
|
||||
|
||||
#region Methods
|
||||
/// <summary>
|
||||
/// Initialize without parameter
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize with parameter - Parent
|
||||
/// </summary>
|
||||
public override void Initialize(object parameter)
|
||||
{
|
||||
Parent = (IViewerShellViewModel)parameter;
|
||||
Parent.IsMenuIncluded = _isMenuIncluded;
|
||||
Parent.IsNavigationIncluded = _isNavigationIncluded;
|
||||
_eventAggregator.GetEvent<AssemblyListNotification>().Subscribe(OnAssemblyListChange, ThreadOption.PublisherThread, true);
|
||||
View.DataContext = this;
|
||||
}
|
||||
|
||||
public override void Activated()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display loaded assemblies
|
||||
/// </summary>
|
||||
/// <param name="e">List of loaded assemblies</param>
|
||||
private void OnAssemblyListChange(AssemblyListInfo e)
|
||||
{
|
||||
//var groupListView = _unityContainer.Resolve<IGroupListView>();
|
||||
//var groupListViewModel = _unityContainer.Resolve<IGroupListViewModel>();
|
||||
|
||||
//var asmImage = new List<AssemblyNameImage>();
|
||||
//foreach (var assembly in e.AssemblyList)
|
||||
//{
|
||||
// asmImage.AddRange(from attribute in assembly.GetCustomAttributes()
|
||||
// where attribute.GetType().Name.EndsWith("ImageAttribute")
|
||||
// select new AssemblyNameImage
|
||||
// {
|
||||
// AssemblyGroup = ((ImageAttribute)attribute).GeAssemblyGroup(),
|
||||
// AssemblyName = Regex.Replace(((ImageAttribute)attribute).GeAssemblyName(), "(\\B[A-Z])", " $1"),
|
||||
// AssemblyImage = ((ImageAttribute)attribute).GeAssemblyImage(),
|
||||
|
||||
// });
|
||||
//}
|
||||
//var asmGroups = new List<AssemblyGroups>();
|
||||
//asmGroups.AddRange(from a in asmImage orderby a.SortOrder group a by a.AssemblyGroup into g select new AssemblyGroups { AssemblyGroupName = g.Key, AssemblyList = new List<AssemblyNameImage>(g.ToList()) });
|
||||
|
||||
//foreach (var group in asmGroups)
|
||||
//{
|
||||
// var groupView = new GroupView();
|
||||
// var groupViewModel = new GroupViewModel(groupView, _regionManager, _eventAggregator, _unityContainer)
|
||||
// {
|
||||
// GroupName = @group.AssemblyGroupName,
|
||||
// AssemblyList = @group.AssemblyList
|
||||
// };
|
||||
// groupViewModel.Initialize(groupListViewModel);
|
||||
// groupView.DataContext = groupViewModel;
|
||||
|
||||
// groupListViewModel.GroupList.Add(groupView);
|
||||
//}
|
||||
|
||||
//groupListViewModel.View = groupListView;
|
||||
//groupListViewModel.Initialize(this);
|
||||
//groupListView.DataContext = groupListViewModel;
|
||||
//ContextMainRegion = groupListView;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Private Event handler for RaiseNotification event.
|
||||
/// </summary>
|
||||
private void OnRaiseNotification(NotificationContentEventArgs eventArgsWithTitle)
|
||||
{
|
||||
// The NotificationRequest.Raise triggers the Invoke() method of the .Infrastructure.PopupWindowAction object
|
||||
// to show the .Infrastructure.NotificationWindow window
|
||||
|
||||
// Notification object expects a NotificationContentEventArgsWithoutTitle object and a Title string.
|
||||
var eventArgsWithoutTitle = new NotificationContentEventArgs(eventArgsWithTitle.Message, eventArgsWithTitle.MessageDetails, eventArgsWithTitle.Image);
|
||||
|
||||
NotificationRequest.Raise(new Notification
|
||||
{
|
||||
Content = eventArgsWithoutTitle,
|
||||
Title = eventArgsWithTitle.Title
|
||||
});
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Occurs when a property value changes.
|
||||
///</summary>
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
private void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChangedEventHandler eventHandler = this.PropertyChanged;
|
||||
if (eventHandler != null)
|
||||
{
|
||||
eventHandler(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ContextRegion
|
||||
public object ContextMainRegion
|
||||
{
|
||||
get
|
||||
{
|
||||
return null; /* ((MainView)View).MainRegion.Content; */ }
|
||||
set
|
||||
{
|
||||
//((MainView)View).MainRegion.Content = value;
|
||||
//var viewModel = (IBaseViewModel)((IBaseView)value).DataContext;
|
||||
//Parent.IsMenuIncluded = viewModel.IsMenuIncluded;
|
||||
//Parent.IsNavigationIncluded = viewModel.IsNavigationIncluded;
|
||||
OnPropertyChanged("ContextMainRegion");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
//List<IGroupView> _assemblyGroupList = new List<IGroupView>();
|
||||
//public List<IGroupView> AssemblyGroupList
|
||||
//{
|
||||
// get { return _assemblyGroupList; }
|
||||
// set { _assemblyGroupList = value; OnPropertyChanged("AssemblyGroupList"); }
|
||||
//}
|
||||
|
||||
|
||||
|
||||
private bool _isMenuIncluded = false;
|
||||
public new bool IsMenuIncluded
|
||||
{
|
||||
get { return _isMenuIncluded; }
|
||||
set
|
||||
{
|
||||
_isMenuIncluded = value;
|
||||
OnPropertyChanged("IsMenuIncluded");
|
||||
}
|
||||
}
|
||||
private bool _isNavigationIncluded = false;
|
||||
public new bool IsNavigationIncluded
|
||||
{
|
||||
get { return _isNavigationIncluded; }
|
||||
set
|
||||
{
|
||||
_isNavigationIncluded = value;
|
||||
OnPropertyChanged("IsNavigationIncluded");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the HeaderInfo.
|
||||
/// </summary>
|
||||
public string HeaderInfo { get { return "MainRegion"; } }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user