Exemplo n.º 1
0
 /// <summary>
 /// Creates a new instance of Resolve Options using most common parameters.
 /// </summary>
 /// <param name="cdmDocument">Document to use as point of reference when resolving relative paths and symbol names.</param>
 /// <param name="Directives">Directives to use when resolving attributes</param>
 public ResolveOptions(CdmDocumentDefinition cdmDocument, AttributeResolutionDirectiveSet Directives = null)
     : this()
 {
     WrtDoc = cdmDocument;
     // provided or default to 'avoid one to many relationship nesting and to use foreign keys for many to one refs'. this is for back compat with behavior before the corpus has a default directive property
     this.Directives = Directives != null?Directives.Copy() : new AttributeResolutionDirectiveSet(new HashSet <string>()
     {
         "normalized", "referenceOnly"
     });
 }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new instance of Resolve Options using most common parameters.
 /// </summary>
 /// <param name="cdmObject"></param>
 public ResolveOptions(CdmObject cdmObject)
 {
     WrtDoc = FetchDocument(cdmObject);
     // avoid one to many relationship nesting and to use foreign keys for many to one refs.
     Directives = new AttributeResolutionDirectiveSet(new HashSet <string>()
     {
         "normalized", "referenceOnly"
     });
     SymbolRefSet = new SymbolSet();
 }
Exemplo n.º 3
0
        /// <summary>
        /// Updates this depth info to the next level.
        /// </summary>
        /// <param name="resOpt"></param>
        /// <param name="isPolymorphic"></param>
        /// <param name="arc"></param>
        internal void UpdateToNextLevel(ResolveOptions resOpt, bool?isPolymorphic, AttributeResolutionContext arc = null)
        {
            AttributeResolutionDirectiveSet directives = resOpt.Directives;
            bool isByRef = false;

            this.MaxDepth = resOpt.MaxDepth;

            // if using resolution guidance, read its properties first
            if (arc != null)
            {
                if (arc.ResOpt != null)
                {
                    directives = arc.ResOpt.Directives;

                    if (isPolymorphic == null)
                    {
                        isPolymorphic = directives?.Has("selectOne") == true;
                    }
                }

                if (arc.ResGuide?.entityByReference != null)
                {
                    if (arc.ResGuide.entityByReference.referenceOnlyAfterDepth != null)
                    {
                        this.MaxDepth = (int)arc.ResGuide.entityByReference.referenceOnlyAfterDepth;
                    }

                    if (arc.ResGuide.entityByReference.allowReference == true)
                    {
                        isByRef = directives?.Has("referenceOnly") == true;
                    }
                }
            }

            if (directives != null)
            {
                if (directives.Has("noMaxDepth"))
                {
                    // no max? really? what if we loop forever? if you need more than 32 nested entities, then you should buy a different metadata description system
                    this.MaxDepth = MaxDepthLimit;
                }
            }

            // if this is a polymorphic, then skip counting this entity in the depth, else count it
            // if it's already by reference, we won't go one more level down so don't increase current depth
            if (isPolymorphic != true && !isByRef)
            {
                this.CurrentDepth++;

                if (this.CurrentDepth > this.MaxDepth)
                {
                    this.MaxDepthExceeded = true;
                }
            }
        }
        public AttributeResolutionDirectiveSet Copy()
        {
            AttributeResolutionDirectiveSet result = new AttributeResolutionDirectiveSet();

            if (this.Set != null)
            {
                result.Set = new HashSet <string>(this.Set);
            }
            if (this.SetRemoved != null)
            {
                result.SetRemoved = new HashSet <string>(this.SetRemoved);
            }
            result.SortedTag = this.SortedTag;
            return(result);
        }
 public void Merge(AttributeResolutionDirectiveSet directives)
 {
     if (directives != null)
     {
         if (directives.SetRemoved != null)
         {
             // copy over the removed list first
             foreach (string d in directives?.SetRemoved)
             {
                 this.Delete(d);
             }
         }
         if (directives.Set != null)
         {
             foreach (string d in directives?.Set)
             {
                 this.Set.Add(d);
             }
         }
         this.SortedTag = null;
     }
 }