Пример #1
0
		public CreateNewJobCommand(int numberOfJobs = 1)
		{
			NumberOfJobs = numberOfJobs;

			HttpSender = new HttpSender();
			ManagerUriBuilder = new ManagerUriBuilder();
		}
Пример #2
0
		public HttpRequestManager()
		{
			HttpSender = new HttpSender();
			MangerUriBuilder = new ManagerUriBuilder();
		}
Пример #3
0
 public HttpRequestManager()
 {
     HttpSender       = new HttpSender();
     MangerUriBuilder = new ManagerUriBuilder();
 }
Пример #4
0
		public void StartDurationTest()
		{
			CancellationTokenSourceDurationTest = new CancellationTokenSource();

			Task.Factory.StartNew(() =>
			{
				while (true)
				{
					var tasksToDispose = _tasks.Where(task => task.IsCompleted);

					foreach (var task in tasksToDispose)
					{
						task.Dispose();

						_tasks.Remove(task);
					}

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

			}, CancellationTokenSourceDurationTest.Token);

			Task.Factory.StartNew(() =>
			{
				var mangerUriBuilder = new ManagerUriBuilder();
				var addToJobQueueUri = mangerUriBuilder.GetAddToJobQueueUri();

				var httpSender = new HttpSender();				
			
				Random random = new Random();

				for (int i = 0; i < NumberOfMessages; i++)
				{

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

					var i1 = i;
					
					var randomTimeSpan = random.Next(MessageDurationFrom, MessageDurationTo);

					_tasks.Add(new Task<HttpResponseMessage>(() =>
						{
							var testJobTimerParams =
							new TestJobParams("Test job name " + i1, 
													TimeSpan.FromSeconds(randomTimeSpan));

						var jobParamsToJson = 
							JsonConvert.SerializeObject(testJobTimerParams);

							var jobQueueItem = new JobQueueItem
							{
							Name = "Job Name " + i1,
								Serialized = jobParamsToJson,
								Type = "NodeTest.JobHandlers.TestJobParams",
								CreatedBy = "WPF Client"
							};

						return httpSender.PostAsync(addToJobQueueUri, 
													jobQueueItem).Result;

					}, CancellationTokenSourceDurationTest.Token));
				}

				var sendJobEveryDurationTimer=
					new SendJobEveryDurationTimer<HttpResponseMessage>(_tasks,
																	   TimeSpan.FromSeconds(5),
																	   ProgressAction);

				CheckManagerDbTimer.Start();
				sendJobEveryDurationTimer.SendTimer.Start();
			});
		}