Пример #1
0
		protected void ClearTaskQueueContext()
		{
			using (var dc = new TaskQueueContext())
			{
				foreach (var item in dc.TaskParams) dc.TaskParams.Remove(item);
				foreach (var item in dc.Tasks) dc.Tasks.Remove(item);

				dc.SaveChanges();
			}
		}
Пример #2
0
		static void Main(string[] args)
		{
			DbConfigManager.SetParameters(args);
			//	Generate IMigrationMetadata.Target 
			using (var db = new DVSContext())
			{
				var st = ModelHelper.GenerateModel(db);
			}

			try
			{
				Stopwatch sw = new Stopwatch();
				sw.Start();
				Console.WriteLine("Start DVS.Database project.");

				foreach (var usedContext in DbConfigManager.UsedContexts)
				{
					DbContext dataContext;
					if (usedContext.Key == "DVSContext")
						dataContext = new DVSContext();
					else if (usedContext.Key == "TaskQueueContext")
						dataContext = new TaskQueueContext();
					else if (usedContext.Key == "LoggerContext")
						dataContext = new LoggerContext();
					else
						throw new NotSupportedException(usedContext.Key);

					if (!DbConfigManager.IsGenerateScriptOnly)
					{
						DatabaseHelper.CreatedDatabase(dataContext, usedContext.Value);

						dataContext.Database.CompatibleWithModel(true);
					}
					else
					{
						string sqlUpdate = DatabaseHelper.GenetateSqlUpdate(dataContext, usedContext.Value);
						string sqlRollback = DatabaseHelper.GenetateSqlRollback(dataContext, usedContext.Value);

						File.WriteAllText(usedContext.Key + "Update_" + usedContext.Key + ".sql", sqlUpdate + Environment.NewLine + "GO");
						//		File.WriteAllText(usedContext.Key + "Rollback_" + usedContext.Key + ".sql", sqlRollback + Environment.NewLine + "GO");
					}
				}

				sw.Stop();
				Console.WriteLine(String.Format("End at {0} s", sw.ElapsedMilliseconds / 1000));
			}
			catch (Exception ex)
			{
				Console.WriteLine(String.Format("Error [{0}], [{1}]", ex.Message, ex.ToString()));
			}
		}
Пример #3
0
		public void TaskSchedulerManager_MaxPoolingTask()
		{
			int lastId = 20;
			int countOfTasks = 20;
			for (int i = 1; i <= countOfTasks; i++)
			{
				var task = new Task();
				task.CreateDate = DateTime.Now;
				task.TaskTypeEnum = TaskTypeEnum.AscGov;
				if (i != countOfTasks)
					task.TaskStatus = TaskStatus.Error;
				else
					task.TaskStatus = TaskStatus.Pending;
				if (i != 1)
					task.ParentTaskId = lastId;
				_repository.Add(task);
				lastId = task.Id;
			}

			_taskQueueManager.ProcessQueue();

			Thread.Sleep(3000);

			int tTaskNotificationId;
			using (var dc = new TaskQueueContext())
			{
				var tTask = dc.Tasks.Single(e => e.Id == lastId);
				tTask.Should().NotBeNull();
				tTask.TaskStatusId.Should().Be((int)TaskStatus.Error);
				tTask.ErrorMessage.Should().Be("Max pooling task");

				string sendDataUpdateServiceFailureNotification = NotificationType.DataUpdateServiceFailure.ToString();
				var tTaskNotification = dc.Tasks.Single(e => e.TaskTypeId == (int)TaskTypeEnum.Notifications && e.TaskParams.Any(p => p.Value == sendDataUpdateServiceFailureNotification));
				tTaskNotification.Should().NotBeNull();
				tTaskNotification.TaskStatusId.Should().Be((int)TaskStatus.Pending);
				tTaskNotificationId = tTaskNotification.Id;
			}

			Thread.Sleep(1000);

			_taskQueueManager.ProcessQueue();

			Thread.Sleep(30000);

			using (var dc = new TaskQueueContext())
			{
				var tTaskNotification = dc.Tasks.Find(tTaskNotificationId);
				tTaskNotification.TaskStatusId.Should().Be((int)TaskStatus.Completed);
			}
		}
Пример #4
0
		public void TaskQueueRepositoryTest_Add()
		{
			var task = new Task();
			task.CreateDate = DateTime.Now;
			task.TaskTypeEnum = TaskTypeEnum.Notifications;
			task.TaskStatus = TaskStatus.Pending;
			_repository.Add(task);

			using (var dc = new TaskQueueContext())
			{
				var tTask = dc.Tasks.Single(e => e.TaskTypeId == (int)TaskTypeEnum.Notifications);
				tTask.Should().NotBeNull();
				tTask.TaskStatusId.Should().Be((int)TaskStatus.Pending);
			}
		}
Пример #5
0
		public void TaskQueueRepositoryTest_KillBuzzTask()
		{
			var task = new Task();
			task.CreateDate = DateTime.Now.AddMinutes(-22);
			task.StartDate = DateTime.Now.AddMinutes(-21);
			task.TaskTypeEnum = TaskTypeEnum.AscGov;
			task.TaskStatus = TaskStatus.Executing;
			_repository.Add(task);

			var tasks = _repository.GetTasksToRun();
			tasks.Should().NotBeNull();
			tasks.Should().HaveCount(0);

			using (var dc = new TaskQueueContext())
			{
				var tTask = dc.Tasks.Single(e => e.TaskTypeId == (int)TaskTypeEnum.AscGov);
				tTask.Should().NotBeNull();
				tTask.TaskStatusId.Should().Be((int)TaskStatus.Error);
			}
		}
Пример #6
0
		public void TaskQueueRepositoryTest_GetTasksToRun()
		{
			var task = new Task();
			task.CreateDate = DateTime.Now;
			task.TaskTypeEnum = TaskTypeEnum.AscGov;
			task.TaskStatus = TaskStatus.Pending;
			_repository.Add(task);

			var tasks = _repository.GetTasksToRun();
			tasks.Should().NotBeNull();
			tasks.Should().HaveCount(1);
			tasks.First().TaskType.Should().NotBeNull();
			tasks.First().TaskType.Name.Should().Be(TaskTypeEnum.AscGov.ToString());
			tasks.First().TaskType.MaxPoolingTask.Should().Be(5);


			using (var dc = new TaskQueueContext())
			{
				var tTask = dc.Tasks.Single(e => e.TaskTypeId == (int)TaskTypeEnum.AscGov);
				tTask.Should().NotBeNull();
				tTask.TaskStatusId.Should().Be((int)TaskStatus.Executing);
			}
		}
Пример #7
0
		public void TaskSchedulerManager_Task_AssignmentAppraisersForOrder_Duplicates()
		{
			var testOrder = OrderServiceTest.CreateTestOrder();
			var duplicateOrder = OrderServiceTest.CreateTestOrder();

			using (var db = new DVSContext())
			{
				db.Orders.Attach(testOrder);
				db.Orders.Attach(duplicateOrder);

				testOrder.AppraisalInfo.DuplicateOrderId = duplicateOrder.Id;
				duplicateOrder.AcceptedAppraiserUserId = TestConstants.TestAppraiserUser;

				var appraiserUser = db.AppraiserUsers.Find(TestConstants.TestAppraiserUser);
				appraiserUser.ServiceArea = new AppraiserServiceArea();
				appraiserUser.ServiceArea.Longitude = 1;
				appraiserUser.ServiceArea.Latitude = 1;
				appraiserUser.ServiceArea.ServiceAreaRadiusId = 1;

				db.SaveChanges();
			}

			var taskParams = new List<TaskParam>();
			taskParams.Add(new TaskParam(TaskParamsKey.OrderId, testOrder.Id.ToString()));
			int taskId = TestTaskLifeCycleInternal(TaskTypeEnum.AssignmentAppraisersForOrder, taskParams);

			using (var dc = new TaskQueueContext())
			{
				var duplicateOrderTask = dc.Tasks.Single(e => e.ParentTaskId == taskId);
				duplicateOrderTask.Should().NotBeNull();
				duplicateOrderTask.MinStartDate.Should().HaveValue();
			}
		}
Пример #8
0
		private int TestTaskLifeCycleInternal(TaskTypeEnum taskType, ICollection<TaskParam> taskParams = null)
		{
			var task = new Task();
			task.CreateDate = DateTime.Now;
			task.TaskTypeEnum = taskType;
			task.TaskStatus = TaskStatus.Pending;
			task.TaskParams = taskParams;

			_repository.Add(task);

			_taskQueueManager.ProcessQueue();

			using (var dc = new TaskQueueContext())
			{
				var tTask = dc.Tasks.Single(e => e.TaskTypeId == (int)taskType);
				tTask.Should().NotBeNull();
				tTask.TaskStatusId.Should().Be((int)TaskStatus.Executing);
			}

			int maxIterationsCount = 30;
			while (maxIterationsCount-- != 0)
			{
				using (var dc = new TaskQueueContext())
				{
					var tTask = dc.Tasks.Single(t => t.Id == task.Id);
					if (tTask.TaskStatus != TaskStatus.Executing)
						break;

					Thread.Sleep(1000);
				}
			}

			using (var dc = new TaskQueueContext())
			{
				var tTask = dc.Tasks.Single(t => t.Id == task.Id);
				tTask.TaskStatus.Should().Be(TaskStatus.Completed);
			}

			return task.Id;
		}
Пример #9
0
		public void TaskSchedulerManager_UpdateLicense()
		{
			var dbFactory = new DatabaseFactory();
			var dvsContext = dbFactory.Get<DVSContext>();
			var appraiserUserRepository = new AppraiserUserRepository(dbFactory);
			var user = appraiserUserRepository.GetByUserId(TestConstants.TestAppraiserUser);
			user.Licenses.Add(new License() { LicenseNumber = "2", State = "NY", Status = LicenseStatus.Active, ExpirationDate = DateTime.Now.AddYears(-1) });
			appraiserUserRepository.Update(user);
			dvsContext.SaveChanges();

			var task = new Task();
			task.CreateDate = DateTime.Now;
			task.TaskTypeEnum = TaskTypeEnum.LicenseDailyUpdateByAscGov;
			task.TaskStatus = TaskStatus.Pending;
			_repository.Add(task);


			_taskQueueManager.ProcessQueue();

			int maxIterationsCount = 10;
			while (maxIterationsCount-- != 0)
			{
				using (var dc = new TaskQueueContext())
				{
					var tTask = dc.Tasks.Single(t => t.Id == task.Id);
					if (tTask.TaskStatus != TaskStatus.Executing)
						break;

					Thread.Sleep(1000 * 60);
				}
			}

			dbFactory = new DatabaseFactory();
			user = (new AppraiserUserRepository(dbFactory)).GetByUserId(TestConstants.TestAppraiserUser);
			user.Licenses.Where(e => e.LicenseNumber == "2").Should().HaveCount(1);
			user.Licenses.Single(e => e.LicenseNumber == "2").Status.Should().Be(LicenseStatus.Expired);
		}
Пример #10
0
		public void TaskSchedulerManager_Some_Notifications_In_One_Time()
		{
			_userRepository.GetById(Arg.Any<int>()).Returns(new User() { Email = "*****@*****.**" });

			for (int i = 1; i <= 20; i++)
			{
				var task = new Task();
				task.Id = i;
				task.CreateDate = DateTime.Now;
				task.TaskTypeEnum = TaskTypeEnum.Notifications;
				task.TaskStatus = TaskStatus.Pending;

				task.TaskParams = new List<TaskParam>();
				task.TaskParams.Add(new TaskParam(TaskParamsKey.UserId, "1"));
				task.TaskParams.Add(new TaskParam(TaskParamsKey.NotificationType, NotificationType.UserRegistered.ToString()));

				_repository.Add(task);
			}

			_taskQueueManager.ProcessQueue();

			int maxIterationsCount = 20;
			while (maxIterationsCount-- != 0)
			{
				using (var dc = new TaskQueueContext())
				{
					var isDone = dc.Tasks.All(t => t.TaskStatusId == (int)TaskStatus.Completed || t.TaskStatusId == (int)TaskStatus.Error);
					if (isDone)
						break;

					Thread.Sleep(1000 * 5);
				}
			}

			using (var dc = new TaskQueueContext())
			{
				var isSuccess = dc.Tasks.All(t => t.TaskStatusId == (int)TaskStatus.Completed);
				isSuccess.Should().BeTrue();
			}
		}