public MainViewModel(IPromptService promptService, IEventAggregator eventAggregator, Func<FileSelectionViewModel> fileSelectionViewModelfactory, Func<OkCancelPanelViewModel> okCancelViewModelfactory) { string selectedPath = null; SelectFilesCommand = new DelegateCommand<object>(o => { selectedPath = promptService.ShowFolderBrowserDialogue(); if (string.IsNullOrEmpty(selectedPath)) return; FileSelection = fileSelectionViewModelfactory(); FileSelection.LoadFiles(selectedPath); OkCancelPanel = okCancelViewModelfactory(); }); eventAggregator.Subscribe<CleanUpFilesMessage>(this, message => { try { if(FileSelection == null) return; FileSelection.CleanUpFiles(selectedPath); } catch (UnauthorizedAccessException exception) { var errorMessage = string.Format("Failed to clean up files. {0} " + "This may be due to the file being marked as 'Read Only'", exception.Message); promptService.ShowError(errorMessage); } ClearFileSelection(); }); eventAggregator.Subscribe<ClearFileSelectionMessage>(this, message => ClearFileSelection()); }