Exemple #1
0
        /// <summary>
        /// Helper method for matching value ranges. Called after an
        /// <see cref="IElementEquivalence"/> implementation has determined
        /// that this <see cref="CardinalityConstraint"/> and <paramref name="otherCardinalityConstraint"/>
        /// correspond to the same instance.
        /// </summary>
        /// <param name="otherCardinalityConstraint">The equivalent value constraint.</param>
        /// <param name="elementTracker">The <see cref="IEquivalentElementTracker"/> used
        /// to equate ranges.</param>
        protected void MatchRanges(CardinalityConstraint otherCardinalityConstraint, IEquivalentElementTracker elementTracker)
        {
            LinkedElementCollection <CardinalityRange> ranges = RangeCollection;
            int rangeCount = ranges.Count;

            if (rangeCount != 0)
            {
                LinkedElementCollection <CardinalityRange> otherRanges = otherCardinalityConstraint.RangeCollection;
                int otherRangeCount = otherRanges.Count;
                if (otherRangeCount != 0)
                {
                    BitTracker otherMatches = new BitTracker(otherRangeCount);
                    for (int i = 0; i < rangeCount; ++i)
                    {
                        CardinalityRange range = ranges[i];
                        int lower = range.LowerBound;
                        int upper = range.UpperBound;
                        for (int j = 0; j < otherRangeCount; ++j)
                        {
                            if (!otherMatches[j])
                            {
                                CardinalityRange otherRange = otherRanges[j];
                                if (otherRange.LowerBound == lower && otherRange.UpperBound == upper)
                                {
                                    elementTracker.AddEquivalentElement(range, otherRange);
                                    otherMatches[j] = true;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
 private static void AddDelayedValidation(CardinalityConstraint constraint)
 {
     if (!constraint.IsDeleted)
     {
         if (FrameworkDomainModel.DelayValidateElement(constraint, DelayValidateRanges))
         {
             constraint.OnTextChanged();
         }
     }
 }
Exemple #3
0
        private static bool UpdateCardinality(string rangeText, CardinalityConstraint constraint, ConstraintCreator creator)
        {
            LinkedElementCollection <CardinalityRange> ranges;
            int       rangeCount;
            Partition partition;

            if (constraint != null)
            {
                rangeCount = (ranges = constraint.RangeCollection).Count;
                partition  = constraint.Partition;
            }
            else
            {
                ranges     = null;
                rangeCount = 0;
                partition  = null;
            }
            int  nextRange = 0;
            bool retVal    = BasicRange.ParseRangeText(
                rangeText,
                delegate(BasicRange basicRange)
            {
                if (ranges == null)
                {
                    ranges    = (constraint = creator()).RangeCollection;
                    partition = constraint.Partition;
                }
                if (nextRange == rangeCount)
                {
                    ++rangeCount;
                    ranges.Add(new CardinalityRange(partition, new PropertyAssignment(CardinalityRange.LowerBoundDomainPropertyId, basicRange.LowerBound), new PropertyAssignment(CardinalityRange.UpperBoundDomainPropertyId, basicRange.UpperBound)));
                }
                else
                {
                    CardinalityRange range = ranges[nextRange];
                    range.LowerBound       = basicRange.LowerBound;
                    range.UpperBound       = basicRange.UpperBound;
                }
                ++nextRange;
            });

            if (nextRange < rangeCount)
            {
                ranges.RemoveRange(nextRange, rangeCount - nextRange);
            }
            return(retVal);
        }
Exemple #4
0
 /// <summary>
 /// Get an editable display of the current ranges in this constraint.
 /// An editable constraint display must be editable with standard keyboard
 /// characters, so we cannot use symbols such as unicode 2264 (less than or equal)
 /// or 2265 (greater than or equal) to express the editable form of the value ranges.
 /// Therefore, we use ..n for a range with a zero lower bound and n.. for a
 /// range with no upper bound. We will also parse &lt;n as ..(n-1) and &lt;=n as ..n,
 /// as well as &gt;n and &gt;=n.
 /// </summary>
 /// <param name="constraint">The constraint to test. If this is not specified
 /// then return the default range.</param>
 /// <returns>The editable range, or the default range of '0..'.</returns>
 public static string GetEditableRangeDisplay(CardinalityConstraint constraint)
 {
     if (constraint != null)
     {
         LinkedElementCollection <CardinalityRange> ranges = constraint.RangeCollection;
         int count = ranges.Count;
         if (count == 1)
         {
             return(GetEditableRangeText(ranges[0]));
         }
         else
         {
             string[] rangeFields = new string[count];
             for (int i = 0; i < count; ++i)
             {
                 rangeFields[i] = GetEditableRangeText(ranges[i]);
             }
             return(string.Join(CultureInfo.CurrentCulture.TextInfo.ListSeparator + " ", rangeFields));
         }
     }
     return("0..");
 }