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 { 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 NotificationRequest { get; private set; } public InteractionRequest ConfirmationRequest { get; private set; } /// /// Creates a new instance of the MainViewModel. /// /// The MainView View. /// The logical placeholder defined within the application's UI (in the shell or within views) into which views are displayed. /// The EventAggregator which allows different components to publish/subscribe to events without being coupled to each other. /// The Unity container. public MainViewModel(IMainView view, IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer unityContainer) : base(regionManager, eventAggregator, unityContainer) { View = view; View.DataContext = this; NotificationRequest = new InteractionRequest(); ConfirmationRequest = new InteractionRequest(); _eventAggregator = eventAggregator; _unityContainer = unityContainer; _regionManager = regionManager; _eventAggregator.GetEvent().Subscribe(OnRaiseNotification); _unityContainer.RegisterType(); _unityContainer.RegisterType(); _unityContainer.RegisterType(); _unityContainer.RegisterType(); } #region Methods /// /// Initialize without parameter /// public override void Initialize() { } /// /// Initialize with parameter - Parent /// public override void Initialize(object parameter) { Parent = (IViewerShellViewModel)parameter; Parent.IsMenuIncluded = _isMenuIncluded; Parent.IsNavigationIncluded = _isNavigationIncluded; _eventAggregator.GetEvent().Subscribe(OnAssemblyListChange, ThreadOption.PublisherThread, true); View.DataContext = this; } public override void Activated() { } /// /// Display loaded assemblies /// /// List of loaded assemblies private void OnAssemblyListChange(AssemblyListInfo e) { //var groupListView = _unityContainer.Resolve(); //var groupListViewModel = _unityContainer.Resolve(); //var asmImage = new List(); //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(); //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(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; } /// /// Private Event handler for RaiseNotification event. /// 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 }); } /// ///Occurs when a property value changes. /// 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 _assemblyGroupList = new List(); //public List 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"); } } /// /// Gets the HeaderInfo. /// public string HeaderInfo { get { return "MainRegion"; } } #endregion } }