internal void GenerateRandomPeopleData(string dbName, string host, int numberOfEntities)
        {
            var dbController = new MongoDbController(dbName, host);
            var db = dbController.GetDatabase();
            var collection = db.GetCollection<PersonMongo>("Person");
            var personCollection = new List<PersonMongo>();
            var countryGenerator = new CountriesCollection();
            var randomGenerator = new RandomGenerator();

            for (int i = 1; i <= numberOfEntities; i++)
            {
                personCollection.Add(new PersonMongo(
                    i,
                    randomGenerator.GetRandomString(3, 5, true),
                    randomGenerator.GetRandomString(4, 7, true),
                    GetGender(i),
                    randomGenerator.GetRandomInt(1920,2015),
                    countryGenerator.GetRandomCountry()));
            }

            collection.InsertManyAsync(personCollection);
            Console.Write("Press key");
            Console.ReadKey();

            Console.WriteLine("Person data created");
        }
Esempio n. 2
0
        private static void AddToysToManufacturers(ToyStoreEntities db, RandomGenerator generator, IList<int> manufacturerIds, IList<Toy> toys)
        {
            var numberOfManufacturers = manufacturerIds.Count;
            Console.Write("Adding Toys to Manufacturers");

            var i = 0;
            foreach (var toy in toys)
            {
                toy.ManufacturerId = manufacturerIds[generator.GetRandomInt(0, numberOfManufacturers - 1)];
                db.SaveChanges();
                Printer.Print(20, numberOfManufacturers, i);
                i++;
            }
            Console.WriteLine();
        }
        public static void InsertNewCountries(int count)
        {
            while (count > 0)
            {
                var rand = new RandomGenerator();

                CinameNetworkEntities northwindEntities = new CinameNetworkEntities();

                Country newEntry = new Country
                {
                    Name = rand.GetRandomString(5, 20)
                };

                northwindEntities.Countries.Add(newEntry);
                northwindEntities.SaveChanges();

                Console.WriteLine("Row affected - new country with movieId {0} created", newEntry.CountryId);
                count--;
            }
        }
        public static int InserNewMovie()
        {
            var rand = new RandomGenerator();

            CinameNetworkEntities northwindEntities = new CinameNetworkEntities();

            Movy newProduct = new Movy
            {
                Title = rand.GetRandomString(5, 15),
                GenreId = rand.GetRandomInt(1, 1000),
                ReleaseDate = rand.GetRandomDateTime(),
                Director = rand.GetRandomInt(1, 1000),
                Actors = rand.GetRandomInt(1, 100),
                Description = rand.GetRandomString(20, 60),
                CoverLink = rand.GetRandomString(5, 25),
                Subtitles = false,
                DurationMinutes = rand.GetRandomInt(40, 150)
            };

            northwindEntities.Movies.Add(newProduct);
            northwindEntities.SaveChanges();

            return newProduct.MovieId;
        }
 public XmlRandomDataGenerator(RandomGenerator randomGenerator, int numberOfGenres, int numberOfMovies)
 {
     this.randomGenerator = randomGenerator;
     this.numberOfGenres = numberOfGenres;
     this.numberOfMovies = numberOfMovies;
 }
Esempio n. 6
0
        static void Main()
        {
            var db = new ToyStoreEntities();
            var generator = new RandomGenerator();
            var toyStoreGenerator = new ToyStoreDataController(generator);

            GenerateRandomAgeRanges(db, 100, toyStoreGenerator);
            db.SaveChanges();

            GenerateRandomColors(db, 30, toyStoreGenerator);
            db.SaveChanges();

            GenerateRandomCountries(db, 50, toyStoreGenerator);
            db.SaveChanges();

            GenerateRandomCategories(db, 100, toyStoreGenerator);
            db.SaveChanges();

            var countryIds = db.Countries.Select(c => c.CountryId).ToList();
            var colorIds = db.Colors.Select(c => c.ColorId).ToList();

            GenerateRandomManufacturers(db, 50, toyStoreGenerator, countryIds);
            db.SaveChanges();

            var manufacturerIds = db.Manufacturers.Select(m => m.ManufacturerId).ToList();
            var ageRangeIds = db.AgeRanges.Select(ar => ar.AgeRangeId).ToList();

            db.Toys.AddRange(GetRandomToys(db, 1000, toyStoreGenerator, colorIds, manufacturerIds, ageRangeIds));
            db.SaveChanges();

            var toys = db.Toys.ToList();

            AddToysToManufacturers(db, generator, manufacturerIds, toys);
            db.SaveChanges();
        }
 public ToyStoreDataController(RandomGenerator generator)
 {
     this.generator = new RandomGenerator();
 }