public DeploymentValidationResult ValidateDeployment(DeployProject project, DeployComponent component, DeployEnvironment environment)
		{
			var returnValue = new DeploymentValidationResult();
			DeployEnvironmentConfiguration environmentConfiguration;
			List<DeployStep> deploymentStepList;
			if(component.UseConfigurationGroup)
			{
				environmentConfiguration = environment.TryGetConfigurationItem(component.ConfigurationId);
				var configuration = project.GetConfiguration(component.ConfigurationId);
				deploymentStepList = configuration.DeploymentStepList;;
			}
			else
			{
				environmentConfiguration = environment.TryGetComponentItem(component.Id);
				deploymentStepList = component.DeploymentStepList;
			}
			if(environmentConfiguration != null)
			{
				foreach(var deploymentStep in deploymentStepList)
				{
					var taskDefinition = _taskFactory.CreateTaskDefinition(deploymentStep.TaskTypeName, deploymentStep.TaskOptionsJson);
					var validationItem = this.ValidateTaskDefinition(taskDefinition, environmentConfiguration);
					returnValue.AddResult(deploymentStep, validationItem);
				}
			}
			return returnValue;
		}
		public void Run(string deployStateId, IDeployTaskStatusManager statusManager, List<IDeployTaskDefinition> taskDefinitionList, DeployComponent component, DeployEnvironmentConfiguration environmentComponent, DeployMachine machine, DeployBuild build, RuntimeSystemSettings runtimeSystemSettings)
		{
			int stepCounter = 0;
			foreach(var taskDefinition in taskDefinitionList)
			{
				stepCounter++;
				statusManager.Info(deployStateId, string.Format("Step {0}: Starting {1}", stepCounter, taskDefinition.TaskDefintionName));
				DeployTaskExecutionResult result;
				//using (var impersontator = BeginImpersonation(deployStateId, statusManager, environmentComponent))
				//{
					var executor = _deployTaskFactory.CreateTaskExecutor(taskDefinition.GetTaskExecutorType());
					result = executor.Execute(deployStateId, statusManager, taskDefinition, component, environmentComponent, machine, build, runtimeSystemSettings);
				//}
				switch(result.Status)
				{
					case EnumDeployTaskExecutionResultStatus.Success:
						statusManager.Info(deployStateId, string.Format("Step {0}: End {1}, completed successfully", stepCounter, taskDefinition.TaskDefintionName));
						break;
					case EnumDeployTaskExecutionResultStatus.Error:
						statusManager.Info(deployStateId, string.Format("Step {0}: End {1}, failed", stepCounter, taskDefinition.TaskDefintionName));
						return;	//error error eject!
						//break;
					case EnumDeployTaskExecutionResultStatus.Warning:
						statusManager.Info(deployStateId, string.Format("Step {0}: End {1}, completed with warnings", stepCounter, taskDefinition.TaskDefintionName));
						break;
					default:
						throw new UnknownEnumValueException(result.Status);
				}
			}
		}
 private DeployStep CreateTestStep(IProjectRepository sut, DeployComponent component = null)
 {
     if(component == null)
     {
         component = this.CreateTestComponent(sut);
     }
     return sut.CreateComponentDeploymentStep(component.ProjectId, component.Id, this.Fixture.Create<string>("StepName"), this.Fixture.Create<string>("TaskTypeName"), this.Fixture.Create<string>("TaskOptionsJson"), null);
 }
		public object Post(DeployComponent component)
		{
			if (string.IsNullOrEmpty(component.Id))
			{
				return _projectManager.CreateComponent(component.ProjectId, component.ComponentName, component.UseConfigurationGroup, component.ConfigurationId, component.IsolationType);
			}
			else
			{
				return _projectManager.UpdateComponent(component.Id, component.ProjectId, component.ComponentName, component.UseConfigurationGroup, component.ConfigurationId, component.IsolationType);
			}
		}
		public object Get(DeployComponent request)
		{
			if(request == null || 
				(string.IsNullOrEmpty(request.Id) && string.IsNullOrEmpty(request.ProjectId)))
			{
				throw new ArgumentNullException();
			}
			if (string.IsNullOrEmpty(request.Id))
			{
				return _projectManager.GetComponent(request.Id, request.ProjectId);
			}
			else 
			{
				return _projectManager.GetComponentList(request.ProjectId);
			}
		}
 public DeployState CreateDeployState(DeployBuild build, DeployProjectBranch branch, DeployEnvironment environment, DeployComponent component, IEnumerable<DeployMachine> machineList, string deployBatchRequestItemId)
 {
     if (build == null)
     {
         throw new ArgumentNullException("Missing build");
     }
     if (branch == null)
     {
         throw new ArgumentNullException("Missing branch");
     }
     if (component == null)
     {
         throw new ArgumentNullException("Missing component");
     }
     if (environment == null)
     {
         throw new ArgumentNullException("Missing environment");
     }
     if (machineList == null)
     {
         throw new ArgumentNullException("Missing machineList");
     }
     if (deployBatchRequestItemId == null)
     {
         throw new ArgumentNullException("Missing deployBatchRequestItemId");
     }
     var deployState = new DeployState
     {
         Id = Guid.NewGuid().ToString(),
         ProjectId = environment.ProjectId,
         Build = build,
         Branch = branch,
         Environment = environment,
         Component = component,
         MachineList = machineList.ToList(),
         Status = EnumDeployStatus.NotStarted,
         SubmittedDateTimeUtc = DateTime.UtcNow,
         DeployBatchRequestItemId = deployBatchRequestItemId,
         CreatedDateTimeUtc = DateTime.UtcNow,
         CreatedByUserName = _userIdentity.UserName,
         UpdatedDateTimeUtc = DateTime.UtcNow,
         UpdatedByUserName = _userIdentity.UserName
     };
     _documentSession.StoreSaveEvict(deployState);
     return deployState;
 }
        private void AssertCreatedComponent(DeployComponent result, string projectId, string componentName, EnumDeploymentIsolationType isolationType, IProjectRepository sut)
        {
            AssertHelpers.AssertCreatedBaseDto(result, this.UserName);
            Assert.AreEqual(projectId, result.ProjectId);
            Assert.AreEqual(componentName, result.ComponentName);
            Assert.AreEqual(false, result.UseConfigurationGroup);
            Assert.AreEqual(null, result.ConfigurationId);
            Assert.AreEqual(isolationType, result.IsolationType);


            var dbItem = sut.GetComponent(result.Id, projectId);
            AssertHelpers.AssertComponent(result, dbItem);

            var dbProject = sut.GetProject(projectId);
            var dbProjectComponent = dbProject.ComponentList.SingleOrDefault(i => i.Id == result.Id);
            Assert.IsNotNull(dbProjectComponent);
            AssertHelpers.AssertComponent(result, dbProjectComponent);
        }
		public string EvaluateDeployParameter(string parameterName, RuntimeSystemSettings runtimeSettings, DeployMachine machine, DeployComponent component)
		{
			if (string.IsNullOrEmpty(parameterName))
			{
				throw new ArgumentNullException("Missing parameterName");
			}
			if (runtimeSettings == null)
			{
				throw new ArgumentNullException("Missing runtimeSettings");
			}
			switch (parameterName.ToLower())
			{
				case "directory":
					return runtimeSettings.GetLocalMachineComponentDirectory(machine.MachineName, component.Id);
				default:
					throw new ArgumentException(string.Format("Unrecognized deploy parameter \"{0}\"", parameterName));
			}
		}
        private void AssertCreatedStep(DeployStep result, DeployComponent component, string stepName, string taskTypeName, string taskOptionsJson, IProjectRepository sut)
        {
            Assert.IsNotNull(result);
            Assert.IsNotNullOrEmpty(result.Id);
            Assert.AreEqual(component.ProjectId, result.ProjectId);
            Assert.AreEqual(component.Id, result.ParentId);
            Assert.AreEqual(EnumDeployStepParentType.Component, result.ParentType);
            Assert.AreEqual(stepName, result.StepName);
            Assert.AreEqual(taskTypeName, result.TaskTypeName);
            Assert.AreEqual(taskOptionsJson, result.TaskOptionsJson);
            Assert.IsNotNullOrEmpty(result.SharedDeploymentStepId);
            Assert.AreEqual(this.UserName, result.CreatedByUserName);
            AssertIsRecent(result.CreatedDateTimeUtc);
            Assert.AreEqual(this.UserName, result.UpdatedByUserName);
            AssertIsRecent(result.UpdatedDateTimeUtc);

            var dbItem = sut.GetComponentDeploymentStep(result.Id, result.ProjectId);
            AssertStep(result, dbItem);
        }
 public DeployState CreateDeployState(DeployBuild build, DeployProjectBranch branch, DeployEnvironment environment, DeployComponent component, IEnumerable<DeployMachine> machineList, string deployBatchRequestItemId)
 {
     var deployState = new DeployState
     {
         Id = Guid.NewGuid().ToString(),
         ProjectId = environment.ProjectId,
         Build = build,
         Branch = branch,
         Environment = environment,
         Component = component,
         MachineList = machineList.ToList(),
         Status = EnumDeployStatus.NotStarted,
         SubmittedDateTimeUtc = DateTime.UtcNow,
         DeployBatchRequestItemId = deployBatchRequestItemId,
         CreatedDateTimeUtc = DateTime.UtcNow,
         CreatedByUserName = _userIdentity.UserName,
         UpdatedDateTimeUtc = DateTime.UtcNow,
         UpdatedByUserName = _userIdentity.UserName
     };
     _offlineDataProvider.SaveDeployState(deployState);
     return deployState;
 }
 public DeployComponent CreateComponent(string projectId, string componentName, bool useConfigurationGroup, string configurationId, EnumDeploymentIsolationType isolationType)
 {
     if(string.IsNullOrEmpty(projectId))
     {
         throw new ArgumentNullException("Missing project ID");
     }
     if(string.IsNullOrEmpty(componentName))
     {
         throw new ArgumentNullException("Missing component name");
     }
     VerifyProjectExists(projectId);
     var component = new DeployComponent
     {
         Id = Guid.NewGuid().ToString(),
         ComponentName = componentName,
         ProjectId = projectId, 
         UseConfigurationGroup = useConfigurationGroup,
         ConfigurationId = configurationId,
         IsolationType = isolationType,
         CreatedByUserName = _userIdentity.UserName,
         CreatedDateTimeUtc = DateTime.UtcNow,
         UpdatedByUserName = _userIdentity.UserName,
         UpdatedDateTimeUtc = DateTime.UtcNow
     };
     using(var db = _sqlConnectionInfo.GetDB())
     {
         var sql = PetaPoco.Sql.Builder
                     .Append("INSERT INTO DeployComponent (ID, DeployProjectID, ComponentName, UseConfigurationGroup, DeployConfigurationID, EnumDeploymentIsolationTypeID, CreatedByUserName, CreatedDateTimeUtc, UpdatedByUserName, UpdatedDateTimeUtc)")
                     .Append("VALUES (@Id, @ProjectId, @ComponentName, @UseConfigurationGroup, @ConfigurationId, @IsolationType, @CreatedByUserName, @CreatedDateTimeUtc, @UpdatedByUserName, @UpdatedDateTimeUtc)", component);
         db.Execute(sql);
     }
     return component;
 }
 private void LoadComponentChildren(DeployComponent item)
 {
     item.DeploymentStepList = this.GetComponentDeploymentStepList(item.Id, item.ProjectId);
 }
		public void Delete(DeployComponent component)
		{
			_projectManager.DeleteComponent(component.ProjectId, component.Id);
		}
 private DeployEnvironmentConfiguration GetCreateTestDeployEnvironmentConfiguration(DeployComponent component)
 {
     return new DeployEnvironmentConfiguration
     {
         ConfigurationValueList = this.CreateTestConfigurationValueList(),
         DeployCredentialsId = null,
         ParentId = component.Id,
         MachineList = this.CreateTestMachineList(5)
     };
 }
        public DeployState CreateDeployState(DeployBuild build, DeployProjectBranch branch, DeployEnvironment environment, DeployComponent component, IEnumerable<DeployMachine> machineList, string deployBatchRequestItemId)
        {
            if (build == null)
            {
                throw new ArgumentNullException("Missing build");
            }
            if (branch == null)
            {
                throw new ArgumentNullException("Missing branch");
            }
            if (component == null)
            {
                throw new ArgumentNullException("Missing component");
            }
            if (environment == null)
            {
                throw new ArgumentNullException("Missing environment");
            }
            if (machineList == null)
            {
                throw new ArgumentNullException("Missing machineList");
            }
            if (deployBatchRequestItemId == null)
            {
                throw new ArgumentNullException("Missing deployBatchRequestItemId");
            }
            var sqlDeployState = new SqlDeployState
            {
                ID = Guid.NewGuid().ToString(),
                ProjectID = build.ProjectId,
                BranchID = branch.Id,
                BranchJson = branch.ToJson(),
                BuildID = build.Id,
                BuildJson = build.ToJson(),
                ComponentID = component.Id,
                ComponentJson = component.ToJson(),
                EnvironmentID = environment.Id,
                EnvironmentName = environment.EnvironmentName,
                EnvironmentJson = environment.ToJson(),
                DeployBatchRequestItemID = deployBatchRequestItemId,
                DeploymentCompleteDateTimeUtc = null,
                DeploymentStartedDateTimeUtc = null,
                ErrorDetails = null,
                SortableVersion = build.SortableVersion,
                EnumDeployStatusID = (int)EnumDeployStatus.NotStarted,
                CreatedByUserName = _userIdentity.UserName,
                CreatedDateTimeUtc = DateTime.UtcNow,
                UpdatedByUserName = _userIdentity.UserName,
                UpdatedDateTimeUtc = DateTime.UtcNow,
                SubmittedDateTimeUtc = DateTime.UtcNow
            };
            var branchJson = branch.ToJson();
            var buildJson = build.ToJson();
            var componentJson = component.ToJson();
            var environmentJson = environment.ToJson();
            using(var db = _sqlConnectionInfo.GetDB())
            {
                var deployStateSql = PetaPoco.Sql.Builder
                            .Append("INSERT INTO DeployState (ID, DeployBatchRequestItemID, EnumDeployStatusID, ProjectID, BranchID, BuildID, EnvironmentID, EnvironmentName, ComponentID,")
                                            .Append("BranchJson, BuildJson, EnvironmentJson, ComponentJson, SubmittedDateTimeUtc, DeploymentStartedDateTimeUtc, DeploymentCompleteDateTimeUtc, ")
                                            .Append("ErrorDetails, SortableVersion, CreatedByUserName, CreatedDateTimeUtc, UpdatedByUserName, UpdatedDateTimeUtc)")
                            .Append("VALUES (@ID, @DeployBatchRequestItemID, @EnumDeployStatusID, @ProjectID, @BranchID, @BuildID, @EnvironmentID, @EnvironmentName, @ComponentID,", sqlDeployState)
                                .Append("@BranchJson, @BuildJson, @EnvironmentJson, @ComponentJson, @SubmittedDateTimeUtc, @DeploymentStartedDateTimeUtc, @DeploymentCompleteDateTimeUtc,", sqlDeployState)
                                .Append("@ErrorDetails, @SortableVersion, @CreatedByUserName, @CreatedDateTimeUtc, @UpdatedByUserName, @UpdatedDateTimeUtc)", sqlDeployState);
                db.Execute(deployStateSql);

                foreach(var machine in machineList)
                {
                    var sqlMachine = new SqlDeployStateMachine
                    {
                        ID = Guid.NewGuid().ToString(),
                        DeployStateID = sqlDeployState.ID,
                        MachineID = machine.Id,  
                        MachineName = machine.MachineName,
                        MachineJson = machine.ToJson(),
                        CreatedByUserName = _userIdentity.UserName,
                        CreatedDateTimeUtc = DateTime.UtcNow,
                        UpdatedByUserName = _userIdentity.UserName,
                        UpdatedDateTimeUtc = DateTime.UtcNow
                    };
                    var machineSql = PetaPoco.Sql.Builder  
                            .Append("INSERT INTO DeployStateMachine (ID, DeployStateID, MachineID, MachineName, MachineJson, CreatedByUserName, CreatedDateTimeUtc, UpdatedByUserName, UpdatedDateTimeUtc)")
                            .Append("VALUES (@ID, @DeployStateID, @MachineID, @MachineName, @MachineJson, @CreatedByUserName, @CreatedDateTimeUtc, @UpdatedByUserName, @UpdatedDateTimeUtc)", sqlMachine);
                    db.Execute(machineSql);
                }
            }
            return GetDeployState(sqlDeployState.ID);
        }