Example #1
0
        public IActionResult Create(DeploymentCreateViewModel deployment)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var newDeployment = _handler.CreateDeployment(deployment, User);

            return(CreateRedirect(newDeployment));
        }
Example #2
0
        private void CheckCreateConflicts(DeploymentCreateViewModel deployment)
        {
            bool conflictAlreadyLinkedGitAndFtp = _unitOfWork.Deployments.Any(x =>
                                                                              x.GitUrl == deployment.GitUrl &&
                                                                              x.GitBranch == deployment.GitBranch &&
                                                                              x.FtpHostname == deployment.FtpHostname &&
                                                                              x.FtpRootDirectory == deployment.FtpRootDirectory);

            if (conflictAlreadyLinkedGitAndFtp)
            {
                throw new Exception("Git and FTP host already linked.");
            }
        }
Example #3
0
        public Deployment CreateDeployment(DeploymentCreateViewModel deployment, ClaimsPrincipal user)
        {
            var userId = _userManager.GetUserAsync(user).Result;

            CheckCreateConflicts(deployment);

            var newDeployment = new Deployment()
            {
                User             = userId,
                FtpHostname      = deployment.FtpHostname,
                FtpPassword      = deployment.FtpPassword,
                FtpPort          = deployment.FtpPort,
                FtpUsername      = deployment.FtpUsername,
                GitBranch        = deployment.GitBranch,
                GitUrl           = deployment.GitUrl,
                FtpRootDirectory = deployment.FtpRootDirectory,
                State            = DeploymentState.WaitingForPingEvent
            };

            _unitOfWork.Deployments.Add(newDeployment);

            newDeployment.Logs.Add(new DeploymentLog()
            {
                Description   = "Created",
                Status        = ResultStatus.Successful,
                DateTime      = DateTime.Now,
                EventType     = "create",
                ResultMessage = string.Empty,
            });

            _unitOfWork.Complete();

            _communicator.Bus.Publish(new IntegrationCreateEvent()
            {
                FtpHostname      = newDeployment.FtpHostname,
                FtpPassword      = newDeployment.FtpPassword,
                FtpPort          = newDeployment.FtpPort,
                FtpUsername      = newDeployment.FtpUsername,
                GitBranch        = newDeployment.GitBranch,
                GitUrl           = newDeployment.GitUrl,
                FtpRootDirectory = newDeployment.FtpRootDirectory,
                IntegrationGuid  = newDeployment.Guid
            });

            return(newDeployment);
        }