123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- using System;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.Linq;
- using Microsoft.TeamFoundation.Client;
- using Microsoft.TeamFoundation.Framework.Common;
- using Microsoft.TeamFoundation.VersionControl.Client;
- using Microsoft.TeamFoundation.WorkItemTracking.Client;
- namespace pulse
- {
-
-
-
- public class PollingService : BackgroundWorker
- {
-
-
-
-
-
-
- public TfsConfigurationServer TeamFoundationServer { get; set; }
-
-
-
-
-
-
-
- public Dashboard Dashboard { get; set; }
-
-
-
-
-
- public PollingService(TfsConfigurationServer tfs, Dashboard dashboard)
- {
- this.TeamFoundationServer = tfs;
- this.Dashboard = dashboard;
- }
-
-
-
-
- protected override void OnDoWork(DoWorkEventArgs e)
- {
- base.OnDoWork(e);
- var now = DateTime.Now;
- this.Dashboard.ClearHighlights();
- Debug.WriteLine("Worker started at " + DateTime.Now);
- if (e.Cancel)
- {
- return;
- }
-
- var collections = this.TeamFoundationServer.CatalogNode.QueryChildren(
- new[] { CatalogResourceTypes.ProjectCollection },
- false,
- CatalogQueryOptions.None);
- foreach (var collection in collections)
- {
- if (e.Cancel)
- {
- return;
- }
-
- var projectCollectionId = new Guid(collection.Resource.Properties["InstanceId"]);
- var projectCollection = this.TeamFoundationServer.GetTeamProjectCollection(projectCollectionId);
- if (e.Cancel)
- {
- return;
- }
-
- var projects = projectCollection.CatalogNode.QueryChildren(
- new[] { CatalogResourceTypes.TeamProject },
- false,
- CatalogQueryOptions.None);
- this.Dashboard.AddProjects(projects.ToArray());
- if (e.Cancel)
- {
- return;
- }
-
- var workItemStore = projectCollection.GetService<WorkItemStore>();
- var workItemCollection = workItemStore.Query("select * from workitems order by [changed date] asc");
- if (this.Dashboard.DateRefresh.HasValue)
- {
- this.Dashboard.AddWorkItems(workItemCollection.Cast<WorkItem>().Where(x => x.ChangedDate > this.Dashboard.DateRefresh.Value));
- }
- else
- {
- this.Dashboard.AddWorkItems(workItemCollection.Cast<WorkItem>());
- }
- if (e.Cancel)
- {
- return;
- }
-
- var versionControlServer = projectCollection.GetService<VersionControlServer>();
- var commits = versionControlServer.QueryHistory("$/", RecursionType.Full);
- if (this.Dashboard.DateRefresh.HasValue)
- {
- this.Dashboard.AddCommits(commits.Where(x => x.CreationDate > this.Dashboard.DateRefresh.Value));
- }
- else
- {
- this.Dashboard.AddCommits(commits);
- }
- }
- e.Result = now;
- }
-
-
-
-
- protected override void OnRunWorkerCompleted(RunWorkerCompletedEventArgs e)
- {
- base.OnRunWorkerCompleted(e);
- Debug.WriteLine("Worker completed at " + DateTime.Now);
- this.Dashboard.DateRefresh = (DateTime?)e.Result;
- this.Dashboard.Cache();
- }
- }
- }
|