Esempio n. 1
0
        void GoToVertexWithAirplane(FollowMeCar followme, int DestinationVertex)
        {
            Console.WriteLine($"FollowMe {followme.FollowMeId} is waiting for motion permission in " +
                              $"vertex {followme.LocationVertex} to go to vertex {DestinationVertex}");
            WaitForMotionPermission(followme, DestinationVertex);
            Console.WriteLine($"FollowMe {followme.FollowMeId} got permission to go to {DestinationVertex}");
            var StartVertex = followme.LocationVertex;

            MqClient.Send <FollowMeCommand>(queuesTo[Component.Airplane], new FollowMeCommand()
            {
                FollowMeId        = followme.FollowMeId,
                DestinationVertex = DestinationVertex,
                PlaneId           = followme.PlaneId
            });
            MakeAMove(followme, DestinationVertex);
            Console.WriteLine($"FollowMe {followme.FollowMeId} is in vertex {DestinationVertex}");
            Console.WriteLine($"FollowMe {followme.FollowMeId} is waiting for airplane " +
                              $"{followme.PlaneId} in {followme.LocationVertex}");
            while (!followme.GotAirplaneResponse)           //wait for airplane response
            {
                source.CreateToken().Sleep(10);
            }
            Console.WriteLine($"FollowMe {followme.FollowMeId} got airplane {followme.PlaneId} response staying in {followme.LocationVertex}");
            MqClient.Send <MotionPermissionRequest>(queuesTo[Component.GroundMotion], //free edge
                                                    new MotionPermissionRequest()
            {
                Action            = MotionAction.Free,
                DestinationVertex = DestinationVertex,
                Component         = Component.FollowMe,
                ObjectId          = followme.FollowMeId,
                StartVertex       = StartVertex
            });
            followme.GotAirplaneResponse = false;
        }
Esempio n. 2
0
 Task TransferAirplane(FollowMeCar followme, AirplaneTransferCommand cmd)
 {
     return(new Task(() =>
     {
         GoPath(GoToVertexAlone, followme, cmd.PlaneLocationVertex);
         GoPath(GoToVertexWithAirplane, followme, cmd.DestinationVertex);
         MqClient.Send <ServiceCompletionMessage>(queuesTo[Component.GroundService], new ServiceCompletionMessage()
         {
             Component = Component.FollowMe,
             PlaneId = followme.PlaneId
         });
         SendToLogs("Completed transfering airplane ID " + cmd.PlaneId);
         Console.WriteLine($"FollowMe {followme.FollowMeId} completed transfering airplane ID "
                           + cmd.PlaneId);
         followme.Status = Status.Free;
         Console.WriteLine($"FollowMe {followme.FollowMeId} is free now and going home");
         var source = new CancellationTokenSource();     //adds token and remove it after went home/new cmd
         tokens.TryAdd(followme.FollowMeId, source);
         GoPathHome(followme, GetHomeVertex(), source.Token);
         if (source.Token.IsCancellationRequested)
         {
             Console.WriteLine($"FollowMe {followme.FollowMeId} is going on new task");
         }
         else
         {
             Console.WriteLine($"FollowMe {followme.FollowMeId} is in garage now");
         }
         tokens.Remove(followme.FollowMeId, out source);
     }));
 }
Esempio n. 3
0
 void FillCollections()
 {
     for (int i = 0; i < countCars; i++)
     {
         var followme = new FollowMeCar(i);
         followme.LocationVertex = GetHomeVertex();
         cars.TryAdd(followme.FollowMeId, followme);
     }
 }
Esempio n. 4
0
        void GoPath(GoToVertexAction action, FollowMeCar followme, int destinationVertex)
        {
            var path = map.FindShortcut(followme.LocationVertex, destinationVertex);

            for (int i = 0; i < path.Count - 1; i++)
            {
                action(followme, path[i + 1]);
            }
        }
Esempio n. 5
0
        void MakeAMove(FollowMeCar followme, int DestinationVertex)     //just move to vertex
        {
            int distance = map.Graph.GetWeightBetweenNearVerties(followme.LocationVertex, DestinationVertex);

            SendVisualizationMessage(followme, DestinationVertex, FollowMeCar.Speed);
            source.CreateToken().Sleep(distance * 1000 / FollowMeCar.Speed);
            SendVisualizationMessage(followme, DestinationVertex, 0);
            followme.LocationVertex  = DestinationVertex;
            followme.MotionPermitted = false;
        }
Esempio n. 6
0
 void SendVisualizationMessage(FollowMeCar followme, int DestinationVertex, int speed)
 {
     MqClient.Send <VisualizationMessage>(queuesTo[Component.Visualizer], new VisualizationMessage()
     {
         ObjectId          = followme.FollowMeId,
         DestinationVertex = DestinationVertex,
         Speed             = speed,
         StartVertex       = followme.LocationVertex,
         Type = Component.FollowMe
     });
 }
Esempio n. 7
0
        void GoPathHome(FollowMeCar followme, int destinationVertex,
                        CancellationToken cancellationToken)
        {
            var path = map.FindShortcut(followme.LocationVertex, destinationVertex);

            for (int i = 0; i < path.Count - 1; i++)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    break;
                }
                GoToVertexAlone(followme, path[i + 1]);
            }
        }
Esempio n. 8
0
        void WaitForMotionPermission(FollowMeCar followme, int DestinationVertex)
        {
            MqClient.Send <MotionPermissionRequest>(queuesTo[Component.GroundMotion], //permission request
                                                    new MotionPermissionRequest()
            {
                Action            = MotionAction.Occupy,
                Component         = Component.FollowMe,
                DestinationVertex = DestinationVertex,
                ObjectId          = followme.FollowMeId,
                StartVertex       = followme.LocationVertex
            });

            while (!followme.MotionPermitted)               //check if followme can go
            {
                source.CreateToken().Sleep(10);
            }
        }
Esempio n. 9
0
        void GoToVertexAlone(FollowMeCar followme, int DestinationVertex)
        {
            Console.WriteLine($"FollowMe {followme.FollowMeId} is waiting for motion permission in " +
                              $"vertex {followme.LocationVertex} to go to vertex {DestinationVertex}");
            WaitForMotionPermission(followme, DestinationVertex);
            Console.WriteLine($"FollowMe {followme.FollowMeId} got permission to go to {DestinationVertex}");
            var startVertex = followme.LocationVertex;

            MakeAMove(followme, DestinationVertex);
            Console.WriteLine($"FollowMe {followme.FollowMeId} is in vertex {DestinationVertex}");
            MqClient.Send <MotionPermissionRequest>(queuesTo[Component.GroundMotion], //free edge
                                                    new MotionPermissionRequest()
            {
                Action            = MotionAction.Free,
                DestinationVertex = DestinationVertex,
                Component         = Component.FollowMe,
                ObjectId          = followme.FollowMeId,
                StartVertex       = startVertex
            });
        }
Esempio n. 10
0
 void Subscribe()
 {
     MqClient.SubscribeTo <NewTimeSpeedFactor>(queuesFrom[Component.TimeService], mes =>  //timespeed
     {
         timeFactor        = mes.Factor;
         source.TimeFactor = timeFactor;
     });
     MqClient.SubscribeTo <AirplaneTransferCommand>(queuesFrom[Component.GroundService], cmd =>      //groundservice
                                                    GotTransferRequest(cmd).Start());
     MqClient.SubscribeTo <MotionPermissionResponse>(queuesFrom[Component.GroundMotion], response => //groundmotion
                                                     cars[response.ObjectId].MotionPermitted = true);
     MqClient.SubscribeTo <ArrivalConfirmation>(queuesFrom[Component.Airplane], mes =>               //airpane
     {
         FollowMeCar followme = null;
         followme             = cars[mes.FollowMeId];
         if (followme.PlaneId == mes.PlaneId)
         {
             followme.GotAirplaneResponse = true;
         }
     });
 }