Click here to Skip to main content
15,886,035 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 162.9K   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
using Extensibility;
using EnvDTE;

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

namespace WebReports8 {

  /// <summary>Report the newest files in the current Project.</summary>
  /// <remarks>This kind of report exists in Frontapge, but not in Visual Studio,
  /// and is useful for reviewing the work of the last days.</remarks>
  public class ReportOldest : Report {

    // these paramters may be changed by a future Options page.
    private int topParam = 50; // default number of files to be reported.
    private DateTime since = DateTime.MinValue; // report files newer than this datetime

    private int found = 0; // number of found files.
    private DateTime newest = DateTime.MaxValue; // date-watermark: older files need not to be included into the list
    private string [] fNames; // list of filenames
    private DateTime [] fDates; // list of last Write Date


    /// <summary>Construtor, that initializes the private analysis data.</summary>
    public ReportOldest() {
      found = 0; // number of found files.
      newest = DateTime.MaxValue; // newest date of any entry in fNames
      fNames = new string[topParam];
      fDates = new DateTime[topParam];
    } // ReportOldest


    /// <summary>Number of arguments this report needs to run.</summary>
    public override int Arguments {
      get { return (1); }
    } // Arguments


    /// <summary>is set to true, when this report starts on a folder basis.</summary>
    public override bool FolderParameter {
      get { return (true); }
    }


    /// <summary>Use the root of the current Project as the default argument.</summary>
    public override string DefaultArgument(_DTE applicationObject) {
      return(Report.CurrentProjectFolder(applicationObject));
    } // DefaultArgument


    /// <summary>Do the analysis by walking through the current project and send html to the output.</summary>
    /// <param name="applicationObject">reference to the VS.NET</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) {
      string path = args[0];

      // do the work
      Walk(path);

      // sort all data
      Array.Sort(fDates, fNames, 0, found);

      string html = ExtractHtmlResource("WebReports.ReportOldest.htm");

      // write the starting html
      output.Write(html.Substring(0, html.IndexOf("[RESULT]")));

      // write the result to output table
      for (int n = found-1; n >= 0; n--) {
        output.Write("<tr><td nowrap><a href='DTE:file?file=" + System.Web.HttpUtility.UrlEncode(fNames[n]) + "'>" + System.Web.HttpUtility.HtmlEncode(fNames[n]) + "</a></td>");
        output.Write("<td>" + fDates[n].ToString() + "</td>");
        output.WriteLine("<td><a href='dte:backup?file=" + System.Web.HttpUtility.UrlEncode(fNames[n]) + "'>backup</a></td></tr>");
      } // for

      // write the end html
      output.Write(html.Substring(html.IndexOf("[RESULT]")+8));
    } // Render


    /// <summary>Analyze all sub-folder by recursion and all files of a folder.
    /// Do not analyse any folder starting with a undeline character.</summary>
    /// <param name="aFolder">Full name of the folder.</param>
    private void Walk(string aFolder) {
      string [] folders = Directory.GetDirectories (aFolder);
      for (int i = 0 ; i < folders.Length ; i++ ) {
        string aName = folders[i];
        int n = aName.LastIndexOf ('\\');
        if ((n+1 < aName.Length) && (aName[n+1] != '_' ))
          Walk(aName);
      } // for

      string [] files = Directory.GetFiles ( aFolder );
      for (int i = 0 ; i < files.Length ; i++ ) {
        string aName = files[i];
        DateTime aDate = File.GetLastWriteTime(aName);

        if (aDate < since) {
          // forget about that file

        } else if (found == 0) {
          // first found file
          newest = aDate;
          fNames[found] = aName;
          fDates[found] = aDate;
          found++;

        } else if (found < topParam) {
          // still space available
          if (aDate > newest)
            newest = aDate;
          fNames[found] = aName;
          fDates[found] = aDate;
          found++;

        } else if (aDate > newest) {
          Array.Sort(fDates, fNames, 0, found);
          // remove newest file and add current file.
          fDates[topParam-1] = aDate;
          fNames[topParam-1] = aName;
          newest = aDate;
          if (fDates[topParam-2] < newest)
            newest = fDates[topParam-2];
        } // if
      } // for
    } // Walk

  } // class

} // namespace

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