private void AssignShipmentToDrone(ShipmentInfo shipment, DroneInfo drone)
 {
     _logger.Log("Assignig shipment #{0} to drone {1}", shipment.Id, drone.Name);
     shipment.DroneId = drone.Id;
     _shipmentBll.UpdateShipment(shipment);
     _shipmentBll.AssignDroneToShipment(drone.Id, shipment.Id);
 }
        public int AddDrone(DroneInfo drone)
        {
            // Validate input
            if (drone == null) {
                throw new ArgumentNullException("drone");
            }

            return dal.AddDrone(drone);
        }
        public int AddDrone(DroneInfo drone)
        {
            int id = 0;

            using (SqlDataReader rdr = SqlHelper.ExecuteReader(_connString, ADD_DRONE,
                drone.Name, drone.Status, drone.Longitude, drone.Latitude, drone.MaxWeight)) {
                if (rdr.Read())
                    id = Convert.ToInt32(rdr.GetDecimal(0));
            }

            drone.Id = id;

            return id;
        }
 public ActionResult AddDrone(string name, decimal maxWeight, int baseId)
 {
     var addressBll = new AddressBLL();
     var baseInfo = _baseBll.Get(baseId);
     var postalCodeInfo = addressBll.GeoCodePostalCode(baseInfo.Address.ZipCode);
     var drone = new DroneInfo {
         Name =  name,
         MaxWeight = maxWeight,
         Status = DroneStatus.Available,
         Latitude = postalCodeInfo.Latitude,
         Longitude = postalCodeInfo.Longitude
     };
     _droneBll.AddDrone(drone);
     return RedirectToAction("Index");
 }
        private DroneInfo FillFromReader(SqlDataReader rdr)
        {
            DroneInfo drone = new DroneInfo();

            drone.Id = (int) rdr["Id"];

            if (rdr["Name"] != DBNull.Value) {
                drone.Name = (string) rdr["Name"];
            }

            if (rdr["Status"] != DBNull.Value) {
                drone.Status = (DroneStatus) rdr["Status"];
            }

            if (rdr["MaxWeight"] != DBNull.Value) {
                drone.MaxWeight = (decimal) rdr["MaxWeight"];
            }

            drone.Longitude = (decimal) rdr["Longitude"];
            drone.Latitude = (decimal) rdr["Latitude"];

            return drone;
        }
示例#6
0
        static void Main(string[] args)
        {
            ShipmentBLL shipBll = new ShipmentBLL();
            DroneBLL droneBll = new DroneBLL();

            ShipmentInfo shipment = new ShipmentInfo();
            shipment.DestinationAddress = new AddressInfo();
            shipment.DestinationAddress.Address1 = "335 Laird Road";
            shipment.DestinationAddress.City = "Guelph";
            shipment.DestinationAddress.Country = "Canada";
            shipment.DestinationAddress.State = "Ontario";
            shipment.DestinationAddress.ZipCode = "N1H 6J3";
            shipment.DestinationAddress.Latitude = 43.50501M;
            shipment.DestinationAddress.Longitude = -80.26827M;
            shipment.Weight = 1M;
            shipment.Status = ShipmentStatus.AwaitingShipment;
            shipment.SourceAddress = new AddressInfo();
            shipment.SourceAddress.Address1 = "8725 Yonge St";
            shipment.SourceAddress.City = "Richmond Hill";
            shipment.SourceAddress.Country = "Canada";
            shipment.SourceAddress.State = "Ontario";
            shipment.SourceAddress.ZipCode = "L4C 6Z1";
            shipment.SourceAddress.Latitude = 43.84292M;
            shipment.SourceAddress.Longitude = -79.43053M;
            shipBll.AddShipment(shipment);

            DroneInfo drone = new DroneInfo();
            drone.Latitude = 43.86071M;
            drone.Longitude = -79.37736M;
            drone.MaxWeight = 1000M;
            drone.Name = "DRONE 001";
            drone.Status = DroneStatus.Available;
            droneBll.AddDrone(drone);

            shipBll.AssignDroneToShipment(drone.Id, shipment.Id);
        }
        private void TravelTo(DroneBLL droneBLL, DroneInfo drone, decimal destinationLongitude, decimal destinationLatitude, int maxTravelTime)
        {
            int currentTravelTime = 0;

            decimal totalLatitudeDistanceToTravel = drone.Latitude > destinationLatitude ? -(drone.Latitude - destinationLatitude) : destinationLatitude - drone.Latitude;
            decimal totalLongitudeDistanceToTravel = drone.Longitude > destinationLongitude ? -(drone.Longitude - destinationLongitude) : destinationLongitude - drone.Longitude;

            decimal latitudeIncrement = totalLatitudeDistanceToTravel / Convert.ToDecimal(maxTravelTime);
            decimal longitudeIncrement = totalLongitudeDistanceToTravel / Convert.ToDecimal(maxTravelTime);

            // will update every second
            while (currentTravelTime < maxTravelTime) {

                drone.Latitude += latitudeIncrement;
                drone.Longitude += longitudeIncrement;

                droneBLL.UpdateDrone(drone);

                currentTravelTime += 1;
                Thread.Sleep(1000);
            }
        }
 public void UpdateDrone(DroneInfo drone)
 {
     SqlHelper.ExecuteNonQuery(_connString, UPDATE_DRONE, drone.Id,
      drone.Name, drone.Status, drone.Longitude, drone.Latitude, drone.MaxWeight);
 }
 public void UpdateDrone(DroneInfo drone)
 {
     dal.UpdateDrone(drone);
 }