public ScatterExample() { InitializeComponent(); dataService = new DataGeneratorService(); dataService.GenerateData(Int32.Parse(Range_min.Text), Int32.Parse(Range_max.Text), Int32.Parse(Step_Range_min.Text), Int32.Parse(Step_Range_max.Text), groupQty, elementQty, Int32.Parse(Density_min.Text)); dataService.GenerateEmptyNeurons(groupQty); GenerateChart(dataService.dataGroup, dataService.neurons, wpfPlot1); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; services.GetRequiredService <ProductsDbContext>(); DataGeneratorService.Initialize(services); } host.Run(); }
public ActionResult GenerateData() { // create random data var drillSites = DataGeneratorService.GenerateDrillSitesWithDepthReadings(); // try insert data into DB try { using (var db = new DsmContext()) { db.TryCreateDatabase(); // remove all data var allDepthReadings = from readings in db.DepthReadings select readings; db.DepthReadings.RemoveRange(allDepthReadings); var allDrillSites = from sites in db.DrillSites select sites; db.DrillSites.RemoveRange(allDrillSites); db.SaveChanges(); // add newly generated data foreach (var drillSite in drillSites.Select(x => x.DrillSiteModel)) { var drillSiteDbReference = db.Add(drillSite); db.SaveChanges(); var depthReadings = DataGeneratorService.GenerateDepthReadings( drillSite.CollarDip, drillSite.CollarAzimuth); foreach (var depthReading in depthReadings) { drillSiteDbReference.Entity.DepthReadings.Add(depthReading); db.SaveChanges(); } } } } catch (SqliteException ex) { // TODO - consider redirecting to a "failed to create/insert data" page Console.WriteLine("Failed to insert generated drill site & depth readings data into database", ex); } return(RedirectToAction("Index", "Home")); }
private void ExecuteDbUpdate() { // in order to draw the progress bar use Dispatcher... Info = string.Empty; bool succeed = true; int number_of_items = (Convert.ToInt32(Administrator)) + (Convert.ToInt32(Countries)) + (Convert.ToInt32(AirlineCompany)) + (Convert.ToInt32(Customer)) + (Convert.ToInt32(Flights)) * (Convert.ToInt32(AirlineCompany)) + (Convert.ToInt32(Ticket)) * (Convert.ToInt32(Customer)); int current = 0; WorkNotInProgress = false; Task.Run(() => { Random rnd = new Random(); bool trynumber = int.TryParse(Countries, out int countries); // 3 or more countries doesn't work help for (int i = 0; i < countries; i++) { do { try { wpfFacade.CreateNewCountry(DataGeneratorService.GenerateRandomCountry()); succeed = true; } catch (UserNameAlreadyExistsException) { succeed = false; } }while (!succeed); current++; ProgressBarValue = (int)(((double)current / number_of_items) * 100); ProgressBarValueInfo = ProgressBarValue.ToString(); } Info = $"Added {countries} countries to the dataBase \n"; // countries trynumber = int.TryParse(Administrator, out int administrator); for (int i = 0; i < administrator; i++) { do { try { wpfFacade.CreateNewAdmin(DataGeneratorService.GenerateRandomUserRepositoryForAdmin(), DataGeneratorService.GenerateRandomAdmin()); succeed = true; } catch (UserNameAlreadyExistsException) { succeed = false; } }while (!succeed); current++; ProgressBarValue = (int)(((double)current / number_of_items) * 100); ProgressBarValueInfo = ProgressBarValue.ToString(); } Info += $"Added {administrator} administrator to the dataBase \n"; // admins List <Country> listCountries = (List <Country>)wpfFacade.GetAllCountries(); trynumber = int.TryParse(AirlineCompany, out int airlineCompany); for (int i = 0; i < airlineCompany; i++) { do { try { int country = rnd.Next(0, listCountries.Count()); wpfFacade.CreateNewAirline(DataGeneratorService.GenerateRandomUserRepositoryForAirlineCompany(), DataGeneratorService.GenerateRandomAirlineCompany(), listCountries[country]); succeed = true; } catch (UserNameAlreadyExistsException) { succeed = false; } }while (!succeed); current++; ProgressBarValue = (int)(((double)current / number_of_items) * 100); ProgressBarValueInfo = ProgressBarValue.ToString(); } Info += $"Added {airlineCompany} airlineCompanies to the dataBase \n"; // airlines List <AirlineCompany> listAirlineCompanies = (List <AirlineCompany>)wpfFacade.GetAllAirlineCompanies(); trynumber = int.TryParse(Flights, out int flights); for (int i = 0; i < listAirlineCompanies.Count; i++) { for (int j = 0; j < flights; j++) { int country = rnd.Next(0, listCountries.Count()); Flight flight = DataGeneratorService.GenerateRandomFlight(); flight.DestinationCountryCode = listCountries[country].ID; country = rnd.Next(0, listCountries.Count()); flight.OriginCountryCode = listCountries[country].ID; wpfFacade.CreateFlight(listAirlineCompanies[i], flight); current++; ProgressBarValue = (int)(((double)current / number_of_items) * 100); ProgressBarValueInfo = ProgressBarValue.ToString(); } } Info += $"Added {flights} flights to every airline in the dataBase \n"; // flights trynumber = int.TryParse(Customer, out int customers); for (int i = 0; i < customers; i++) { do { try { wpfFacade.CreateCustomerAndUserRepository(DataGeneratorService.GenerateRandomUserRepositoryForCustomer(), DataGeneratorService.GenerateRandomCustomer());// help succeed = true; } catch (UserNameAlreadyExistsException) { succeed = false; } }while (!succeed); current++; ProgressBarValue = (int)(((double)current / number_of_items) * 100); ProgressBarValueInfo = ProgressBarValue.ToString(); } Info += $"Added {customers} customers to the dataBase \n"; // customers List <Flight> listFlights = (List <Flight>)wpfFacade.GetAllFlights(); List <Customer> listCustomers = (List <Customer>)wpfFacade.GetAllCustomers(); trynumber = int.TryParse(Ticket, out int ticket); for (int i = 0; i < listCustomers.Count; i++) { for (int j = 0; j < ticket; j++) { int flight = rnd.Next(0, listFlights.Count()); wpfFacade.PurchaseTicket(listCustomers[i], listFlights[flight]); current++; ProgressBarValue = (int)(((double)current / number_of_items) * 100); ProgressBarValueInfo = ProgressBarValue.ToString(); } } Info += $"Added {ticket} tickets to every customer in the dataBase \n"; WorkNotInProgress = true; } ); // tickets }
/// <summary> /// Main program! /// </summary> static void Main(string[] args) { // Logger.LogDebug(LE.Main, "Starting Program .."); // DI ServiceProvider serviceProvider = Startup.BuildServiceProvider(); // The Logger ILogger <Program> logger = serviceProvider.GetService <ILoggerFactory>().CreateLogger <Program>(); logger.LogInformation("Starting the Program .."); // Generate the data! { Random rnd = new Random(); var logoIndex = 0; IMainController mainController = serviceProvider.GetService <IMainController>(); DataGeneratorService gen = serviceProvider.GetService <DataGeneratorService>(); logger.LogDebug("Saving Personas..."); List <Persona> personas = gen.GeneratePersonas(); foreach (var persona in personas) { mainController.Save(persona); logger.LogDebug(LE.Generate, JsonConvert.SerializeObject(persona)); } logger.LogDebug("Saving Logos..."); List <Logo> logos = gen.GenerateLogos(); foreach (var logo in logos) { mainController.Save(logo); logger.LogDebug(LE.Generate, JsonConvert.SerializeObject(logo)); } // Una vez guardados en la base de datos, obtenerlos. var dbLogos = mainController.GetLogos(); var dbPersonas = mainController.GetPersonas(); logger.LogDebug("Saving Vehiculos..."); List <Vehiculo> vehiculos = gen.GenerateVehiculos(); foreach (var vehiculo in vehiculos) { // Set persona (aleatorio): vehiculo.persona = dbPersonas[rnd.Next(personas.Count)]; // Get logo: vehiculo.logos = new List <Logo>(); var logo = dbLogos[logoIndex++]; // Set rol al logo: logo.rol = vehiculo.persona.rol; // Set logo: vehiculo.logos.Add(logo); // Update logo + Save vehiculo: mainController.Update(logo); mainController.Save(vehiculo); logger.LogDebug(LE.Generate, JsonConvert.SerializeObject(vehiculo)); } // Generar registros: var dbVehiculos = mainController.GetVehiculos(); int registroIndex = 0; logger.LogDebug("Saving Registros..."); List <Registro> registros = gen.GenerateRegistros(dbVehiculos.Count); foreach (var registro in registros) { registro.vehiculo = dbVehiculos[registroIndex++]; mainController.Save(registro); logger.LogDebug(LE.Generate, JsonConvert.SerializeObject(registro)); } } // The Netscape Communicator try { logger.LogDebug("Configuring ZeroIce Communicator .."); using (var communicator = serviceProvider.GetService <ZeroIceCommunicator>()) { // Initialize in port 10000 communicator.initialize(10000); // Wait for communicator to shut down logger.LogDebug("Communicator OK, starting the server .."); communicator.start(); } } catch (System.Exception e) { logger.LogError("Error", e); } logger.LogInformation("Done."); }