Esempio n. 1
0
        public SetIntendedShipmentInfoForNotification ToRequest(Guid notificationId)
        {
            DateTime startDate;

            SystemTime.TryParse(StartYear.GetValueOrDefault(), StartMonth.GetValueOrDefault(), StartDay.GetValueOrDefault(), out startDate);

            DateTime endDate;

            SystemTime.TryParse(EndYear.GetValueOrDefault(), EndMonth.GetValueOrDefault(), EndDay.GetValueOrDefault(), out endDate);

            return(new SetIntendedShipmentInfoForNotification(
                       notificationId,
                       int.Parse(NumberOfShipments, NumberStyles.AllowThousands),
                       Convert.ToDecimal(Quantity),
                       Units.GetValueOrDefault(),
                       startDate,
                       endDate));
        }
Esempio n. 2
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            DateTime startDate;
            bool     isValidStartDate = SystemTime.TryParse(StartYear.GetValueOrDefault(), StartMonth.GetValueOrDefault(), StartDay.GetValueOrDefault(), out startDate);

            if (!isValidStartDate)
            {
                yield return(new ValidationResult(IndexResources.FromValid, new[] { "StartDay" }));
            }

            DateTime endDate;
            bool     isValidEndDate = SystemTime.TryParse(EndYear.GetValueOrDefault(), EndMonth.GetValueOrDefault(), EndDay.GetValueOrDefault(), out endDate);

            if (!isValidEndDate)
            {
                yield return(new ValidationResult(IndexResources.ToValid, new[] { "EndDay" }));
            }

            if (!(isValidStartDate && isValidEndDate))
            {
                // Stop further validation if either date is not a valid date
                yield break;
            }

            if (startDate > endDate)
            {
                yield return(new ValidationResult(IndexResources.FromDateAfterToDate, new[] { "StartYear" }));
            }
        }
Esempio n. 3
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (!IsNumberOfShipmentsValid())
            {
                yield return(new ValidationResult(ShipmentResources.NumberOfShipmentsValid, new[] { "NumberOfShipments" }));
            }

            if (!IsQuantityValid() && Units.HasValue)
            {
                yield return(new ValidationResult(string.Format(ShipmentResources.DecimalPlacesValid,
                                                                ShipmentQuantityUnitsMetadata.Precision[Units.Value]), new[] { "Quantity" }));
            }

            DateTime startDate;
            bool     isValidStartDate = SystemTime.TryParse(StartYear.GetValueOrDefault(), StartMonth.GetValueOrDefault(), StartDay.GetValueOrDefault(), out startDate);

            if (!isValidStartDate)
            {
                yield return(new ValidationResult(ShipmentResources.FirstDepartureValid, new[] { "StartDay" }));
            }

            DateTime endDate;
            bool     isValidEndDate = SystemTime.TryParse(EndYear.GetValueOrDefault(), EndMonth.GetValueOrDefault(), EndDay.GetValueOrDefault(), out endDate);

            if (!isValidEndDate)
            {
                yield return(new ValidationResult(ShipmentResources.LastDepartureValid, new[] { "EndDay" }));
            }

            if (!(isValidStartDate && isValidEndDate))
            {
                // Stop further validation if either date is not a valid date
                yield break;
            }

            if (startDate < SystemTime.Now.Date && Status == NotificationStatus.NotSubmitted)
            {
                yield return(new ValidationResult(ShipmentResources.FirstDeparturePastDate, new[] { "StartDay" }));
            }

            if (startDate > endDate)
            {
                yield return(new ValidationResult(ShipmentResources.FirstDepartureBeforeLastDate, new[] { "StartYear" }));
            }

            var monthPeriodLength = IsPreconsentedRecoveryFacility ? 36 : 12;

            if (endDate >= startDate.AddMonths(monthPeriodLength))
            {
                yield return(new ValidationResult(string.Format(ShipmentResources.DepartureDateRange, monthPeriodLength), new[] { "EndYear" }));
            }
        }
Esempio n. 4
0
        public byte[] ToPayload(byte scheduleId, byte?scheduleIdBlock = null)
        {
            int numBytes = 12 + Commands.Sum(cmd => cmd.Command.Length + 1);

            var bytes = new byte[numBytes];

            byte durationType, durationByte1, durationByte2;

            if (Duration.HasValue)
            {
                var    duration = Duration.Value;
                ushort durationNumber;
                if (Duration >= TimeSpan.FromHours(60000))
                {
                    durationType   = DurationTypeDays;
                    durationNumber = (ushort)Math.Min(duration.Days, ushort.MaxValue);
                }
                else if (Duration >= TimeSpan.FromMinutes(60000))
                {
                    durationType   = DurationTypeHours;
                    durationNumber = (ushort)(duration.Days * 24 + duration.Hours);
                }
                else
                {
                    durationType   = DurationTypeMinutes;
                    durationNumber = (ushort)((duration.Days * 24 + duration.Hours) * 60 + duration.Minutes);
                }
                durationByte1 = (byte)(durationNumber / 256);
                durationByte2 = (byte)(durationNumber % 256);
            }
            else
            {
                durationType  = DurationTypeOverride;
                durationByte1 = 0;
                durationByte2 = (byte)OverrideType;
            }

            bytes[0]  = scheduleId;
            bytes[1]  = scheduleIdBlock.GetValueOrDefault(1);
            bytes[2]  = (byte)(StartYear.HasValue ? StartYear - YearOffset : StartYearNotSpecified);
            bytes[3]  = (byte)((int)State << 4 | StartMonth.GetValueOrDefault(StartMonthNotSpecified));
            bytes[4]  = (byte)StartDayOfMonth.GetValueOrDefault(StartDayOfMonthNotSpecified);
            bytes[5]  = (byte)(durationType << 5 | (int)StartWeekdays);
            bytes[6]  = (byte)StartHour.GetValueOrDefault(StartHourNotSpecified);
            bytes[7]  = (byte)StartMinute.GetValueOrDefault(StartMinuteNotSpecified);
            bytes[8]  = durationByte1;
            bytes[9]  = durationByte2;
            bytes[10] = 0; // reports to follow
            bytes[11] = (byte)Commands.Length;

            int index = 12;

            foreach (var cmd in Commands)
            {
                bytes[index] = (byte)cmd.Command.Length;
                index++;
                Array.Copy(cmd.Command, 0, bytes, index, cmd.Command.Length);
                index += cmd.Command.Length;
            }

            return(bytes);
        }