Source

TrafficLight / src / UI / BaseForm.cs

Full commit
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using RossCode.TrafficLight.Core.Domain;
using RossCode.TrafficLight.UI.Properties;

namespace RossCode.TrafficLight.UI
{
    public partial class BaseForm : Form
    {
        private readonly IDictionary<BuildStatus, Action> setBuildIcon;

        protected BaseForm()
        {
            InitializeComponent();

            setBuildIcon = new Dictionary<BuildStatus, Action>
                {
                    { BuildStatus.Unknown, () => Icon = Resources.DefaultTrafficLightIcon},
                    { BuildStatus.Success, () => Icon = Resources.GreenTrafficLightIcon},
                    { BuildStatus.Building, () => Icon = Resources.YellowTrafficLightIcon},
                    { BuildStatus.Failing, () => Icon = Resources.RedTrafficLightIcon}
                };

            Icon = Resources.DefaultTrafficLightIcon;
        }

        public virtual void SetBuildStatusTo(BuildStatus status)
        {
            if (InvokeRequired)
            {
                Invoke(setBuildIcon[status]);
            }
            else
            {
                setBuildIcon[status]();
            }
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == Keys.Escape)
            {
                Close();
            }

            return base.ProcessCmdKey(ref msg, keyData);
        }
    }
}