StarTeamHistoryParser.cs :  » Build-Systems » CruiseControl.NET » ThoughtWorks » CruiseControl » Core » Sourcecontrol » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Build Systems » CruiseControl.NET 
CruiseControl.NET » ThoughtWorks » CruiseControl » Core » Sourcecontrol » StarTeamHistoryParser.cs
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text.RegularExpressions;

namespace ThoughtWorks.CruiseControl.Core.Sourcecontrol{
  /// <summary>
  /// Implementation of IHistoryParser to handle StarTeam output that
  /// describes modifications within the version control system.
  /// </summary>
  public class StarTeamHistoryParser : IHistoryParser
  {
    private readonly IStarTeamRegExProvider starTeamRegExProvider;
    internal static readonly string FolderInfoSeparator = "Folder: ";
    internal static readonly string FileHistorySeparator = "----------------------------";

//    DateTimeFormatInfo dfi;
    public CultureInfo Culture = CultureInfo.CurrentCulture;

    public StarTeamHistoryParser(IStarTeamRegExProvider starTeamRegExProvider)
    {
      this.starTeamRegExProvider = starTeamRegExProvider;
      // Create DateTimeFormatInfo
//      dfi = new DateTimeFormatInfo();
//      dfi.AMDesignator = "AM";
//      dfi.PMDesignator = "PM";
//      dfi.MonthDayPattern = @"M/d/yy h:mm:ss tt";
    }

    /// <summary>
    /// Method implementaion for IHistoryParser
    /// </summary>
    /// <param name="starTeamLog"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
    /// <returns></returns>
    public Modification[] Parse(TextReader starTeamLog, DateTime from, DateTime to)
    {
      Regex folderRegex = new Regex(starTeamRegExProvider.FolderRegEx);
      Regex fileRegex = new Regex(starTeamRegExProvider.FileRegEx);
      Regex historyRegex = new Regex(starTeamRegExProvider.FileHistoryRegEx);

      // Temporary holder of Modification objects
            var modList = new List<Modification>();

      // Read conetent of the stream as a string
      // ASSUMPTION: entire log fits into the available memory
      String s = starTeamLog.ReadToEnd();

      // Append folder info separator at the end of the string so
      // that the regular expression engine does not miss the last
      // folder's information. This is required because of the way
      // the expression FolderRegEx is constructed.
      s += FolderInfoSeparator;

      // Parse the whole content to separate the info about each
      // folder and the files it has
      for (Match mFolder = folderRegex.Match(s); mFolder.Success; mFolder = mFolder.NextMatch())
      {
        // Working folder
        String folder = mFolder.Result("${working_directory}");

        // Scan changes for each file in the folder
        for (Match mFile = fileRegex.Match(mFolder.Value); mFile.Success; mFile = mFile.NextMatch())
        {
          // Create a Modification object for the current file
          Modification mod = new Modification();

          // Set the modification attributes
          mod.FolderName = folder;
          mod.FileName = mFile.Result("${file_name}");
          mod.Type = mFile.Result("${file_status}");

          // Substring that contains file history. Append a new line 
          // followed by the FileHistorySeparator so that the parse
          // engine can extract the comments for the last history
          String fileHistory = mFile.Result("${file_history}") + "\n" +
                               FileHistorySeparator;

          // Only get the first match which describes the 
          // most recent changes
          Match mHistory = historyRegex.Match(fileHistory);
          if (mHistory.Success)
          {
            mod.EmailAddress = "N/A";
            mod.UserName = mHistory.Result("${author_name}");

            // date_string looks like "12/9/02 10:33:36 AM"
            // ASSUMPTION: StarTeam server and this application
            // runs in the same TIMEZONE
            mod.ModifiedTime = DateTime.Parse(mHistory.Result("${date_string}"), Culture.DateTimeFormat);
            mod.Comment = mHistory.Result("${change_comment}");
          }
          modList.Add(mod);
        }
      }
      return modList.ToArray();
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.