public static File ResolveArtifact(string groupId, string artifactId, string version)
    {
        var ivyFile = CreateIvyFileFor(groupId, artifactId, version);

        var ivy = CreateIvy();

        var confs = new string[] {"default"};
        var resolveOptions = new ResolveOptions().setConfs(confs);
        var report = ivy.resolve(ivyFile.toURL(), resolveOptions);

        var artifactFile = report.getAllArtifactsReports()[0].getLocalFile();
        return artifactFile;
    }
Пример #2
0
        public static async Task <ReferenceEntity> ToData(CdmReferencedEntityDeclarationDefinition instance, ResolveOptions resOpt, CopyOptions options)
        {
            var sourceIndex = instance.EntityPath.LastIndexOf("/");

            if (sourceIndex == -1)
            {
                Logger.Error(nameof(ReferencedEntityDeclarationPersistence), instance.Ctx, "There was an error while trying to convert cdm data partition to model.json partition.");

                return(null);
            }

            var referenceEntity = new ReferenceEntity
            {
                Type                    = "ReferenceEntity",
                Name                    = instance.EntityName,
                Source                  = instance.EntityPath.Slice(sourceIndex + 1),
                Description             = instance.Explanation,
                LastFileModifiedTime    = instance.LastFileModifiedTime,
                LastFileStatusCheckTime = instance.LastFileStatusCheckTime
            };

            Utils.ProcessTraitsAndAnnotationsToData(instance.Ctx, referenceEntity, instance.ExhibitsTraits);

            var t2pm = new TraitToPropertyMap(instance);

            var isHiddenTrait = t2pm.FetchTraitReference("is.hidden");

            if (isHiddenTrait != null)
            {
                referenceEntity.IsHidden = true;
            }

            var propertiesTrait = t2pm.FetchTraitReference("is.propertyContent.multiTrait");

            if (propertiesTrait != null)
            {
                referenceEntity.ModelId = propertiesTrait.Arguments.AllItems[0].Value as string;
            }

            return(referenceEntity);
        }
 /// <inheritdoc />
 public override bool IsDerivedFrom(string baseDef, ResolveOptions resOpt = null)
 {
     return(false);
 }
Пример #4
0
        internal ResolvedTraitSet _fetchResolvedTraits(ResolveOptions resOpt = null)
        {
            if (resOpt == null)
            {
                resOpt = new ResolveOptions(this, this.Ctx.Corpus.DefaultResolutionDirectives);
            }

            if (this.NamedReference != null && this.AppliedTraits == null)
            {
                const string   kind             = "rts";
                ResolveContext ctx              = this.Ctx as ResolveContext;
                var            objDef           = this.FetchObjectDefinition <CdmObjectDefinitionBase>(resOpt);
                string         cacheTag         = ctx.Corpus.CreateDefinitionCacheTag(resOpt, this, kind, "", true, objDef != null ? objDef.AtCorpusPath : null);
                dynamic        rtsResultDynamic = null;
                if (cacheTag != null)
                {
                    ctx.Cache.TryGetValue(cacheTag, out rtsResultDynamic);
                }
                ResolvedTraitSet rtsResult = rtsResultDynamic as ResolvedTraitSet;

                // store the previous document set, we will need to add it with
                // children found from the constructResolvedTraits call
                SymbolSet currSymRefSet = resOpt.SymbolRefSet;
                if (currSymRefSet == null)
                {
                    currSymRefSet = new SymbolSet();
                }
                resOpt.SymbolRefSet = new SymbolSet();

                if (rtsResult == null)
                {
                    if (objDef != null)
                    {
                        rtsResult = (objDef as CdmObjectDefinitionBase).FetchResolvedTraits(resOpt);
                        if (rtsResult != null)
                        {
                            rtsResult = rtsResult.DeepCopy();
                        }

                        // register set of possible docs
                        ctx.Corpus.RegisterDefinitionReferenceSymbols(objDef, kind, resOpt.SymbolRefSet);

                        // get the new cache tag now that we have the list of docs
                        cacheTag = ctx.Corpus.CreateDefinitionCacheTag(resOpt, this, kind, "", true, objDef.AtCorpusPath);
                        if (!string.IsNullOrWhiteSpace(cacheTag))
                        {
                            ctx.Cache[cacheTag] = rtsResult;
                        }
                    }
                }
                else
                {
                    // cache was found
                    // get the SymbolSet for this cached object
                    string key = CdmCorpusDefinition.CreateCacheKeyFromObject(this, kind);
                    ctx.Corpus.DefinitionReferenceSymbols.TryGetValue(key, out SymbolSet tempDocRefSet);
                    resOpt.SymbolRefSet = tempDocRefSet;
                }

                // merge child document set with current
                currSymRefSet.Merge(resOpt.SymbolRefSet);
                resOpt.SymbolRefSet = currSymRefSet;

                return(rtsResult);
            }
            else
            {
                return(base.FetchResolvedTraits(resOpt));
            }
        }
Пример #5
0
        internal bool ValidateLineage(ResolveOptions resOpt)
        {
            // run over the attCtx tree and validate that it is self consistent on lineage

            // collect all nodes in the tree
            HashSet <CdmAttributeContext> attCtxInTree    = new HashSet <CdmAttributeContext>();
            Action <CdmObject>            collectAllNodes = null;

            collectAllNodes = (subItem) =>
            {
                CdmAttributeContext ac = subItem as CdmAttributeContext;
                if (ac == null)
                {
                    return;
                }
                attCtxInTree.Add(ac);
                if (ac.Contents == null || ac.Contents.Count == 0)
                {
                    return;
                }
                // look at all children
                foreach (var subSub in ac.Contents)
                {
                    if (subSub.ObjectType == CdmObjectType.AttributeContextDef)
                    {
                        collectAllNodes(subSub);
                    }
                }
            };
            collectAllNodes(this);

            // now make sure every lineage ref is in that set
            Func <CdmObject, bool> CheckLineage = null;

            CheckLineage = (subItem) =>
            {
                CdmAttributeContext ac = subItem as CdmAttributeContext;
                if (ac == null)
                {
                    return(true);
                }

                if (ac.Lineage != null && ac.Lineage.Count > 0)
                {
                    foreach (var lin in ac.Lineage)
                    {
                        if (!attCtxInTree.Contains(lin.ExplicitReference as CdmAttributeContext))
                        {
                            return(false);
                        }
                        //if (!resOpt.MapOldCtxToNewCtx.ContainsKey(lin.ExplicitReference as CdmAttributeContext))
                        //{
                        //return false;
                        //}
                    }
                }

                if (ac.Contents == null || ac.Contents.Count == 0)
                {
                    return(true);
                }
                // look at all children
                foreach (var subSub in ac.Contents)
                {
                    if (subSub.ObjectType == CdmObjectType.AttributeContextDef)
                    {
                        if (CheckLineage(subSub) == false)
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            };
            CheckLineage(this);

            return(true);
        }
Пример #6
0
        internal bool AssociateTreeCopyWithAttributes(ResolveOptions resOpt, ResolvedAttributeSet ras)
        {
            // deep copy the tree. while doing this also collect a map from old attCtx to new equivalent
            // this is where the returned tree fits in
            var cachedCtx = ras.AttributeContext;

            if (cachedCtx.CopyAttributeContextTree(resOpt, this) == null)
            {
                return(false);
            }
            ras.AttributeContext = this;

            // run over the resolved attributes in the copy and use the map to swap the old ctx for the new version
            Action <ResolvedAttributeSet> fixResolveAttributeCtx = null;

            fixResolveAttributeCtx = (rasSub) =>
            {
                rasSub.Set.ForEach(ra =>
                {
                    ra.AttCtx = resOpt.MapOldCtxToNewCtx[ra.AttCtx];
                    // the target for a resolved att can be a typeAttribute OR it can be another resolvedAttributeSet (meaning a group)
                    if (ra.Target is ResolvedAttributeSet)
                    {
                        (ra.Target as ResolvedAttributeSet).AttributeContext = ra.AttCtx;
                        fixResolveAttributeCtx(ra.Target as ResolvedAttributeSet);
                    }
                });
            };
            fixResolveAttributeCtx(ras);

            // now fix any lineage references
            Action <CdmAttributeContext, CdmAttributeContext> FixAttCtxNodeLineage = null;

            FixAttCtxNodeLineage = (ac, acParent) =>
            {
                if (ac == null)
                {
                    return;
                }
                if (acParent != null && ac.Parent != null && ac.Parent.ExplicitReference != null)
                {
                    ac.Parent.ExplicitReference = acParent;
                }
                if (ac.Lineage != null && ac.Lineage.Count > 0)
                {
                    // fix lineage
                    foreach (var lin in ac.Lineage)
                    {
                        if (lin.ExplicitReference != null)
                        {
                            // swap the actual object for the one in the new tree
                            lin.ExplicitReference = resOpt.MapOldCtxToNewCtx[lin.ExplicitReference as CdmAttributeContext];
                        }
                    }
                }

                if (ac.Contents == null || ac.Contents.Count == 0)
                {
                    return;
                }
                // look at all children
                foreach (CdmAttributeContext subSub in ac.Contents)
                {
                    FixAttCtxNodeLineage(subSub, ac);
                }
            };
            FixAttCtxNodeLineage(this, null);

            return(true);
        }
Пример #7
0
 internal override ResolvedAttributeSetBuilder ConstructResolvedAttributes(ResolveOptions resOpt, CdmAttributeContext under = null)
 {
     return(null);
 }
Пример #8
0
 public override dynamic CopyData(ResolveOptions resOpt, CopyOptions options)
 {
     return(CdmObjectBase.CopyData <CdmAttributeContext>(this, resOpt, options));
 }
Пример #9
0
        internal virtual ResolvedTraitSet FetchResolvedTraits(ResolveOptions resOpt = null)
        {
            bool wasPreviouslyResolving = this.Ctx.Corpus.isCurrentlyResolving;

            this.Ctx.Corpus.isCurrentlyResolving = true;
            if (resOpt == null)
            {
                resOpt = new ResolveOptions(this);
            }

            const string            kind      = "rtsb";
            ResolveContext          ctx       = this.Ctx as ResolveContext;
            string                  cacheTagA = ((CdmCorpusDefinition)ctx.Corpus).CreateDefinitionCacheTag(resOpt, this, kind);
            ResolvedTraitSetBuilder rtsbAll   = null;

            if (this.TraitCache == null)
            {
                this.TraitCache = new Dictionary <string, ResolvedTraitSetBuilder>();
            }
            else if (!string.IsNullOrWhiteSpace(cacheTagA))
            {
                this.TraitCache.TryGetValue(cacheTagA, out rtsbAll);
            }

            // store the previous document set, we will need to add it with
            // children found from the constructResolvedTraits call
            SymbolSet currDocRefSet = resOpt.SymbolRefSet;

            if (currDocRefSet == null)
            {
                currDocRefSet = new SymbolSet();
            }
            resOpt.SymbolRefSet = new SymbolSet();

            if (rtsbAll == null)
            {
                rtsbAll = new ResolvedTraitSetBuilder();

                if (!resolvingTraits)
                {
                    resolvingTraits = true;
                    this.ConstructResolvedTraits(rtsbAll, resOpt);
                    resolvingTraits = false;
                }

                CdmObjectDefinitionBase objDef = this.FetchObjectDefinition <CdmObjectDefinitionBase>(resOpt);
                if (objDef != null)
                {
                    // register set of possible docs
                    ((CdmCorpusDefinition)ctx.Corpus).RegisterDefinitionReferenceSymbols(objDef, kind, resOpt.SymbolRefSet);

                    if (rtsbAll.ResolvedTraitSet == null)
                    {
                        // nothing came back, but others will assume there is a set in this builder
                        rtsbAll.ResolvedTraitSet = new ResolvedTraitSet(resOpt);
                    }
                    // get the new cache tag now that we have the list of docs
                    cacheTagA = ((CdmCorpusDefinition)ctx.Corpus).CreateDefinitionCacheTag(resOpt, this, kind);
                    if (!string.IsNullOrWhiteSpace(cacheTagA))
                    {
                        this.TraitCache[cacheTagA] = rtsbAll;
                    }
                }
            }
            else
            {
                // cache was found
                // get the SymbolSet for this cached object
                string key = CdmCorpusDefinition.CreateCacheKeyFromObject(this, kind);
                ((CdmCorpusDefinition)ctx.Corpus).DefinitionReferenceSymbols.TryGetValue(key, out SymbolSet tempDocRefSet);
                resOpt.SymbolRefSet = tempDocRefSet;
            }

            // merge child document set with current
            currDocRefSet.Merge(resOpt.SymbolRefSet);
            resOpt.SymbolRefSet = currDocRefSet;

            this.Ctx.Corpus.isCurrentlyResolving = wasPreviouslyResolving;
            return(rtsbAll.ResolvedTraitSet);
        }
        public static EntityDeclarationDefinition ToData(CdmLocalEntityDeclarationDefinition instance, ResolveOptions resOpt, CopyOptions options)
        {
            var result = new EntityDeclarationDefinition
            {
                Type                         = EntityDeclarationDefinitionType.LocalEntity,
                EntityName                   = instance.EntityName,
                Explanation                  = instance.Explanation,
                ExhibitsTraits               = CopyDataUtils.ListCopyData(resOpt, instance.ExhibitsTraits, options),
                LastFileStatusCheckTime      = TimeUtils.GetFormattedDateString(instance.LastFileStatusCheckTime),
                LastFileModifiedTime         = TimeUtils.GetFormattedDateString(instance.LastFileModifiedTime),
                LastChildFileModifiedTime    = TimeUtils.GetFormattedDateString(instance.LastChildFileModifiedTime),
                EntityPath                   = instance.EntityPath,
                DataPartitions               = Utils.ListCopyData <DataPartition>(resOpt, instance.DataPartitions, options, ensureNonIncremental(instance)),
                DataPartitionPatterns        = Utils.ListCopyData <DataPartitionPattern>(resOpt, instance.DataPartitionPatterns, options, ensureNonIncremental(instance)),
                IncrementalPartitions        = Utils.ListCopyData <DataPartition>(resOpt, instance.IncrementalPartitions, options, ensureIncremental(instance)),
                IncrementalPartitionPatterns = Utils.ListCopyData <DataPartitionPattern>(resOpt, instance.IncrementalPartitionPatterns, options, ensureIncremental(instance))
            };

            return(result);
        }
        public static OperationArrayExpansion ToData(CdmOperationArrayExpansion instance, ResolveOptions resOpt, CopyOptions options)
        {
            if (instance == null)
            {
                return(null);
            }

            OperationArrayExpansion obj = OperationBasePersistence.ToData <OperationArrayExpansion>(instance, resOpt, options);

            obj.StartOrdinal = instance.StartOrdinal;
            obj.EndOrdinal   = instance.EndOrdinal;

            return(obj);
        }
Пример #12
0
        /// <summary>
        /// Get the list of entities that the given entity references
        /// </summary>
        /// <param name="resolvedEntity"> The resolved version of the entity. </param>
        /// <param name="resOpt"> The resolution options to use. </param>
        /// <param name="cdmCorpus"> The instance of the CDM corpus. </param>
        /// <returns> The list of referenced entities. </returns>
        private async Task <List <CdmEntityDefinition> > GetEntityReferences(CdmEntityDefinition resolvedEntity, ResolveOptions resOpt, CdmCorpusDefinition cdmCorpus)
        {
            var atts       = resolvedEntity.Attributes.Cast <CdmTypeAttributeDefinition>();
            var reqdTraits = atts.Select(att => att.AppliedTraits.AllItems.FirstOrDefault(trait => trait.FetchObjectDefinitionName() == "is.linkedEntity.identifier")).Where(trait => trait != null);
            var references = new List <CdmEntityDefinition>();

            foreach (var trait in reqdTraits)
            {
                var constEnt = (trait.Arguments.FetchValue("entityReferences") as CdmEntityReference)?.FetchObjectDefinition <CdmConstantEntityDefinition>(resOpt);
                if (constEnt != null)
                {
                    List <CdmEntityDefinition> refs = new List <CdmEntityDefinition>();
                    foreach (List <string> val in constEnt.ConstantValues)
                    {
                        refs.Add(await cdmCorpus.FetchObjectAsync <CdmEntityDefinition>(cdmCorpus.Storage.CreateAbsoluteCorpusPath(val[0])));
                    }
                    references.AddRange(refs);
                }
            }

            return(references);
        }
Пример #13
0
        public async Task ResolveEntitiesWrt()
        {
            var cdmCorpus = new CdmCorpusDefinition();

            var testInputPath = TestHelper.GetInputFolderPath(testsSubpath, "TestResolveEntitiesWrt");

            ((CdmCorpusDefinition)cdmCorpus).RootPath = testInputPath;
            cdmCorpus.Storage.Mount("local", new LocalAdapter(testInputPath));
            cdmCorpus.Storage.DefaultNamespace = "local";
            var entities           = this.GetAllEntities(cdmCorpus);
            var incomingReferences = new Dictionary <CdmEntityDefinition, List <CdmEntityDefinition> >();

            foreach (var data in entities)
            {
                var entity = data.Item1;
                incomingReferences[entity] = new List <CdmEntityDefinition>();
            }

            // Start by populating all the incoming references to the entities
            foreach (var data in entities)
            {
                var entity     = data.Item1;
                var doc        = data.Item2;
                var directives = new AttributeResolutionDirectiveSet(new HashSet <string> {
                    "normalized", "referenceOnly"
                });
                var resOpt = new ResolveOptions {
                    WrtDoc = doc, Directives = directives
                };
                var resolvedEntity = await entity.CreateResolvedEntityAsync($"{entity.GetName()}_", resOpt);

                var references = await this.GetEntityReferences(resolvedEntity, resOpt, cdmCorpus);

                if (references.Count > 0)
                {
                    foreach (var reference in references)
                    {
                        incomingReferences[reference].Add(entity);
                    }
                }
            }

            // Next resolve the entity with all of it's incoming references and save the times
            var entityResolutionTimes = new List <Tuple <string, long> >();

            foreach (var data in entities)
            {
                var entity     = data.Item1;
                var doc        = data.Item2;
                var directives = new AttributeResolutionDirectiveSet(new HashSet <string> {
                    "normalized", "referenceOnly"
                });
                var resOpt = new ResolveOptions {
                    WrtDoc = doc, Directives = directives
                };
                var watch      = Stopwatch.StartNew();
                var references = incomingReferences[entity];
                foreach (var entRef in references)
                {
                    await entRef.CreateResolvedEntityAsync($"{entRef.GetName()}_", resOpt);
                }

                watch.Stop();
                entityResolutionTimes.Add(Tuple.Create(entity.AtCorpusPath, watch.ElapsedMilliseconds));
            }

            entityResolutionTimes.Sort((lhs, rhs) =>
            {
                var diff = rhs.Item2 - lhs.Item2;
                return(diff == 0 ? 0 : diff < 0 ? -1 : 1);
            });

            foreach (var data in entityResolutionTimes)
            {
                Trace.WriteLine($"{data.Item1}:{data.Item2}");
            }

            Assert.Performance(1000, entityResolutionTimes[0].Item2);
            var total = entityResolutionTimes.Sum(data => data.Item2);

            Assert.Performance(4200, total);
        }
Пример #14
0
        internal override ResolvedTraitSet FetchResolvedTraits(ResolveOptions resOpt = null)
        {
            if (resOpt == null)
            {
                resOpt = new ResolveOptions(this, this.Ctx.Corpus.DefaultResolutionDirectives);
            }

            const string   kind = "rtsb";
            ResolveContext ctx  = this.Ctx as ResolveContext;
            // this may happen 0, 1 or 2 times. so make it fast
            CdmTraitDefinition baseTrait  = null;
            ResolvedTraitSet   baseRts    = null;
            List <dynamic>     baseValues = null;

            System.Action GetBaseInfo = () =>
            {
                if (this.ExtendsTrait != null)
                {
                    baseTrait = this.ExtendsTrait.FetchObjectDefinition <CdmTraitDefinition>(resOpt);
                    if (baseTrait != null)
                    {
                        baseRts = this.ExtendsTrait.FetchResolvedTraits(resOpt);
                        if (baseRts?.Size == 1)
                        {
                            ParameterValueSet basePv = baseRts.Get(baseTrait)?.ParameterValues;
                            if (basePv != null)
                            {
                                baseValues = basePv.Values;
                            }
                        }
                    }
                }
            };

            // see if one is already cached
            // if this trait has parameters, then the base trait found through the reference might be a different reference
            // because trait references are unique per argument value set. so use the base as a part of the cache tag
            // since it is expensive to figure out the extra tag, cache that too!
            if (this.BaseIsKnownToHaveParameters == null)
            {
                GetBaseInfo();
                // is a cache tag needed? then make one
                this.BaseIsKnownToHaveParameters = false;
                if (baseValues?.Count > 0)
                {
                    this.BaseIsKnownToHaveParameters = true;
                }
            }
            string cacheTagExtra = "";

            if (this.BaseIsKnownToHaveParameters == true)
            {
                cacheTagExtra = this.ExtendsTrait.Id.ToString();
            }

            string  cacheTag         = ctx.Corpus.CreateDefinitionCacheTag(resOpt, this, kind, cacheTagExtra);
            dynamic rtsResultDynamic = null;

            if (cacheTag != null)
            {
                ctx.Cache.TryGetValue(cacheTag, out rtsResultDynamic);
            }
            ResolvedTraitSet rtsResult = rtsResultDynamic as ResolvedTraitSet;

            // store the previous reference symbol set, we will need to add it with
            // children found from the constructResolvedTraits call
            SymbolSet currSymbolRefSet = resOpt.SymbolRefSet;

            if (currSymbolRefSet == null)
            {
                currSymbolRefSet = new SymbolSet();
            }
            resOpt.SymbolRefSet = new SymbolSet();

            // if not, then make one and save it
            if (rtsResult == null)
            {
                GetBaseInfo();
                if (baseTrait != null)
                {
                    // get the resolution of the base class and use the values as a starting point for this trait's values
                    if (!this.HasSetFlags)
                    {
                        // inherit these flags
                        if (this.Elevated == null)
                        {
                            this.Elevated = baseTrait.Elevated;
                        }
                        if (this.Ugly == null)
                        {
                            this.Ugly = baseTrait.Ugly;
                        }
                        if (this.AssociatedProperties == null)
                        {
                            this.AssociatedProperties = baseTrait.AssociatedProperties;
                        }
                    }
                }
                this.HasSetFlags = true;
                ParameterCollection pc     = this.FetchAllParameters(resOpt);
                List <dynamic>      av     = new List <dynamic>();
                List <bool>         wasSet = new List <bool>();
                this.ThisIsKnownToHaveParameters = pc.Sequence.Count > 0;
                for (int i = 0; i < pc.Sequence.Count; i++)
                {
                    // either use the default value or (higher precidence) the value taken from the base reference
                    dynamic value     = (pc.Sequence[i] as CdmParameterDefinition).DefaultValue;
                    dynamic baseValue = null;
                    if (baseValues != null && i < baseValues.Count)
                    {
                        baseValue = baseValues[i];
                        if (baseValue != null)
                        {
                            value = baseValue;
                        }
                    }
                    av.Add(value);
                    wasSet.Add(false);
                }

                // save it
                ResolvedTrait resTrait = new ResolvedTrait(this, pc, av, wasSet);
                rtsResult = new ResolvedTraitSet(resOpt);
                rtsResult.Merge(resTrait, false);

                // register set of possible symbols
                ctx.Corpus.RegisterDefinitionReferenceSymbols(this.FetchObjectDefinition <CdmObjectDefinitionBase>(resOpt), kind, resOpt.SymbolRefSet);
                // get the new cache tag now that we have the list of docs
                cacheTag = ctx.Corpus.CreateDefinitionCacheTag(resOpt, this, kind, cacheTagExtra);
                if (!string.IsNullOrWhiteSpace(cacheTag))
                {
                    ctx.Cache[cacheTag] = rtsResult;
                }
            }
            else
            {
                // cache found
                // get the SymbolSet for this cached object
                string key = CdmCorpusDefinition.CreateCacheKeyFromObject(this, kind);
                ((CdmCorpusDefinition)ctx.Corpus).DefinitionReferenceSymbols.TryGetValue(key, out SymbolSet tempSymbolRefSet);
                resOpt.SymbolRefSet = tempSymbolRefSet;
            }
            // merge child document set with current
            currSymbolRefSet.Merge(resOpt.SymbolRefSet);
            resOpt.SymbolRefSet = currSymbolRefSet;

            return(rtsResult);
        }
        public static async Task <LocalEntity> ToData(CdmLocalEntityDeclarationDefinition instance, ResolveOptions resOpt, CopyOptions options)
        {
            var localEntity = await DocumentPersistence.ToData(instance.EntityPath, resOpt, options, instance.Ctx);

            if (localEntity != null)
            {
                var t2pm          = new TraitToPropertyMap(instance);
                var isHiddenTrait = t2pm.FetchTraitReference("is.hidden");

                localEntity.Description = instance.Explanation;
                localEntity.LastChildFileModifiedTime = instance.LastChildFileModifiedTime;
                localEntity.LastFileModifiedTime      = instance.LastFileModifiedTime;
                localEntity.LastFileStatusCheckTime   = instance.LastFileStatusCheckTime;

                if (isHiddenTrait != null)
                {
                    localEntity.IsHidden = true;
                }

                if (t2pm.FetchPropertyValue("cdmSchemas") is List <string> schemas)
                {
                    localEntity.Schemas = schemas;
                }

                if (instance.DataPartitions != null && instance.DataPartitions.Count > 0)
                {
                    localEntity.Partitions = new List <Partition>();

                    foreach (var element in instance.DataPartitions)
                    {
                        var partition = await DataPartitionPersistence.ToData(element, resOpt, options);

                        if (partition != null)
                        {
                            localEntity.Partitions.Add(partition);
                        }
                        else
                        {
                            Logger.Error(nameof(LocalEntityDeclarationPersistence), instance.Ctx, "There was an error while trying to convert cdm data partition to model.json partition.");
                            return(null);
                        }
                    }
                }
            }

            return(localEntity);
        }
        public static OperationAddCountAttribute ToData(CdmOperationAddCountAttribute instance, ResolveOptions resOpt, CopyOptions options)
        {
            if (instance == null)
            {
                return(null);
            }

            return(new OperationAddCountAttribute
            {
                Type = OperationTypeConvertor.OperationTypeToString(CdmOperationType.AddCountAttribute),
                Explanation = instance.Explanation,
                CountAttribute = Utils.JsonForm(instance.CountAttribute, resOpt, options)
            });
        }
Пример #17
0
        internal ResolvedAttributeSet FetchResolvedAttributes(ResolveOptions resOpt = null, AttributeContextParameters acpInContext = null)
        {
            bool wasPreviouslyResolving = this.Ctx.Corpus.isCurrentlyResolving;

            this.Ctx.Corpus.isCurrentlyResolving = true;
            if (resOpt == null)
            {
                resOpt = new ResolveOptions(this);
            }

            const string   kind      = "rasb";
            ResolveContext ctx       = this.Ctx as ResolveContext;
            string         cacheTag  = ctx.Corpus.CreateDefinitionCacheTag(resOpt, this, kind, acpInContext != null ? "ctx" : "");
            dynamic        rasbCache = null;

            if (cacheTag != null)
            {
                ctx.Cache.TryGetValue(cacheTag, out rasbCache);
            }
            CdmAttributeContext underCtx = null;

            // store the previous document set, we will need to add it with
            // children found from the constructResolvedTraits call
            SymbolSet currDocRefSet = resOpt.SymbolRefSet;

            if (currDocRefSet == null)
            {
                currDocRefSet = new SymbolSet();
            }
            resOpt.SymbolRefSet = new SymbolSet();

            // get the moniker that was found and needs to be appended to all
            // refs in the children attribute context nodes
            string fromMoniker = resOpt.FromMoniker;

            resOpt.FromMoniker = null;

            if (rasbCache == null)
            {
                if (this.resolvingAttributes)
                {
                    // re-entered this attribute through some kind of self or looping reference.
                    this.Ctx.Corpus.isCurrentlyResolving = wasPreviouslyResolving;
                    return(new ResolvedAttributeSet());
                }
                this.resolvingAttributes = true;

                // if a new context node is needed for these attributes, make it now
                if (acpInContext != null)
                {
                    underCtx = CdmAttributeContext.CreateChildUnder(resOpt, acpInContext);
                }

                rasbCache = this.ConstructResolvedAttributes(resOpt, underCtx);
                this.resolvingAttributes = false;

                // register set of possible docs
                CdmObjectDefinition oDef = this.FetchObjectDefinition <CdmObjectDefinitionBase>(resOpt);
                if (oDef != null)
                {
                    ((CdmCorpusDefinition)ctx.Corpus).RegisterDefinitionReferenceSymbols(oDef, kind, resOpt.SymbolRefSet);

                    // get the new cache tag now that we have the list of docs
                    cacheTag = ((CdmCorpusDefinition)ctx.Corpus).CreateDefinitionCacheTag(resOpt, this, kind, acpInContext != null ? "ctx" : null);

                    // save this as the cached version
                    if (!string.IsNullOrWhiteSpace(cacheTag))
                    {
                        ctx.Cache[cacheTag] = rasbCache;
                    }

                    if (!string.IsNullOrWhiteSpace(fromMoniker) && acpInContext != null &&
                        (this is CdmObjectReferenceBase) && (this as CdmObjectReferenceBase).NamedReference != null)
                    {
                        // create a fresh context
                        CdmAttributeContext oldContext = acpInContext.under.Contents[acpInContext.under.Contents.Count - 1] as CdmAttributeContext;
                        acpInContext.under.Contents.RemoveAt(acpInContext.under.Contents.Count - 1);
                        underCtx = CdmAttributeContext.CreateChildUnder(resOpt, acpInContext);

                        CdmAttributeContext newContext = oldContext.CopyAttributeContextTree(resOpt, underCtx, rasbCache.ResolvedAttributeSet, null, fromMoniker);
                        // since THIS should be a refererence to a thing found in a moniker document, it already has a moniker in the reference
                        // this function just added that same moniker to everything in the sub-tree but now this one symbol has too many
                        // remove one
                        string monikerPathAdded = $"{fromMoniker}/";
                        if (newContext.Definition != null && newContext.Definition.NamedReference != null &&
                            newContext.Definition.NamedReference.StartsWith(monikerPathAdded))
                        {
                            // slice it off the front
                            newContext.Definition.NamedReference = newContext.Definition.NamedReference.Substring(monikerPathAdded.Length);
                        }
                    }
                }
            }
            else
            {
                // cache found. if we are building a context, then fix what we got instead of making a new one
                if (acpInContext != null)
                {
                    // make the new context
                    underCtx = CdmAttributeContext.CreateChildUnder(resOpt, acpInContext);

                    rasbCache.ResolvedAttributeSet.AttributeContext.CopyAttributeContextTree(resOpt, underCtx, rasbCache.ResolvedAttributeSet, null, fromMoniker);
                }
            }

            // merge child document set with current
            currDocRefSet.Merge(resOpt.SymbolRefSet);
            resOpt.SymbolRefSet = currDocRefSet;

            this.Ctx.Corpus.isCurrentlyResolving = wasPreviouslyResolving;
            return(rasbCache?.ResolvedAttributeSet);
        }
Пример #18
0
 internal override void ConstructResolvedTraits(ResolvedTraitSetBuilder rtsb, ResolveOptions resOpt)
 {
     return;
 }
Пример #19
0
 public abstract dynamic CopyData(ResolveOptions resOpt = null, CopyOptions options = null);
Пример #20
0
        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
            ResolveOptions resOptCopy = resOpt.Copy();

            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)
            {
                // make a portable reference. this MUST be fixed up when the context node lands in the final document
                definition = (acp.Regarding as CdmObjectBase).CreatePortableReference(resOptCopy);
                // 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.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);

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

            return(underChild);
        }
Пример #21
0
 /// <inheritdoc />
 public abstract CdmObjectReference CreateSimpleReference(ResolveOptions resOpt = null);
Пример #22
0
        internal bool FinalizeAttributeContext(ResolveOptions resOpt, string pathStart, CdmDocumentDefinition docHome, CdmDocumentDefinition docFrom, string monikerForDocFrom, bool finished = false)
        {
            // run over the attCtx tree again and 'fix it' fix means replace the parent and lineage reference path strings with
            // final values from new home and set the inDocument and fix any references to definitions

            // keep track of the paths to documents for fixing symbol refs. expensive to compute
            Dictionary <CdmDocumentDefinition, string> foundDocPaths = new Dictionary <CdmDocumentDefinition, string>();

            if (!string.IsNullOrWhiteSpace(monikerForDocFrom))
            {
                monikerForDocFrom = $"{monikerForDocFrom}/";
            }

            // first step makes sure every node in the tree has a good path for itself and a good document
            // second pass uses the paths from nodes to fix references to other nodes
            Action <CdmObject, string> FixAttCtxNodePaths = null;

            FixAttCtxNodePaths = (subItem, pathFrom) =>
            {
                CdmAttributeContext ac = subItem as CdmAttributeContext;
                if (ac == null)
                {
                    return;
                }
                ac.InDocument = docHome;

                // fix up the reference to defintion. need to get path from this document to the
                // add moniker if this is a reference
                if (ac.Definition != null)
                {
                    ac.Definition.InDocument = docHome;

                    if (ac.Definition?.NamedReference != null)
                    {
                        // need the real path to this thing from the explicitRef held in the portable reference
                        // the real path is {monikerFrom/}{path from 'from' document to document holding the explicit ref/{declaredPath of explicitRef}}
                        // if we have never looked up the path between docs, do that now
                        CdmDocumentDefinition docFromDef = (ac.Definition as CdmObjectReferenceBase).PortableReference.InDocument; // if all parts not set, this is a broken portal ref!
                        string pathBetweenDocs;
                        if (foundDocPaths.TryGetValue(docFromDef, out pathBetweenDocs) == false)
                        {
                            pathBetweenDocs = docFrom.ImportPathToDoc(docFromDef);
                            if (pathBetweenDocs == null)
                            {
                                // hmm. hmm.
                                pathBetweenDocs = "";
                            }
                            foundDocPaths[docFrom] = pathBetweenDocs;
                        }

                        (ac.Definition as CdmObjectReferenceBase).LocalizePortableReference($"{monikerForDocFrom}{pathBetweenDocs}");
                    }
                }
                // doc of parent ref
                if (ac.Parent != null)
                {
                    ac.Parent.InDocument = docHome;
                }
                // doc of lineage refs
                if (ac.Lineage != null && ac.Lineage.Count > 0)
                {
                    foreach (var lin in ac.Lineage)
                    {
                        lin.InDocument = docHome;
                    }
                }

                string divider = (string.IsNullOrEmpty(ac.AtCorpusPath) || !pathFrom.EndsWith("/")) ? "/" : "";
                ac.AtCorpusPath = $"{pathFrom}{divider}{ac.Name}";

                if (ac.Contents == null || ac.Contents.Count == 0)
                {
                    return;
                }
                // look at all children
                foreach (var subSub in ac.Contents)
                {
                    if (subSub.ObjectType == CdmObjectType.AttributeContextDef)
                    {
                        FixAttCtxNodePaths(subSub, ac.AtCorpusPath);
                    }
                }
            };
            FixAttCtxNodePaths(this, pathStart);

            // now fix any lineage and parent references
            Action <CdmObject> FixAttCtxNodeLineage = null;

            FixAttCtxNodeLineage = (subItem) =>
            {
                CdmAttributeContext ac = subItem as CdmAttributeContext;
                if (ac == null)
                {
                    return;
                }
                // for debugLineage, write id
                //ac.Name = $"{ac.Name}({ac.Id})";

                // parent ref
                if (ac.Parent != null && ac.Parent.ExplicitReference != null)
                {
                    ac.Parent.NamedReference = (ac.Parent.ExplicitReference as CdmAttributeContext).AtCorpusPath;
                    // for debugLineage, write id
                    //ac.Parent.NamedReference = $"{ (ac.Parent.ExplicitReference as CdmAttributeContext).AtCorpusPath}({ac.Parent.ExplicitReference.Id})";
                }

                // fix lineage
                if (ac.Lineage != null && ac.Lineage.Count > 0)
                {
                    foreach (var lin in ac.Lineage)
                    {
                        if (lin.ExplicitReference != null)
                        {
                            // use the new path as the ref
                            lin.NamedReference = (lin.ExplicitReference as CdmAttributeContext).AtCorpusPath;
                            // for debugLineage, write id
                            //lin.NamedReference = $"{ (lin.ExplicitReference as CdmAttributeContext).AtCorpusPath}({lin.ExplicitReference.Id})";
                        }
                    }
                }


                if (ac.Contents == null || ac.Contents.Count == 0)
                {
                    return;
                }
                // look at all children
                foreach (var subSub in ac.Contents)
                {
                    FixAttCtxNodeLineage(subSub);
                }
            };
            FixAttCtxNodeLineage(this);

            if (finished)
            {
                resOpt.SaveResolutionsOnCopy = false;
                resOpt.MapOldCtxToNewCtx     = null;
            }

            return(true);
        }
Пример #23
0
 /// <inheritdoc />
 public abstract CdmObject Copy(ResolveOptions resOpt = null, CdmObject host = null);
Пример #24
0
 internal abstract CdmObjectReferenceBase CopyRefObject(ResolveOptions resOpt, dynamic refTo, bool simpleReference, CdmObjectReferenceBase host = null);
Пример #25
0
 /// <inheritdoc />
 public abstract bool IsDerivedFrom(string baseDef, ResolveOptions resOpt = null);
 public override dynamic CopyData(ResolveOptions resOpt, CopyOptions options)
 {
     return(CdmObjectBase.CopyData <CdmTypeAttributeDefinition>(this, resOpt, options));
 }
Пример #27
0
 /// <inheritdoc />
 public abstract T FetchObjectDefinition <T>(ResolveOptions resOpt = null) where T : CdmObjectDefinition;
 public override ResolvedEntityReferenceSet FetchResolvedEntityReferences(ResolveOptions resOpt = null)
 {
     return(null);
 }
Пример #29
0
        /// <summary>
        /// This method runs the tests with a set expected attributes & attribute context values and validated the actual result
        /// </summary>
        /// <param name="testName"></param>
        /// <param name="sourceEntityName"></param>
        /// <param name="expectedContext_*">expected attribute context object - for each resolution option combination</param>
        /// <param name="expected_*">expected attribute object - for each resolution option combination</param>
        /// <returns></returns>
        protected static async Task RunTestWithValues(
            string testName,
            string sourceEntityName,

            AttributeContextExpectedValue expectedContext_default,
            AttributeContextExpectedValue expectedContext_normalized,
            AttributeContextExpectedValue expectedContext_referenceOnly,
            AttributeContextExpectedValue expectedContext_structured,
            AttributeContextExpectedValue expectedContext_normalized_structured,
            AttributeContextExpectedValue expectedContext_referenceOnly_normalized,
            AttributeContextExpectedValue expectedContext_referenceOnly_structured,
            AttributeContextExpectedValue expectedContext_referenceOnly_normalized_structured,

            List <AttributeExpectedValue> expected_default,
            List <AttributeExpectedValue> expected_normalized,
            List <AttributeExpectedValue> expected_referenceOnly,
            List <AttributeExpectedValue> expected_structured,
            List <AttributeExpectedValue> expected_normalized_structured,
            List <AttributeExpectedValue> expected_referenceOnly_normalized,
            List <AttributeExpectedValue> expected_referenceOnly_structured,
            List <AttributeExpectedValue> expected_referenceOnly_normalized_structured,
            bool updateExpectedOutput = false
            )
        {
            try
            {
                string testInputPath    = TestHelper.GetInputFolderPath(TestsSubpath, testName);
                string testActualPath   = TestHelper.GetActualOutputFolderPath(TestsSubpath, testName);
                string testExpectedPath = TestHelper.GetExpectedOutputFolderPath(TestsSubpath, testName);
                string corpusPath       = testInputPath.Substring(0, testInputPath.Length - "/Input".Length);
                testActualPath = Path.GetFullPath(testActualPath);

                CdmCorpusDefinition corpus = new CdmCorpusDefinition();
                corpus.SetEventCallback(new EventCallback {
                    Invoke = CommonDataModelLoader.ConsoleStatusReport
                }, CdmStatusLevel.Warning);
                corpus.Storage.Mount("local", new LocalAdapter(corpusPath));
                corpus.Storage.Mount("cdm", new LocalAdapter(SchemaDocsPath));
                corpus.Storage.DefaultNamespace = "local";

                string outFolderPath          = corpus.Storage.AdapterPathToCorpusPath(testActualPath) + "/"; // interesting 'bug'
                CdmFolderDefinition outFolder = await corpus.FetchObjectAsync <CdmFolderDefinition>(outFolderPath);

                CdmEntityDefinition srcEntityDef = await corpus.FetchObjectAsync <CdmEntityDefinition>($"local:/Input/{sourceEntityName}.cdm.json/{sourceEntityName}");

                Assert.IsTrue(srcEntityDef != null);

                var resOpt = new ResolveOptions
                {
                    WrtDoc     = srcEntityDef.InDocument,
                    Directives = new AttributeResolutionDirectiveSet(new HashSet <string> {
                    })
                };

                CdmEntityDefinition resolvedEntityDef = null;
                string outputEntityName     = string.Empty;
                string outputEntityFileName = string.Empty;
                string entityFileName       = string.Empty;


                if (expectedContext_default != null && expected_default != null)
                {
                    entityFileName       = "d";
                    resOpt.Directives    = new AttributeResolutionDirectiveSet(new HashSet <string> {
                    });
                    outputEntityName     = $"{sourceEntityName}_R_{entityFileName}";
                    outputEntityFileName = $"{outputEntityName}.cdm.json";
                    resolvedEntityDef    = await srcEntityDef.CreateResolvedEntityAsync(outputEntityName, resOpt, outFolder);
                    await SaveActualEntityAndValidateWithExpected(Path.Combine(testExpectedPath, outputEntityFileName), resolvedEntityDef, updateExpectedOutput);
                }

                if (expectedContext_normalized != null && expected_normalized != null)
                {
                    entityFileName    = "n";
                    resOpt.Directives = new AttributeResolutionDirectiveSet(new HashSet <string> {
                        "normalized"
                    });
                    outputEntityName     = $"{sourceEntityName}_R_{entityFileName}";
                    outputEntityFileName = $"{outputEntityName}.cdm.json";
                    resolvedEntityDef    = await srcEntityDef.CreateResolvedEntityAsync(outputEntityName, resOpt, outFolder);
                    await SaveActualEntityAndValidateWithExpected(Path.Combine(testExpectedPath, outputEntityFileName), resolvedEntityDef, updateExpectedOutput);
                }

                if (expectedContext_referenceOnly != null && expected_referenceOnly != null)
                {
                    entityFileName    = "ro";
                    resOpt.Directives = new AttributeResolutionDirectiveSet(new HashSet <string> {
                        "referenceOnly"
                    });
                    outputEntityName     = $"{sourceEntityName}_R_{entityFileName}";
                    outputEntityFileName = $"{outputEntityName}.cdm.json";
                    resolvedEntityDef    = await srcEntityDef.CreateResolvedEntityAsync(outputEntityName, resOpt, outFolder);
                    await SaveActualEntityAndValidateWithExpected(Path.Combine(testExpectedPath, outputEntityFileName), resolvedEntityDef, updateExpectedOutput);
                }

                if (expectedContext_structured != null && expected_structured != null)
                {
                    entityFileName    = "s";
                    resOpt.Directives = new AttributeResolutionDirectiveSet(new HashSet <string> {
                        "structured"
                    });
                    outputEntityName     = $"{sourceEntityName}_R_{entityFileName}";
                    outputEntityFileName = $"{outputEntityName}.cdm.json";
                    resolvedEntityDef    = await srcEntityDef.CreateResolvedEntityAsync(outputEntityName, resOpt, outFolder);
                    await SaveActualEntityAndValidateWithExpected(Path.Combine(testExpectedPath, outputEntityFileName), resolvedEntityDef, updateExpectedOutput);
                }

                if (expectedContext_normalized_structured != null && expected_normalized_structured != null)
                {
                    entityFileName    = "n_s";
                    resOpt.Directives = new AttributeResolutionDirectiveSet(new HashSet <string> {
                        "normalized", "structured"
                    });
                    outputEntityName     = $"{sourceEntityName}_R_{entityFileName}";
                    outputEntityFileName = $"{outputEntityName}.cdm.json";
                    resolvedEntityDef    = await srcEntityDef.CreateResolvedEntityAsync(outputEntityName, resOpt, outFolder);
                    await SaveActualEntityAndValidateWithExpected(Path.Combine(testExpectedPath, outputEntityFileName), resolvedEntityDef, updateExpectedOutput);
                }

                if (expectedContext_referenceOnly_normalized != null && expected_referenceOnly_normalized != null)
                {
                    entityFileName    = "ro_n";
                    resOpt.Directives = new AttributeResolutionDirectiveSet(new HashSet <string> {
                        "referenceOnly", "normalized"
                    });
                    outputEntityName     = $"{sourceEntityName}_R_{entityFileName}";
                    outputEntityFileName = $"{outputEntityName}.cdm.json";
                    resolvedEntityDef    = await srcEntityDef.CreateResolvedEntityAsync(outputEntityName, resOpt, outFolder);
                    await SaveActualEntityAndValidateWithExpected(Path.Combine(testExpectedPath, outputEntityFileName), resolvedEntityDef, updateExpectedOutput);
                }

                if (expectedContext_referenceOnly_structured != null && expected_referenceOnly_structured != null)
                {
                    entityFileName    = "ro_s";
                    resOpt.Directives = new AttributeResolutionDirectiveSet(new HashSet <string> {
                        "referenceOnly", "structured"
                    });
                    outputEntityName     = $"{sourceEntityName}_R_{entityFileName}";
                    outputEntityFileName = $"{outputEntityName}.cdm.json";
                    resolvedEntityDef    = await srcEntityDef.CreateResolvedEntityAsync(outputEntityName, resOpt, outFolder);
                    await SaveActualEntityAndValidateWithExpected(Path.Combine(testExpectedPath, outputEntityFileName), resolvedEntityDef, updateExpectedOutput);
                }

                if (expectedContext_referenceOnly_normalized_structured != null && expected_referenceOnly_normalized_structured != null)
                {
                    entityFileName    = "ro_n_s";
                    resOpt.Directives = new AttributeResolutionDirectiveSet(new HashSet <string> {
                        "referenceOnly", "normalized", "structured"
                    });
                    outputEntityName     = $"{sourceEntityName}_R_{entityFileName}";
                    outputEntityFileName = $"{outputEntityName}.cdm.json";
                    resolvedEntityDef    = await srcEntityDef.CreateResolvedEntityAsync(outputEntityName, resOpt, outFolder);
                    await SaveActualEntityAndValidateWithExpected(Path.Combine(testExpectedPath, outputEntityFileName), resolvedEntityDef, updateExpectedOutput);
                }
            }
            catch (Exception e)
            {
                Assert.Fail(e.Message);
            }
        }
Пример #30
0
        ResolvedAttributeSet Apply(ResolvedTraitSet traits, ResolveOptions resOpt, CdmAttributeResolutionGuidance resGuide, List <AttributeResolutionApplier> actions)
        {
            if (traits == null && actions.Count == 0)
            {
                // nothing can change
                return(this);
            }

            // for every attribute in the set run any attribute appliers
            ResolvedAttributeSet appliedAttSet = new ResolvedAttributeSet();
            int l = this.Set.Count;

            appliedAttSet.AttributeContext = this.AttributeContext;

            // check to see if we need to make a copy of the attributes
            // do this when building an attribute context and when we will modify the attributes (beyond traits)
            // see if any of the appliers want to modify
            bool makingCopy = false;

            if (l > 0 && appliedAttSet.AttributeContext != null && actions != null && actions.Count > 0)
            {
                ResolvedAttribute resAttTest = this.Set[0];
                foreach (AttributeResolutionApplier traitAction in actions)
                {
                    ApplierContext ctx = new ApplierContext {
                        ResOpt = resOpt, ResAttSource = resAttTest, ResGuide = resGuide
                    };
                    if (traitAction.WillAttributeModify(ctx) == true)
                    {
                        makingCopy = true;
                        break;
                    }
                }
            }

            if (makingCopy)
            {
                // fake up a generation round for these copies that are about to happen
                AttributeContextParameters acp = new AttributeContextParameters
                {
                    under = appliedAttSet.AttributeContext,
                    type  = Enums.CdmAttributeContextType.GeneratedSet,
                    Name  = "_generatedAttributeSet"
                };
                appliedAttSet.AttributeContext = CdmAttributeContext.CreateChildUnder(traits.ResOpt, acp);
                acp = new AttributeContextParameters
                {
                    under = appliedAttSet.AttributeContext,
                    type  = Enums.CdmAttributeContextType.GeneratedRound,
                    Name  = "_generatedAttributeRound0"
                };
                appliedAttSet.AttributeContext = CdmAttributeContext.CreateChildUnder(traits.ResOpt, acp);
            }
            for (int i = 0; i < l; i++)
            {
                ResolvedAttribute   resAtt        = this.Set[i];
                CdmAttributeContext attCtxToMerge = resAtt.AttCtx; // start with the current context for the resolved att, if a copy happens this will change
                if (resAtt.Target is ResolvedAttributeSet subSet)
                {
                    if (makingCopy)
                    {
                        resAtt = resAtt.Copy();
                        // making a copy of a subset (att group) also bring along the context tree for that whole group
                        attCtxToMerge = resAtt.AttCtx;
                    }
                    // the set contains another set. process those
                    resAtt.Target = subSet.Apply(traits, resOpt, resGuide, actions);
                }
                else
                {
                    ResolvedTraitSet rtsMerge = resAtt.ResolvedTraits.MergeSet(traits);
                    resAtt.ResolvedTraits = rtsMerge;
                    if (actions != null)
                    {
                        foreach (AttributeResolutionApplier traitAction in actions)
                        {
                            ApplierContext ctx = new ApplierContext {
                                ResOpt = traits.ResOpt, ResAttSource = resAtt, ResGuide = resGuide
                            };
                            if (traitAction.WillAttributeModify(ctx) == true)
                            {
                                // make a context for this new copy
                                if (makingCopy)
                                {
                                    AttributeContextParameters acp = new AttributeContextParameters
                                    {
                                        under     = appliedAttSet.AttributeContext,
                                        type      = Enums.CdmAttributeContextType.AttributeDefinition,
                                        Name      = resAtt.ResolvedName,
                                        Regarding = resAtt.Target
                                    };
                                    ctx.AttCtx    = CdmAttributeContext.CreateChildUnder(traits.ResOpt, acp);
                                    attCtxToMerge = ctx.AttCtx as CdmAttributeContext;
                                }

                                // make a copy of the resolved att
                                if (makingCopy)
                                {
                                    resAtt = resAtt.Copy();
                                    attCtxToMerge.AddLineage(resAtt.AttCtx);
                                    resAtt.AttCtx = attCtxToMerge;
                                }

                                ctx.ResAttSource = resAtt;
                                // modify it
                                traitAction.DoAttributeModify(ctx);
                            }
                        }
                    }
                }
                appliedAttSet.Merge(resAtt);
            }

            appliedAttSet.AttributeContext = this.AttributeContext;

            return(appliedAttSet);
        }
Пример #31
0
        public override async Task <List <Book> > GetPageAsync(int pageNumber, int rowCount, ResolveOptions resolveOptions = null)
        {
            var entities = await base.GetPageAsync(pageNumber, rowCount, resolveOptions);

            ClearBook(entities);

            return(entities);
        }