示例#1
0
文件: Program.cs 项目: fSinchuk/swedq
        static void Main(string[] args)
        {
            var connectionString = Environment.GetEnvironmentVariable("CarSignalDb");

            Console.WriteLine(connectionString);

            var serviceProvider = new ServiceCollection().
                                  AddDbContext <DashboardContext>(options => options.UseSqlServer(connectionString)).
                                  AddScoped <ICustomerCarRepository, CustomerCarRepository>().
                                  AddScoped <IRepository <Car_Status>, Repository <Car_Status> >().
                                  AddTransient <ICarStatusService, CarStatusService>().
                                  AddTransient <ICustomerCarService, CustomerCarService>().
                                  BuildServiceProvider();


            ICarStatusService   carStatusService   = serviceProvider.GetService <ICarStatusService>();
            ICustomerCarService customerCarService = serviceProvider.GetService <ICustomerCarService>();

            Do(carStatusService, customerCarService);
        }
示例#2
0
文件: Program.cs 项目: fSinchuk/swedq
        static void Do(ICarStatusService carStatusService, ICustomerCarService customerCarService)
        {
            for (; ;)
            {
                Random rand = new Random();

                var statuses     = carStatusService.GetAll().Result;
                var customerCars = customerCarService.GetAll().Result;

                int statusIndex = GetRandom(statuses, rand);
                int carIndex    = GetRandom(customerCars, rand);

                var statusToSet = statuses.ElementAt(statusIndex);
                var carToChange = customerCars.ElementAt(carIndex);

                customerCarService.UpdateStatus(carToChange.Id, statusToSet.Id);

                Console.WriteLine(DateTime.Now);
                Thread.Sleep(3000);
            }
        }