public void SendPackageToStationSimulator(GeneratedPackage package) { try { string address = "http://localhost:5000/Station/" + package.DepartureStationId; StationServiceClient station = new StationServiceClient(new WSHttpBinding(), new EndpointAddress(new Uri(address))); station.GetPackageFromCustomer(package); station.Close(); } catch (Exception exception) { Log("Exception: " + exception.Message); } }
private void Simulation() { _currentTaskIsFinished = true; while (_isWorking) { if (_tasks.Count > 0) { DoNextTask(); _currentTaskIsFinished = false; switch (_currentTask.Type) { case DroneTaskType.TakePackage: break; case DroneTaskType.GoToStation: Log($"moving to statation {_currentTask.Station.Id}"); // todo over time float distanceLat = Math.Abs(_currentTask.Station.Latitude - Latitude); float distanceLon = Math.Abs(_currentTask.Station.Longitude - Longitude); int ticks = (int)Math.Sqrt(Math.Pow(distanceLat, 2) + Math.Pow(distanceLon, 2)); distanceLat *= Latitude > _currentTask.Station.Latitude ? 1 : -1; distanceLon *= Longitude > _currentTask.Station.Longitude ? 1 : -1; ticks %= 100; for (int i = 0; i < ticks; i++) { Thread.Sleep(5000); Latitude += distanceLat / 100; Longitude += distanceLon / 100; } Latitude = _currentTask.Station.Latitude; Longitude = _currentTask.Station.Longitude; string address = "http://localhost:5000/Station/" + _currentTask.Station.Id; StationServiceClient stationServiceClient = new StationServiceClient(new WSHttpBinding(), new EndpointAddress(new Uri(address))); DronePost.DataModel.Drone tmpDrone = new DronePost.DataModel.Drone() { Id = this.Id, Longitude = this.Longitude, Latitude = this.Latitude, Model = this.Model }; stationServiceClient.CheckIn(tmpDrone); Log($"arrived to statation {_currentTask.Station.Id}"); break; case DroneTaskType.LeavePackage: break; case DroneTaskType.ChargeAtStation: break; } _currentTaskIsFinished = true; } else { Thread.Sleep(5000); // Wait 5 secends for new tasks. } } }