public DeicingComponent()
 {
     cars     = new ConcurrentDictionary <string, DeicingCar>();
     tokens   = new ConcurrentDictionary <string, CancellationTokenSource>();
     mqClient = new RabbitMqClient();
     source   = new PlayDelaySource(TimeSpeedFactor);
 }
 public Baggage()
 {
     cars        = new ConcurrentDictionary <string, BaggageCar>();
     tokens      = new ConcurrentDictionary <string, CancellationTokenSource>();
     mqClient    = new RabbitMqClient();
     sourceDelay = new PlayDelaySource(TimeSpeedFactor);
 }
Example #3
0
 public TransportMotion(string Component, RabbitMqClient MqClient, PlayDelaySource source)
 {
     this.component = Component;
     this.mqClient  = MqClient;
     this.source    = source;
     CreateQueues();
     Subscribe();
 }
Example #4
0
 public FollowMeComponent()
 {
     MqClient = new RabbitMqClient();
     cars     = new ConcurrentDictionary <string, FollowMeCar>();
     tokens   = new ConcurrentDictionary <string, CancellationTokenSource>();
     source   = new PlayDelaySource(timeFactor);
     carTasks = new ConcurrentDictionary <string, Task>();
 }
Example #5
0
 public BusComponent()
 {
     mqClient         = new RabbitMqClient();
     cars             = new ConcurrentDictionary <string, BusCar>();
     commands         = new ConcurrentQueue <PassengersServiceCommand>();
     completionEvents = new ConcurrentDictionary <string, CountdownEvent>();
     playDelaySource  = new PlayDelaySource(timeFactor);
     transportMotion  = new TransportMotion.TransportMotion(Component.Bus, mqClient, playDelaySource);
 }
Example #6
0
 public FuelTruck()
 {
     mqClient         = new RabbitMqClient();
     cars             = new ConcurrentDictionary <string, FuelTruckCar>();
     commands         = new ConcurrentQueue <RefuelServiceCommand>();
     completionEvents = new ConcurrentDictionary <string, CountdownEvent>();
     tokens           = new ConcurrentDictionary <string, CancellationTokenSource>();
     playDelaySource  = new PlayDelaySource(timeFactor);
     transportMotion  = new TransportMotion.TransportMotion(Component.FuelTruck, mqClient, playDelaySource);
 }
 public AirplaneComponent()
 {
     airplanes = new ConcurrentDictionary <string, Airplane>();
     source    = new PlayDelaySource(timeFactor);
 }
Example #8
0
        public void Start()
        {
            mqClient.DeclareQueues(
                queues.ToArray()
                );

            mqClient.PurgeQueues(
                queues.ToArray()
                );

            var cancellationSource = new CancellationTokenSource();
            var cancellationToken  = cancellationSource.Token;
            var playDelaySource    = new PlayDelaySource(timeFactor);

            Task.Run(() =>
            {
                try
                {
                    while (!cancellationToken.IsCancellationRequested)
                    {
                        var num = 4;
                        // generate passengers
                        if (random.NextDouble() < 1.0 / num)
                        {
                            var passenger = generator.GeneratePassenger();
                            Console.WriteLine($"{passenger.PassengerId}: new passenger");
                            idlePassengers.TryAdd(
                                passenger.PassengerId,
                                passenger
                                );
                        }

                        playDelaySource.CreateToken().Sleep(PASSENGER_CREATION_PERIOD_MS / num);
                    }
                } catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }, cancellationToken);

            // Own run for every queue (e.g. waiting-for-response-passengers-from-cashbox)
            Task.Run(() =>
            {
                try
                {
                    while (!cancellationToken.IsCancellationRequested)
                    {
                        // send passengers to do something
                        var copyPassengers = new List <Passenger>(idlePassengers.Values);
                        foreach (var passenger in copyPassengers)
                        {
                            TryToSendPassengerSomewhere(passenger);
                        }

                        playDelaySource.CreateToken().Sleep(PASSENGER_ACTIVITY_PERIOD_MS);
                    }
                } catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }, cancellationToken);

            mqClient.SubscribeTo <Timetable>(TimetableToPassengerQueue, (mes) =>
            {
                try
                {
                    Console.WriteLine("Timetable updated");
                    // Careful: do not change to "updating" of timetable, just replace it
                    // Otherwise it can be modified at the same time it's being traversed
                    timetable   = mes;
                    var flights = mes.Flights.Select(f => f.FlightId);
                    foreach (var passenger in passivePassengers.Values)
                    {
                        if (!flights.Contains(passenger.FlightId))
                        {
                            if (passivePassengers.TryRemove(passenger.PassengerId, out var depPassenger))
                            {
                                Console.WriteLine($"{depPassenger.PassengerId} has departed with {depPassenger.FlightId}");
                            }
                            ;
                        }
                    }
                } catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            });

            mqClient.SubscribeTo <TicketResponse>(CashboxToPassengerQueue, (mes) =>
            {
                try
                {
                    HandleCashboxResponse(mes);
                } catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            });

            mqClient.SubscribeTo <CheckInResponse>(RegistrationToPassengerQueue, (mes) =>
            {
                try {
                    HandleRegistrationResponse(mes);
                } catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            });

            mqClient.SubscribeTo <PassengerPassMessage>(BusStorageToPassengerQueue, (mes) =>
            {
                try {
                    HandleBusStorageResponse(mes);
                } catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            });

            mqClient.SubscribeTo <NewTimeSpeedFactor>(TimeServiceToPassengerQueue, (mes) =>
            {
                playDelaySource.TimeFactor = mes.Factor;
            });

            Console.ReadLine();
            cancellationSource.Cancel();
            mqClient.Dispose();
        }