Esempio n. 1
0
        public void TestInheritedDependencies()
        {
            var week = new Week();

            week.AddShift(DayOfWeek.Monday, 9, 30, 0, 0, TimeSpan.FromHours(4));
            week.AddShift(DayOfWeek.Monday, 14, 30, 0, 0, TimeSpan.FromHours(3));

            DateTime end = week.DateAdd(new DateTime(2011, 11, 1, 9, 30, 0), TimeSpan.FromHours(7));

            Console.WriteLine(end);

            var project = new Project("Some project", new DateTime(2011, 11, 1, 9, 30, 0), week);

            project.AddTask(new Task("Phase 1"));
            project.Tasks[0].AddChild(new Task("Task 1", TimeSpan.FromHours(10)));
            project.Tasks[0].AddChild(new Task("Task 2", TimeSpan.FromHours(15)));

            project.AddTask(new Task("Phase 2"));
            project.Tasks[1].AddChild(new Task("Task 1", TimeSpan.FromHours(12)));

            project.Tasks[1].AddDependency(new FinishToStartDependency(project.Tasks[0]));
            project.RecalculateDates();

            Assert.AreNotEqual(project.Tasks[0].StartDate, project.Tasks[1].StartDate);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Week week = new Week();

            week.AddShift(DayOfWeek.Monday, 9, 30, 0, 0, TimeSpan.FromHours(2));
            week.AddShift(DayOfWeek.Monday, 12, 30, 0, 0, TimeSpan.FromHours(2));
            week.AddShift(DayOfWeek.Monday, 15, 30, 0, 0, TimeSpan.FromHours(2));

            week.AddShift(DayOfWeek.Tuesday, 9, 30, 0, 0, TimeSpan.FromHours(2));
            week.AddShift(DayOfWeek.Tuesday, 12, 30, 0, 0, TimeSpan.FromHours(2));
            week.AddShift(DayOfWeek.Tuesday, 15, 30, 0, 0, TimeSpan.FromHours(2));

            week.AddShift(DayOfWeek.Wednesday, 9, 30, 0, 0, TimeSpan.FromHours(2));
            week.AddShift(DayOfWeek.Wednesday, 12, 30, 0, 0, TimeSpan.FromHours(2));
            week.AddShift(DayOfWeek.Wednesday, 15, 30, 0, 0, TimeSpan.FromHours(2));

            week.RemoveShift(DayOfWeek.Tuesday, 12, 30, 0, 0);

            foreach (Shift shift in week.AscendingShifts(new DateTime(2010, 6, 28, 0, 0, 0), new DateTime(2010, 6, 30, 0, 0, 0)))
            {
                System.Diagnostics.Debug.WriteLine(shift.StartTime);
            }

            foreach (Shift shift in week.DescendingShifts(new DateTime(2010, 6, 30, 0, 0, 0), new DateTime(2010, 6, 28, 0, 0, 0)))
            {
                System.Diagnostics.Debug.WriteLine(shift.StartTime);
            }

            System.Diagnostics.Debug.WriteLine("");

            System.Diagnostics.Debug.WriteLine(week.DateAdd(new DateTime(2010, 6, 30, 0, 0, 0), new TimeSpan(29, 2, 3, 0)));

            System.Diagnostics.Debug.WriteLine("");
            System.Diagnostics.Debug.WriteLine(week.DateAdd(new DateTime(2010, 6, 30, 0, 0, 0), new TimeSpan(-29, 2, 0, 0)));

            System.Diagnostics.Debug.WriteLine("");
            System.Diagnostics.Debug.WriteLine(week.DateDiff(new DateTime(2010, 6, 30, 0, 0, 0), new DateTime(2010, 7, 1, 0, 0, 0)));

            System.Diagnostics.Debug.WriteLine("");
            System.Diagnostics.Debug.WriteLine(week.DateDiff(new DateTime(2010, 7, 1, 0, 0, 0), new DateTime(2010, 6, 30, 0, 0, 0)));

            System.Diagnostics.Debug.WriteLine("");
            System.Diagnostics.Debug.WriteLine(week.Duration);
        }
Esempio n. 3
0
File: Task.cs Progetto: ant512/Tasks
        /// <summary>
        /// Recalculates the dates of the task based on the start dates of its
        /// dependencies.  The earliest date that the task will use as its start date
        /// (in the situation where it has no dependencies, for example) is the value
        /// passed as earliestDate.
        /// </summary>
        /// <param name="earliestDate">The earliest date that the task can use as its start
        /// date.</param>
        /// <param name="week">The working week to base calculations on.</param>
        public void RecalculateDates(DateTime earliestDate, Week week)
        {
            var latestDate = earliestDate;

            // Get a list of all dependencies that affect this task.
            // That includes all dependencies that this task has and
            // that its parents have.
            var   allDependencies = new List <IDependency>();
            ITask task            = this;

            while (task != null)
            {
                foreach (var dependency in task.Dependencies)
                {
                    allDependencies.Add(dependency);
                }

                task = task.Parent;
            }

            foreach (var dependency in allDependencies)
            {
                var dependencyDate = dependency.StartDate(week);

                // Only update the date if the dependency starts later than the
                // currently calculated date
                if (dependencyDate > latestDate)
                {
                    latestDate = dependencyDate;
                }
            }

            // Ensure that the start date falls within a working shift
            mStartDate = week.AscendingShifts(latestDate, DateTime.MaxValue).ElementAt(0).StartTime;

            // Work out end date using working week.  We subtract 1 from the duration
            // to ensure that, should the end date be at the end of a working shift,
            // we retrieve the correct shift from the working week later
            mEndDate = week.DateAdd(mStartDate, mDuration.Subtract(new TimeSpan(0, 0, 0, 0, 1)));

            // Ensure that the end date falls within a working shift
            mEndDate = week.AscendingShifts(mEndDate, DateTime.MaxValue).ElementAt(0).StartTime;

            // Add the millisecond back on to the date that we subtracted earlier
            mEndDate = mEndDate.Add(new TimeSpan(0, 0, 0, 0, 1));
        }
Esempio n. 4
0
 /// <summary>
 /// Gets the start date of the dependency, using the supplied working week
 /// definition to identify working vs. non-working times.
 /// </summary>
 /// <param name="week">The working week definition.</param>
 /// <returns>The start date of the dependency.</returns>
 public override DateTime StartDate(Week week)
 {
     return(week.DateAdd(DependentOn.EndDate, Owner.Duration.Negate().Add(Lag)));
 }
Esempio n. 5
0
 /// <summary>
 /// Gets the start date of the dependency, using the supplied working week
 /// definition to identify working vs. non-working times.
 /// </summary>
 /// <param name="week">The working week definition.</param>
 /// <returns>The start date of the dependency.</returns>
 public override DateTime StartDate(Week week)
 {
     return(week.DateAdd(DependentOn.StartDate, Lag));
 }
Esempio n. 6
0
 /// <summary>
 /// Gets the start date of the dependency, using the supplied working week
 /// definition to identify working vs. non-working times.
 /// </summary>
 /// <param name="week">The working week definition.</param>
 /// <returns>The start date of the dependency.</returns>
 public override DateTime StartDate(Week week)
 {
     return(week.DateAdd(mEndDate, Owner.Duration.Negate()));
 }