public void Generate(ComputersEntitiesDb db, IRandomGenerator random) { if (db.Vendors.Count() >= this.Count) { return; } var vendorNames = new HashSet <string>(); while (vendorNames.Count < this.Count) { var nameLength = random.GetRandomNumber(3, 50); var randomString = random.GetRandomString(nameLength); vendorNames.Add(randomString); } var vendorsToInsert = vendorNames.Select(vendorName => new Vendor() { Name = vendorName }); foreach (var vendor in vendorsToInsert) { db.Vendors.AddOrUpdate(vendor); } db.SaveChanges(); }
public void Generate(ComputersEntitiesDb db, IRandomGenerator random) { if (db.Cpus.Count() >= this.Count) { return; } var cpusToAdd = new HashSet <Cpu>(); var vendors = db.Vendors.ToList(); while (cpusToAdd.Count < this.Count) { var nameLength = random.GetRandomNumber(3, 50); var randomString = random.GetRandomString(nameLength); var cpu = new Cpu() { Vendor = vendors[random.GetRandomNumber(0, vendors.Count - 1)], Model = randomString, ClockCycles = (float)random.GetRandomNumber(100, 500) / 100, Cores = random.GetRandomNumber(1, 24) }; cpusToAdd.Add(cpu); } foreach (var cpu in cpusToAdd) { db.Cpus.AddOrUpdate(cpu); } db.SaveChanges(); }
public void Generate(ComputersEntitiesDb db, IRandomGenerator random) { if (db.Computers.Count() >= this.Count) { return; } var computersToAdd = new HashSet <Computer>(); var vendors = db.Vendors.ToList(); var cpus = db.Cpus.ToList(); var storages = db.Storages.ToList(); var gpus = db.Gpus.ToList(); var types = db.ComputerTypes.ToList(); var possibleMemories = new[] { 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 64, 128 }; while (computersToAdd.Count < this.Count) { var nameLength = random.GetRandomNumber(3, 50); var randomString = random.GetRandomString(nameLength); var numberOfStorages = random.GetRandomNumber(1, 10); var numberOfGpus = random.GetRandomNumber(1, 4); var computerGpus = new HashSet <Gpu>(); var computerStorages = new HashSet <Storage>(); for (int i = 0; i < numberOfGpus; i++) { var gpu = gpus[random.GetRandomNumber(0, gpus.Count - 1)]; computerGpus.Add(gpu); } for (int i = 0; i < numberOfStorages; i++) { var storage = storages[random.GetRandomNumber(0, storages.Count - 1)]; computerStorages.Add(storage); } var computer = new Computer() { Vendor = vendors[random.GetRandomNumber(0, vendors.Count - 1)], Cpu = cpus[random.GetRandomNumber(0, cpus.Count - 1)], Model = randomString, Storages = computerStorages, Gpus = computerGpus, Memory = possibleMemories[random.GetRandomNumber(0, possibleMemories.Length - 1)], ComputerType = types[random.GetRandomNumber(0, types.Count - 1)] }; computersToAdd.Add(computer); } foreach (var computer in computersToAdd) { db.Computers.AddOrUpdate(computer); } db.SaveChanges(); }
public void Generate(ComputersEntitiesDb db, IRandomGenerator random) { if (db.Gpus.Count() >= this.Count) { return; } var possibleMemories = new[] { 1, 2, 3, 4, 8, 12, 24 }; var gpusToAdd = new HashSet <Gpu>(); var gpuTypes = db.GpuTypes.ToList(); var vendors = db.Vendors.ToList(); while (gpusToAdd.Count < this.Count) { var randomNumber = random.GetRandomNumber(0, 100); GpuType gpuType = null; if (randomNumber < 33) { gpuType = gpuTypes[0]; } else { gpuType = gpuTypes[1]; } var nameLength = random.GetRandomNumber(3, 50); var randomString = random.GetRandomString(nameLength); var gpu = new Gpu() { Vendor = vendors[random.GetRandomNumber(0, vendors.Count - 1)], Model = randomString, GpuType = gpuType, Memory = possibleMemories[random.GetRandomNumber(0, possibleMemories.Length - 1)], }; gpusToAdd.Add(gpu); } foreach (var gpu in gpusToAdd) { db.Gpus.AddOrUpdate(gpu); } db.SaveChanges(); }
public void Generate(ComputersEntitiesDb db, IRandomGenerator random) { if (db.GpuTypes.Count() >= this.Count) { return; } db.GpuTypes.AddOrUpdate(new GpuType() { Name = "Internal" }); db.GpuTypes.AddOrUpdate(new GpuType() { Name = "External" }); db.SaveChanges(); }
public void Generate(ComputersEntitiesDb db, IRandomGenerator random) { if (db.StorageTypes.Count() >= this.Count) { return; } db.StorageTypes.AddOrUpdate(new StorageType() { StorageType1 = "HDD" }); db.StorageTypes.AddOrUpdate(new StorageType() { StorageType1 = "SSD" }); db.SaveChanges(); }
public void Generate(ComputersEntitiesDb db, IRandomGenerator random) { if (db.ComputerTypes.Count() >= this.Count) { return; } db.ComputerTypes.AddOrUpdate(new ComputerType() { Type = "Notebook" }); db.ComputerTypes.AddOrUpdate(new ComputerType() { Type = "Desktop" }); db.ComputerTypes.AddOrUpdate(new ComputerType() { Type = "Ultrabook" }); db.SaveChanges(); }
public void Generate(ComputersEntitiesDb db, IRandomGenerator random) { if (db.Storages.Count() >= this.Count) { return; } var capacities = new[] { 256, 512, 1024, 2048, 4096 }; var storageDevices = new HashSet <Storage>(); var storageTypes = db.StorageTypes.ToList(); while (storageDevices.Count < this.Count) { var storageIndex = random.GetRandomNumber(0, 100); StorageType type = null; if (storageIndex < 25) { type = storageTypes[1]; } else { type = storageTypes[0]; } var device = new Storage() { StorageType = type, Capacity = capacities[random.GetRandomNumber(0, capacities.Length - 1)], }; storageDevices.Add(device); db.Storages.AddOrUpdate(device); } db.SaveChanges(); }