Ejemplo n.º 1
0
        /// <summary>
        /// Loads the persisted state for this project.
        /// </summary>
        public virtual void LoadPersistedState()
        {
            var configFile = this.GenerateProjectPath("project.state");

            if (this.FileSystem.CheckIfFileExists(configFile))
            {
                logger.Debug("Loading project state for '{0}'", this.Name);
                using (var stream = this.FileSystem.OpenFileForRead(configFile))
                {
                    try
                    {
                        this.PersistedState = XamlServices.Load(stream) as PersistedProjectState;
                    }
                    catch (Exception error)
                    {
                        logger.WarnException("Unable to load project state for '" + this.Name + "'", error);
                    }
                }
            }

            if (this.PersistedState == null)
            {
                logger.Debug("Starting new project state for '{0}'", this.Name);
                this.PersistedState = new PersistedProjectState();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks if an integration can proceed.
        /// </summary>
        private void CheckForIntegration()
        {
            // Get the first trigger that has been tripped
            var request = this.Triggers
                          .Select(t => t.Check())
                          .FirstOrDefault(r => r != null);

            if (request != null)
            {
                logger.Info(
                    "Received integration request from '{0}' for '{1}'",
                    request.SourceTrigger,
                    this.Name);

                // Check if we can integrate
                var context = new IntegrationContext(this);
                this.AskToIntegrate(context);
                // TODO: make the time out configurable
                if (context.Wait(TimeSpan.FromDays(7)))
                {
                    // Make sure there is always a state object
                    if (this.PersistedState == null)
                    {
                        this.PersistedState = new PersistedProjectState();
                    }

                    // Perform the actual integration
                    logger.Info("Starting integration for '{0}'", this.Name);
                    var startTime = this.Clock.Now;
                    var status    = IntegrationStatus.Unknown;
                    try
                    {
                        status = this.Integrate(request);
                    }
                    catch (Exception error)
                    {
                        logger.ErrorException("An unexpected error crashed the integration", error);
                        status = IntegrationStatus.Error;
                    }
                    finally
                    {
                        this.PersistedState.LastIntegration = new IntegrationSummary
                        {
                            StartTime  = startTime,
                            FinishTime = this.Clock.Now,
                            Status     = status
                        };
                        this.SavePersistedState();
                    }
                    logger.Info("Completed integration for '{0}'", this.Name);
                }
                else
                {
                    logger.Info("Cancelling integration for '{0}'", this.Name);
                }
            }
        }