Skip to content

Commit

Permalink
Updated Attachement downloading function to use the WorkItemServer. (#42
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jtucker authored and MrHinsh committed Aug 12, 2017
1 parent a579ad7 commit ec2e194
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Proxy;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -40,9 +41,9 @@ internal override void InternalExecute()
tfsqc.Query = string.Format(@"SELECT [System.Id], [System.Tags] FROM WorkItems WHERE [System.TeamProject] = @TeamProject {0} ORDER BY [System.ChangedDate] desc", _config.QueryBit);
WorkItemCollection sourceWIS = tfsqc.Execute();

WebClient webClient = new WebClient();
webClient.Credentials = CredentialCache.DefaultNetworkCredentials;
int current = sourceWIS.Count;
var workItemServer = me.Source.Collection.GetService<WorkItemServer>();

foreach (WorkItem wi in sourceWIS)
{
Trace.Write(string.Format("Attachement Export: {0} of {1} - {2}", current, sourceWIS.Count, wi.Id));
Expand All @@ -58,13 +59,14 @@ internal override void InternalExecute()
Trace.Write("...downloading");
try
{
webClient.DownloadFile(wia.Uri, fpath);
var fileLocation = workItemServer.DownloadFile(wia.Id);
File.Copy(fileLocation, fpath, true);
Trace.Write("...done");
}
catch (Exception ex)
{
Telemetry.Current.TrackException(ex);
Trace.Write("...failed");
Trace.Write($"\r\nException downloading attachements {ex.Message}");
}

}
Expand Down

0 comments on commit ec2e194

Please sign in to comment.