public async Task <TimeSpan> CreateEntityNew(int n) { using (var uow = UnitOfWorkManager.Begin(new UnitOfWorkOptions { Scope = TransactionScopeOption.RequiresNew })) { var stopwatch = new Stopwatch(); stopwatch.Start(); var jsonString = await File.ReadAllTextAsync("MajaMegi.json"); var listA = JsonConvert.DeserializeObject <List <TestClass> >(jsonString); var types = await _repositoryType.GetAll().Include(x => x.EntityTypeProperties).ToListAsync(); foreach (var type in types) { for (var i = 0; i < n / types.Count(); i++) { Random r = new Random(); int index = r.Next(1, 1000); int index1 = r.Next(1, 1000); var entity = new CoreEntity { Id = Guid.NewGuid(), Name = listA[index].Name, InsertUserId = listA[index].Id, InsertIpAddress = listA[index].IpAddress, Description = listA[index].Description, InsertTime = listA[index].Date, LastUpdateIpAddress = listA[index1].IpAddress, LastUpdateTime = listA[index1].Date, LastUpdateUserId = listA[index].Id, EntityType = type }; guids.Add(entity.Id); foreach (var prop in type.EntityTypeProperties) { Random valueRandom = new Random(); int valueIndex = valueRandom.Next(1, 1000); int valueIndex1 = valueRandom.Next(1, 1000); var value = new CoreEntityPropertyValue { DataTimeValue = listA[valueIndex].Date, DecimalValue = 1.111m, Entity = entity, EntityTypeProperty = prop, InsertUserId = listA[valueIndex].Id, InsertIpAddress = listA[valueIndex].IpAddress, InsertTime = listA[valueIndex].Date, LastUpdateIpAddress = listA[valueIndex].IpAddress, LastUpdateTime = listA[valueIndex].Date, LastUpdateUserId = listA[valueIndex].Id, TextValue = listA[valueIndex1].Name, }; switch (prop.ReferenceType) { case CoreEntityTypeProperty.ReferenceTypeEnum.NoReference: break; case CoreEntityTypeProperty.ReferenceTypeEnum.InternalReference: var guid = GetRandomEntityGuid(); if (guid == Guid.Empty) { break; } while (guid == entity.Id) { guid = GetRandomEntityGuid(); } value.GuidValue = guid; break; case CoreEntityTypeProperty.ReferenceTypeEnum.ExternalReference: value.IntValue = valueRandom.Next(1, 10); break; } entity.EntityPropertyValues.Add(value); } await _repositoryEntity.InsertAsync(entity); } } await uow.CompleteAsync(); stopwatch.Stop(); return(stopwatch.Elapsed); } }
//Probna metoda za kreiranje vrijednosti sa random podacima public async Task CreateValue() { var jsonString = File.ReadAllText("MajaMegi.json"); var listA = JsonConvert.DeserializeObject <List <TestClass> >(jsonString); ////var entityTypes = _repositoryType.GetAll().Include(x => x.EntityTypeProperties); var entities = _repositoryEntity.GetAll().Include(x => x.EntityType) .ThenInclude(x => x.EntityTypeProperties); foreach (var entity in entities) { foreach (var prop in entity.EntityType.EntityTypeProperties) { Random r = new Random(); int index = r.Next(1, 1000); int index1 = r.Next(1, 1000); var value = new CoreEntityPropertyValue { DataTimeValue = listA[index].Date, DecimalValue = 1.111m, EntityId = entity.Id, EntityTypePropertyId = prop.Id, InsertUserId = listA[index].Id, InsertIpAddress = listA[index].IpAddress, InsertTime = listA[index].Date, LastUpdateIpAddress = listA[index].IpAddress, LastUpdateTime = listA[index].Date, LastUpdateUserId = listA[index].Id, TextValue = listA[index1].Name, }; switch (prop.ReferenceType) { case CoreEntityTypeProperty.ReferenceTypeEnum.NoReference: break; case CoreEntityTypeProperty.ReferenceTypeEnum.InternalReference: var guid = GetRandomEntityGuid(); while (guid == entity.Id) { guid = GetRandomEntityGuid(); } value.GuidValue = guid; break; case CoreEntityTypeProperty.ReferenceTypeEnum.ExternalReference: value.IntValue = r.Next(1, 10); break; } _repositoryValue.Insert(value); } } ////foreach (var entity in entityTypes) ////{ //// var properties = entity.EntityTypeProperties; //// foreach (var property in properties) //// { //// switch (property.ReferenceType) //// { //// case CoreEntityTypeProperty.ReferenceTypeEnum.NoReference: //// { //// var value = new CoreEntityPropertyValue() //// { //// DataTimeValue = listA[index].Date, //// DecimalValue = 1.111m, //// EntityId = GetRandomEntityGuid(), //// EntityTypePropertyId = GetRandomEntityPropertyId(), //// InsertUserId = listA[index].Id, //// InsertIpAddress = listA[index].IpAddress, //// InsertTime = listA[index].Date, //// LastUpdateIpAddress = listA[index].IpAddress, //// LastUpdateTime = listA[index].Date, //// LastUpdateUserId = listA[index].Id, //// TextValue = listA[index1].Name, //// GuidValue = null, //// IntValue = null //// }; //// while (PostojiLi(value.EntityId,value.EntityTypePropertyId)) //// { //// value.EntityId = GetRandomEntityGuid(); //// value.EntityTypePropertyId = GetRandomEntityPropertyId(); //// } //// _repositoryValue.Insert(value); //// break; //// } //// case CoreEntityTypeProperty.ReferenceTypeEnum.InternalReference: //// { //// var value = new CoreEntityPropertyValue() //// { //// DataTimeValue = listA[index].Date, //// DecimalValue = 1.111m, //// EntityId = GetRandomEntityGuid(), //// EntityTypePropertyId = GetRandomEntityPropertyId(), //// InsertUserId = listA[index].Id, //// InsertIpAddress = listA[index].IpAddress, //// InsertTime = listA[index].Date, //// LastUpdateIpAddress = listA[index].IpAddress, //// LastUpdateTime = listA[index].Date, //// LastUpdateUserId = listA[index].Id, //// TextValue = null, //// IntValue = null //// }; //// while (PostojiLi(value.EntityId, value.EntityTypePropertyId)) //// { //// value.EntityId = GetRandomEntityGuid(); //// value.EntityTypePropertyId = GetRandomEntityPropertyId(); //// } //// value.GuidValue = GetGuid(value.EntityId); //// _repositoryValue.Insert(value); //// break; //// } //// default: //// { //// var value = new CoreEntityPropertyValue() //// { //// DataTimeValue = listA[index].Date, //// DecimalValue = 1.111m, //// EntityId = GetRandomEntityGuid(), //// EntityTypePropertyId = GetRandomEntityPropertyId(), //// InsertUserId = listA[index].Id, //// InsertIpAddress = listA[index].IpAddress, //// InsertTime = listA[index].Date, //// LastUpdateIpAddress = listA[index].IpAddress, //// LastUpdateTime = listA[index].Date, //// LastUpdateUserId = listA[index].Id, //// TextValue = null, //// GuidValue = null, //// IntValue = r.Next(1, 10) //// }; //// while (PostojiLi(value.EntityId, value.EntityTypePropertyId)) //// { //// value.EntityId = GetRandomEntityGuid(); //// value.EntityTypePropertyId = GetRandomEntityPropertyId(); //// } //// _repositoryValue.Insert(value); //// break; //// } //// } //// } ////} }