Skip to content

Instantly share code, notes, and snippets.

@cjlotz
Last active December 15, 2015 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjlotz/5286255 to your computer and use it in GitHub Desktop.
Save cjlotz/5286255 to your computer and use it in GitHub Desktop.
public class ReportRunner
{
private TswaClientHyperlinkService _linkService;
private TfsTeamProjectCollection _teamProjectCollection;
private Project _tfsProject;
private QueryFolder _tfsQueryFolder;
private QueryItem _tfsQueryItem;
private WorkItemStore _workItemStore;
public ReportRunner()
{
}
#region Methods
public void Generate(CommandLineOptions options)
{
if (string.IsNullOrEmpty(options.ExportFile))
throw new ArgumentException("No ExportFile specified");
try
{
Cursor.Current = Cursors.WaitCursor;
Log(string.Format(CultureInfo.InvariantCulture, "Generating Release Notes Pdf to {0}...", options.ExportFile));
ConnectToTfs(options);
var workItems = GenerateReleaseNoteWorkItems();
IReleaseNotesWriter reportWriter = new ReleaseNotesPdfWriter(
new ReleaseNotesWriterSettings
{
BuildVersionNumber = options.BuildNumber,
GeneratedOn = DateTime.Now,
NewReleaseNotesFile = options.ManualReleaseNotesFile,
LinkWorkItems = options.LinkWorkItems,
FrontPageTemplate = @".\Templates\ReleaseNotes_FrontPage.pdf",
PageTemplate = @".\Templates\ReleaseNotes_PageTemplate.pdf"
},
workItems);
reportWriter.Publish(options.ExportFile);
}
finally
{
Cursor.Current = Cursors.Default;
}
Log("Completed Pdf Generation");
}
private void ConnectToTfs(CommandLineOptions options)
{
Log(string.Format(CultureInfo.InvariantCulture, "Connecting to Tfs at {0}...", options.TfsServerUrl));
// Connect to Team Foundation Server
Uri tfsUri = new Uri(options.TfsServerUrl);
_teamProjectCollection = new TfsTeamProjectCollection(tfsUri);
_linkService = _teamProjectCollection.GetService<TswaClientHyperlinkService>();
_workItemStore = _teamProjectCollection.GetService<WorkItemStore>();
_tfsProject = _workItemStore.Projects[options.TfsProject];
_tfsQueryFolder = _tfsProject.QueryHierarchy[options.TfsQueryHierarchy] as QueryFolder;
_tfsQueryItem = _tfsQueryFolder[options.TfsQueryName];
}
private List<ReleaseNoteWorkItem> GenerateReleaseNoteWorkItems()
{
Log(string.Format(CultureInfo.InvariantCulture, "Querying Tfs using {0}...", _tfsQueryItem.ToString()));
var releaseNotes = new List<ReleaseNoteWorkItem>();
var queryDefinition = _workItemStore.GetQueryDefinition(_tfsQueryItem.Id);
var variables = new Dictionary<string, string>
{
{ "project", _tfsQueryItem.Project.Name }
};
var workItemCollection = _workItemStore.Query(queryDefinition.QueryText, variables);
Log(string.Format(CultureInfo.InvariantCulture, "Found {0} Work Items", workItemCollection.Count));
foreach (WorkItem workItem in workItemCollection)
{
Log(string.Format(CultureInfo.InvariantCulture, "WI: {0}, Title: {1}", workItem.Id, workItem.Title));
// Logic to build list of work items by querying TFS fields
..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment