コード例 #1
0
ファイル: CdmAttributeContext.cs プロジェクト: rt112000/CDM
        internal static CdmAttributeContext CreateChildUnder(ResolveOptions resOpt, AttributeContextParameters acp)
        {
            if (acp == null)
            {
                return(null);
            }

            if (acp.type == CdmAttributeContextType.PassThrough)
            {
                return(acp.under);
            }

            // this flag makes sure we hold on to any resolved object refs when things get copied
            resOpt.SaveResolutionsOnCopy = true;

            CdmObjectReference definition = null;
            ResolvedTraitSet   rtsApplied = null;

            // get a simple reference to definition object to avoid getting the traits that might be part of this ref
            // included in the link to the definition.
            if (acp.Regarding != null)
            {
                // make a portable reference. this MUST be fixed up when the context node lands in the final document
                definition = (acp.Regarding as CdmObjectBase).CreatePortableReference(resOpt);
                // now get the traits applied at this reference (applied only, not the ones that are part of the definition of the object)
                // and make them the traits for this context
                if (acp.IncludeTraits)
                {
                    rtsApplied = (acp.Regarding as CdmObjectBase).FetchResolvedTraits(resOpt);
                }
            }

            CdmAttributeContext underChild = acp.under.Ctx.Corpus.MakeObject <CdmAttributeContext>(CdmObjectType.AttributeContextDef, acp.Name);

            // need context to make this a 'live' object
            underChild.Ctx        = acp.under.Ctx;
            underChild.InDocument = acp.under.InDocument;
            underChild.Type       = acp.type;
            underChild.Definition = definition;
            // add traits if there are any
            if (rtsApplied?.Set != null)
            {
                rtsApplied.Set.ForEach(rt =>
                {
                    var traitRef = CdmObjectBase.ResolvedTraitToTraitRef(resOpt, rt);
                    underChild.ExhibitsTraits.Add(traitRef);
                });
            }

            // add to parent
            underChild.SetParent(resOpt, acp.under);

            if (resOpt.MapOldCtxToNewCtx != null)
            {
                resOpt.MapOldCtxToNewCtx[underChild] = underChild; // so we can find every node, not only the replaced ones
            }

            return(underChild);
        }
コード例 #2
0
        internal static CdmAttributeContext CreateChildUnder(ResolveOptions resOpt, AttributeContextParameters acp)
        {
            if (acp == null)
            {
                return(null);
            }

            if (acp.type == CdmAttributeContextType.PassThrough)
            {
                return(acp.under as CdmAttributeContext);
            }

            // this flag makes sure we hold on to any resolved object refs when things get copied
            ResolveOptions resOptCopy = CdmObjectBase.CopyResolveOptions(resOpt);

            resOptCopy.SaveResolutionsOnCopy = true;

            CdmObjectReference definition = null;
            ResolvedTraitSet   rtsApplied = null;

            // get a simple reference to definition object to avoid getting the traits that might be part of this ref
            // included in the link to the definition.
            if (acp.Regarding != null)
            {
                definition            = acp.Regarding.CreateSimpleReference(resOptCopy);
                definition.InDocument = acp.under.InDocument; // ref is in same doc as context
                // now get the traits applied at this reference (applied only, not the ones that are part of the definition of the object)
                // and make them the traits for this context
                if (acp.IncludeTraits)
                {
                    rtsApplied = (acp.Regarding as CdmObjectBase).FetchResolvedTraits(resOptCopy);
                }
            }

            CdmAttributeContext underChild = acp.under.Ctx.Corpus.MakeObject <CdmAttributeContext>(CdmObjectType.AttributeContextDef, acp.Name);

            // need context to make this a 'live' object
            underChild.Ctx        = acp.under.Ctx;
            underChild.InDocument = (acp.under as CdmAttributeContext).InDocument;
            underChild.Type       = acp.type;
            underChild.Definition = definition;
            // add traits if there are any
            if (rtsApplied?.Set != null)
            {
                rtsApplied.Set.ForEach(rt =>
                {
                    var traitRef = CdmObjectBase.ResolvedTraitToTraitRef(resOptCopy, rt);
                    underChild.ExhibitsTraits.Add(traitRef);
                });
            }

            // add to parent
            underChild.SetParent(resOptCopy, acp.under as CdmAttributeContext);

            return(underChild);
        }
コード例 #3
0
ファイル: CdmAttributeContext.cs プロジェクト: ppothnis/CDM-1
        internal CdmAttributeContext CopyAttributeContextTree(ResolveOptions resOpt, CdmAttributeContext newNode, ResolvedAttributeSet ras, HashSet <CdmAttributeContext> attCtxSet = null, string moniker = null)
        {
            ResolvedAttribute ra = null;

            ras.AttCtx2ra.TryGetValue(this, out ra);
            if (ra != null)
            {
                ras.CacheAttributeContext(newNode, ra);
            }

            // add context to set
            if (attCtxSet != null)
            {
                attCtxSet.Add(newNode);
            }

            // add moniker if this is a reference
            //if (!string.IsNullOrWhiteSpace(moniker) && newNode.Definition?.NamedReference?.StartsWith(moniker) == false)
            if (!string.IsNullOrWhiteSpace(moniker) && newNode.Definition?.NamedReference != null)
            {
                newNode.Definition.NamedReference = $"{moniker}/{newNode.Definition.NamedReference}";
            }

            // now copy the children
            if (this.Contents?.Count > 0)
            {
                foreach (CdmObject child in this.Contents)
                {
                    CdmAttributeContext newChild = null;
                    if (child is CdmAttributeContext childAsAttributeContext)
                    {
                        newChild = childAsAttributeContext.CopyNode(resOpt) as CdmAttributeContext;

                        if (newNode != null)
                        {
                            newChild.SetParent(resOpt, newNode);
                        }
                        ResolvedAttributeSet currentRas = ras;
                        if (ra?.Target is ResolvedAttributeSet)
                        {
                            currentRas = ra.Target;
                        }
                        childAsAttributeContext.CopyAttributeContextTree(resOpt, newChild, currentRas, attCtxSet, moniker);
                    }
                }
            }
            return(newNode);
        }