Пример #1
0
        public async Task <IHttpActionResult> Post(string name, string serverName, [FromBody] NewDeployment payload)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(payload?.NetworkPath))
                {
                    return(BadRequest("You must include the field `NetworkPath` in the body."));
                }
                var application = await applicationRepository.GetApplicationAsync(name);

                if (application == null)
                {
                    return(BadRequest("The application " + name + " does not exist."));
                }

                if (!Directory.Exists(payload.NetworkPath))
                {
                    return(BadRequest("The path `" + payload.NetworkPath + "` is invalid or inaccessible."));
                }

                var deployment = new Deployment
                {
                    ApplicationName = name,
                    ServerName      = serverName,
                    NetworkPath     = payload.NetworkPath
                };

                var deploymentAudit = await applicationHashingService.HashDeployment(deployment, application.GetRegularExpressions(), application.HashHiddenFiles, true);

                await deploymentRepository.InsertDeploymentAsync(deployment);

                await auditRepository.CreateAuditAsync(deploymentAudit);

                deployment.FileHashes = null;
                return(Ok(deployment));
            }
            catch (Exception ex)
            {
                Log.Error("Error in deployment controller:", ex);
                return(InternalServerError());
            }
        }