Esempio n. 1
0
        private void RunTest(TimePeriod tpA, TimePeriod tpB, TimePeriod.Relationship relationship,
                             TimePeriodPart moveWhichPart, string ofWhich, TimeSpan byHowMuch)
        {
            bool CONSOLE_OUTPUT = false;

            tpA.AddRelationship(relationship, tpB);

            DateTime earliest = DateTimeOperations.Min(tpA.StartTime, tpB.StartTime);
            DateTime left     = earliest - new TimeSpan(0, 0, (earliest.Minute % 10), 0, 0);

            int    spaces, width;
            string A, B;

            if (CONSOLE_OUTPUT)
            {
                Debug.WriteLine("           ....*....|....*....|....*....|....*....|....*....|");
                A      = "Initial A : ";
                spaces = (int)((TimeSpan)(tpA.StartTime - left)).TotalMinutes;
                width  = (int)tpA.Duration.TotalMinutes;
                for (int i = 0; i < spaces; i++)
                {
                    A += " ";
                }
                for (int i = 0; i < width; i++)
                {
                    A += "a";
                }
                for (int i = (spaces + width); i < 50; i++)
                {
                    A += " ";
                }
                Debug.WriteLine(A + tpA.ToString());


                B      = "Initial B : ";
                spaces = (int)((TimeSpan)(tpB.StartTime - left)).TotalMinutes;
                width  = (int)tpB.Duration.TotalMinutes;
                for (int i = 0; i < spaces; i++)
                {
                    B += " ";
                }
                for (int i = 0; i < width; i++)
                {
                    B += "b";
                }
                for (int i = (spaces + width); i < 50; i++)
                {
                    B += " ";
                }
                Debug.WriteLine(B + tpB.ToString());

                Debug.WriteLine("We'll move " + ofWhich + "." + moveWhichPart.ToString() + " by " + byHowMuch.ToString() + "...");
            }

            int selector = 0;

            if (ofWhich.Equals("A"))
            {
                selector += 0;
            }
            if (ofWhich.Equals("B"))
            {
                selector += 1;
            }
            selector <<= 1;
            if (moveWhichPart.Equals(TimePeriodPart.StartTime))
            {
                selector += 0;
            }
            if (moveWhichPart.Equals(TimePeriodPart.EndTime))
            {
                selector += 1;
            }


            tpA.AdjustmentMode = TimeAdjustmentMode.FixedDuration;
            tpB.AdjustmentMode = TimeAdjustmentMode.FixedDuration;
            if (CONSOLE_OUTPUT)
            {
                Console.WriteLine("3.");
                foreach (IMilestone ms in new IMilestone[] { tpB.StartMilestone, tpB.EndMilestone })
                {
                    Console.WriteLine(ms.Name);
                    foreach (MilestoneRelationship mr in ms.Relationships)
                    {
                        Console.WriteLine(mr.ToString());
                    }
                }
                Console.WriteLine("4.");
                foreach (IMilestone ms in new IMilestone[] { tpB.StartMilestone, tpB.EndMilestone })
                {
                    Console.WriteLine(ms.Name);
                    foreach (MilestoneRelationship mr in ms.Relationships)
                    {
                        Console.WriteLine(mr.ToString());
                    }
                }
            }

            switch (selector)
            {
            case 0: tpA.AdjustmentMode = TimeAdjustmentMode.InferEndTime;   tpA.StartTime += byHowMuch; break;

            case 1: tpA.AdjustmentMode = TimeAdjustmentMode.InferStartTime; tpA.EndTime += byHowMuch; break;

            case 2: tpB.AdjustmentMode = TimeAdjustmentMode.InferEndTime;   tpB.StartTime += byHowMuch; break;

            case 3: tpB.AdjustmentMode = TimeAdjustmentMode.InferStartTime; tpB.EndTime += byHowMuch; break;
            }

            if (CONSOLE_OUTPUT)
            {
                A      = "Final A   : ";
                spaces = (int)((TimeSpan)(tpA.StartTime - left)).TotalMinutes;
                width  = (int)tpA.Duration.TotalMinutes;
                for (int i = 0; i < spaces; i++)
                {
                    A += " ";
                }
                for (int i = 0; i < width; i++)
                {
                    A += "A";
                }
                for (int i = (spaces + width); i < 50; i++)
                {
                    A += " ";
                }
                Debug.WriteLine(A + tpA.ToString());

                B      = "Final B   : ";
                spaces = (int)((TimeSpan)(tpB.StartTime - left)).TotalMinutes;
                width  = (int)tpB.Duration.TotalMinutes;
                for (int i = 0; i < spaces; i++)
                {
                    B += " ";
                }
                for (int i = 0; i < width; i++)
                {
                    B += "B";
                }
                for (int i = (spaces + width); i < 50; i++)
                {
                    B += " ";
                }
                Debug.WriteLine(B + tpB.ToString());
            }

            foreach (TimePeriod tp in new TimePeriod[] { tpA, tpB })
            {
                foreach (IMilestone ms in new IMilestone[] { tp.StartMilestone, tp.EndMilestone })
                {
                    foreach (MilestoneRelationship mr in ms.Relationships)
                    {
                        bool b = mr.IsSatisfied();
                        Console.WriteLine(mr + (b?" is ":" is not ") + "satisfied.");
                        //Assert.IsTrue(b, mr + " is not satisfied!");
                    }
                }
            }
        }