Skip to content

Commit

Permalink
Initial add of files from my old Subversion repository
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulStovell committed Jan 17, 2009
0 parents commit ddf57e9
Show file tree
Hide file tree
Showing 26 changed files with 1,342 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Source/TeamBuildMonitorGadget.sln
@@ -0,0 +1,24 @@

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamBuildMonitorGadget", "TeamBuildMonitorGadget\TeamBuildMonitorGadget.csproj", "{BA7022CF-10AD-4F4A-9C01-86E739B92318}"
ProjectSection(WebsiteProperties) = preProject
Debug.AspNetCompiler.Debug = "True"
Release.AspNetCompiler.Debug = "False"
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BA7022CF-10AD-4F4A-9C01-86E739B92318}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BA7022CF-10AD-4F4A-9C01-86E739B92318}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA7022CF-10AD-4F4A-9C01-86E739B92318}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BA7022CF-10AD-4F4A-9C01-86E739B92318}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
19 changes: 19 additions & 0 deletions Source/TeamBuildMonitorGadget/App.xaml
@@ -0,0 +1,19 @@
<Application x:Class="TeamBuildMonitorGadget.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainPage.xaml"
xmlns:local="clr-namespace:PaulStovell.TeamBuildMonitorGadget"
>
<Application.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="FontFamily" Value="Segoe UI" />
<Setter Property="FontSize" Value="9pt" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>

<local:DateConverter x:Key="Converter_DateConverter" />
<local:IsNullVisibilityConverter x:Key="Converter_IsNullVisibilityConverter" />


</Application.Resources>
</Application>
16 changes: 16 additions & 0 deletions Source/TeamBuildMonitorGadget/App.xaml.cs
@@ -0,0 +1,16 @@
using System;
using System.Windows;
using System.Windows.Navigation;
using System.Data;
using System.Xml;
using System.Configuration;

namespace TeamBuildMonitorGadget {
/// <summary>
/// Interaction logic for App.xaml
/// </summary>

public partial class App : System.Windows.Application {

}
}
80 changes: 80 additions & 0 deletions Source/TeamBuildMonitorGadget/BuildStoreDriver.cs
@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using Microsoft.TeamFoundation.Build.Proxy;
using System.ComponentModel;
using System.Windows.Documents;
using System.Collections.ObjectModel;
using Microsoft.TeamFoundation.Client;
using System.Net;
using Microsoft.TeamFoundation.Build.Common;

namespace PaulStovell.TeamBuildMonitorGadget {
public class BuildStoreDriver : DependencyObject {
private BuildStoreWorker _backgroundWorker;

public BuildStoreDriver() {

}

public static readonly DependencyProperty TeamFoundationServerUriProperty = DependencyProperty.Register("TeamFoundationServerUri", typeof(string), typeof(BuildStoreDriver), new UIPropertyMetadata(null, RecreateBackgroundWorker));
public static readonly DependencyProperty TeamProjectNameProperty = DependencyProperty.Register("TeamProjectName", typeof(string), typeof(BuildStoreDriver), new UIPropertyMetadata(null, RecreateBackgroundWorker));
public static readonly DependencyProperty TeamBuildTypeNameProperty = DependencyProperty.Register("TeamBuildTypeName", typeof(string), typeof(BuildStoreDriver), new UIPropertyMetadata(null, RecreateBackgroundWorker));
public static readonly DependencyProperty IsUpdatingProperty = DependencyProperty.Register("IsUpdating", typeof(bool), typeof(BuildStoreDriver), new UIPropertyMetadata(false));
public static readonly DependencyProperty LastExceptionProperty = DependencyProperty.Register("LastException", typeof(Exception), typeof(BuildStoreDriver), new UIPropertyMetadata(null));
private static readonly DependencyPropertyKey PreviousBuildsPropertyKey = DependencyProperty.RegisterReadOnly("PreviousBuilds", typeof(ObservableCollection<BuildSummary>), typeof(BuildStoreDriver), new UIPropertyMetadata(null));
public static readonly DependencyProperty PreviousBuildsProperty = PreviousBuildsPropertyKey.DependencyProperty;

public ObservableCollection<BuildSummary> PreviousBuilds {
get { return (ObservableCollection<BuildSummary>)GetValue(PreviousBuildsProperty); }
private set { SetValue(PreviousBuildsPropertyKey, value); }
}

public string TeamFoundationServerUri {
get { return (string)GetValue(TeamFoundationServerUriProperty); }
set { SetValue(TeamFoundationServerUriProperty, value); }
}

public string TeamProjectName {
get { return (string)GetValue(TeamProjectNameProperty); }
set { SetValue(TeamProjectNameProperty, value); }
}

public string TeamBuildTypeName {
get { return (string)GetValue(TeamBuildTypeNameProperty); }
set { SetValue(TeamBuildTypeNameProperty, value); }
}

public Exception LastException {
get { return (Exception)GetValue(LastExceptionProperty); }
set { SetValue(LastExceptionProperty, value); }
}

private static void RecreateBackgroundWorker(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) {
BuildStoreDriver driver = dependencyObject as BuildStoreDriver;
if (driver != null) {
driver.PreviousBuilds = new ObservableCollection<BuildSummary>();
if (driver._backgroundWorker != null) {
driver._backgroundWorker.CancelAsync();
}
driver._backgroundWorker = new BuildStoreWorker(driver.TeamFoundationServerUri, driver.TeamProjectName, driver.TeamBuildTypeName, driver.PreviousBuilds);
driver._backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
delegate(object sender, RunWorkerCompletedEventArgs workedCompletedEventArgs) {
if (workedCompletedEventArgs.Error != null) {
driver.LastException = workedCompletedEventArgs.Error;
}
});
}
}

public void Monitor() {
VerifyAccess();

if (!_backgroundWorker.IsBusy) {
this.LastException = null;
_backgroundWorker.RunWorkerAsync();
}
}
}
}
63 changes: 63 additions & 0 deletions Source/TeamBuildMonitorGadget/BuildStoreWorker.cs
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Build.Proxy;
using System.Collections.ObjectModel;
using System.Net;
using System.Threading;
using System.Windows;

namespace PaulStovell.TeamBuildMonitorGadget {
public class BuildStoreWorker : BackgroundWorker {
private string _teamFoundationServerUri;
private string _teamProjectName;
private string _teamBuildTypeName;
private BuildSummaryFactory _summaryFactory;
private ObservableCollection<BuildSummary> _buildSummaries;

public BuildStoreWorker(string teamFoundationServerUri, string teamProjectName, string teamBuildTypeName, ObservableCollection<BuildSummary> buildSummaries) {
_teamFoundationServerUri = teamFoundationServerUri;
_teamProjectName = teamProjectName;
_teamBuildTypeName = teamBuildTypeName;
_buildSummaries = buildSummaries;
_summaryFactory = new BuildSummaryFactory();

this.WorkerSupportsCancellation = true;
this.WorkerReportsProgress = true;
this.DoWork += new DoWorkEventHandler(BuildStoreWorker_DoWork);
this.ProgressChanged += new ProgressChangedEventHandler(BuildStoreWorker_ProgressChanged);
}

private void BuildStoreWorker_DoWork(object sender, DoWorkEventArgs e) {

TeamFoundationServer server = new TeamFoundationServer(_teamFoundationServerUri, CredentialCache.DefaultCredentials);
server.EnsureAuthenticated();

while (!this.CancellationPending) {
BuildStore store = (BuildStore)server.GetService(typeof(BuildStore));
BuildData[] builds = store.GetListOfBuilds(_teamProjectName, _teamBuildTypeName);
this.ReportProgress(0, builds);
Thread.Sleep(30000);
}
}

private void BuildStoreWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) {
BuildData[] results = (BuildData[])e.UserState;

List<BuildSummary> summaries = new List<BuildSummary>();
foreach (BuildData buildData in results) {
BuildSummary summary = _summaryFactory.GetBuildSummary(buildData);
summaries.Add(summary);
}
summaries.Sort();

_buildSummaries.Clear();
for (int i = 0; i < summaries.Count && i < 4; i++) {
_buildSummaries.Add(summaries[i]);
}

}
}
}
72 changes: 72 additions & 0 deletions Source/TeamBuildMonitorGadget/BuildSummary.cs
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace PaulStovell.TeamBuildMonitorGadget {
public class BuildSummary : INotifyPropertyChanged, IComparable<BuildSummary> {
private string _buildNumber;
private DateTime _buildDate;
private string _buildStatus;
private string _buildUri;
private string _dropLocation;

public static readonly PropertyChangedEventArgs BuildNumberPropertyChangedEventArgs = new PropertyChangedEventArgs("BuildNumber");
public static readonly PropertyChangedEventArgs BuildDatePropertyChangedEventArgs = new PropertyChangedEventArgs("BuildDate");
public static readonly PropertyChangedEventArgs BuildStatusPropertyChangedEventArgs = new PropertyChangedEventArgs("BuildStatus");
public static readonly PropertyChangedEventArgs DropLocationPropertyChangedEventArgs = new PropertyChangedEventArgs("DropLocation");

public string BuildUri {
get { return _buildUri; }
internal set { _buildUri = value; }
}

public string BuildNumber {
get { return _buildNumber; }
set {
_buildNumber = value;
OnPropertyChanged(BuildNumberPropertyChangedEventArgs);
}
}

public DateTime BuildDate {
get { return _buildDate; }
set {
_buildDate = value;
OnPropertyChanged(BuildDatePropertyChangedEventArgs);
}
}

public string BuildStatus {
get { return _buildStatus; }
set {
_buildStatus = value;
OnPropertyChanged(BuildStatusPropertyChangedEventArgs);
}
}

public string DropLocation {
get { return _dropLocation; }
set {
_dropLocation = value;
OnPropertyChanged(DropLocationPropertyChangedEventArgs);
}
}

public event PropertyChangedEventHandler PropertyChanged;

protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) {
if (this.PropertyChanged != null) {
this.PropertyChanged(this, e);
}
}

#region IComparable<BuildSummary> Members

public int CompareTo(BuildSummary other) {
return other.BuildDate.CompareTo(this.BuildDate);
}

#endregion
}
}
34 changes: 34 additions & 0 deletions Source/TeamBuildMonitorGadget/BuildSummaryFactory.cs
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.TeamFoundation.Build.Proxy;

namespace PaulStovell.TeamBuildMonitorGadget {
public class BuildSummaryFactory {
private List<BuildSummary> _summaries = new List<BuildSummary>();

public BuildSummary GetBuildSummary(BuildData buildData) {
BuildSummary result = null;

foreach (BuildSummary summary in _summaries) {
if (summary.BuildUri == buildData.BuildUri) {
result = summary;
break;
}
}

if (result == null) {
result = new BuildSummary();
_summaries.Add(result);
}

result.BuildDate = buildData.StartTime;
result.BuildNumber = buildData.BuildNumber;
result.BuildStatus = buildData.BuildStatus;
result.BuildUri = buildData.BuildUri;
result.DropLocation = buildData.DropLocation;

return result;
}
}
}
38 changes: 38 additions & 0 deletions Source/TeamBuildMonitorGadget/DateConverter.cs
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Data;

namespace PaulStovell.TeamBuildMonitorGadget {
public class DateConverter : IValueConverter {

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
string result = string.Empty;

if (value != null) {
DateTime dt = (DateTime)value;
if (parameter != null) {
if (parameter.ToString() == "today") {
if (dt.Date == DateTime.Today) {
result = "Today";
} else if (dt.Date == DateTime.Today.AddDays(-1)) {
result = "Yesterday";
} else {
result = dt.ToString("dd-MMM");
}
} else {
result = dt.ToString(parameter.ToString());
}
} else {
result = dt.ToString("dd-MMM");
}
}

return result;
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
throw new Exception("The method or operation is not implemented.");
}
}
}
24 changes: 24 additions & 0 deletions Source/TeamBuildMonitorGadget/Gadget.html
@@ -0,0 +1,24 @@
<html>
<head>
<title>Team Build Monitor Gadget</title>
<style>
body {
width:130;
height:200;
padding:0;
margin:0;
background:transparent;
background-image: url('GadgetBackground.png');
}
</style>

</head>
<body>
<iframe
width="130"
height="200"
src="TeamBuildMonitorGadget.xbap"
>
</iframe>
</body>
</html>

0 comments on commit ddf57e9

Please sign in to comment.