Ejemplo n.º 1
0
            public MatchingItems(AssumedTypes.IList dataChildren, CObject constraint) : base()
            {
                Check.Require(dataChildren != null, string.Format(CommonStrings.XMustNotBeNull, "dataChildren"));
                Check.Require(constraint != null, string.Format(CommonStrings.XMustNotBeNull, "constraint"));

                Constraint    = constraint;
                NameAttribute = NameAttributeConstraint(constraint);
                Lower         = constraint.Occurrences.Lower;
                Upper         = constraint.Occurrences.UpperUnbounded ? long.MaxValue : constraint.Occurrences.Upper;

                CArchetypeRoot archetypeRoot = constraint as CArchetypeRoot;

                NodeId = archetypeRoot != null ? archetypeRoot.ArchetypeId.Value : constraint.NodeId;

                if (!(constraint is ArchetypeSlot))
                {
                    OpenEhr.AssumedTypes.Impl.ILocatableList locatableItems = dataChildren as OpenEhr.AssumedTypes.Impl.ILocatableList;

                    if (locatableItems != null)
                    {
                        Check.Assert(!string.IsNullOrEmpty(NodeId), string.Format(CommonStrings.XMustNotBeNullOrEmpty, "NodeId"));

                        if (locatableItems.Contains(NodeId))
                        {
                            foreach (OpenEhr.RM.Common.Archetyped.Impl.Locatable locatable in (System.Collections.IEnumerable)locatableItems[NodeId])
                            {
                                if (NameAttribute == null || NameAttribute.ValidValue(locatable.Name))
                                {
                                    Add(locatable);
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (object item in dataChildren)
                        {
                            IRmType rmType = item as IRmType;

                            if (rmType != null && constraint.IsSameRmType(rmType))
                            {
                                Add(item);
                            }
                        }
                    }
                }

                Check.Ensure(Constraint == constraint);
            }
Ejemplo n.º 2
0
        private bool IsOrderedChildrenValid(AssumedTypes.IList dataChildren)
        {
            Check.Require(dataChildren != null, string.Format(CommonStrings.XMustNotBeNull, "children"));

            int  n      = 0;
            bool result = true;

            foreach (object dataItem in dataChildren)
            {
                int        startingPoint  = n;
                CObject    matchedCObject = null;
                string     dataItemRmType = ((IRmType)dataItem).GetRmTypeName();
                ILocatable locatable      = dataItem as ILocatable;

                while (n < Children.Count)
                {
                    CObject eachChild = Children[n];

                    if (locatable == null || locatable.ArchetypeNodeId == eachChild.ArchetypeNodeId)
                    {
                        if (eachChild.IsSameRmType(dataItem as IRmType))
                        {
                            matchedCObject = eachChild;
                            CComplexObject complexObject = eachChild as CComplexObject;

                            if (complexObject != null)
                            {
                                CAttribute nameAttribute = NameAttributeConstraint(complexObject);

                                if (nameAttribute != null)
                                {
                                    bool nameMatched = false;
                                    AcceptValidationError previousErrorDelegate = ValidationContext.AcceptError;

                                    try
                                    {
                                        ValidationContext.AcceptError = null;
                                        nameMatched = nameAttribute.ValidValue(locatable.Name);
                                    }
                                    finally
                                    {
                                        ValidationContext.AcceptError = previousErrorDelegate;
                                    }

                                    if (nameMatched)
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        n++;
                                        continue;
                                    }
                                }
                            }

                            break;
                        }
                    }

                    n++;
                }

                if (matchedCObject == null)
                {
                    n = startingPoint;
                    bool validationResult = true;

                    if (MatchedWithSlot(locatable, out validationResult))
                    {
                        result = validationResult;
                    }
                    else
                    {
                        result = false;
                        ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.YNotAllowedByAttributeXConstraint, RmAttributeName, dataItemRmType));
                    }
                }
                else if (!matchedCObject.ValidValue(dataItem))
                {
                    result = false;
                }
            }

            return(result);
        }