Exemplo n.º 1
0
        public string OnBoardParcel(ParcelModel parcel)
        {
            try
            {
                // i.   Validation of parcel data
                _trackingLogic.ValidateParcel(parcel);

                // ii.  Create new Tracking Code
                string trackingCode = _trackingLogic.GenerateTrackingCode();
                parcel.TrackingCode = trackingCode;

                // iii. Get GPS coordinates for package address (using Geo Encoding Agent)
                // TODO save geo to DB, maybe save in parcel domain obj?
                GeoPoint geo = _geoAgent.EncodeAddress(string.Format("{0}, {1} {2}", parcel.Recipient.Street, parcel.Recipient.PostalCode, parcel.Recipient.City));
                parcel.Latitude  = geo.Lat;
                parcel.Longitude = geo.Lon;

                // iv.  Write data to database
                _trackingLogic.AddParcel(parcel);

                // v.   Return TrackingCode
                return(trackingCode);
            }
            catch (Exception ex)
            {
                throw new BLException("", ex);
            }
        }
Exemplo n.º 2
0
        public void GoogleAPITest()
        {
            GeoPoint g1 = new GeoPoint((decimal)48.2392831, (decimal)16.3773241); // Technikum
            GeoPoint g2 = _agent.EncodeAddress("Technikum Wien");

            Assert.IsTrue(g1.DistToOtherInMeters(g2) < 100);
        }
Exemplo n.º 3
0
        private DataAccess.Entities.TrackingInformation GenerateTrackingInformation(DataAccess.Entities.Parcel parcel)
        {
            //Create new empty TrackingInformation
            var dalTrackInfo = new DataAccess.Entities.TrackingInformation(DataAccess.Entities.TrackingInformation.StateEnum.InTransportEnum);
            var trackInfoId  = _trackingRepo.Create(dalTrackInfo);

            dalTrackInfo.FutureHops  = new List <DataAccess.Entities.HopArrival>();
            dalTrackInfo.VisitedHops = new List <DataAccess.Entities.HopArrival>();

            //Get destination of parcel
            var blRecipient = _mapper.Map <Entities.Recipient>(parcel.Recipient);
            var saRecipient = _mapper.Map <ServiceAgents.DTOs.Recipient>(blRecipient);
            var saLocation  = _encodingAgent.EncodeAddress(saRecipient);
            var blLocation  = _mapper.Map <Entities.Location>(saLocation);

            //Select nearest truck
            var truck = SelectNearestTruck(blLocation);

            if (truck == null)
            {
                throw new BlException("The given address is not in the range of service");
            }

            //Get itinerary of parcel and create hop arrival estimations
            var warehouses = GetItinerary(truck);
            var date       = DateTime.Now;

            foreach (var wh in warehouses)
            {
                date = date.AddDays((double)wh.Duration);
                var hop = new DataAccess.Entities.HopArrival {
                    DateTime = date, Code = wh.Code, Status = "future", TrackingInformationId = trackInfoId
                };
                _hopArrivalRepo.Create(hop);
                dalTrackInfo.FutureHops.Add(hop);
            }
            date = date.AddDays((double)truck.Duration);
            var truckHop = new DataAccess.Entities.HopArrival {
                DateTime = date, Code = truck.Code, Status = "future", TrackingInformationId = trackInfoId
            };

            _hopArrivalRepo.Create(truckHop);
            dalTrackInfo.FutureHops.Add(truckHop);
            return(dalTrackInfo);
        }