Exemple #1
0
        /// <summary>
        /// args[0] = heartbeat frequency in seconds,
        ///           after startup 1 event is added per heartbeat
        /// args[1] = repeat events?  'true' or 'false'
        ///           once we run out of simulated data, should we start over?
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            _heartbeatInterval = Int32.Parse(args[0]) * 1000;
            bool bKeepGoing = bool.Parse(args[1]);

            //setup
            var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
            var config      = new ConfigurationBuilder()
                              .SetBasePath(Path.Combine(AppContext.BaseDirectory))
                              .AddJsonFile("appsettings.json", optional: true)
                              .Build();
            var options = new DbContextOptionsBuilder <TelematicsContext>()
                          .UseSqlServer(config.GetConnectionString("SecurityConnection"))
                          .Options;
            var context = new TelematicsContext(options);

            LogEventSimulator sim = new LogEventSimulator(context, bKeepGoing);

            //handle Ctrl+C to cancel the simulation
            Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress);
            Console.CancelKeyPress += new ConsoleCancelEventHandler(LogEventSimulator.Stop);
            CancellationTokenSource source = new CancellationTokenSource();
            CancellationToken       token  = source.Token;

            sim.Go();
        }
Exemple #2
0
        public ExportHelper(string connString)
        {
            var options = new DbContextOptionsBuilder <TelematicsContext>()
                          .UseSqlServer(connString)
                          .Options;

            m_Context = new TelematicsContext(options);
        }
Exemple #3
0
        public TelematicsBaseController(TelematicsContext context, IOptions <AppSettings> settings, IDataProtectionProvider provider)
        {
            m_Context     = context;
            m_appSettings = settings.Value;

            string providerId = m_appSettings.ProviderId ?? "otapidemo.nmfta.org";

            m_dataProtector = provider.CreateProtector(providerId);
        }
Exemple #4
0
        public Trip(Driver driver, Vehicle vehicle, List <SimulatedData_HwyDataPoints> route, int heartbeat, string connString)
        {
            m_driver    = driver;
            m_vehicle   = vehicle;
            m_route     = route;
            m_heartbeat = heartbeat;
            var options = new DbContextOptionsBuilder <TelematicsContext>()
                          .UseSqlServer(connString)
                          .Options;

            m_context = new TelematicsContext(options);
        }
Exemple #5
0
        public LogEventSimulator(TelematicsContext context, bool bKeepGoing)
        {
            m_context   = context;
            m_vehicles  = m_context.Vehicle.ToList();
            m_drivers   = m_context.Driver.ToList();
            m_logEvents = m_context.SimulatedData_LogEvent.OrderBy(x => x.createdOrder).ToList();
            m_eventIdx  = 0;
            m_keepGoing = bKeepGoing;

            //the driverId will be used to index into the vehicle
            //and driver lists, so we need to find out how many are available
            m_maxTrucks = m_logEvents.Max(x => x.driverId);
            m_maxTrucks = Math.Min(m_maxTrucks, m_drivers.Count);
            m_maxTrucks = Math.Min(m_maxTrucks, m_vehicles.Count);
        }
Exemple #6
0
        public FaultSimulator(TelematicsContext context, bool bKeepGoing)
        {
            m_context     = context;
            m_trucks      = m_context.Vehicle.ToList();
            m_faultEvents = m_context.SimulatedData_FaultEvents.OrderBy(x => x.createOrder).ToList();
            m_vehicleIdx  = 0;
            m_eventIdx    = 0;
            m_keepGoing   = bKeepGoing;

            if (m_trucks.Count < 1)
            {
                Console.WriteLine("Need at least one vehicle!");
                Console.ReadKey();
                return;
            }
            if (m_faultEvents.Count < 1)
            {
                Console.WriteLine("Need at least one fault event!");
                Console.ReadKey();
                return;
            }
        }
Exemple #7
0
 public VehicleController(TelematicsContext context, IOptions <AppSettings> settings, IDataProtectionProvider provider)
     : base(context, settings, provider)
 {
 }
Exemple #8
0
 public ExportController(TelematicsContext context, IOptions <AppSettings> settings,
                         IDataProtectionProvider provider, IHostingEnvironment host)
     : base(context, settings, provider)
 {
     m_Host = host;
 }
Exemple #9
0
 public BasicAuthenticationService(TelematicsContext dbContext, UserManager <IdentityUser> userManager, RoleManager <IdentityRole> roleManager)
 {
     DbContext     = dbContext;
     m_UserManager = userManager;
     m_RoleManager = roleManager;
 }
Exemple #10
0
 public AccountManagerController(TelematicsContext dbContext, UserManager <IdentityUser> userManager, RoleManager <IdentityRole> roleManager)
 {
     m_DbContext   = dbContext;
     m_UserManager = userManager;
     m_RoleManager = roleManager;
 }
Exemple #11
0
        /// <summary>
        /// args[0] = number of drivers to simulate
        /// args[1] = seconds between adding a location history for a vehicle, in seconds
        /// args[2] = seconds between system status health updates
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            int NumberOfDrivers  = Int32.Parse(args[0]);
            int HeartbeatSeconds = Int32.Parse(args[1]);

            _StatusUpdateInterval = Int32.Parse(args[2]) * 1000;

            //setup
            var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
            var config      = new ConfigurationBuilder()
                              .SetBasePath(Path.Combine(AppContext.BaseDirectory))
                              .AddJsonFile("appsettings.json", optional: true)
                              .Build();
            var options = new DbContextOptionsBuilder <TelematicsContext>()
                          .UseSqlServer(config.GetConnectionString("SecurityConnection"))
                          .Options;
            var context = new TelematicsContext(options);

            //handle Ctrl+C to cancel the simulation
            Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress);
            CancellationTokenSource source = new CancellationTokenSource();
            CancellationToken       token  = source.Token;

            //setup the system health status simulator
            StatusSimulator statusSim = new StatusSimulator(context);

            Console.CancelKeyPress += new ConsoleCancelEventHandler(StatusSimulator.Stop);

            //get the drivers, vechicles and routes
            List <Driver>  drivers    = context.Driver.ToList();
            List <Vehicle> vehicles   = context.Vehicle.ToList();
            List <string>  routeNames = context.SimulatedData_HwyDataPoints.Select(x => x.HwySectionName).Distinct().ToList();

            if ((NumberOfDrivers > drivers.Count) ||
                (NumberOfDrivers > vehicles.Count) ||
                (NumberOfDrivers > routeNames.Count))
            {
                Console.WriteLine("Too many drivers!");
                Console.ReadKey();
                return;
            }
            if (NumberOfDrivers < 1)
            {
                Console.WriteLine("Need at least one driver!");
                Console.ReadKey();
                return;
            }

            //start vehicle location simulation
            var backgroundTasks = new Task[NumberOfDrivers + 1];

            for (int i = 0; i < NumberOfDrivers; i++)
            {
                Driver  driver  = drivers[i];
                Vehicle vehicle = vehicles[i];
                List <SimulatedData_HwyDataPoints> route = context.SimulatedData_HwyDataPoints.Where(x => x.HwySectionName == routeNames[i]).ToList();
                Trip trip = new Trip(driver, vehicle, route, HeartbeatSeconds, config.GetConnectionString("SecurityConnection"));
                Console.WriteLine(string.Format("Adding driver {0} and vehicle {1} to route {2}", driver.username, vehicle.name, routeNames[i]));

                backgroundTasks[i] = Task.Run(() => trip.Go(i));
            }
            backgroundTasks[NumberOfDrivers] = Task.Run(() => statusSim.Go());
            Console.WriteLine("Press Ctrl+C to stop.");
            Task.WaitAll(backgroundTasks, token);
        }
Exemple #12
0
 public StatusSimulator(TelematicsContext context)
 {
     m_context       = context;
     m_statusCounter = 1;
 }