Exemple #1
0
        public void TestNestedMethods()
        {
            currentProgress = -1f;
            using (Progress.BeginWeightedTask(new[] { 10f, 20f, 550f }).SetCallback(AssertProgressIsGrowing))
            {
                Progress.NextStep();
                AssertCurrentProgress(0f);

                Iterate10();

                AssertCurrentProgress(100f * (10f / 580f));
                Progress.NextStep();
                AssertCurrentProgress(100f * (10f / 580f));

                Iterate20();

                AssertCurrentProgress(100f * (30f / 580f));
                Progress.NextStep();
                AssertCurrentProgress(100f * (30f / 580f));

                Iterate550();

                AssertCurrentProgress(100f);
                Progress.EndTask();
            }
            AssertCurrentProgress(100f);
        }
Exemple #2
0
        public void TestNested()
        {
            currentProgress = -1f;
            // Begin main task with 4 sections, each one taking longer:
            using (Progress.BeginWeightedTask(new[] { 10f, 20f, 30f, 40f }).SetCallback(AssertProgressIsGrowing))
            {
                Progress.NextStep(); // Advance the main task
                // Normal for-loop:
                Progress.BeginFixedTask(10);
                for (int i = 0; i < 10; i++)
                {
                    Progress.NextStep();
                    AssertCurrentProgress((0.0f) + i);
                }
                Progress.EndTask();

                Progress.NextStep(); // Advance the main task
                // "Iterate" an array of 20 items:
                var twenty = new[] { 1f, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
                foreach (var i in twenty.WithProgress())
                {
                    AssertCurrentProgress((10f) + (i - 1f));
                }

                Progress.NextStep(); // Advance the main task
                // "Iterate" a weighted array of 30 items:
                var thirty = new[] { 1f, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
                foreach (var i in thirty.WithProgress(thirty))
                {
                    // Calculate the step progress:
                    var x = i - 1f;
                    x = 30f * x * (x + 1f) / 930f;
                    AssertCurrentProgress((10f + 20f) + x);
                }

                Progress.NextStep(); // Advance the main task
                // Normal for-loop, with a "using" block instead of EndTask.
                using (Progress.BeginFixedTask(40))
                {
                    for (int i = 0; i < 40; i++)
                    {
                        Progress.NextStep();
                        AssertCurrentProgress(60f + i);
                    }
                    Progress.EndTask();
                }
                AssertCurrentProgress(100f);
                Progress.EndTask();
            }
            AssertCurrentProgress(100f);
        }
Exemple #3
0
        public void TestUnknownTimer()
        {
            currentProgress = -1f;
            using (Progress.BeginWeightedTask(10f, 80f, 10f).SetCallback(AssertProgressIsGrowing))
            {
                Progress.SetTaskKey("Stall 1 second").NextStep();
                Progress.BeginFixedTask(10);
                for (int i = 0; i < 10; i++)
                {
                    Progress.NextStep();
                    System.Threading.Thread.Sleep(100);
                }
                Progress.EndTask();


                // Start a task that takes unknown time:
                Progress.SetTaskKey("Unknown for 8+ seconds").NextStep();
                using (Progress.BeginUnknownTask(8, .90f))
                {
                    System.Threading.Thread.Sleep(8000);
                    System.Threading.Thread.Sleep(3000); // Take some extra time!
                    Progress.EndTask();
                }


                Progress.SetTaskKey("Stall another second").NextStep();
                using (Progress.BeginFixedTask(10))
                {
                    for (int i = 0; i < 10; i++)
                    {
                        Progress.NextStep();
                        System.Threading.Thread.Sleep(100);
                    }
                    Progress.EndTask();
                }
                Progress.EndTask();
            }
        }