コード例 #1
0
 public ShipmentProcessor(ILogger logger)
 {
     _shipmentBll = new ShipmentBLL();
     _addressBll = new AddressBLL();
     _droneBll = new DroneBLL();
     _logger = logger;
 }
コード例 #2
0
        public ActionResult AddShipment(
              string sourceAddress, string sourceCity, string sourcePostalCode
            , string destinationAddress, string destinationCity, string destinationPostalCode
            , decimal weight)
        {
            var shipment = new ShipmentInfo {
                SourceAddress = new AddressInfo{Address1 = sourceAddress, City = sourceCity, ZipCode = sourcePostalCode},
                DestinationAddress = new AddressInfo{Address1 = destinationAddress, City = destinationCity, ZipCode = destinationPostalCode},
                Weight = weight
            };

            var bll = new ShipmentBLL();

            bll.AddShipment(shipment);

            return RedirectToAction("Index");
        }
コード例 #3
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);
        }
コード例 #4
0
        private void ProcessShipment(int shipmentId, int droneId)
        {
            Random r = new Random();
            int travelTime;

            ShipmentBLL shipBLL = new ShipmentBLL();
            DroneBLL droneBLL = new DroneBLL();
            DroneShipmentActivityLogBLL logBLL = new DroneShipmentActivityLogBLL();
            BaseBLL baseBll = new BaseBLL();
            AddressBLL addressBll = new AddressBLL();

            // Start
            ShipmentInfo shipment = shipBLL.GetShipment(shipmentId);
            shipment.Status = ShipmentStatus.InTransit;
            shipment.DroneId = droneId;
            shipBLL.UpdateShipment(shipment);

            DroneShipmentActivityLogInfo log = new DroneShipmentActivityLogInfo();
            log.DroneId = droneId;
            log.ShipmentId = shipmentId;
            log.Message = "Beginning processing";
            logBLL.AddDroneShipmentActivityLog(log);

            // Go pick up shipment
            DroneInfo drone = droneBLL.GetDrone(droneId);
            drone.Status = DroneStatus.PickingUpShipment;
            droneBLL.UpdateDrone(drone);

            log.Message = "Travelling to shipment source for pickup";
            logBLL.AddDroneShipmentActivityLog(log);

            travelTime= r.Next(MIN_TRAVEL_TIME_IN_SECONDS, MAX_TRAVEL_TIME_IN_SECONDS);
            log.Message = string.Format("Estimated time to reach shipment source (in seconds): {0}", travelTime);
            logBLL.AddDroneShipmentActivityLog(log);

            TravelTo(droneBLL, drone, shipment.SourceAddress.Longitude, shipment.SourceAddress.Latitude, travelTime);

            // Deliver shipment

            log.Message = "Delivering shipment to destination";
            logBLL.AddDroneShipmentActivityLog(log);

            drone.Status = DroneStatus.DeliveringShipment;
            droneBLL.UpdateDrone(drone);

            travelTime = r.Next(MIN_TRAVEL_TIME_IN_SECONDS, MAX_TRAVEL_TIME_IN_SECONDS);
            log.Message = string.Format("Estimated time to reach shipment destination (in seconds): {0}", travelTime);
            logBLL.AddDroneShipmentActivityLog(log);

            TravelTo(droneBLL, drone, shipment.DestinationAddress.Longitude, shipment.DestinationAddress.Latitude, travelTime);

            // Shipment delivered
            shipment.Status = ShipmentStatus.Shipped;
            shipBLL.UpdateShipment(shipment);

            log.Message = "Shipment delivered";
            logBLL.AddDroneShipmentActivityLog(log);

            // Returning home
            log.Message = "Returning to base";
            logBLL.AddDroneShipmentActivityLog(log);
            drone.Status = DroneStatus.ReturningToBase;
            droneBLL.UpdateDrone(drone);

            // Find the nearest base and go there
            log.Message = "Locating the nearest base";
            logBLL.AddDroneShipmentActivityLog(log);

            var bases = baseBll.GetAll();
            BaseInfo nearestBase = null;
            double shortestDistance = double.MaxValue;
            foreach (var baseInfo in bases) {
                var distance = addressBll.GetDistanceKm((double)drone.Latitude, (double)drone.Longitude, (double)baseInfo.Address.Latitude, (double)baseInfo.Address.Longitude);
                if (distance < shortestDistance) {
                    shortestDistance = distance;
                    nearestBase = baseInfo;
                }
            }

            log.Message = string.Format("Nearest base is: {0}", nearestBase.Name);
            logBLL.AddDroneShipmentActivityLog(log);
            travelTime = r.Next(MIN_TRAVEL_TIME_IN_SECONDS, MAX_TRAVEL_TIME_IN_SECONDS);
            log.Message = string.Format("Estimated time to reach base (in seconds): {0}", travelTime);
            logBLL.AddDroneShipmentActivityLog(log);

            TravelTo(droneBLL, drone, nearestBase.Address.Longitude, nearestBase.Address.Latitude, travelTime);

            // End
            log.Message = "Now available";
            logBLL.AddDroneShipmentActivityLog(log);

            drone.Status = DroneStatus.Available;
            droneBLL.UpdateDrone(drone);
        }
コード例 #5
0
 // GET: Shipments
 public ActionResult Index()
 {
     var bll = new ShipmentBLL();
     var model = bll.GetShipments(new List<ShipmentStatus> {ShipmentStatus.AwaitingShipment, ShipmentStatus.InTransit, ShipmentStatus.Shipped});
     return View(model);
 }