示例#1
0
        /// <summary>
        /// Determines whether this Spot instance can be placed within the requested
        /// break or container.
        /// </summary>
        /// <param name="spot">The spot.</param>
        /// <param name="progSmoothBreaks">The prog smooth breaks.</param>
        /// <param name="breakPositionRules">The break position rules.</param>
        /// <param name="respectSpotTime">if set to <c>true</c>, respect spot time.</param>
        /// <param name="validBreaksForSpotTime">The valid breaks for spot time.</param>
        /// <param name="isRestrictedSpotTime">if set to <c>true</c>, is restricted spot time.</param>
        /// <param name="progSmoothBreak">The prog smooth break.</param>
        /// <returns>
        ///   <c>true</c> if this Spot instance can be placed within the break or container requested; otherwise, <c>false</c>.
        /// </returns>
        public static bool CanSpotBePlacedInRequestedBreakOrContainer(
            Spot spot,
            IReadOnlyList <SmoothBreak> progSmoothBreaks,
            SpotPositionRules breakPositionRules,
            bool respectSpotTime,
            IOrderedEnumerable <SmoothBreak> validBreaksForSpotTime,
            bool isRestrictedSpotTime,
            SmoothBreak progSmoothBreak)
        {
            var canAddSpotService = CanAddSpotService.Factory(progSmoothBreak);

            string spotBreakOrContainerRequest = spot.BreakRequest;

            if (ContainerReference.TryParse(spotBreakOrContainerRequest, out ContainerReference cr))
            {
                spotBreakOrContainerRequest = cr.ToString();
            }

            if (canAddSpotService.CanAddSpotWithBreakRequest(spotBreakOrContainerRequest, progSmoothBreaks, breakPositionRules))
            {
                return(true);
            }
            else if (IsBreakWithinSpotTimeRestriction(respectSpotTime, isRestrictedSpotTime, validBreaksForSpotTime, progSmoothBreak))
            {
                return(true);
            }

            return(false);
        }
示例#2
0
        public void TryParse_BreakExternalReferenceIsNotContainer_ReturnsFalse(string breakExternalReference)
        {
            // Arrange

            // Act
            bool result = ContainerReference.TryParse(breakExternalReference, out ContainerReference _);

            // Assert
            _ = result.Should().BeFalse(null);
        }
示例#3
0
        public void TryParse_BreakExternalReferenceIsContainer_ReturnsTrue(string breakExternalReference)
        {
            // Arrange

            // Act
            bool result = ContainerReference.TryParse(breakExternalReference, out ContainerReference cr);

            // Assert
            _ = result.Should().BeTrue(null);
            _ = cr.ToString().Should().Be("break-1", null);
        }
示例#4
0
        /// <inheritdoc/>
        public override bool CanAddSpotWithBreakRequest(
            string spotPositionRequest,
            IReadOnlyList <SmoothBreak> programmeBreaks,
            SpotPositionRules breakPositionRules)
        {
            if (String.IsNullOrWhiteSpace(spotPositionRequest))
            {
                return(true);
            }

            if (ContainerReference.TryParse(
                    _smoothBreak.TheBreak.ExternalBreakRef,
                    out ContainerReference breakContainerReference))
            {
                if (breakContainerReference.Equals(spotPositionRequest))
                {
                    return(true);
                }
            }

            if (!Int32.TryParse(spotPositionRequest, out int requestedContainerNumber))
            {
                return(false);
            }

            // Note: this should never happen but it's better to check to stop
            // index out of range exceptions.
            if (programmeBreaks.Count == 0)
            {
                return(false);
            }

            // All smooth breaks have a link back to their smooth programme, so
            // just use the first one.
            var breakContainer = programmeBreaks[0].SmoothProgramme.BreakContainers;

            requestedContainerNumber = GetActualBreakPositionFromRelativePosition(
                requestedContainerNumber,
                breakContainer.Count);

            return(CanAddSpotAtBreakPosition(
                       requestedContainerNumber,
                       breakContainerReference.ContainerNumber,
                       breakPositionRules));
        }
 public static bool IsContainerReference(BreakExternalReference breakExternalReference) =>
 ContainerReference.TryParse(breakExternalReference, out var _);