public ValidationTest()
 {
     _parcelV       = new ParcelValidator();
     _recipientV    = new RecipientValidator();
     _truckV        = new TruckValidator();
     _hopArrivalV   = new HopArrivalValidator();
     _trackingInfoV = new TrackingInformationValidator();
     _errorV        = new ErrorValidator();
 }
Esempio n. 2
0
        public TrackingLogic(IParcelRepository parcelRepository, IHopRepository hopRepository, IWarehouseRepository warehouseRepository, ITruckRepository truckRepository)
        {
            _pVal = new ParcelValidator();
            _hVal = new HopArrivalValidator();

            _parcelRepository    = parcelRepository;
            _hopRepository       = hopRepository;
            _warehouseRepository = warehouseRepository;
            _truckRepository     = truckRepository;
        }
Esempio n. 3
0
        public string ValidateParcel(Entities.Parcel blParcel)
        {
            StringBuilder             validationResults   = new StringBuilder();
            var                       validator           = new ParcelValidator();
            ValidationResult          results             = validator.Validate(blParcel);
            bool                      validationSucceeded = results.IsValid;
            IList <ValidationFailure> failures            = results.Errors;

            foreach (var failure in failures)
            {
                validationResults.Append(failure);
            }
            return(validationResults.ToString());
        }
Esempio n. 4
0
        public string TransferParcel(string parcelID, Parcel parcel)
        {
            string senderGeoString    = parcel.Sender.ToGeoCodingString();
            string recipientGeoString = parcel.Recipient.ToGeoCodingString();

            logger.LogDebug($"converting sender geoCodingString '{senderGeoString}' to Location");
            logger.LogDebug($"converting recepient geoCodingString '{recipientGeoString}' to Location");

            Geocoding.Location senderAddress    = geoCodingAgent.EncodeAddress(senderGeoString);
            Geocoding.Location recipientAddress = geoCodingAgent.EncodeAddress(recipientGeoString);

            Data.Hop dataSenderHop;
            Data.Hop dataRecipientHop;
            try
            {
                dataSenderHop    = hopRepository.GetByCoordinates(senderAddress.Latitude, senderAddress.Longitude);
                dataRecipientHop = hopRepository.GetByCoordinates(recipientAddress.Latitude, recipientAddress.Longitude);
            }
            catch (DataAccessLayerException e)
            {
                throw new BusinessLayerException("DAL Exception", e);
            }

            if (dataSenderHop == null || dataRecipientHop == null)
            {
                string errorMessage = "Error";

                NoHopException e = new NoHopException(errorMessage);
                logger.LogError(e, $"No Hop found");
                throw e;
            }

            Data.Warehouse dataWarehouse;
            try
            {
                logger.LogDebug("load full warehouse hierarchy");
                dataWarehouse = wareHouseRepository.Read();
            }
            catch (DataAccessLayerException e)
            {
                throw new BusinessLayerException("DAL Exception", e);
            }

            Hop       senderHop    = this.mapper.Map <Hop>(dataSenderHop);
            Hop       recipientHop = this.mapper.Map <Hop>(dataRecipientHop);
            Warehouse warehouse    = this.mapper.Map <Warehouse>(dataWarehouse);

            logger.LogDebug($"Submiting parcel {parcelID}");
            parcel.Submit(parcelID);

            logger.LogDebug($"calculating route betweend sender {senderHop.Code} and recipeint {recipientHop.Code}");
            List <HopArrival> route = routeCalculator.CalculateRoute(warehouse, senderHop.Code, recipientHop.Code, parcel.EntryDate);



            logger.LogDebug($"validating parcel ({parcelID})");
            ParcelValidator  validator = new ParcelValidator();
            ValidationResult result    = validator.Validate(parcel);

            if (result.IsValid)
            {
                logger.LogDebug($"Parcel ({parcelID}) was valid");
                Data.Parcel dataParcel = this.mapper.Map <Data.Parcel>(parcel);


                logger.LogInformation("Creating Parcel DB entry");
                try {
                    parcelRepository.Create(dataParcel);
                    return(parcelID);
                }
                catch (DataAccessLayerException e)
                {
                    throw new BusinessLayerException("DAL Exception", e);
                }
            }

            else
            {
                InvalidParcelException e = new InvalidParcelException(string.Join("", result.Errors));
                logger.LogError(e, $"Parcel ({parcelID}) was invalid");
                throw e;
            }
        }