Beispiel #1
0
        public static void Main()
        {
            var dataGeneratorExecutors = new List<DataGeneratorExecutor>
                                             {
                                                 new DataGeneratorExecutor(new DepartmentDataGenerator(), 100),
                                                 new DataGeneratorExecutor(new EmployeeDataGenerator(), 5000),
                                                 new DataGeneratorExecutor(new ProjectsDataGenerator(), 1000),
                                                 new DataGeneratorExecutor(new EmployeesInProjectsDataGenerator(), 10), // per employee
                                                 new DataGeneratorExecutor(new ReportsDataGenerator(), 50), // per employee
                                             };

            foreach (var dataGeneratorExecutor in dataGeneratorExecutors)
            {
                using (var data = new CompanyEntities())
                {
                    data.Configuration.AutoDetectChangesEnabled = false;
                    //// data.Configuration.ProxyCreationEnabled = false;

                    Console.WriteLine("Staring {0}...", dataGeneratorExecutor.DataGenerator.GetType().Name);
                    dataGeneratorExecutor.Execute(data, RandomGenerator.Instance);
                    Console.WriteLine("Saving {0}...", dataGeneratorExecutor.DataGenerator.GetType().Name);
                    data.SaveChanges();
                    Console.WriteLine("Finished {0}.", dataGeneratorExecutor.DataGenerator.GetType().Name);
                }
            }
        }
        private static void Main()
        {
            var random = RandomDataGenerator.Instance;
            var db = new CompanyEntities();
            var logger = new ConsoleLogger();

            db.Configuration.AutoDetectChangesEnabled = false;                  // Speed-up the application

            var listOfGenerators = new List<IDataGenerator>() {
                new DepartmentDataGenerator(random, db, 100, logger),           // Creates 100 departments
                new EmployeeDataGenerator(random, db, 5000, logger),            // Creates 5 000 employees
                new ProjectDataGenerator(random, db, 1000, logger),             // Creates 1 000 projects
                new ReportDataGenerator(random, db, 250000, logger),            // Creates 250 000 reports
            };

            foreach (var generator in listOfGenerators)
            {
                generator.Generate();
                db.SaveChanges();
            }

            AddManagers(random, db);

            db.Configuration.AutoDetectChangesEnabled = true;
        }
        public static void Main()
        {
            var random = RandomData.Instance;
            var db = new CompanyEntities();
            db.Configuration.AutoDetectChangesEnabled = false;

            var listOfGenerators = new List<IDataGenerator>
            {
                new DepartmentsGenerator(db, random, 100),
                new EmployeesGenerator(db, random, 5000),
                new ProjectsGenerator(db, random, 1000),
                new ReportsGenerator(db, random, 250000)
            };

            foreach (var generator in listOfGenerators)
            {
                generator.Generate();
                db.SaveChanges();
            }
        }
        private static void Main()
        {
            var databaseContext = new CompanyEntities();
            databaseContext.Configuration.AutoDetectChangesEnabled = false;
            var generatorFacotry = new CompanyGeneratorsFactory(new RandomDataGenerator(), new ConsoleLogger(), databaseContext, 100);
            var generators = new List<DataGenerator>
                                 {
                                     generatorFacotry.GetDepartmentGenerator(100),
                                     generatorFacotry.GetEmployeeGenerator(5000),
                                     generatorFacotry.GetProjectGenerator(100),
                                     generatorFacotry.GetReportGenerator(250)
                                 };

            foreach (var generator in generators)
            {
                generator.Generate();
                databaseContext.SaveChanges();
            }

            databaseContext.Configuration.AutoDetectChangesEnabled = true;
        }
        private static void AddManagers(IRandomDataGenerator random, CompanyEntities db)
        {
            var employeeIDs = db.Employees.Select(c => c.ID).ToList();
            int i = 0;

            foreach (var employee in db.Employees)
            {
                if (random.GetRandomNumber(0, employeeIDs.Count - 1) < 95 * employeeIDs.Count / 100)
                {
                    var managerID = random.GetRandomNumber(1, employeeIDs.Count - 1);
                    while (managerID == i)
                    {
                        managerID = random.GetRandomNumber(1, employeeIDs.Count - 1);
                    }

                    employee.ManagerID = managerID;
                    db.SaveChanges();
                }

                i++;
            }
        }
Beispiel #6
0
        public static void Main(string[] args)
        {
            var dataGeneratorExecutors = new List<DataGeneratorExecutor>
                                             {
                                                 new DataGeneratorExecutor(new DepartmentDataGenerator(), 100),
                                                 new DataGeneratorExecutor(new EmployeeDataGenerator(), 5000),
                                                 new DataGeneratorExecutor(new ProjectDataGenerator(), 1000),
                                                 new DataGeneratorExecutor(new EmployeesInProjectsDataGenerator(), 10), // per employee
                                                 new DataGeneratorExecutor(new ReportsDataGenerator(), 50), // per employee
                                             };

            foreach (var dataGeneratorExecutor in dataGeneratorExecutors)
            {
                using (var data = new CompanyEntities())
                {
                    data.Configuration.AutoDetectChangesEnabled = false;

                    dataGeneratorExecutor.Execute(data, RandomGenerator.Instance);
                    data.SaveChanges();
                }
            }
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            var random = RandomDataGenerator.Instance;
            var db = new CompanyEntities();
            db.Configuration.AutoDetectChangesEnabled = false;

            var listOfGenerators = new List<IDataGenerator>
            {
                new DepartmentDataGenerator(random, db, 100),
                new EmployeeDataGenerator(random, db, 2000),
                new ProjectDataGenerator(random, db, 2000),
                new EmployeeProjectRelationDataGenerator(random, db, 2000),
                new ReportDataGenerator(random, db, 250000)
            };

            foreach (var generator in listOfGenerators)
            {
                generator.Generate();
                db.SaveChanges();
            }

            db.Configuration.AutoDetectChangesEnabled = true;
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            var random = RandomDataGenerator.Instance;
            var db = new CompanyEntities();
            db.Configuration.AutoDetectChangesEnabled = false;

            Console.WriteLine("\nAdding departments");

            for (int i = 0; i < 100; i++)
            {
                var department = new Department
                {
                    Name = random.GetRandomStringWithRandomLength(10,50)
                };

                db.Departments.Add(department);

                if (i%100 == 0)
                {
                    Console.Write(".");
                    db.SaveChanges();
                }
            }
            db.SaveChanges();
            Console.WriteLine("\nDepartents added");

            Console.WriteLine("\nAdding employees");

            var departmentIds = db.Departments.Select(d => d.Id).ToList();
            for (int i = 0; i < 5000; i++)
            {
              var employee = new Employee
                {
                    FirstName = random.GetRandomStringWithRandomLength(5,20),
                    LastName = random.GetRandomStringWithRandomLength(5,20),
                    DepartmentId = departmentIds[random.GetRandomNumber(0, departmentIds.Count - 1)],
                    YearSalary = random.GetRandomNumber(50000,200000),
                    ManagerId = (i > 250) ? i - 1 :(int?)null // 4750 employees will have a manager (95%) :)
                                                                  // it is very stupid i know but I left it for last and forgot it
                };

              db.Employees.Add(employee);

              if (i % 100 == 0)
              {
                  Console.Write(".");
                  db.SaveChanges();
              }
            }
            db.SaveChanges();
            Console.WriteLine("\nEmployees added");

            Console.WriteLine("\nAdding Projects"); //For some reason it does not want to work
            var employeeIds = db.Employees.Select(e => e.Id).ToList();
            for (int i = 0; i < 1000; i++)
            {
                var project = new Project
                {
                    Name = "Project" + i.ToString(),
                };

                var count = random.GetRandomNumber(5, 20);

                for (int j = 0; j < count; j++)
                {
                    var projectEmployee = new ProjectsEmployee
                    {
                        EmployeeId = employeeIds[i+j],
                        ProjectId = i+1,
                        StartDate = new DateTime(random.GetRandomNumber(1980, 2005), random.GetRandomNumber(1, 12), random.GetRandomNumber(1, 28)),
                        EndDate = new DateTime(random.GetRandomNumber(2005, 2020), random.GetRandomNumber(1, 12), random.GetRandomNumber(1, 28))

                    };

                    project.ProjectsEmployees.Add(projectEmployee);
                }

                db.Projects.Add(project);

                if (i % 100 == 0)
                {
                    Console.Write(".");
                    db.SaveChanges();
                }
            }
            db.SaveChanges();
            Console.WriteLine("\nProjects added");

            Console.WriteLine("\nAdding Reports");
            var employeeIds2 = db.Employees.Select(d => d.Id).ToList();
            for (int i = 0; i < 5000; i++)
            {
                var empId = employeeIds2[i];

                for (int j = 0; j < 50; j++) // every empolyee gets 50 reports
                {
                    var report = new Report
                    {
                        EmployeeId = empId,
                        TimeOfReport = new DateTime(random.GetRandomNumber(1980, 2014), random.GetRandomNumber(1, 12), random.GetRandomNumber(1, 28))
                    };
                    db.Reports.Add(report);
                }
                Console.Write(".");
                db.SaveChanges();

            }
            db.SaveChanges();
            Console.WriteLine("\nReports added");

            db.Configuration.AutoDetectChangesEnabled = true;
        }