Click here to Skip to main content
15,885,915 members
Articles / Programming Languages / C#

CodeDOM Classes for Solution and Project Files (Part 5)

Rate me:
Please Sign up or sign in to vote.
5.00/5 (12 votes)
30 Nov 2012CDDL7 min read 29.9K   1.2K   18  
CodeDOM objects for VS Solution and Project files.
// Nova.Studio - a GUI test framework for the Nova.CodeDOM C# object model library.
// Copyright (C) 2007-2012 Inevitable Software, all rights reserved.
// Released under the Common Development and Distribution License, CDDL-1.0: http://opensource.org/licenses/cddl1.php

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;

using Nova.CodeDOM;

namespace Nova.Studio
{
    /// <summary>
    /// Interaction logic for ConfigurationManager.xaml
    /// </summary>
    public partial class ConfigurationManager : Window
    {
        private readonly Solution _solution;

        public ConfigurationManager(Solution solution)
        {
            InitializeComponent();

            _solution = solution;
            List<string> configurations;
            List<string> platforms;
            _solution.GetConfigurationsAndPlatforms(out configurations, out platforms);
            comboBoxConfiguration.ItemsSource = configurations;
            comboBoxConfiguration.SelectedItem = _solution.ActiveConfiguration;
            comboBoxPlatform.ItemsSource = platforms;
            comboBoxPlatform.SelectedItem = _solution.ActivePlatform;

            listViewProjectContexts.ItemsSource = GetProjectConfigurations();
        }

        private List<Tuple<string, string, string>> GetProjectConfigurations()
        {
            List<Tuple<string, string, string>> results = new List<Tuple<string, string, string>>();
            IOrderedEnumerable<Project> projects = Enumerable.OrderBy<Project, string>(_solution.Projects, delegate(Project project) { return project.Name; });
            string solutionConfiguration = comboBoxConfiguration.SelectedItem as string;
            string solutionPlatform = comboBoxPlatform.SelectedItem as string;
            foreach (Project project in projects)
            {
                string projectConfiguration, projectPlatform;
                _solution.GetProjectConfiguration(solutionConfiguration, solutionPlatform, project, out projectConfiguration, out projectPlatform);
                results.Add(new Tuple<string, string, string>(project.Name, projectConfiguration, projectPlatform));
            }
            return results;
        }

        private void comboBoxConfiguration_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            listViewProjectContexts.ItemsSource = GetProjectConfigurations();
        }

        private void comboBoxPlatform_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            listViewProjectContexts.ItemsSource = GetProjectConfigurations();
        }

        private void buttonSave_Click(object sender, RoutedEventArgs e)
        {
            // Save the modified configuration and platform
            _solution.ActiveConfiguration = comboBoxConfiguration.SelectedItem as string;
            _solution.ActivePlatform = comboBoxPlatform.SelectedItem as string;

            DialogResult = true;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)


Written By
Software Developer (Senior)
United States United States
I've been writing software since the late 70's, currently focusing mainly on C#.NET. I also like to travel around the world, and I own a Chocolate Factory (sadly, none of my employees are oompa loompas).

Comments and Discussions