예제 #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              IEventConsumer eventConsumer, IVisitorControl visitorControl, ILocationTypeStrategy locationTypeStrategy,
                              IEventProducer producer, IFairyTaleClient fairyTaleClient, IRideClient rideClient, IStandClient standClient)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            locationTypeStrategy.Register(LocationType.FAIRYTALE,
                                          new VisitorFairyTaleStrategy(producer, fairyTaleClient));
            locationTypeStrategy.Register(LocationType.RIDE,
                                          new VisitorRideStrategy(producer, rideClient));
            locationTypeStrategy.Register(LocationType.STAND,
                                          new VisitorStandStrategy(producer, standClient));

            app.UseRouting();
            app.UseCors(DefaultCorsPolicy);

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            _ = Task.Run(() => eventConsumer.Listen());

            _ = Task.Run(() =>
            {
                while (true)
                {
                    visitorControl.HandleIdleVisitors();

                    Task.Delay(300).Wait();
                }
            });

            _ = Task.Run(() =>
            {
                Random random       = new Random();
                int maxVisitors     = 2000;
                int currentVisitors = 0;
                while (currentVisitors <= maxVisitors)
                {
                    int newVisitors = random.Next(5, 15);

                    visitorControl.AddVisitors(newVisitors);
                    currentVisitors += newVisitors;
                    Task.Delay(2000).Wait();
                }
            });
        }
예제 #2
0
 public VisitorBoundary(IVisitorControl visitorControl)
 {
     this.visitorControl = visitorControl;
 }
예제 #3
0
 public EventConsumer(IVisitorControl visitorControl, IConfiguration configuration) :
     base("domainEvents", configuration["KafkaBroker"], "visitors")
 {
     this.visitorControl = visitorControl;
 }
 public VisitorNotificationHandler(IVisitorControl visitorControl)
 {
     this.visitorControl = visitorControl;
 }