Click here to Skip to main content
15,896,557 members
Articles / Programming Languages / C#

Visual Studio 2010 Add-in that Adds Diff Tools, Web Project Reporting and Some Subversion Support

Rate me:
Please Sign up or sign in to vote.
4.56/5 (13 votes)
12 May 2010CPOL4 min read 163.1K   2.7K   98  
With this add-in, you get new tools and commands that boost your productivity while developing, and some helpful reports especially for web projects - Version 2.2
// Options.cs
// Copyright by Matthias Hertel, http://www.mathertel.de
// This work is licensed under a Creative Commons Attribution 2.0 Germany License.
// See http://creativecommons.org/licenses/by/2.0/de/
// ----- 
// 31.01.2006 created by Matthias Hertel

using System;
using System.Collections;
using System.IO;
using System.Text;
using System.Web;

using Extensibility;
using EnvDTE;
using EnvDTE80;

namespace WebReports8 {

  /// <summary>Represents a collection of Options for the WebReports Add-In.</summary>
  public class Options  : Report {

    /// <summary>Global option: check for a base-version of a file in a subversion folder.</summary>
    public const string SVNMODE = "svnmode";

    /// <summary>Use a separate folder for a base-version of a file.</summary>
    public const string BASEVERSIONFOLDER = "baseversionfolder";

    /// <summary>static list of all boolean Options.</summary>
    private static Hashtable _booleanOptions;


    /// <summary>static list of all text Options.</summary>
    private static Hashtable _textOptions;


    /// <summary>Create a new Options Object.</summary>
    public Options() {
      Init();
    }


    /// <summary>Returns false, because this command reports to the command window.</summary>
    public override bool HasHTMLOutput {
      get { return (false); }
    }


    /// <summary>Init static members. This method must be called in every static method of this class
    /// to be sure that all members are initialized.</summary>
    private static void Init() {
      if (_booleanOptions == null) {
        _booleanOptions = new Hashtable();
        _textOptions = new Hashtable();
      } // if
    } // Init


    /// <summary>Save all the option as text in the solution file.</summary>
    /// <param name="applicationObject">Reference to the VS.NET application.</param>
    public static void SaveOptions(_DTE applicationObject) {
      Globals store = applicationObject.Solution.Globals;
      foreach (DictionaryEntry o in _textOptions) {
        string key = "webreports-" + (string)(o.Key);
        if ((string)store[key] != o.Value.ToString()) {
          store[key] = (string)(o.Value);
          store.set_VariablePersists(key, true);
        } // if      
      } // foreach

      foreach (DictionaryEntry o in _booleanOptions) {
        string key = "webreports-" + (string)(o.Key);
        if ((string)store[key] != o.Value.ToString()) {
          store[key] = (string)(o.Value);
          store.set_VariablePersists(key, true);
        } // if      
      } // foreach
    } // SaveOptions


    /// <summary>Load all the option from the solution file.</summary>
    /// <param name="applicationObject">Reference to the VS.NET application.</param>
    public static void LoadOptions(_DTE applicationObject) {
      Globals store = applicationObject.Solution.Globals;
      System.Array keys;
      try {
        keys = new Object[_textOptions.Count];
        _textOptions.Keys.CopyTo(keys, 0);
        foreach (String k in keys) {
          string key = "webreports-" + k;
          if (store.get_VariableExists(key))
            _textOptions[k] = store[key].ToString();
        } // foreach

        keys = new Object[_booleanOptions.Count];
        _booleanOptions.Keys.CopyTo(keys, 0);
        foreach (String k in keys) {
          string key = "webreports-" + k;
          if (store.get_VariableExists(key))
            _booleanOptions[k] = bool.Parse(store[key].ToString().ToLower());
        } // foreach
      } catch (Exception) {
      }
    } // LoadOptions


    /// <summary>Report or set Options.</summary>
    /// <param name="applicationObject">Reference to the VS.NET application.</param>
    /// <param name="Output">ouput stream</param>
    /// <param name="Args">List of all arguments passed to this command.</param>
    public override void Render(_DTE applicationObject, StringWriter Output, params string[] Args) {
      EnvDTE.Window win = applicationObject.Windows.Item(EnvDTE.Constants.vsWindowKindCommandWindow);
      EnvDTE.CommandWindow cmdWin = (EnvDTE.CommandWindow)win.Object;

      if (Args.Length == 0) {
        // Report all Options to the commandWindow
        // write all known options
        foreach (DictionaryEntry o in _booleanOptions) {
          cmdWin.OutputString((string)(o.Key) + " = " + o.Value.ToString() + "\n");
        } // foreach

        foreach (DictionaryEntry o in _textOptions) {
          cmdWin.OutputString((string)(o.Key) + " = " + (string)(o.Value) + "\n");
        } // foreach

      } else if (Args.Length == 1) {
        // Report a single Option to the commandWindow
        string name = Args[0].ToLower();
        if (_booleanOptions[name] != null)
          cmdWin.OutputString(name + " = " + _booleanOptions[name].ToString() + "\n");
        if (_textOptions.ContainsKey(name))
          cmdWin.OutputString(name + " = " + _textOptions[name].ToString() + "\n");

      } else if (Args.Length >= 2) {
        // Set a Options to a new value and report to the commandWindow
        string name = Args[0].ToLower();
        if (_booleanOptions[name] != null) {
          _booleanOptions[name] = bool.Parse(Args[1].ToLower());
          cmdWin.OutputString(name + " = " + _booleanOptions[name].ToString() + "\n");
        } else if (_textOptions.ContainsKey(name)) {
          _textOptions[name] = Args[1];
          cmdWin.OutputString(name + " = " + _textOptions[name].ToString() + "\n");
        } // if
      }
    } // Render


    /// <summary>Return the current value of a boolean option.</summary>
    /// <param name="Name">The name of the Text Option.</param>
    public static bool GetBoolOption(string Name) {
      bool ret = false;
      if (_booleanOptions[Name.ToLower()] != null) {
        ret = (bool)_booleanOptions[Name.ToLower()];
      } // if
      return(ret);
    }  // GetBoolOption


    /// <summary>Return the current value of a text option.</summary>
    /// <param name="Name">The name of the Text Option.</param>
    public static string GetTextOption(string Name) {
      string ret = null;
      if (_textOptions.ContainsKey(Name.ToLower())) {
        ret = (string)_textOptions[Name.ToLower()];
      } // if
      return(ret);
    }  // GetTextOption


    /// <summary>Define a Text Option and load the cuurent value from the registry.</summary>
    /// <remarks>If no entry in the registry is found, because the Options have never been set to the registry the given DefaultValue is used for the current value.</remarks>
    /// <param name="Name">The name of the Text Option.</param>
    /// <param name="DefaultValue">The implemented default value.</param>
    public static void DefineBoolOption(string Name, bool DefaultValue) {
      Init();
      if (_booleanOptions[Name.ToLower()] == null)
        _booleanOptions.Add(Name.ToLower(), DefaultValue);
    }  // DefineBoolOption


    /// <summary>Define a Text Option and load the cuurent value from the registry.</summary>
    /// <remarks>If no entry in the registry is found, because the Options have never been set to the registry the given DefaultValue is used for the current value.</remarks>
    /// <param name="Name">The name of the Text Option.</param>
    /// <param name="DefaultValue">The implemented default value.</param>
    public static void DefineTextOption(string Name, string DefaultValue) {
      Init();
      if (! _textOptions.ContainsKey(Name.ToLower()))
        _textOptions.Add(Name.ToLower(), DefaultValue);
    }  // DefineTextOption

  }
}

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
Architect Deutsche Bank AG
Germany Germany
see https://www.mathertel.de

Comments and Discussions