Пример #1
0
        /// <summary>
        /// Implements IModelErrorOwner.GetErrorCollection
        /// </summary>
        protected new IEnumerable <ModelErrorUsage> GetErrorCollection(ModelErrorUses filter)
        {
            if (filter == 0)
            {
                filter = (ModelErrorUses)(-1);
            }
            if (0 != (filter & (ModelErrorUses.Verbalize | ModelErrorUses.DisplayPrimary)))
            {
                CardinalityRangeOverlapError overlapError = CardinalityRangeOverlapError;
                if (overlapError != null)
                {
                    yield return(overlapError);
                }
                ConstraintDuplicateNameError duplicateName = DuplicateNameError;
                if (duplicateName != null)
                {
                    yield return(duplicateName);
                }
            }

            // Get errors off the base
            foreach (ModelErrorUsage baseError in base.GetErrorCollection(filter))
            {
                yield return(baseError);
            }
        }
Пример #2
0
        /// <summary>
        /// Verify that ranges are ordered and non-overlapping and handle the
        /// corresponding error.
        /// </summary>
        private void ValidateRanges(INotifyElementAdded notifyAdded)
        {
            LinkedElementCollection <CardinalityRange> ranges = RangeCollection;
            int  rangeCount = ranges.Count;
            int  prevMin    = -1;
            int  prevMax    = -1;
            bool hasError   = false;

            for (int i = 0; i < rangeCount; ++i)
            {
                CardinalityRange range = ranges[i];
                int lower = range.LowerBound;
                int upper = range.UpperBound;
                if (upper == -1)
                {
                    upper = int.MaxValue;
                }
                if (lower < 0 ||
                    lower <= prevMin ||
                    lower <= prevMax ||
                    upper <= prevMax)
                {
                    hasError = true;
                    break;
                }
                prevMin = lower;
                prevMax = upper;
            }
            CardinalityRangeOverlapError overlapError = this.CardinalityRangeOverlapError;

            if (hasError)
            {
                if (overlapError == null)
                {
                    overlapError = new CardinalityRangeOverlapError(Partition);
                    overlapError.CardinalityConstraint = this;
                    overlapError.Model = this.Model;
                    overlapError.GenerateErrorText();
                    if (notifyAdded != null)
                    {
                        notifyAdded.ElementAdded(overlapError, true);
                    }
                }
            }
            else if (overlapError != null)
            {
                overlapError.Delete();
            }
        }