public void CreateIntegrators()
		{
			Project project1 = new Project();
			project1.Name = "project1";
			Project project2 = new Project();
			project2.Name = "project2";

			Configuration config = new Configuration();
			config.AddProject(project1);
			config.AddProject(project2);
		}
        public void SetUp()
        {
            project = new Project();
            project.Name = TestQueueName;

            configuration = new Configuration();
            configuration.AddProject(project);
            stateManagerMock = new DynamicMock(typeof(IProjectStateManager));

            queueManager = new IntegrationQueueManager(new ProjectIntegratorListFactory(),            
                configuration,
                (IProjectStateManager)stateManagerMock.MockInstance);
        }
예제 #3
0
        /// <summary>
        /// Loads and validates a queue.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="loadedItem">The loaded item.</param>
        private void LoadAndValidateQueue(Configuration configuration, object loadedItem)
        {
            var queueConfig = loadedItem as IQueueConfiguration;

            configuration.QueueConfigurations.Add(queueConfig);
            if (queueConfig.Projects != null)
            {
                foreach (var project in queueConfig.Projects)
                {
                    configuration.AddProject(project);
                    project.QueueName = queueConfig.Name;
                }
            }
        }
 public IConfiguration Read(XmlDocument document)
 {
     VerifyDocumentHasValidRootElement(document);
     try
     {
         Configuration configuration = new Configuration();
         foreach (XmlNode node in document.DocumentElement)
         {
             if (!(node is XmlComment))
             {
                 IProject project = reader.Read(node) as IProject;	// could this be null?  should check
                 configuration.AddProject(project);
             }
         }
         return configuration;
     }
     catch (NetReflectorException ex)
     {
         throw new ConfigurationException("Unable to instantiate CruiseControl projects from configuration document. " +
             "Configuration document is likely missing Xml nodes required for properly populating CruiseControl configuration." + ex.Message, ex);
     }
 }
예제 #5
0
 public IConfiguration Read(XmlDocument document)
 {
     VerifyDocumentHasValidRootElement(document);
     try
     {
         Configuration configuration = new Configuration();
         foreach (XmlNode node in document.DocumentElement)
         {
             if (!(node is XmlComment))
             {
                 IProject project = reader.Read(node) as IProject;                               // could this be null?  should check
                 configuration.AddProject(project);
             }
         }
         return(configuration);
     }
     catch (NetReflectorException ex)
     {
         throw new ConfigurationException("Unable to instantiate CruiseControl projects from configuration document. " +
                                          "Configuration document is likely missing Xml nodes required for properly populating CruiseControl configuration." + ex.Message, ex);
     }
 }
예제 #6
0
        private void LoadAndValidateProject(IConfigurationErrorProcesser errorProcesser,
                                            List <string> projectNames, Configuration configuration, object loadedItem)
        {
            IProject project = loadedItem as IProject;

            // Validate that the project name is unique
            string projectName = project.Name.ToLowerInvariant();

            if (projectNames.Contains(projectName))
            {
                errorProcesser.ProcessError(
                    new CruiseControlException(
                        string.Format(
                            CultureInfo.CurrentCulture, "A duplicate project name ({0})has been found - projects must be unique per server",
                            projectName)));
            }
            else
            {
                projectNames.Add(projectName);
            }

            configuration.AddProject(project);
        }
예제 #7
0
        private object ValidateElement(HtmlElement tableEl, XmlNode node, int row, Configuration configuration)
        {
            HtmlAttribute rowClass = new HtmlAttribute("class", (row % 2) == 1 ? "even" : "odd");
            object loadedItem = null;
            try
            {
                loadedItem = myConfigReader.Read(node);
                this.configurationHierarchy.Add(loadedItem);
                if (loadedItem is IProject)
                {
                    IProject project = loadedItem as IProject;
                    configuration.AddProject(project);
                    tableEl.AppendChild(
                        GenerateElement("tr",
                            rowClass,
                            GenerateElement("td", project.Name),
                            GenerateElement("td", "Project"),
                            GenerateElement("td", "Yes")));
                    LogMessage(string.Format("Loaded project '{0}'", project.Name));
                }
                else if (loadedItem is IQueueConfiguration)
                {
                    IQueueConfiguration queueConfig = loadedItem as IQueueConfiguration;
                    configuration.QueueConfigurations.Add(queueConfig);
                    tableEl.AppendChild(
                        GenerateElement("tr",
                            rowClass,
                            GenerateElement("td", queueConfig.Name),
                            GenerateElement("td", "Queue"),
                            GenerateElement("td", "Yes")));
                    LogMessage(string.Format("Loaded queue '{0}'", queueConfig.Name));
                }
                else if (loadedItem is ISecurityManager)
                {
                    ISecurityManager securityManager = loadedItem as ISecurityManager;
                    configuration.SecurityManager = securityManager as ISecurityManager;
                    LogMessage("Loaded security manager");
                }
                else
                {
                    tableEl.AppendChild(
                        GenerateElement("tr",
                            rowClass,
                            GenerateElement("td", (node as XmlElement).GetAttribute("name")),
                            GenerateElement("td", node.Name),
                            GenerateElement("td", "No")));
                    var message = "Unknown configuration type: " + loadedItem.GetType().Name;
                    tableEl.AppendChild(
                        GenerateElement("tr",
                            rowClass,
                            GenerateElement("td",
                                new HtmlAttribute("colspan", "3"),
                                GenerateElement("div",
                                    new HtmlAttribute("class", "error"),
                                    message))));
                    LogMessage(message);
                    isConfigValid = false;
                }
            }
            catch (Exception error)
            {
                string errorMsg = error.Message;
                int index = errorMsg.IndexOf("Xml Source");
                if (index >= 0) errorMsg = errorMsg.Substring(0, index - 1);
                tableEl.AppendChild(
                    GenerateElement("tr",
                        rowClass,
                        GenerateElement("td", (node as XmlElement).GetAttribute("name")),
                        GenerateElement("td", node.Name),
                        GenerateElement("td", "No")));
                tableEl.AppendChild(
                    GenerateElement("tr",
                        rowClass,
                        GenerateElement("td",
                            new HtmlAttribute("colspan", "3"),
                            GenerateElement("div",
                                new HtmlAttribute("class", "error"),
                                errorMsg))));
                isConfigValid = false;
                LogMessage(error.Message);
            }

            return loadedItem;
        }
예제 #8
0
		protected void SetUp()
		{
			projectSerializerMock = new DynamicMock(typeof (IProjectSerializer));

			integratorMock1 = new DynamicMock(typeof (IProjectIntegrator));
			integratorMock2 = new DynamicMock(typeof (IProjectIntegrator));
			integratorMock3 = new DynamicMock(typeof (IProjectIntegrator));
			integrator1 = (IProjectIntegrator) integratorMock1.MockInstance;
			integrator2 = (IProjectIntegrator) integratorMock2.MockInstance;
			integrator3 = (IProjectIntegrator) integratorMock3.MockInstance;
            integratorMock1.SetupResult("Name", "Project 1");
			integratorMock2.SetupResult("Name", "Project 2");
			integratorMock3.SetupResult("Name", "Project 3");

			fileSystem = mocks.DynamicMock<IFileSystem>();
			executionEnvironment = mocks.DynamicMock<IExecutionEnvironment>();

			SetupResult.For(executionEnvironment.IsRunningOnWindows).Return(true);
			SetupResult.For(executionEnvironment.GetDefaultProgramDataFolder(ApplicationType.Server)).Return(applicationDataPath);
			SetupResult.For(fileSystem.DirectoryExists(applicationDataPath)).Return(true);
			mocks.ReplayAll();

			integrationQueue = null; // We have no way of injecting currently.

			configuration = new Configuration();
			project1 = new Project();
			project1.Name = "Project 1";
            integratorMock1.SetupResult("Project", project1);
			
			project2 = new Project();
			project2.Name = "Project 2";
            integratorMock2.SetupResult("Project", project1);

			mockProject = new DynamicMock(typeof(IProject));
			mockProject.SetupResult("Name", "Project 3");
            mockProject.SetupResult("QueueName", "Project 3");
            mockProject.SetupResult("QueueName", "Project 3");
            mockProjectInstance = (IProject)mockProject.MockInstance;
			mockProject.SetupResult("Name", "Project 3");
            mockProject.SetupResult("StartupMode", ProjectStartupMode.UseLastState);
            integratorMock3.SetupResult("Project", mockProjectInstance);

			configuration.AddProject(project1);
			configuration.AddProject(project2);
			configuration.AddProject(mockProjectInstance);

			integratorList = new ProjectIntegratorList();
			integratorList.Add(integrator1);
			integratorList.Add(integrator2);
			integratorList.Add(integrator3);
            
			configServiceMock = new DynamicMock(typeof (IConfigurationService));
			configServiceMock.ExpectAndReturn("Load", configuration);

			projectIntegratorListFactoryMock = new DynamicMock(typeof (IProjectIntegratorListFactory));
			projectIntegratorListFactoryMock.ExpectAndReturn("CreateProjectIntegrators", integratorList, configuration.Projects, integrationQueue);

            stateManagerMock = new DynamicMock(typeof(IProjectStateManager));
            stateManagerMock.SetupResult("CheckIfProjectCanStart", true, typeof(string));

			server = new CruiseServer((IConfigurationService) configServiceMock.MockInstance,
			                          (IProjectIntegratorListFactory) projectIntegratorListFactoryMock.MockInstance,
			                          (IProjectSerializer) projectSerializerMock.MockInstance,
                                      (IProjectStateManager)stateManagerMock.MockInstance,
									  fileSystem,
									  executionEnvironment,
                                      null);
		}
예제 #9
0
		public void OnRestartKillAllIntegratorsRefreshConfigAndStartupNewIntegrators()
		{
			integratorMock1.Expect("Start");
			integratorMock2.Expect("Start");

			server.Start();

			integratorMock1.Expect("Stop",true);
			integratorMock1.Expect("WaitForExit");
			integratorMock2.Expect("Stop",true);
			integratorMock2.Expect("WaitForExit");

			configuration = new Configuration();
			configuration.AddProject(project1);
			integratorList = new ProjectIntegratorList();
			integratorList.Add(integrator1);
			configServiceMock.ExpectAndReturn("Load", configuration);
			projectIntegratorListFactoryMock.ExpectAndReturn("CreateProjectIntegrators", integratorList, configuration.Projects, integrationQueue);

			integratorMock1.Expect("Start");
			integratorMock2.ExpectNoCall("Start");

			server.Restart();

			VerifyAll();
		}
        private void LoadAndValidateProject(IConfigurationErrorProcesser errorProcesser, 
            List<string> projectNames, Configuration configuration, object loadedItem)
        {
            IProject project = loadedItem as IProject;

            // Validate that the project name is unique
            string projectName = project.Name.ToLowerInvariant();
            if (projectNames.Contains(projectName))
            {
                errorProcesser.ProcessError(
                    new CruiseControlException(
                        string.Format(
                            "A duplicate project name ({0})has been found - projects must be unique per server",
                            projectName)));
            }
            else
            {
                projectNames.Add(projectName);
            }

            configuration.AddProject(project);
        }
 /// <summary>
 /// Loads and validates a queue.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 /// <param name="loadedItem">The loaded item.</param>
 private void LoadAndValidateQueue(Configuration configuration, object loadedItem)
 {
     var queueConfig = loadedItem as IQueueConfiguration;
     configuration.QueueConfigurations.Add(queueConfig);
     if (queueConfig.Projects != null)
     {
         foreach (var project in queueConfig.Projects)
         {
             configuration.AddProject(project);
             project.QueueName = queueConfig.Name;
         }
     }
 }