private List<DeployEnvironmentConfiguration> UpdateEnvironmentComponentList(IEnumerable<DeployEnvironmentConfiguration> componentList, string environmentId, string projectId, string environmentName, EnumDeployStepParentType parentType) { foreach (var component in componentList) { switch(parentType) { case EnumDeployStepParentType.Component: VerifyComponentExists(component.ParentId, projectId); break; case EnumDeployStepParentType.Configuration: VerifyConfigurationExists(component.ParentId, projectId); break; default: throw new UnknownEnumValueException(parentType); } if (string.IsNullOrEmpty(component.Id)) { component.Id = Guid.NewGuid().ToString(); component.CreatedDateTimeUtc = DateTime.UtcNow; component.CreatedByUserName = _userIdentity.UserName; } component.EnvironmentId = environmentId; component.ProjectId = projectId; component.ParentType = parentType; component.UpdatedDateTimeUtc = DateTime.UtcNow; component.UpdatedByUserName = _userIdentity.UserName; if (component.MachineList != null) { foreach (var machine in component.MachineList) { if (string.IsNullOrEmpty(machine.Id)) { machine.Id = Guid.NewGuid().ToString(); machine.CreatedDateTimeUtc = DateTime.UtcNow; machine.CreatedByUserName = _userIdentity.UserName; } machine.ProjectId = projectId; machine.ParentId = component.Id; machine.EnvironmentId = environmentId; machine.EnvironmentName = environmentName; machine.UpdatedDateTimeUtc = DateTime.UtcNow; machine.UpdatedByUserName = _userIdentity.UserName; } } } return componentList.ToList(); }
//private void LoadMachineChildren(DeployMachine item) //{ // item.ConfigurationValueList = this.GetMachineConfigurationValueList(item.Id).ToDictionary(i=>i.ConfigurationName, i=>i.ConfigurationValue); //} //private void SaveEnvironmentComponentValueList(DeployEnvironmentConfiguration configuration) //{ // var itemsToInsert = new List<ConfigurationPair>(); // var itemsToUpdate = new List<ConfigurationPair>(); // var itemsToDelete = new List<ConfigurationPair>(); // var existingList = GetEnvironmentConfigurationValueList(configuration.Id); // foreach(var newKey in configuration.ConfigurationValueList.Keys) // { // var existingItem = existingList.SingleOrDefault(i=>i.ConfigurationName == newKey); // if(existingItem == null) // { // itemsToInsert.Add(new ConfigurationPair { ConfigurationName=newKey, ConfigurationValue=configuration.ConfigurationValueList[newKey] }); // } // else if(existingItem.ConfigurationValue != configuration.ConfigurationValueList[newKey]) // { // existingItem.ConfigurationValue = configuration.ConfigurationValueList[newKey]; // itemsToUpdate.Add(existingItem); // } // } // foreach(var existingItem in existingList) // { // if(!configuration.ConfigurationValueList.ContainsKey(existingItem.ConfigurationName)) // { // itemsToDelete.Add(existingItem); // } // } // using(var db = _sqlConnectionInfo.GetDB()) // { // foreach(var item in itemsToInsert) // { // item.Id = Guid.NewGuid().ToString(); // var sql = PetaPoco.Sql.Builder // .Append("INSERT INTO DeployEnvironmentConfigurationValue (ID, DeployEnvironmentConfigurationID, ConfigurationName, ConfigurationValue, CreatedByUserName, CreatedDateTimeUtc, UpdatedByUserName, UpdatedDateTimeUtc)") // .Append("VALUES (@0, @1, @2, @3, @4, @5, @6, @7)", item.Id, configuration.Id, item.ConfigurationName, item.ConfigurationValue, _userIdentity.UserName, DateTime.UtcNow, _userIdentity.UserName, DateTime.UtcNow); // db.Execute(sql); // } // foreach(var item in itemsToUpdate) // { // var sql = PetaPoco.Sql.Builder // .Append("UPDATE DeployEnvironmentConfigurationValue") // .Append("SET ConfigurationValue=@0", item.ConfigurationValue) // .Append("WHERE ID=@0", item.Id); // db.Execute(sql); // } // foreach(var item in itemsToDelete) // { // var sql = PetaPoco.Sql.Builder // .Append("DELETE FROM DeployEnvironmentConfigurationValue") // .Append("WHERE ID=@0", item.Id); // db.Execute(sql); // } // } //} private List<DeployEnvironmentConfiguration> GetEnvironmentConfigurationList(string environmentID, EnumDeployStepParentType parentType) { using(var db = _sqlConnectionInfo.GetDB()) { var dbList = db.Query<SqlDeployEnvironmentConfiguration>("WHERE DeployEnvironmentID=@0 AND EnumDeployStepParentTypeID=@1", environmentID, parentType); var list = dbList.Select(i=>i.ToDto()).ToList(); foreach(var item in list) { LoadEnvironmentConfigurationChildren(item); } return list; } }
private void AssertCreatedEnvironmentConfiguration(DeployEnvironmentConfiguration sourceItem, DeployEnvironmentConfiguration createdItem, DeployProject project, DeployEnvironment environment, EnumDeployStepParentType parentType) { Assert.IsNotNull(createdItem); AssertHelpers.AssertCreatedBaseDto(createdItem, this.UserName); Assert.AreEqual(project.Id, createdItem.ProjectId); Assert.AreEqual(sourceItem.ParentId, createdItem.ParentId); Assert.AreEqual(parentType, createdItem.ParentType); Assert.AreEqual(sourceItem.DeployCredentialsId, createdItem.DeployCredentialsId); AssertHelpers.AssertDictionary(sourceItem.ConfigurationValueList, createdItem.ConfigurationValueList); Assert.AreEqual(sourceItem.MachineList.Count, createdItem.MachineList.Count); foreach(var sourceMachine in sourceItem.MachineList) { var createdMachine = createdItem.MachineList.SingleOrDefault(i=>i.MachineName == sourceMachine.MachineName); Assert.IsNotNull(createdMachine); AssertHelpers.AssertCreatedBaseDto(createdMachine, this.UserName); Assert.AreEqual(project.Id, createdMachine.ProjectId); Assert.AreEqual(environment.Id, createdMachine.EnvironmentId); Assert.AreEqual(environment.EnvironmentName, createdMachine.EnvironmentName); Assert.AreEqual(sourceItem.Id, createdMachine.ParentId); AssertHelpers.AssertDictionary(sourceMachine.ConfigurationValueList, createdMachine.ConfigurationValueList); } }
private void SaveEnvironmentConfigurationList(string environmentId, IEnumerable<DeployEnvironmentConfiguration> componentList, EnumDeployStepParentType parentType) { var itemsToInsert = new List<DeployEnvironmentConfiguration>(); var itemsToUpdate = new List<DeployEnvironmentConfiguration>(); var itemsToDelete = new List<DeployEnvironmentConfiguration>(); var existingItemList = this.GetEnvironmentConfigurationList(environmentId, parentType); foreach(var newItem in componentList) { var existingItem = existingItemList.Any(i=>i.Id == newItem.Id); if(existingItem) { itemsToUpdate.Add(newItem); } else { itemsToInsert.Add(newItem); } } foreach(var existingItem in existingItemList) { var newItem = componentList.Any(i=>i.Id == existingItem.Id); if(!newItem) { itemsToDelete.Add(existingItem); } } using(var db = _sqlConnectionInfo.GetDB()) { foreach (var item in itemsToInsert) { if(string.IsNullOrEmpty(item.Id)) { item.Id = Guid.NewGuid().ToString(); } item.SetCreatedFields(_userIdentity.UserName); var dbItem = SqlDeployEnvironmentConfiguration.FromDto(item); db.Insert("DeployEnvironmentConfiguration", "ID", false, dbItem); SaveMachineList(item); } foreach (var item in itemsToUpdate) { item.SetUpdatedFields(_userIdentity.UserName); var dbItem = SqlDeployEnvironmentConfiguration.FromDto(item); db.Update("DeployEnvironmentConfiguration", "ID", dbItem, dbItem.Id); SaveMachineList(item); } foreach (var item in itemsToDelete) { item.SetUpdatedFields(_userIdentity.UserName); var sql = PetaPoco.Sql.Builder //.Append("DELETE FROM DeployMachineConfigurationValue WHERE DeployMachineID IN (SELECT ID FROM DeployMachine WHERE DeployEnvironmentConfigurationID=@0);", item.Id) .Append("DELETE FROM DeployMachine WHERE DeployEnvironmentConfigurationID=@0;", item.Id) //.Append("DELETE FROM DeployEnvironmentConfigurationValue WHERE DeployEnvironmentConfigurationID=@0;", item.Id) .Append("DELETE FROM DeployEnvironmentConfiguration WHERE ID=@0;", item.Id); db.Execute(sql); } } }
public DeployStep MoveDeploymentStepDown(string projectId, EnumDeployStepParentType parentType, string parentId, string deployStepId) { List<DeployStep> stepList; switch (parentType) { case EnumDeployStepParentType.Component: stepList = _projectRepository.GetComponentDeploymentStepList(parentId, projectId); break; case EnumDeployStepParentType.Configuration: stepList = _projectRepository.GetConfigurationDeploymentStepList(parentId, projectId); break; default: throw new UnknownEnumValueException(parentType); } var itemToMove = stepList.FirstOrDefault(i => i.Id == deployStepId); if (itemToMove == null) { throw new ArgumentException("Step not found: " + deployStepId); } stepList = stepList.OrderBy(i => i.OrderNumber).ToList(); if (itemToMove == stepList.Last()) { return itemToMove; } for (int i = 0; i < stepList.Count; i++) { stepList[i].OrderNumber = i; } itemToMove.OrderNumber++; stepList[itemToMove.OrderNumber].OrderNumber--; foreach (var step in stepList) { switch (parentType) { case EnumDeployStepParentType.Component: _projectRepository.UpdateComponentDeploymentStep(step.Id, step.ProjectId, step.ParentId, step.StepName, step.TaskTypeName, step.TaskOptionsJson, step.SharedDeploymentStepId, step.OrderNumber); break; case EnumDeployStepParentType.Configuration: _projectRepository.UpdateConfigurationDeploymentStep(step.Id, step.ProjectId, step.ParentId, step.StepName, step.TaskTypeName, step.TaskOptionsJson, step.OrderNumber); break; default: throw new UnknownEnumValueException(parentType); } } return itemToMove; }