public object Get(DeployState request)
		{
			if(request == null || string.IsNullOrWhiteSpace(request.Id))
			{
				throw new ArgumentNullException();
			}
			return _deployStateManager.GetDeployState(request.Id);
		}
 public void Notify(DeployState state)
 {
     if (this.DeployStateNotificationReceived != null)
     {
         var args = new EventArgs<DeployState>(state);
         this.DeployStateNotificationReceived(this, args);
     }
 }
 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;
 }
 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 DeployState ImportDeployState(DeployState newDeployState)
 {
     var existingDeployState = this.TryGetDeployState(newDeployState.ProjectId, newDeployState.Build.Id, newDeployState.Environment.Id, newDeployState.MachineList.First().Id, newDeployState.DeployBatchRequestItemId);
     if (existingDeployState == null)
     {
         var existingIdItem = _documentSession.Load<DeployState>(newDeployState.Id);
         if(existingIdItem != null)
         {
             newDeployState.Id = Guid.NewGuid().ToString();
         }
         foreach (var newMessage in newDeployState.MessageList)
         {
             if (string.IsNullOrEmpty(newMessage.Id))
             {
                 newMessage.Id = Guid.NewGuid().ToString();
             }
         }
         return _documentSession.StoreSaveEvict(newDeployState);
     }
     else 
     {
         existingDeployState = _documentSession.LoadEnsure<DeployState>(existingDeployState.Id); //Get a change-tracking enabled version
         foreach(var newMessage in newDeployState.MessageList)
         {
             if(string.IsNullOrEmpty(newMessage.Id))
             {
                 newMessage.Id = Guid.NewGuid().ToString();
             }
             if(!existingDeployState.MessageList.Any(i=>i.Id == newMessage.Id))
             {
                 var messageCopy = AutoMapper.Mapper.Map(newMessage, new DeployStateMessage());
                 existingDeployState.MessageList.Add(messageCopy);
             }
         }
         existingDeployState.UpdatedByUserName = newDeployState.UpdatedByUserName;
         existingDeployState.UpdatedDateTimeUtc = newDeployState.UpdatedDateTimeUtc;
         if(!string.IsNullOrEmpty(newDeployState.ErrorDetails))
         {
             existingDeployState.ErrorDetails = newDeployState.ErrorDetails;
         }
         existingDeployState.Status = newDeployState.Status;
         return _documentSession.SaveEvict(existingDeployState);
     }
 }
        public void SaveDeployState(DeployState deployState)
        {
            string json = deployState.ToJson();

            string deployStateDirectory = Path.Combine(_workingDirectory, "states");
            if(!Directory.Exists(deployStateDirectory))
            {
                Directory.CreateDirectory(deployStateDirectory);
            }
            string filePath = Path.Combine(deployStateDirectory, deployState.Id + ".json");
            File.WriteAllText(filePath, json);
        }
 public DeployState ImportDeployState(DeployState newDeployState)
 {
     throw new NotSupportedException();
 }
 public void Update(DeployState state)
 {
     this.DeployState = state;
     this.SetStatus(state.Status);
 }
 public DeployState ImportDeployState(DeployState newDeployState)
 {
     var existingItem = this.TryGetDeployState(newDeployState.ProjectId, newDeployState.Build.Id, newDeployState.Environment.Id, newDeployState.MachineList.First().Id, newDeployState.DeployBatchRequestItemId);
     if(existingItem == null)
     {
         if(!string.IsNullOrEmpty(newDeployState.Id) && DeployStateExists(newDeployState.Id))
         {
             newDeployState.Id = Guid.NewGuid().ToString();
         }
         var id = SaveDeployState(newDeployState);
         return GetDeployState(id);
     }
     else 
     {
         existingItem.ErrorDetails = newDeployState.ErrorDetails;
         existingItem.UpdatedByUserName = newDeployState.UpdatedByUserName;
         existingItem.UpdatedDateTimeUtc = newDeployState.UpdatedDateTimeUtc;
         existingItem.Status = newDeployState.Status;
         if(newDeployState.MessageList != null)
         {
             if(existingItem.MessageList == null)
             {
                 existingItem.MessageList = new List<DeployStateMessage>();
             }
             foreach(var message in newDeployState.MessageList)
             {
                 if(string.IsNullOrEmpty(message.Id) || !existingItem.MessageList.Any(i=>i.Id == message.Id))
                 {
                     existingItem.MessageList.Add(message);
                 }
             }
         }
         var id = SaveDeployState(existingItem);
         return GetDeployState(id);
     }
 }
 private string SaveDeployState(DeployState state)
 {
     if (state.Build == null)
     {
         throw new ArgumentNullException("Missing build");
     }
     if (state.Branch == null)
     {
         throw new ArgumentNullException("Missing branch");
     }
     if (state.Component == null)
     {
         throw new ArgumentNullException("Missing component");
     }
     if (state.Environment == null)
     {
         throw new ArgumentNullException("Missing environment");
     }
     if (state.MachineList == null)
     {
         throw new ArgumentNullException("Missing machineList");
     }
     if (state.DeployBatchRequestItemId == null)
     {
         throw new ArgumentNullException("Missing deployBatchRequestItemId");
     }
     var sqlDeployState = new SqlDeployState
     {
         ID = state.Id,
         ProjectID = state.ProjectId,
         BranchID = state.Branch.Id,
         BranchJson = state.Branch.ToJson(),
         BuildID = state.Build.Id,
         BuildJson = state.Build.ToJson(),
         ComponentID = state.Component.Id,
         ComponentJson = state.Component.ToJson(),
         EnvironmentID = state.Environment.Id,
         EnvironmentName = state.Environment.EnvironmentName,
         EnvironmentJson = state.Environment.ToJson(),
         DeployBatchRequestItemID = state.DeployBatchRequestItemId,
         DeploymentCompleteDateTimeUtc = state.DeploymentCompleteDateTimeUtc,
         DeploymentStartedDateTimeUtc = state.DeploymentStartedDateTimeUtc,
         ErrorDetails = state.ErrorDetails,
         SortableVersion = state.Build.SortableVersion,
         EnumDeployStatusID = (int)state.Status,
         CreatedByUserName = state.CreatedByUserName,
         CreatedDateTimeUtc = state.CreatedDateTimeUtc,
         UpdatedByUserName = state.UpdatedByUserName,
         UpdatedDateTimeUtc = state.UpdatedDateTimeUtc,
         SubmittedDateTimeUtc = state.SubmittedDateTimeUtc
     };
     if(state.MessageList != null)
     {
         foreach(var message in state.MessageList)
         {
             if(string.IsNullOrEmpty(message.Id))
             {
                 message.Id = Guid.NewGuid().ToString();
             }
         }
         sqlDeployState.MessageListJson = state.MessageList.ToJson();
     }
     var sqlMachineList = new List<SqlDeployStateMachine>();
     foreach (var machine in state.MachineList)
     {
         var sqlMachine = new SqlDeployStateMachine
         {
             ID = machine.Id,
             DeployStateID = sqlDeployState.ID,
             MachineID = machine.Id,
             MachineName = machine.MachineName,
             MachineJson = machine.ToJson(),
             CreatedByUserName = _userIdentity.UserName,
             CreatedDateTimeUtc = DateTime.UtcNow,
             UpdatedByUserName = _userIdentity.UserName,
             UpdatedDateTimeUtc = DateTime.UtcNow
         };
         sqlMachineList.Add(sqlMachine);
     }
     using (var db = _sqlConnectionInfo.GetDB())
     {
         if (string.IsNullOrEmpty(sqlDeployState.ID) || !DeployStateExists(sqlDeployState.ID))
         {
             if (string.IsNullOrEmpty(sqlDeployState.ID))
             {
                 sqlDeployState.ID = Guid.NewGuid().ToString();
             }
             db.Insert("DeployState", "ID", false, sqlDeployState);
             foreach (var machine in sqlMachineList)
             {
                 machine.ID = Guid.NewGuid().ToString();
                 machine.DeployStateID = sqlDeployState.ID;
                 db.Insert("DeployStateMachine", "ID", false, machine);
             }
         }
         else 
         {
             db.Update("DeployState", "ID", sqlDeployState);
         }
     }
     return sqlDeployState.ID;
 }
 private DeployState PopulateDeployState(SqlDeployState item, bool loadChildren)
 {
     var returnValue = new DeployState();
     PopulateDeployState(item, loadChildren, returnValue);
     return returnValue;
 }
 public ViewDeployStateForm(DeployBatchRequestItem deployBatchRequestItem, DeployState deployState)
 {
     _deployBatchRequestItem = deployBatchRequestItem;
     _deployState = deployState;
     InitializeComponent();
 }