/// <summary>Changes a solution based on the users selection.</summary> /// <param name="sender">The ComboBox containing the selection.</param> public void ChangeSolution(ComboBox sender) { if (sender.SelectedItem == null) { return; } string solutionName = ((Solution)sender.SelectedItem).Name; if (solutionName == Constants.EditSolution.Name) { // Create a copy of the solution list excluding the edit item. IEnumerable <Solution> solutions = this.Solutions.Where(s => s != Constants.EditSolution); SolutionManagerViewModel viewModel = new SolutionManagerViewModel(this.windowManager, solutions); Dictionary <string, object> settingsDictionary = new Dictionary <string, object> { { "ResizeMode", ResizeMode.NoResize } }; bool?answer = this.windowManager.ShowDialog(viewModel, null, settingsDictionary); if (answer.HasValue && answer.Value) { // Get the solutions from the view model this.Solutions = viewModel.GetSolutions(); // Write to the log, that we are updating the solutions LogEntry updatingSolutionsEntry = new LogEntry { EventId = 00207, Title = "Updating Repository", Message = "Updating solutions in the repository with changed information.", Categories = { LoggingConstants.CategoryGeneralConst }, Severity = TraceEventType.Information }; this.logWriter.Write(updatingSolutionsEntry); // Actually update the solutions this.solutionRepository.Update(new DictionaryRange <string, Solution>(this.Solutions.ToDictionary(s => s.Name, s => s))); // Get the names of the solutions we want to delete IList <string> deletedSolutions = viewModel.DeletedSolutions; // Write to the log, that we are deleting solutions LogEntry deletingSolutionsEntry = new LogEntry { EventId = 00207, Title = "Deleting Solutions", Message = string.Format("Deleting {0} solutions from the file system. Additional information below.", deletedSolutions.Count), Categories = { LoggingConstants.CategoryGeneralConst }, Severity = TraceEventType.Information }; this.logWriter.Write(deletingSolutionsEntry); foreach (string deletedSolution in deletedSolutions) { LogEntry deletingSolutionEntry = new LogEntry { EventId = 00207, Title = "Deleting Solution", Message = string.Format("Deleting solution \"{0}\" from the file system", deletedSolution), Categories = { LoggingConstants.CategoryGeneralConst }, Severity = TraceEventType.Information }; this.logWriter.Write(deletingSolutionEntry); } this.solutionRepository.Delete(deletedSolutions); this.Solutions.Add(Constants.EditSolution); } return; } LogEntry changedSolutionEntry = new LogEntry { EventId = 00201, Title = "Changed Solution", Message = string.Format("The solution was changed to \"{0}\"", solutionName), Categories = { LoggingConstants.CategoryGeneralConst }, Severity = TraceEventType.Information }; this.logWriter.Write(changedSolutionEntry); Solution selectedSolution = this.Solutions.Single(s => s.Name == solutionName); this.SelectedSolution = new SolutionViewModel(this.windowManager, this.settingsRepository, this.solutionRepository, selectedSolution, this.logWriter, this.eventAggregator); }
/// <summary>Changes a solution based on the users selection.</summary> /// <param name="sender">The ComboBox containing the selection.</param> public void ChangeSolution(ComboBox sender) { if (sender.SelectedItem == null) { return; } string solutionName = ((Solution)sender.SelectedItem).Name; if (solutionName == Constants.EditSolution.Name) { // Create a copy of the solution list excluding the edit item. IEnumerable<Solution> solutions = this.Solutions.Where(s => s != Constants.EditSolution); SolutionManagerViewModel viewModel = new SolutionManagerViewModel(this.windowManager, solutions); Dictionary<string, object> settingsDictionary = new Dictionary<string, object> { { "ResizeMode", ResizeMode.NoResize } }; bool? answer = this.windowManager.ShowDialog(viewModel, null, settingsDictionary); if (answer.HasValue && answer.Value) { // Get the solutions from the view model this.Solutions = viewModel.GetSolutions(); // Write to the log, that we are updating the solutions LogEntry updatingSolutionsEntry = new LogEntry { EventId = 00207, Title = "Updating Repository", Message = "Updating solutions in the repository with changed information.", Categories = { LoggingConstants.CategoryGeneralConst }, Severity = TraceEventType.Information }; this.logWriter.Write(updatingSolutionsEntry); // Actually update the solutions this.solutionRepository.Update(new DictionaryRange<string, Solution>(this.Solutions.ToDictionary(s => s.Name, s => s))); // Get the names of the solutions we want to delete IList<string> deletedSolutions = viewModel.DeletedSolutions; // Write to the log, that we are deleting solutions LogEntry deletingSolutionsEntry = new LogEntry { EventId = 00207, Title = "Deleting Solutions", Message = string.Format("Deleting {0} solutions from the file system. Additional information below.", deletedSolutions.Count), Categories = { LoggingConstants.CategoryGeneralConst }, Severity = TraceEventType.Information }; this.logWriter.Write(deletingSolutionsEntry); foreach (string deletedSolution in deletedSolutions) { LogEntry deletingSolutionEntry = new LogEntry { EventId = 00207, Title = "Deleting Solution", Message = string.Format("Deleting solution \"{0}\" from the file system", deletedSolution), Categories = { LoggingConstants.CategoryGeneralConst }, Severity = TraceEventType.Information }; this.logWriter.Write(deletingSolutionEntry); } this.solutionRepository.Delete(deletedSolutions); this.Solutions.Add(Constants.EditSolution); } return; } LogEntry changedSolutionEntry = new LogEntry { EventId = 00201, Title = "Changed Solution", Message = string.Format("The solution was changed to \"{0}\"", solutionName), Categories = { LoggingConstants.CategoryGeneralConst }, Severity = TraceEventType.Information }; this.logWriter.Write(changedSolutionEntry); Solution selectedSolution = this.Solutions.Single(s => s.Name == solutionName); this.SelectedSolution = new SolutionViewModel(this.windowManager, this.settingsRepository, this.solutionRepository, selectedSolution, this.logWriter, this.eventAggregator); }