Skip to content

Instantly share code, notes, and snippets.

@bzbetty
Created March 17, 2015 21:33
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 bzbetty/f3f615c24cf27acb3fb8 to your computer and use it in GitHub Desktop.
Save bzbetty/f3f615c24cf27acb3fb8 to your computer and use it in GitHub Desktop.
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.Client;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var builds = GetBuildInfo();
if (builds.Any(i => i.Status == BuildStatus.Failed))
{
SetColor(Color.FromArgb(200,40,40));
}
else if (builds.Any(i => i.Status == BuildStatus.PartiallySucceeded))
{
SetColor(Color.FromArgb(200, 150, 40));
}
else
{
SetColor(Color.FromArgb(0, 0, 0));
}
}
private static IEnumerable<IBuildDetail> GetBuildInfo()
{
var server = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://tfs:8080/tfs/"));
server.EnsureAuthenticated();
var buildServer = server.GetService<IBuildServer>();
var spec = buildServer.CreateBuildDetailSpec("*", "*");
spec.QueryOrder = BuildQueryOrder.StartTimeDescending;
spec.Status = BuildStatus.InProgress | BuildStatus.Succeeded | BuildStatus.PartiallySucceeded | BuildStatus.Failed;
spec.MinFinishTime = DateTime.Now.AddDays(-7).Date;
spec.InformationTypes = new string[0]; // Don't return extra information. We are only interested in the basic build info.
var result = buildServer.QueryBuilds(spec);
return result.Builds;
}
public static void SetColor(Color color)
{
// Remove the current wallpaper
NativeMethods.SystemParametersInfo(
NativeMethods.SPI_SETDESKWALLPAPER,
0,
"",
NativeMethods.SPIF_UPDATEINIFILE | NativeMethods.SPIF_SENDWININICHANGE);
// Set the new desktop solid color for the current session
int[] elements = { NativeMethods.COLOR_DESKTOP };
int[] colors = { System.Drawing.ColorTranslator.ToWin32(color) };
NativeMethods.SetSysColors(elements.Length, elements, colors);
// Save value in registry so that it will persist
RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Colors", true);
key.SetValue(@"Background", string.Format("{0} {1} {2}", color.R, color.G, color.B));
}
private static class NativeMethods
{
public const int COLOR_DESKTOP = 1;
public const int SPI_SETDESKWALLPAPER = 20;
public const int SPIF_UPDATEINIFILE = 0x01;
public const int SPIF_SENDWININICHANGE = 0x02;
[DllImport("user32.dll")]
public static extern bool SetSysColors(int cElements, int[] lpaElements, int[] lpaRgbValues);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment