/* * 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. */ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using ThoughtWorks.CruiseControl.Remote; using ThoughtWorks.CruiseControl.Remote.Monitor; using FastForward.WinCore.Configuration; using FastForward.WinCore; namespace FastForward.VisualStudio { /// /// Allow the user to configure the settings for FastForward.NET. /// public partial class SettingsForm : Form { #region Private fields private VisualStudioPackage package; #endregion #region Constructors /// /// Initializes a new instance of . /// /// public SettingsForm(VisualStudioPackage package) { InitializeComponent(); this.package = package; var clientfactory = new CruiseServerClientFactory(); Configuration = package.Configuration.Clone(); foreach (var server in this.Configuration.Servers) { // Need to make sure there is a server instance for each item var client = clientfactory.GenerateClient(server.Address, server.TargetServer); server.Server = new Server(client); server.Server.DisplayName = server.Name; // Now it can be added to the listview serversList.Items.Add(new ServerConfigItem(server)); } } #endregion #region Public properties #region Configuration /// /// Gets the new configuration. /// public VisualStudioConfig Configuration { get; private set; } #endregion #endregion #region Public events #region OkClicked /// /// The OK button has been clicked. /// public event EventHandler OkClicked; #endregion #endregion #region Private methods #region ShowProjectsForServer() /// /// Display the projects that are available for a server. /// private void ShowProjectsForServer() { if (serversList.SelectedItems.Count == 1) { var item = serversList.SelectedItems[0] as ServerConfigItem; var form = new ServerProjectsForm(item.Server); form.ShowDialog(this); } else { MessageBox.Show(this, "You must select a server first", "Unable to configure server", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } #endregion #endregion #region Event handlers #region okButton_Click /// /// The ok button has been clicked. /// /// /// private void okButton_Click(object sender, EventArgs e) { if (OkClicked != null) { OkClicked(this, EventArgs.Empty); } DialogResult = DialogResult.OK; Close(); } #endregion #region addButton_Click() /// /// The user has clicked on the Add server button. /// /// /// private void addButton_Click(object sender, EventArgs e) { var addForm = new AddServerForm((from serverItem in Configuration.Servers select serverItem.Address.ToLower()).ToList()); ServerConfig server = null; addForm.OkClicked += (o, a) => { server = new ServerConfig { Address = addForm.ServerAddress, Settings = addForm.Settings, TargetServer = addForm.TargetServer, TransportMode = addForm.TransportMode, Version = addForm.ServerVersion, Server = new Server(addForm.Client) }; Configuration.Servers.Add(server); serversList.Items.Add(new ServerConfigItem(server)); }; var result = addForm.ShowDialog(this); if (result == DialogResult.OK) { var configForm = new ServerConfigurationForm(server); configForm.ShowDialog(this); } } #endregion #region configureButton_Click() /// /// The user has clicked on the configure server button. /// /// /// private void configureButton_Click(object sender, EventArgs e) { if (serversList.SelectedItems.Count == 1) { var item = serversList.SelectedItems[0] as ServerConfigItem; var configForm = new ServerConfigurationForm(item.Server); if (configForm.ShowDialog(this) == DialogResult.OK) { item.Server.Server.DisplayName = item.Server.Name; } } else { MessageBox.Show(this, "You must select a server first", "Unable to configure server", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } #endregion #region removeButton_Click() /// /// The user has clicked on the remove server button. /// /// /// private void removeButton_Click(object sender, EventArgs e) { if (serversList.SelectedItems.Count == 1) { var item = serversList.SelectedItems[0] as ServerConfigItem; if (MessageBox.Show(this, string.Format("Are you sure you want to remove the server '{0}'?", item.Server.Server.GetDisplayName(true)), "Remove server", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { Configuration.Servers.Remove(item.Server); item.Remove(); } } else { MessageBox.Show(this, "You must select a server first", "Unable to remove server", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } #endregion #region serversList_DoubleClick() /// /// The user has double-clicked on a server in the servers list view. /// /// /// private void serversList_DoubleClick(object sender, EventArgs e) { ShowProjectsForServer(); } #endregion #region projectsButton_Click() /// /// The user has clicked on the projects button. /// /// /// private void projectsButton_Click(object sender, EventArgs e) { ShowProjectsForServer(); } #endregion #endregion #region Private classes #region ServerConfigItem /// /// A that displays details on a server. /// private class ServerConfigItem : ListViewItem { #region Constructors /// /// Initialise a new . /// /// public ServerConfigItem(ServerConfig value) { Server = value; Text = value.Server.GetDisplayName(true); SubItems.Add(string.Empty); SetTransport(); value.Server.PropertyChanged += Server_PropertyChanged; } #endregion #region Public properties #region Server /// /// The server that is being displayed. /// public ServerConfig Server { get; set; } #endregion #endregion #region Private methods #region SetTransport() /// /// Display the transport - both the text and the image. /// private void SetTransport() { string transport = "(Default)"; string image = "DefaultTransport"; switch (Server.TransportMode) { case ServerTransportMode.Http: transport = "HTTP"; image = "HttpTransport"; break; case ServerTransportMode.Remoting: transport = ".NET Remoting"; image = "RemotingTransport"; break; case ServerTransportMode.TcpCache: transport = "FastForward.NET Cache (TCP)"; image = "FastForward"; break; } SubItems[1].Text = transport; ImageKey = image; } #endregion #region Server_PropertyChanged() private void Server_PropertyChanged(object sender, PropertyChangedEventArgs e) { Text = Server.Server.GetDisplayName(true); } #endregion #endregion } #endregion #endregion } }