(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / nant / src / Tasks / SleepTask.cs
blobd6c69cc90b1181fa7d1b9897e77b38de3320b936
1 // NAnt - A .NET build tool
2 // Copyright (C) 2001 Gerry Shaw
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // Ian MacLean (ian_maclean@another.com)
20 namespace SourceForge.NAnt {
22 using System;
23 using System.Xml;
24 using System.Threading;
26 /// <summary>
27 /// A task for sleeping a short period of time, useful when a build or deployment process
28 /// requires an interval between tasks.
29 /// </summary>
31 [TaskName("sleep")]
32 public class SleepTask : Task {
34 /// <summary>hours to to add to the sleep time</summary>
35 [TaskAttribute("hours")]
36 string _hours = null;
38 /// <summary>minutes to add to the sleep time</summary>
39 [TaskAttribute("minutes")]
40 string _minutes = 0.ToString();
42 /// <summary>seconds to add to the sleep time</summary>
43 [TaskAttribute("seconds")]
44 string _seconds = 0.ToString();
46 /// <summary>milliseconds to add to the sleep time</summary>
47 [TaskAttribute("milliseconds")]
48 string _milliseconds = 0.ToString();
50 /// <summary>flag controlling whether to break the build on an error</summary>
51 [TaskAttribute("failonerror")]
52 [BooleanValidator()]
53 string _failonerror = Boolean.FalseString;
55 // Attribute properties
56 public int Hours { get { return Convert.ToInt32(_hours); } }
57 public int Minutes { get { return Convert.ToInt32(_minutes); } }
58 public int Seconds { get { return Convert.ToInt32(_seconds); } }
59 public int Milliseconds { get { return Convert.ToInt32(_milliseconds); } }
60 public bool FailOnError { get { return Convert.ToBoolean(_failonerror); } }
62 ///return time to sleep
63 private int GetSleepTime() {
64 return ((((int) Hours * 60) + Minutes) * 60 + Seconds) * 1000 + Milliseconds;
67 ///<summary> return time to sleep </summary>
68 ///<param name="millis"> </param>
69 private void DoSleep(int millis ) {
70 Thread.Sleep(millis);
73 /// <summary>
74 /// verify parameters
75 ///</summary>
76 ///<param name="taskNode"> taskNode used to define this task instance </param>
77 protected override void InitializeTask(XmlNode taskNode) {
78 if (GetSleepTime() < 0) {
79 throw new BuildException("Negative sleep periods are not supported", Location);
83 protected override void ExecuteTask() {
84 int sleepTime = GetSleepTime();
85 Log.WriteLine(LogPrefix + "sleeping for {0} milliseconds", sleepTime);
86 DoSleep(sleepTime);