/* * Copyright (c) 2009 Craig Sutherland * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ namespace FastForward.Monitor { using System; using System.ComponentModel; using System.Linq; using System.Xml.Linq; using ThoughtWorks.CruiseControl.Remote; using ThoughtWorks.CruiseControl.Remote.Monitor; /// /// Exposes the properties of a project. /// [TypeConverter(typeof(ExpandableObjectConverter))] public class ProjectProperties : INotifyPropertyChanged, IDisposable { #region Private fields private Project item; private ServerProperties server; private BuildQueueProperties queue; #endregion #region Constructors /// /// Initializes a new instance of the classes. /// /// The item to display. public ProjectProperties(Project item) { this.item = item; this.item.PropertyChanged += this.item_PropertyChanged; this.server = new ServerProperties(this.item.Server); this.queue = new BuildQueueProperties(this.item.BuildQueue); } #endregion #region Public properties #region Server /// /// The server this project belongs to. /// [DisplayName("Server")] [Category("Server")] [Description("The server that the project belongs to.")] public ServerProperties Server { get { return this.server; } } #endregion #region Name /// /// The name of the project. /// [DisplayName("Project Name")] [Category("Metadata")] [Description("The name of the project.")] public string Name { get { return item.Name; } } #endregion #region BuildStage /// /// The current build stage. /// [DisplayName("Build Stage")] [Category("Status")] [Description("The current build stage.")] public string BuildStage { get { var stage = string.Empty; if (!string.IsNullOrEmpty(item.BuildStage)) { try { var data = XDocument.Parse(item.BuildStage); var itemEl = (from record in data.Descendants("Item") select record).SingleOrDefault(); if (itemEl != null) { var stageEl = itemEl.Attribute("Data"); if (stageEl != null) { stage = stageEl.Value; } } } catch { stage = item.BuildStage; } } return stage; } } #endregion #region Status /// /// The current project status. /// [DisplayName("Project Status")] [Category("Status")] [Description("The current status of the project.")] public ProjectIntegratorState Status { get { return item.Status; } } #endregion #region BuildStatus /// /// The current build status. /// [DisplayName("Build Status")] [Category("Status")] [Description("The status of the build, if one is currently running.")] public IntegrationStatus BuildStatus { get { return item.BuildStatus; } } #endregion #region Activity /// /// The current activity. /// [DisplayName("Activity")] [Category("Status")] [Description("The current activity the project is doing.")] public ProjectActivity Activity { get { return item.Activity; } } #endregion #region Description /// /// The description of the project. /// [DisplayName("Description")] [Category("Metadata")] [Description("The decription of the project.")] public string Description { get { return item.Description; } } #endregion #region Category /// /// The project category. /// [DisplayName("Category")] [Category("Metadata")] [Description("The category of the project.")] public string Category { get { return item.Category; } } #endregion #region Queue /// /// The build queue this project belongs to. /// [DisplayName("Queue")] [Category("Queue")] [Description("The queue this project belongs to.")] public BuildQueueProperties Queue { get { return this.queue; } } #endregion #region QueuePriority /// /// The priority of the project within the queue. /// [DisplayName("Queue Priroity")] [Category("Queue")] [Description("The priority of this project within the queue.")] public int QueuePriority { get { return item.QueuePriority; } } #endregion #region WebURL /// /// The URL for the project. /// [DisplayName("Web URL")] [Category("Metadata")] [Description("The URL of the project.")] public string WebURL { get { return item.WebURL; } } #endregion #region LastBuildDate /// /// The date and time the project was last built. /// [DisplayName("Last Build Date/Time")] [Category("Status")] [Description("The date and time the project last built.")] public DateTime LastBuildDate { get { return item.LastBuildDate; } } #endregion #region LastBuildLabel /// /// The last build label (independent of the outcome of the build). /// [DisplayName("Last Build Label")] [Category("Status")] [Description("The label for the project when it was last built.")] public string LastBuildLabel { get { return item.LastBuildLabel; } } #endregion #region LastSuccessfulBuildLabel /// /// The last successful build label. /// [DisplayName("Last Successful Build Label")] [Category("Status")] [Description("The label for the project when it was last successfully built.")] public string LastSuccessfulBuildLabel { get { return item.LastSuccessfulBuildLabel; } } #endregion #region NextBuildTime /// /// The date and time of the next build check. /// [DisplayName("Next Build Date/Time")] [Category("Status")] [Description("The date and time the project will next check for modifications.")] public DateTime NextBuildTime { get { return item.NextBuildTime; } } #endregion #endregion #region Public events #region PropertyChanged /// /// A property on the underlying item has changed. /// public event PropertyChangedEventHandler PropertyChanged; #endregion #endregion #region Event handlers #region item_PropertyChanged() /// /// A property on the item has changed. /// /// /// private void item_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (PropertyChanged != null) { PropertyChanged(this, e); } } #endregion #endregion #region Public methods #region Dispose() /// /// Dispose of this item. /// public void Dispose() { this.item.PropertyChanged -= this.item_PropertyChanged; } #endregion #region ToString() /// /// Returns the name of the item. /// /// public override string ToString() { return item.Name; } #endregion #endregion } }