Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Windows.Forms;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
namespace GourceTFS
{
class Program
{
private const string outFile = "output_log.txt";
const string tfsServerURL = "http://server:8080";
/* If you want to use Gource with something other than the supported systems, there is a pipe delimited custom log format:
* timestamp - A unix timestamp of when the update occured.
* username - The name of the user who made the update.
* type - Single character for the update type - (A)dded, (M)odified or (D)eleted.
* file - Path of the file updated.
* colour - A colour for the file in hex (FFFFFF) format. Optional.
*/
/// <summary>
/// method for converting a System.DateTime value to a UNIX Timestamp
/// </summary>
/// <param name="value">date to convert</param>
/// <returns></returns>
private static double ConvertToTimestamp(DateTime value)
{
//create Timespan by subtracting the value provided from
//the Unix Epoch
TimeSpan span = (value - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime());
//return the total seconds (which is a UNIX timestamp)
return span.TotalSeconds;
}
[Serializable]
class ChangeItem
{
public double timestamp { get; set;}
public string username { get; set; }
public char type { get; set; }
public string file { get; set; }
/// <summary>
/// Converts the specified type.
/// </summary>
/// <param name="type">The type.</param>
/// <returns></returns>
public static char Convert(ChangeType type)
{
char _out = '\0';
if (type == (ChangeType.Add | ChangeType.Edit | ChangeType.Encoding))
{
_out = 'A';
return _out;
}
if (type == (ChangeType.Encoding | ChangeType.Delete | ChangeType.Branch))
{
_out = 'D';
return _out;
}
switch (type)
{
case ChangeType.Add:
_out = 'A';
break;
case ChangeType.Merge:
_out = 'M';
break;
case ChangeType.Edit:
_out = 'M';
break;
case ChangeType.Delete:
_out = 'D';
break;
}
if (_out == '\0')
{
throw new ArgumentException("fff");
}
return _out;
}
}
static void Main()
{
var TFSLogs = TFSLogsList();
using (var sw = new StreamWriter(outFile, false, Encoding.UTF8))
{
foreach (var item in TFSLogs)
{
sw.WriteLine("{0}|{1}|{2}|{3}", Math.Floor(item.timestamp), item.username, item.type, item.file);
}
}
var pi = new ProcessStartInfo
{
FileName = Application.StartupPath + @"\Gource\gource.exe",
Arguments = outFile + "--log-format custom -1280x1024 -f --highlight-all-users --multi-sampling ",
UseShellExecute = true
};
var p = new Process {StartInfo = pi};
p.Start();
Console.Read();
}
static List<ChangeItem> TFSLogsList()
{
const string _tfsPath = "$/SomePlace";
var tfs = TeamFoundationServerFactory.GetServer(tfsServerURL);
var vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer)); // Null means All
const VersionSpec versionFrom = null;
var history = vcs.QueryHistory(_tfsPath,
VersionSpec.Latest,
0,
RecursionType.Full,
"",
versionFrom,
VersionSpec.Latest,
Int32.MaxValue,
true,
false);
var GourceList = new List<ChangeItem>();
var changesets = new List<Changeset>();
foreach (var _item in history)
{
changesets.Add((Changeset)_item);
}
var o = new Comparison<Changeset>((p, y) => p.ChangesetId.CompareTo(y.ChangesetId));
changesets.Sort(o);
foreach (var changeset in changesets)
{
foreach (var change in changeset.Changes)
{
if (change.Item.ItemType == ItemType.Folder) continue;
var item = new ChangeItem
{
username = changeset.Committer,
type = ChangeItem.Convert(change.ChangeType),
file = change.Item.ServerItem,
timestamp = ConvertToTimestamp(change.Item.CheckinDate)
};
GourceList.Add(item);
}
Console.WriteLine("Adding changeset: " + changeset.ChangesetId);
}
return GourceList;
}
}
}
* This source code was highlighted with Source Code Highlighter.
Gource — визуализируем историю работы над проектом