Click here to Skip to main content
15,893,644 members
Articles / Programming Languages / C#

Visual Studio .NET 2003 Add-in that adds diff tools, an explore command, Subversion support and web project reporting. Version 2.1

Rate me:
Please Sign up or sign in to vote.
4.88/5 (25 votes)
27 Jul 200528 min read 219.8K   2.8K   142  
With this add-in, you get new tools and commands that boost your productivity while developing and some helpful reports specially for web projects. Version 2.1.
using System;
using System.Collections;
using System.IO;
using System.Text;
using System.Web;

using Extensibility;
using EnvDTE;


namespace WebReports {

  /// <summary>Represents a collection of Options for the WebReports Add-In.</summary>
  internal 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 ex) {
        ex = ex;
      }
    } // 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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect Deutsche Bank AG
Germany Germany
see https://www.mathertel.de

Comments and Discussions