Ejemplo n.º 1
0
		public void Seed()
		{
			if (!IsPostgres)
			{
				string journalClusteredIndex = GetIndexName("UID", "Journals");
				if (journalClusteredIndex != null)
					SetPkNonclustered(journalClusteredIndex, "Journals");
			}
			if (Organisations.Count() == 0)
			{
				var organisation = new Organisation
				{
					UID = Guid.NewGuid(),
					Name = "Организация",
					Users = new List<OrganisationUser>
					{  
						new OrganisationUser 
						{ 
							UID = Guid.NewGuid(), 
							UserUID = new Guid("10e591fb-e017-442d-b176-f05756d984bb") 
						}
					}
				};
				Organisations.Add(organisation);
			}
			if (GKDaySchedules.Count() == 0)
			{
				var neverDaySchedule = new GKDaySchedule
				{
					UID = Guid.NewGuid(),
					Name = "<Никогда>",
					No = 1
				};
				GKDaySchedules.Add(neverDaySchedule);

				var alwaysDaySchedule = new GKDaySchedule
				{
					UID = Guid.NewGuid(),
					Name = "<Всегда>",
					No = 2
				};
				alwaysDaySchedule.GKDayScheduleParts.Add(new GKDaySchedulePart()
					{
						StartMilliseconds = 0,
						EndMilliseconds = (int)new TimeSpan(1, 0, 0, 0, 0).TotalMilliseconds
					});
				GKDaySchedules.Add(alwaysDaySchedule);
			}
		}
Ejemplo n.º 2
0
		public List<Guid> TestEmployeeCards()
		{
			Context.Database.Delete();
			int totalOrganisations = 1;
			int positionsPerOrganisation = 1000;
			int rootDepartmentsPerOrganisation = 100;
			int employeesPerOrganisation = 6600;
			int cardsPerEmployee = 10;

			int cardNumber = 0;
			Context.Configuration.AutoDetectChangesEnabled = false;
			Context.Configuration.ValidateOnSaveEnabled = false;
			var stopwatch = new Stopwatch();
			stopwatch.Start();
			var employees = new List<Employee>();
			var cards = new List<Card>();
			var positions = new List<Position>();
			var departments = new List<Department>();
			var random = new Random();
			for (int i = 0; i < totalOrganisations; i++)
			{
				var org = new Organisation { Name = "Тестовая Организация " + i, UID = Guid.NewGuid(), ExternalKey = "-1" };
				Context.Organisations.Add(org);

				var user = new OrganisationUser { UID = Guid.NewGuid(), UserUID = new Guid("10e591fb-e017-442d-b176-f05756d984bb"), OrganisationUID = org.UID };
				Context.OrganisationUsers.Add(user);

				var organisationPositions = new List<Position>();
				for (int j = 0; j < positionsPerOrganisation; j++)
				{
					var pos = new Position { Name = "Должность " + i + j, OrganisationUID = org.UID, UID = Guid.NewGuid(), RemovalDate = new DateTime(1900, 1, 1), ExternalKey = "-1" };
					organisationPositions.Add(pos);
				}

				var opranisationDepartments = new List<Department>();
				for (int j = 0; j < rootDepartmentsPerOrganisation; j++)
				{
					var dept = new Department { UID = Guid.NewGuid(), Name = "Подразделение " + i + j, OrganisationUID = org.UID };
					opranisationDepartments.Add(dept);
					for (int k = 0; k < 2; k++)
					{
						var dept2 = new Department { UID = Guid.NewGuid(), Name = "Подразделение " + i + j + k, OrganisationUID = org.UID, ParentDepartmentUID = dept.UID };
						opranisationDepartments.Add(dept2);
						for (int m = 0; m < 2; m++)
						{
							var dept3 = new Department { UID = Guid.NewGuid(), Name = "Подразделение " + i + j + k + m, OrganisationUID = org.UID, ParentDepartmentUID = dept2.UID };
							opranisationDepartments.Add(dept3);
							for (int n = 0; n < 2; n++)
							{
								var dept4 = new Department { UID = Guid.NewGuid(), Name = "Подразделение " + i + j + k + m + n, OrganisationUID = org.UID, ParentDepartmentUID = dept3.UID };
								opranisationDepartments.Add(dept4);
							}
						}
					}
				}

				for (int j = 0; j < employeesPerOrganisation; j++)
				{
					var empl = CreateEmployee(i.ToString() + j.ToString(), org.UID, opranisationDepartments[random.Next(15 * rootDepartmentsPerOrganisation)].UID, organisationPositions[random.Next(positionsPerOrganisation)].UID);
					employees.Add(empl);

					for (int k = 0; k < cardsPerEmployee; k++)
					{
						cardNumber++;
						var card = CreateCard(cardNumber, empl.UID);
						cards.Add(card);
					}
				}
				positions.AddRange(organisationPositions);
				departments.AddRange(opranisationDepartments);
			}

			switch (GlobalSettingsHelper.GlobalSettings.DbSettings.DbType)
			{
				case DbType.MsSql:
					Context.BulkInsert(positions);
					Context.BulkInsert(departments);
					Context.BulkInsert(employees);
					Context.BulkInsert(cards);
					Context.SaveChanges();
					break;
				case DbType.Postgres:
					bool isBreak = false;
					Context.Departments.AddRange(departments);
					Context.Positions.AddRange(positions);
					int currentPage = 0;
					int pageSize = 10000;
					while (!isBreak)
					{
						var employeePortion = employees.Skip(currentPage * pageSize).Take(pageSize).ToList();
						var cardPortion = cards.Skip(currentPage * pageSize).Take(pageSize).ToList();
						Context.Employees.AddRange(employeePortion);
						Context.Cards.AddRange(cardPortion);
						Context.SaveChanges();
						isBreak = cardPortion.Count < pageSize;
						currentPage++;
					}
					break;
			}

			return cards.Select(x => x.UID).ToList();
		}