예제 #1
0
 /// <summary>
 /// Notify ancestors that an element has been added to this <see cref="SchemaAwareContentModelEntity"/>.<br/>
 /// Let the <see cref="ChoiceContentModelEntity"/> class a chance to remove other elements.
 /// </summary>
 /// <param name="owner">The owner of the added element.</param>
 /// <param name="element">The added element.</param>
 /// <param name="parentElement">The parent of the added element.</param>
 internal virtual void OnElementAdded(SchemaAwareContentModelEntity owner, XElement element, XElement parentElement)
 {
     if (this.ParentContentModel != null)
     {
         this.ParentContentModel.OnElementAdded(owner, element, parentElement);
     }
 }
예제 #2
0
        protected SchemaAwareContentModelEntity(params ContentModelEntity[] items)
        {
            elementPositions = new Dictionary <XName, NamedContentModelEntity>();

            foreach (ContentModelEntity cmEntity in items)
            {
                NamedContentModelEntity named = cmEntity as NamedContentModelEntity;
                if (named != null)
                {
                    if (!elementPositions.ContainsKey(named.Name))   //Pick the first position for a repeating name
                    {
                        named.ElementPosition    = last++;
                        named.ParentContentModel = this;
                        elementPositions.Add(named.Name, named);
                        //Add subst members to the same position as head if this a substitution head
                        CheckSubstitutionGroup(named);
                    }
                }
                else   //cmEntity is choice or sequence
                {
                    SchemaAwareContentModelEntity scmEntity = cmEntity as SchemaAwareContentModelEntity;
                    Debug.Assert(scmEntity != null);
                    foreach (NamedContentModelEntity childEntity in scmEntity.ElementPositions.Values)
                    {
                        if (!elementPositions.ContainsKey(childEntity.Name))
                        {
                            childEntity.ElementPosition = last++; //Update position w.r.t parent
                            elementPositions.Add(childEntity.Name, childEntity);
                        }
                    }
                }
            }
        }
예제 #3
0
        private void RemoveChoices(SchemaAwareContentModelEntity elementOwner, XElement parentElement)
        {
            var owners     = elementOwner.GetSelfAndAncestorsUntil(this).ToArray();
            var candidates = parentElement.Elements().Where(elem => this.Contains(elem));
            var toKeep     = parentElement.Elements().Where(elem => owners.Any(owner => owner.Contains(elem)));
            var toRemove   = candidates.Except(toKeep).ToArray();

            foreach (var element in toRemove)
            {
                element.Remove();
            }
        }
예제 #4
0
        protected SchemaAwareContentModelEntity(params ContentModelEntity[] items)
        {
            int num;

            this.elementPositions = new Dictionary <XName, NamedContentModelEntity>();
            ContentModelEntity[] contentModelEntityArray = items;
            for (int i = 0; i < (int)contentModelEntityArray.Length; i++)
            {
                ContentModelEntity      cmEntity = contentModelEntityArray[i];
                NamedContentModelEntity named    = cmEntity as NamedContentModelEntity;
                if (named == null)
                {
                    SchemaAwareContentModelEntity scmEntity = cmEntity as SchemaAwareContentModelEntity;
                    Debug.Assert(scmEntity != null);
                    foreach (NamedContentModelEntity childEntity in scmEntity.ElementPositions.Values)
                    {
                        if (!this.elementPositions.ContainsKey(childEntity.Name))
                        {
                            SchemaAwareContentModelEntity schemaAwareContentModelEntity = this;
                            int num1 = schemaAwareContentModelEntity.last;
                            num = num1;
                            schemaAwareContentModelEntity.last = num1 + 1;
                            childEntity.ElementPosition        = num;
                            this.elementPositions.Add(childEntity.Name, childEntity);
                        }
                    }
                }
                else if (!this.elementPositions.ContainsKey(named.Name))
                {
                    SchemaAwareContentModelEntity schemaAwareContentModelEntity1 = this;
                    int num2 = schemaAwareContentModelEntity1.last;
                    num = num2;
                    schemaAwareContentModelEntity1.last = num2 + 1;
                    named.ElementPosition    = num;
                    named.ParentContentModel = this;
                    this.elementPositions.Add(named.Name, named);
                    this.CheckSubstitutionGroup(named);
                }
            }
        }
예제 #5
0
 internal override void OnElementAdded(SchemaAwareContentModelEntity owner, XElement element, XElement parentElement)
 {
     this.RemoveChoices(owner, parentElement);
     base.OnElementAdded(this, element, parentElement);
 }
예제 #6
0
        internal IEnumerable <SchemaAwareContentModelEntity> GetSelfAndAncestorsUntil(SchemaAwareContentModelEntity ancestor)
        {
            yield return(this);

            foreach (var thisAncestor in this.Ancestors)
            {
                if (thisAncestor == ancestor)
                {
                    break;
                }
                else
                {
                    yield return(thisAncestor);
                }
            }
        }