7

I am trying to write a small Relase Notes program with C#. I need to fetch all changesets and related work items belongs to specified project between specified dates.

I tried to use QueryHistory method but i couldn't find how could i give date filter.

bahadir arslan
  • 4,535
  • 7
  • 44
  • 82

2 Answers2

10

You can set

VersionSpec versionFrom = GetDateVSpec(date);
VersionSpec versionTo = GetDateVSpec(DateTime.Now);

Then with

IEnumerable results = versionServer.QueryHistory(sourceControlPath, VersionSpec.Latest, 0, RecursionType.Full, null, versionFrom, versionTo, int.MaxValue, true, true);
List<Changeset> changesets = results.Cast<Changeset>().ToList();

you get the changesets you 're after.

GetDateVSpec goes as follows:

private static VersionSpec GetDateVSpec(DateTime date)
{
   string dateSpec = string.Format("D{0:yyy}-{0:MM}-{0:dd}T{0:HH}:{0:mm}", date);
   return VersionSpec.ParseSingleSpec(dateSpec, "");
}

I use this in one of my own tools, originally I had found the core for this here (a great post by Robaticus)

Community
  • 1
  • 1
pantelif
  • 8,524
  • 2
  • 33
  • 48
  • This is the answer that i want. Thank you :) Now i thing i can find easily related work item. [Edit: I saw, every changeset item contains WorkItems collection. So this is very good :)] – bahadir arslan Dec 08 '11 at 12:08
  • Hey thanks @dbobrowski, but, as mentioned, I 've only copied the work by Robaticus. – pantelif Mar 27 '12 at 19:10
3

Just found out that there are several classes that inherit from VersionSpec and will do the work for you and are very easy to use. For example, there is a DateVersionSpec which accepts a DateTime. The full list of specific VersionSpec classes is:

WorkspaceVersionSpec LatestVersionSpec LabelVersionSpec DateVersionSpec ChangesetVersionSpec

Hope this helps.

Milan Nankov
  • 1,442
  • 12
  • 15