Click here to Skip to main content
15,885,914 members
Articles / .NET

Versioning Controlled Build

Rate me:
Please Sign up or sign in to vote.
4.90/5 (237 votes)
8 Dec 2013CPOL35 min read 2.2M   20.6K   779  
A Visual Studio add-in and command-line utility that automates versioning of .NET and VC++ projects
using System;
using System.Diagnostics;
using System.IO;
using System.Xml.Serialization;
using System.Xml;
using System.Collections.Specialized;

namespace BuildAutoIncrement {
    /// <summary>
    ///   Class responsible to load and save add-in GUI configuration file.
    /// </summary>
    public sealed class VcbCommandBarsConfigurationPersister {

        private static readonly VcbCommandBarsConfigurationPersister m_instance = new VcbCommandBarsConfigurationPersister();
   
        /// <summary>
        ///   Creates <c>VcbCommandBarsConfigurationPersister</c> object.
        /// </summary>
        private VcbCommandBarsConfigurationPersister() {
            ConfigurationFolder = FileUtil.GetConfigurationFolder();
            ConfigurationFilename = Path.Combine(ConfigurationFolder, Filename);

            // read current configuration or create empty one if file not found
            m_uiElementsConfigurations = LoadConfiguration();
        }

        public static VcbCommandBarsConfigurationPersister Instance {
            get {
                return m_instance;
            }
        }

        /// <summary>
        ///   Gets configuration.
        /// </summary>
        public VcbCommandBarsConfiguration Configurations {
            get {
                Debug.Assert(m_uiElementsConfigurations != null);
                return m_uiElementsConfigurations;
            }
        }

        /// <summary>
        ///   Reads configuration from the file. If file does not exists,
        ///   creates default configuration.
        /// </summary>
        /// <returns></returns>
        private VcbCommandBarsConfiguration LoadConfiguration() {
            if (Directory.Exists(ConfigurationFolder)) {
                try {
                    using (FileStream reader = new FileStream(ConfigurationFilename, FileMode.Open)) {
                        XmlSerializer serializer = new XmlSerializer(typeof(VcbCommandBarsConfiguration));
                        return (VcbCommandBarsConfiguration)serializer.Deserialize(reader);
                    }
                }
                catch (FileNotFoundException) {
                }
                catch (Exception exception) {
                    ExceptionForm.Show(exception);
                }
            }
            return new VcbCommandBarsConfiguration();
        }

        /// <summary>
        ///   Saves configuration to the file.
        /// </summary>
        public void StoreConfiguration() {
            try {
                if (!Directory.Exists(ConfigurationFolder)) {
                    // create directory where configuration will be saved
                    Directory.CreateDirectory(ConfigurationFolder);
                }
                using (FileStream writer = new FileStream(ConfigurationFilename, FileMode.Create)) {
                    XmlSerializer serializer = new XmlSerializer(typeof(VcbCommandBarsConfiguration));
                    serializer.Serialize(writer, m_uiElementsConfigurations);
                }
            }
            catch (Exception exception) {
                ExceptionForm.Show(exception);
            }
        }

        private readonly VcbCommandBarsConfiguration m_uiElementsConfigurations;

        private readonly string ConfigurationFolder;
        private readonly string ConfigurationFilename;

        public const string Filename = "UiSettings.xml";
    }
}

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 Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Croatia Croatia
Graduated at the Faculty of Electrical Engineering and Computing, University of Zagreb (Croatia) and received M.Sc. degree in electronics. For several years he was research and lecturing assistant in the fields of solid state electronics and electronic circuits, published several scientific and professional papers, as well as a book "Physics of Semiconductor Devices - Solved Problems with Theory" (in Croatian).
During that work he gained interest in C++ programming language and have co-written "C++ Demystified" (in Croatian), 1st edition published in 1997, 2nd in 2001, 3rd in 2010, 4th in 2014.
After book publication, completely switched to software development, programming mostly in C++ and in C#.
In 2016 coauthored the book "Python for Curious" (in Croatian).

Comments and Discussions