AddProjects.cs :  » Build-Systems » CruiseControl.NET » ThoughtWorks » CruiseControl » CCTrayLib » Presentation » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Build Systems » CruiseControl.NET 
CruiseControl.NET » ThoughtWorks » CruiseControl » CCTrayLib » Presentation » AddProjects.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using ThoughtWorks.CruiseControl.CCTrayLib.Configuration;
using ThoughtWorks.CruiseControl.CCTrayLib.Monitoring;

namespace ThoughtWorks.CruiseControl.CCTrayLib.Presentation{
  public partial class AddProjects : Form
  {
    private BuildServer selectedServer;

    private readonly ICruiseProjectManagerFactory cruiseProjectManagerFactory;
        private readonly ICruiseServerManagerFactory cruiseServerManagerFactory;
        private Button butConfigure;
        private ColumnHeader columnHeader1;
        private ImageList imlSmall;
    private readonly CCTrayProject[] currentProjectList;

    public AddProjects(ICruiseProjectManagerFactory cruiseProjectManagerFactory,
            ICruiseServerManagerFactory cruiseServerManagerFactory,
            CCTrayProject[] currentProjectList)
    {
      this.cruiseProjectManagerFactory = cruiseProjectManagerFactory;
            this.cruiseServerManagerFactory = cruiseServerManagerFactory;
      this.currentProjectList = currentProjectList;

      InitializeComponent();

            List<BuildServer> serverList = new List<BuildServer>();
      foreach (CCTrayProject project in currentProjectList)
      {
                if (!serverList.Contains(project.BuildServer)) serverList.Add(project.BuildServer);
    }

            foreach (BuildServer server in serverList)
    {
                AddServer(server);
      }
    }

    public CCTrayProject[] GetListOfNewProjects(IWin32Window owner)
    {
      if (ShowDialog(owner) == DialogResult.OK)
      {
        ArrayList newProjects = new ArrayList();
      foreach (string projectName in lbProject.SelectedItems)
        {
        newProjects.Add(new CCTrayProject(selectedServer, projectName));
        }
        return (CCTrayProject[]) newProjects.ToArray(typeof (CCTrayProject));
      }
      return null;
    }

    private void btnAddServer_Click(object sender, EventArgs e)
    {
      AddBuildServer addBuildServer = new AddBuildServer(cruiseProjectManagerFactory);

      BuildServer buildServer = addBuildServer.ChooseNewBuildServer(this);
      if (buildServer != null)
      {
                AddServer(buildServer).Selected = true;
    }
    }

    private void RetrieveListOfProjects(BuildServer server)
    {
      Cursor.Current = Cursors.WaitCursor;
      try
      {
        lbProject.Items.Clear();

        CCTrayProject[] projectList = cruiseProjectManagerFactory.GetProjectList(server, false);

        foreach (CCTrayProject project in projectList)
        {
          if (! IsProjectAlreadyAdded(project))
            lbProject.Items.Add(project.ProjectName);
        }
      }
      catch (Exception ex)
      {
        MessageBox.Show(this, "Unable to connect to server " + server.DisplayName + ": " + ex.Message, "Error");
      }
      finally
      {
        Cursor.Current = Cursors.Default;
      }
    }

    private bool IsProjectAlreadyAdded(CCTrayProject project)
    {
      foreach (CCTrayProject currentProject in currentProjectList)
      {
        if (project.ServerUrl == currentProject.ServerUrl && project.ProjectName == currentProject.ProjectName)
          return true;
      }
      return false;
    }

    private void KeyEventHelper(object sender, KeyEventArgs e)
    {
      if (e.KeyCode == Keys.Enter)
      {
        this.DialogResult = System.Windows.Forms.DialogResult.OK;
        this.Close();
      }
      
      if (e.KeyCode == Keys.Escape)
      {
        this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        this.Close();
      }
    }
    
    private void lbProject_KeyDown(object sender, KeyEventArgs e)
    {
      if ((e.Modifiers == Keys.Control) && (e.KeyCode == Keys.A))
      {
        for (int i = 0; i < lbProject.Items.Count; i++)
        {
          lbProject.SetSelected(i, true);
      }
    }
      
      KeyEventHelper(sender, e);
    }
    
    private void lbServer_KeyDown(object sender, KeyEventArgs e)
    {
      KeyEventHelper(sender, e);
    }
    
    private void AddProjects_KeyDown(object sender, KeyEventArgs e)
    {
      KeyEventHelper(sender, e);
    }

        private void lbServer_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lbServer.SelectedItems.Count > 0)
            {
                selectedServer = (BuildServer)lbServer.SelectedItems[0].Tag;
            }
            else
            {
                selectedServer = null;
            }
            if (selectedServer != null) RetrieveListOfProjects(selectedServer);
        }

        private ListViewItem AddServer(BuildServer server)
        {
            ListViewItem newServerItem = lbServer.Items.Add(server.DisplayName, "NonSecure");
            newServerItem.Tag = server;
            SetSecurityIcon(newServerItem, server);
            return newServerItem;
        }

        private void SetSecurityIcon(ListViewItem item, BuildServer server)
        {
            if (server.SecurityType != null)
            {
                item.ImageKey = "Secure";
            }
            else
            {
                item.ImageKey = "NonSecure";
            }
        }

        private void butConfigure_Click(object sender, EventArgs e)
        {
            if (selectedServer == null)
            {
                MessageBox.Show(this, "Please select a server first", "Unable to configure", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                if (ConfigureServer.Configure(this, selectedServer))
                {
                    var server = this.cruiseServerManagerFactory.Create(selectedServer);
                    server.Logout();
                    RetrieveListOfProjects(selectedServer);
                    SetSecurityIcon(lbServer.SelectedItems[0], selectedServer);
                }
            }
        }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.