Exemple #1
0
		public void DoTheThing(TestJobParams message,
		                       CancellationTokenSource cancellationTokenSource,
		                       Action<string> progress)
		{
			// -----------------------------------------------------------
			// Start execution.
			// -----------------------------------------------------------
			var jobProgress = new TestJobProgress
			{
				Text = "Starting job: " + message.Name
			};
			progress(jobProgress.Text);

			jobProgress = new TestJobProgress
			{
				Text = "Will execute for : " + message.Duration.TotalSeconds + " seconds."
			};
			progress(jobProgress.Text);

			Stopwatch stopwatch = new Stopwatch();
			stopwatch.Start();

			int progressCounter = 0;

			var sleep = 5;

			while (stopwatch.Elapsed <= message.Duration)
			{
				progressCounter++;

				if (cancellationTokenSource.IsCancellationRequested)
				{
					cancellationTokenSource.Token.ThrowIfCancellationRequested();
				}
				
				jobProgress = new TestJobProgress
				{
					Text = "Progress loop number :" + progressCounter + ". Will sleep a couple of seconds."
				};
				progress(jobProgress.Text);

				Thread.Sleep(TimeSpan.FromSeconds(sleep));
			}

			// -----------------------------------------------------------
			// Finished execution.
			// -----------------------------------------------------------
			jobProgress = new TestJobProgress
			{
				Text = "Finished job: " + message.Name
			};
			progress(jobProgress.Text);
		}
Exemple #2
0
        public void DoTheThing(FailingJobParams message,
                               CancellationTokenSource cancellationTokenSource,
                               Action <string> progress)
        {
            Logger.DebugWithLineNumber("'Failing Job Code' Do The Thing method called.");

            var jobProgress = new TestJobProgress
            {
                Text         = WhoAmI + ": This job will soon throw exeception.",
                ConsoleColor = ConsoleColor.DarkRed
            };

            progress(jobProgress.Text);

            throw new Exception(message.Error);
        }
Exemple #3
0
		public void DoTheThing(FailingJobParams message,
		                       CancellationTokenSource cancellationTokenSource,
		                       Action<string> progress)
		{
			Logger.DebugWithLineNumber("'Failing Job Code' Do The Thing method called.");

			var jobProgress = new TestJobProgress
			{
				Text = WhoAmI + ": This job will soon throw exeception.",
				ConsoleColor = ConsoleColor.DarkRed
			};

			progress(jobProgress.Text);

			throw new Exception(message.Error);
		}
Exemple #4
0
        public void DoTheThing(TestJobParams message,
                               CancellationTokenSource cancellationTokenSource,
                               Action <string> progress, ref IEnumerable <object> returnObjects)
        {
            // -----------------------------------------------------------
            // Start execution.
            // -----------------------------------------------------------
            var jobProgress = new TestJobProgress
            {
                Text = "Starting job: " + message.Name
            };

            progress(jobProgress.Text);

            jobProgress = new TestJobProgress
            {
                Text = "Will execute for : " + message.Duration + " seconds."
            };
            progress(jobProgress.Text);

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            var progressCounter = 0;

            while (stopwatch.Elapsed <= TimeSpan.FromSeconds(message.Duration))
            {
                progressCounter++;

                if (cancellationTokenSource.IsCancellationRequested)
                {
                    cancellationTokenSource.Token.ThrowIfCancellationRequested();
                }

                jobProgress = new TestJobProgress
                {
                    Text = "Progress loop number :" + progressCounter
                };
                progress(jobProgress.Text);

                Thread.Sleep(TimeSpan.FromSeconds(1));
            }

            // -----------------------------------------------------------
            // Finished execution.
            // -----------------------------------------------------------
            jobProgress = new TestJobProgress
            {
                Text = "Finished job: " + message.Name
            };
            progress(jobProgress.Text);

            var objects = new List <object>();

            objects.Add(new ExitApplication()
            {
                ExitCode = 0
            });
            returnObjects = objects;
        }