Пример #1
0
        private void CheckDronesStatus()
        {
            if (_lastDroneTechInfosUpdate == null)
            {
                _lastDroneTechInfosUpdate = new SortedList <int, DroneTechInfo>();
            }
            List <Drone> drones = _db.Drones.Include("Model").ToList();

            foreach (Drone drone in drones)
            {
                string             address = "http://localhost:4999/Drone/" + drone.Id;
                DroneServiceClient client  = new DroneServiceClient(new WSHttpBinding(), new EndpointAddress(new Uri(address)));

                try
                {
                    if (_lastDroneTechInfosUpdate.ContainsKey(drone.Id))
                    {
                        _lastDroneTechInfosUpdate[drone.Id] = client.GetTechInfo();
                    }
                    else
                    {
                        _lastDroneTechInfosUpdate.Add(drone.Id, client.GetTechInfo());
                    }

                    if (_lastDroneTechInfosUpdate[drone.Id].CountOfTasks == 0)
                    {
                        List <Transfer> transfers = _db.Transfers.Include("Drone").ToList();
                        Transfer        transfer  = null;
                        foreach (Transfer t in transfers)
                        {
                            if (t.Drone != null)
                            {
                                if (t.Drone.Id == drone.Id)
                                {
                                    transfer = t;
                                    break;
                                }
                            }
                        }
                        if (transfer == null)
                        {
                        }
                    }
                }
                catch (EndpointNotFoundException e)
                {
                    Log("Could not connect to drone (EndpointNotFoundException)");
                }
                catch (CommunicationException e)
                {
                    Log("Could not connect to drone (CommunicationException)");
                }
                catch (Exception e)
                {
                    Log(e.GetType().ToString());
                    Log(e.Message);
                    Log(e.StackTrace);
                }
            }
        }
Пример #2
0
 public void can_be_established_and_operated()
 {
     var client = new DroneServiceClient();
     client.StartLoadTest(new LoadTestScenario
     {
         Users = new VirtualUserSettings { Amount = 1 },
         Data = new[] { new[] { "" } },
         Endpoint = ""
     });
 }
Пример #3
0
        public void can_be_established_and_operated()
        {
            var client = new DroneServiceClient();

            client.StartLoadTest(new LoadTestScenario
            {
                Users = new VirtualUserSettings {
                    Amount = 1
                },
                Data     = new[] { new[] { "" } },
                Endpoint = ""
            });
        }
Пример #4
0
        private void Simulation()
        {
            _isWorking = true;
            Log("Simulation started.");

            List <Drone> drones = _db.Drones.Include("Model").ToList();
            Random       random = new Random(DateTime.Now.GetHashCode());
            int          max    = _db.Stations.ToList().Count;

            foreach (Drone drone in drones)
            {
                string             address = "http://localhost:4999/Drone/" + drone.Id;
                DroneServiceClient client  =
                    new DroneServiceClient(new WSHttpBinding(), new EndpointAddress(new Uri(address)));
                int closestStationId = random.Next(max) + 1;
                client.AddTask(new DroneTask(DroneTaskType.GoToStation,
                                             _db.Stations.First(s => s.Id == closestStationId)));
                _messageHandler.Handle(String.Format("Drone {0} set to go to station {1}.", drone.Id,
                                                     closestStationId));
            }

            while (_isWorking)
            {
                if (_tasks.Count > 0)
                {
                    CoreTask task = _tasks.Dequeue();
                    switch (task.Type)
                    {
                    case CoreTaskType.CheckDronesStatus:
                        CheckDronesStatus();
                        break;

                    case CoreTaskType.CheckStationsStatus:
                        CheckStationsStatus();
                        break;
                    }
                }
                else
                {
                    Thread.Sleep(5000);
                    _tasks.Enqueue(new CoreTask(CoreTaskType.CheckDronesStatus));
                    _tasks.Enqueue(new CoreTask(CoreTaskType.CheckStationsStatus));
                }
            }
            _messageHandler.Handle("Simulation stoped.");
        }