Save() public méthode

public Save ( ) : void
Résultat void
        /// <summary>
        /// Runs post deployment steps.
        /// - Marks the active deployment
        /// - Sets the complete flag
        /// </summary>
        private void FinishDeployment(string id, ITracer tracer, IDisposable deployStep)
        {
            DeploymentStatusFile currentStatus = null;
            ILogger logger = null;

            try
            {
                currentStatus = OpenStatusFile(id);
                logger        = GetLogger(id);

                // Write the active deployment file
                MarkActive(id);

                logger.Log(Resources.Log_DeploymentSuccessful);

                currentStatus.Status             = DeployStatus.Success;
                currentStatus.StatusText         = String.Empty;
                currentStatus.EndTime            = DateTime.Now;
                currentStatus.LastSuccessEndTime = currentStatus.EndTime;
                currentStatus.Save(_fileSystem);
            }
            catch (Exception ex)
            {
                tracer.TraceError(ex);

                MarkFailed(currentStatus);

                logger.LogUnexpetedError();
            }
            finally
            {
                // Set the deployment as complete
                currentStatus.Complete = true;
                currentStatus.Save(_fileSystem);

                ReportStatus(id);

                // End the deployment step
                deployStep.Dispose();
            }
        }
        private void MarkFailed(DeploymentStatusFile currentStatus)
        {
            if (currentStatus == null)
            {
                return;
            }

            currentStatus.Complete   = true;
            currentStatus.Status     = DeployStatus.Failed;
            currentStatus.StatusText = String.Empty;
            currentStatus.EndTime    = DateTime.Now;
            currentStatus.Save(_fileSystem);
        }
Exemple #3
0
        public IDisposable CreateTemporaryDeployment(string statusText)
        {
            var    tracer = _traceFactory.GetTracer();
            string id     = TemporaryDeploymentId;

            using (tracer.Step("Creating temporary deployment"))
            {
                DeploymentStatusFile statusFile = CreateStatusFile(id);
                statusFile.Status     = DeployStatus.Pending;
                statusFile.StatusText = statusText;
                statusFile.Save(_fileSystem);
            }

            // Return a handle that deletes the deployment on dispose.
            return(new DisposableAction(DeleteTemporaryDeployment));
        }
        private ILogger CreateAndPopulateStatusFile(ITracer tracer, string id, string deployer)
        {
            ILogger logger = GetLogger(id);

            using (tracer.Step("Collecting changeset information"))
            {
                // Create the status file and store information about the commit
                DeploymentStatusFile statusFile = CreateStatusFile(id);
                statusFile.Id = id;
                ChangeSet changeSet = _serverRepository.GetChangeSet(id);
                statusFile.Message     = changeSet.Message;
                statusFile.Author      = changeSet.AuthorName;
                statusFile.Deployer    = deployer;
                statusFile.AuthorEmail = changeSet.AuthorEmail;
                statusFile.Save(_fileSystem);

                logger.Log(Resources.Log_NewDeploymentReceived);
            }

            return(logger);
        }
Exemple #5
0
        private void MarkFailed(DeploymentStatusFile currentStatus)
        {
            if (currentStatus == null)
            {
                return;
            }

            currentStatus.Complete = true;
            currentStatus.Status = DeployStatus.Failed;
            currentStatus.StatusText = String.Empty;
            currentStatus.EndTime = DateTime.Now;
            currentStatus.Save(_fileSystem);
        }
        /// <summary>
        /// Builds and deploys a particular changeset. Puts all build artifacts in a deployments/{id}
        /// </summary>
        private void Build(string id, ITracer tracer, IDisposable deployStep)
        {
            if (String.IsNullOrEmpty(id))
            {
                throw new ArgumentException();
            }

            ILogger logger = null;
            DeploymentStatusFile currentStatus = null;
            IDisposable          buildStep     = null;

            try
            {
                logger = GetLogger(id);
                ILogger innerLogger = logger.Log(Resources.Log_PreparingDeployment, TrimId(id));

                currentStatus            = OpenStatusFile(id);
                currentStatus.Complete   = false;
                currentStatus.StartTime  = DateTime.Now;
                currentStatus.Status     = DeployStatus.Building;
                currentStatus.StatusText = String.Format(CultureInfo.CurrentCulture, Resources.Status_BuildingAndDeploying, id);
                currentStatus.Save(_fileSystem);

                ReportStatus(id);

                ISiteBuilder builder = null;

                try
                {
                    builder = _builderFactory.CreateBuilder(tracer, innerLogger);
                }
                catch (Exception ex)
                {
                    _globalLogger.Log(ex);

                    tracer.TraceError(ex);

                    innerLogger.Log(ex);

                    MarkFailed(currentStatus);

                    ReportStatus(id);

                    deployStep.Dispose();

                    return;
                }

                buildStep = tracer.Step("Building");

                var context = new DeploymentContext
                {
                    ManifestWriter   = GetDeploymentManifestWriter(id),
                    PreviousMainfest = GetActiveDeploymentManifestReader(),
                    Tracer           = tracer,
                    Logger           = logger,
                    GlobalLogger     = _globalLogger,
                    OutputPath       = _environment.DeploymentTargetPath,
                };

                builder.Build(context)
                .Then(() =>
                {
                    // End the build step
                    buildStep.Dispose();

                    // Run post deployment steps
                    FinishDeployment(id, tracer, deployStep);
                })
                .Catch(ex =>
                {
                    // End the build step
                    buildStep.Dispose();

                    MarkFailed(currentStatus);

                    ReportStatus(id);

                    // End the deploy step
                    deployStep.Dispose();
                });
            }
            catch (Exception ex)
            {
                tracer.TraceError(ex);

                logger.LogUnexpetedError();

                if (buildStep != null)
                {
                    buildStep.Dispose();
                }

                deployStep.Dispose();
            }
        }
        private void NotifyError(ILogger logger, DeploymentStatusFile trackingFile, Exception exception)
        {
            logger.Log("Deployment failed.", LogEntryType.Error);

            // Failed to deploy
            trackingFile.Percentage = 100;
            trackingFile.Status = DeployStatus.Failed;
            trackingFile.StatusText = String.Empty;
            trackingFile.DeploymentEndTime = DateTime.Now;
            trackingFile.Save(_fileSystem);
        }
        // Temporary dirty code to install node packages. Switch to real NPM when available
        private void DownloadNodePackages(string id, DeploymentStatusFile trackingFile, ILogger logger)
        {
            var p = new nji.Program();
            p.ModulesDir = Path.Combine(_environment.DeploymentTargetPath, "node_modules");
            p.TempDir = Path.Combine(p.ModulesDir, ".tmp");
            p.Logger = logger;
            p.UpdateStatusText = (statusText) => {
                trackingFile.StatusText = statusText;
                trackingFile.Save(_fileSystem);
                NotifyStatus(id);
            };

            p.InstallDependencies(_environment.DeploymentTargetPath);
        }
Exemple #9
0
        public void Deploy(string id, string deployer, bool clean)
        {
            ITracer     tracer     = _traceFactory.GetTracer();
            IDisposable deployStep = null;

            try
            {
                deployStep = tracer.Step("DeploymentManager.Deploy(id)");

                // Check to see if we have a deployment with this id already
                string trackingFilePath = GetStatusFilePath(id, ensureDirectory: false);

                if (!_fileSystem.File.Exists(trackingFilePath))
                {
                    // If we don't then throw
                    throw new FileNotFoundException(String.Format(CultureInfo.CurrentCulture, Resources.Error_DeployNotFound, id));
                }

                // Remove the old log file for this deployment id
                string logPath = GetLogPath(id);
                FileSystemHelpers.DeleteFileSafe(logPath);

                ILogger logger = GetLogger(id);

                using (tracer.Step("Updating to specific changeset"))
                {
                    // Update to the the specific changeset
                    _serverRepository.Update(id);
                }

                if (clean)
                {
                    tracer.Trace("Cleaning git repository");

                    logger.Log(Resources.Log_CleaningGitRepository);

                    _serverRepository.Clean();
                }

                if (!String.IsNullOrEmpty(deployer))
                {
                    // Update the deployer
                    DeploymentStatusFile statusFile = OpenStatusFile(id);
                    statusFile.Deployer = deployer;
                    statusFile.Save(_fileSystem);
                }

                // Perform the build deployment of this changeset
                Build(id, tracer, deployStep);
            }
            catch (Exception ex)
            {
                tracer.TraceError(ex);

                if (deployStep != null)
                {
                    deployStep.Dispose();
                }

                throw;
            }
        }
        private void NotifyError(ILogger logger, DeploymentStatusFile trackingFile, Exception exception)
        {
            logger.Log("Deployment failed.", LogEntryType.Error);

            if (trackingFile != null)
            {
                // Failed to deploy
                trackingFile.Percentage = 100;
                trackingFile.Complete = true;
                trackingFile.Status = DeployStatus.Failed;
                trackingFile.StatusText = trackingFile.Status == DeployStatus.Failed ? logger.GetTopLevelError() : String.Empty;
                trackingFile.DeploymentEndTime = DateTime.Now;
                trackingFile.Save(_fileSystem);
            }
        }