IntervalTrigger.cs :  » Build-Systems » CruiseControl.NET » ThoughtWorks » CruiseControl » Core » Triggers » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Build Systems » CruiseControl.NET 
CruiseControl.NET » ThoughtWorks » CruiseControl » Core » Triggers » IntervalTrigger.cs
namespace ThoughtWorks.CruiseControl.Core.Triggers{
    using System;
    using Exortech.NetReflector;
    using ThoughtWorks.CruiseControl.Core.Util;
    using ThoughtWorks.CruiseControl.Remote;

    /// <summary>
    /// <para>
    /// The Interval Trigger is used to specify that an integration should be run periodically, after a certain amount of time. By default, an integration
    /// will only be triggered if modifications have been detected since the last integration. The trigger can also be configured to force a build even if
    /// no changes have occurred to source control. The items to watch for modifications are specified with <link>Source Control Blocks</link>.
    /// </para>
    /// <para type="info">
    /// Like all triggers, the intervalTrigger must be enclosed within a triggers element in the appropriate <link>Project Configuration Block</link>.
    /// </para>
    /// </summary>
    /// <title>Interval Trigger</title>
    /// <version>1.0</version>
    /// <remarks>
    /// <para type="warning">
    /// This trigger replaces the <b>PollingIntervalTrigger</b> and the <b>ForceBuildIntervalTrigger</b>.
    /// </para>
    /// </remarks>
    /// <example>
    /// <code title="Minimalist example">
    /// &lt;intervalTrigger /&gt;
    /// </code>
    /// <code title="Full example">
    /// &lt;intervalTrigger name="continuous" seconds="30" buildCondition="ForceBuild" initialSeconds="30" /&gt;
    /// </code>
    /// </example>
    [ReflectorType("intervalTrigger")]
  public class IntervalTrigger : ITrigger
  {
    public const double DefaultIntervalSeconds = 60;
    private readonly DateTimeProvider dateTimeProvider;
    private string name;
    private double intervalSeconds = DefaultIntervalSeconds;
        private double initialIntervalSeconds = -1;         // -1 indicates unset
      private bool isInitialInterval = true;

        private DateTime nextBuildTime;

        /// <summary>
        /// Initializes a new instance of the <see cref="IntervalTrigger"/> class.
        /// </summary>
    public IntervalTrigger() : this(new DateTimeProvider()) { }

        /// <summary>
        /// Initializes a new instance of the <see cref="IntervalTrigger"/> class.
        /// </summary>
        /// <param name="dtProvider">The dt provider.</param>
    public IntervalTrigger(DateTimeProvider dtProvider)
    {
      this.dateTimeProvider = dtProvider;
            IncrementNextBuildTime();
    }

        /// <summary>
        /// The name of the trigger. This name is passed to external tools as a means to identify the trigger that requested the build.
        /// </summary>
        /// <version>1.1</version>
        /// <default>IntervalTrigger</default>
    [ReflectorProperty("name", Required=false)]
    public virtual string Name
    {
      get
      {
        if (name == null) name = GetType().Name;
        return name;
      }
      set { name = value; }
    }

        /// <summary>
        /// The number of seconds after an integration cycle completes before triggering the next integration cycle.
        /// </summary>
        /// <version>1.0</version>
        /// <default>60</default>
        [ReflectorProperty("seconds", Required=false)]
        public double IntervalSeconds
        {
            get { return intervalSeconds; }
            set
            {
                intervalSeconds = value;
                IncrementNextBuildTime();
            }
        }

        /// <summary>
        /// The delay (in seconds) from CCNet startup to the first check for modifications.
        /// </summary>
        /// <version>1.4</version>
        /// <default>Defaults to the IntervalSettings value.</default>
    [ReflectorProperty("initialSeconds", Required = false)]
    public double InitialIntervalSeconds
    {
      get
      {
                if (initialIntervalSeconds == -1) 
                    return IntervalSeconds;     // If no setting for this, use IntervalSeconds instead.
                else
                    return initialIntervalSeconds;
      }
      set
      {
        initialIntervalSeconds = value;
        IncrementNextBuildTime();
      }
    }                    
    
        /// <summary>
        /// The condition that should be used to launch the integration. By default, this value is <b>IfModificationExists</b>, meaning that an integration will
        /// only be triggered if modifications have been detected. Set this attribute to <b>ForceBuild</b> in order to ensure that a build should be launched 
        /// regardless of whether new modifications are detected. 
        /// </summary>
        /// <version>1.0</version>
        /// <default>IfModificationExists</default>
    [ReflectorProperty("buildCondition", Required=false)]
    public BuildCondition BuildCondition = BuildCondition.IfModificationExists;

    public virtual void IntegrationCompleted()
    {
            isInitialInterval = false;

      IncrementNextBuildTime();
    }

    protected DateTime IncrementNextBuildTime()
    {
        double delaySeconds;
            if (isInitialInterval)
        delaySeconds = InitialIntervalSeconds;
            else
                delaySeconds = IntervalSeconds;

            return nextBuildTime = dateTimeProvider.Now.AddSeconds(delaySeconds);
    }

    public DateTime NextBuild
    {
      get {  return nextBuildTime;}
    }

    public virtual IntegrationRequest Fire()
    {
      BuildCondition buildCondition = ShouldRunIntegration();
      if (buildCondition == BuildCondition.NoBuild) return null;
      return new IntegrationRequest(buildCondition, Name, null);
    }

    private BuildCondition ShouldRunIntegration()
    {
      if (dateTimeProvider.Now < nextBuildTime)
        return BuildCondition.NoBuild;

      return BuildCondition;
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.