public CdmObjectDefinition FetchResolvedReference(ResolveOptions resOpt = null) { if (resOpt == null) { resOpt = new ResolveOptions(this, this.Ctx.Corpus.DefaultResolutionDirectives); } if (this.ExplicitReference != null) { return(this.ExplicitReference); } if (this.Ctx == null) { return(null); } ResolveContext ctx = this.Ctx as ResolveContext; CdmObjectDefinitionBase res = null; // if this is a special request for a resolved attribute, look that up now int seekResAtt = offsetAttributePromise(this.NamedReference); if (seekResAtt >= 0) { string entName = this.NamedReference.Substring(0, seekResAtt); string attName = this.NamedReference.Slice(seekResAtt + resAttToken.Length); // get the entity CdmObjectDefinition ent = (this.Ctx.Corpus as CdmCorpusDefinition).ResolveSymbolReference(resOpt, this.InDocument, entName, CdmObjectType.EntityDef, retry: true); if (ent == null) { Logger.Warning(nameof(CdmObjectReferenceBase), ctx, $"unable to resolve an entity named '{entName}' from the reference '{this.NamedReference}"); return(null); } // get the resolved attribute ResolvedAttributeSet ras = (ent as CdmObjectDefinitionBase).FetchResolvedAttributes(resOpt); ResolvedAttribute ra = null; if (ras != null) { ra = ras.Get(attName); } if (ra != null) { res = ra.Target as dynamic; } else { Logger.Warning(nameof(CdmObjectReferenceBase), ctx, $"couldn't resolve the attribute promise for '{this.NamedReference}'", $"{resOpt.WrtDoc.AtCorpusPath}"); } } else { // normal symbolic reference, look up from the Corpus, it knows where everything is res = (this.Ctx.Corpus as CdmCorpusDefinition).ResolveSymbolReference(resOpt, this.InDocument, this.NamedReference, this.ObjectType, retry: true); } return(res); }
internal void CopyDef(ResolveOptions resOpt, CdmObjectDefinitionBase copy) { copy.DeclaredPath = this.DeclaredPath; copy.Explanation = this.Explanation; foreach (var trait in this.ExhibitsTraits) { copy.ExhibitsTraits.Add(trait); } }
internal void CopyDef(ResolveOptions resOpt, CdmObjectDefinitionBase copy) { copy.DeclaredPath = this.DeclaredPath; copy.Explanation = this.Explanation; copy.ExhibitsTraits.Clear(); foreach (var trait in this.ExhibitsTraits) { copy.ExhibitsTraits.Add(trait); } copy.InDocument = this.InDocument; // if gets put into a new document, this will change. until, use the source }
internal CdmObject FetchObjectFromDocumentPath(string objectPath, ResolveOptions resOpt) { // in current document? if (this.InternalDeclarations.ContainsKey(objectPath)) { return(this.InternalDeclarations[objectPath]); } else { // this might be a request for an object def drill through of a reference. // path/(object)/paths // there can be several such requests in one path AND some of the requested // defintions might be defined inline inside a reference meaning the declared path // includes that reference name and could still be inside this document. example: // /path/path/refToInline/(object)/member1/refToSymbol/(object)/member2 // the full path is not in this doc but /path/path/refToInline/(object)/member1/refToSymbol // is declared in this document. we then need to go to the doc for refToSymbol and // search for refToSymbol/member2 // work backward until we find something in this document int lastObj = objectPath.LastIndexOf("/(object)"); string thisDocPart = objectPath; while (lastObj > 0) { thisDocPart = objectPath.Substring(0, lastObj); if (this.InternalDeclarations.ContainsKey(thisDocPart)) { CdmObjectReferenceBase thisDocObjRef = this.InternalDeclarations[thisDocPart] as CdmObjectReferenceBase; CdmObjectDefinitionBase thatDocObjDef = thisDocObjRef.FetchObjectDefinition <CdmObjectDefinitionBase>(resOpt); if (thatDocObjDef != null) { // get from other document. // but first fix the path to look like it is relative to that object as declared in that doc string thatDocPart = objectPath.Substring(lastObj + "/(object)".Length); thatDocPart = $"{thatDocObjDef.DeclaredPath}{thatDocPart}"; if (thatDocPart == objectPath) { // we got back to were we started. probably because something is just not found. return(null); } return(thatDocObjDef.InDocument.FetchObjectFromDocumentPath(thatDocPart, resOpt)); } return(null); } lastObj = thisDocPart.LastIndexOf("/(object)"); } } return(null); }
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, this.Ctx.Corpus.DefaultResolutionDirectives); } const string kind = "rtsb"; ResolveContext ctx = this.Ctx as ResolveContext; string cacheTagA = 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 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 = 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); }
/// <summary> /// Determine if calling FileStatusCheckAsync on the given pattern or the given partition is needed. /// </summary> /// <param name="incrementalType">The incremental type.</param> /// <param name="isPattern">Whether the object is a pattern object or a partition object.</param> /// <param name="patternOrPartitionObj">The pattern object if isPattern is true, otherwise the partition object.</param> private bool ShouldCallFileStatusCheck(CdmIncrementalPartitionType incrementalType, bool isPattern, CdmObjectDefinitionBase patternOrPartitionObj) { var update = true; CdmTraitReference traitRef = patternOrPartitionObj.ExhibitsTraits.Item(Constants.IncrementalTraitName) as CdmTraitReference; if (traitRef == null) { Logger.Error(patternOrPartitionObj.Ctx, Tag, nameof(ShouldCallFileStatusCheck), patternOrPartitionObj.AtCorpusPath, CdmLogCode.ErrMissingIncrementalPartitionTrait, isPattern ? nameof(CdmDataPartitionPatternDefinition) : nameof(CdmDataPartitionDefinition), patternOrPartitionObj.FetchObjectDefinitionName(), Constants.IncrementalTraitName, isPattern ? nameof(IncrementalPartitionPatterns) : nameof(IncrementalPartitions)); } else { // None means update by default if (incrementalType == CdmIncrementalPartitionType.None) { return(update); } var traitRefIncrementalTypeValue = traitRef.Arguments?.FetchValue("type"); if (traitRefIncrementalTypeValue == null) { update = false; Logger.Error(patternOrPartitionObj.Ctx, Tag, nameof(ShouldCallFileStatusCheck), patternOrPartitionObj.AtCorpusPath, CdmLogCode.ErrTraitArgumentMissing, "type", Constants.IncrementalTraitName, patternOrPartitionObj.FetchObjectDefinitionName()); } else if (traitRefIncrementalTypeValue is string == false) { update = false; Logger.Error(patternOrPartitionObj.Ctx, Tag, nameof(ShouldCallFileStatusCheck), patternOrPartitionObj.AtCorpusPath, CdmLogCode.ErrTraitInvalidArgumentValueType, "type", Constants.IncrementalTraitName, patternOrPartitionObj.FetchObjectDefinitionName()); } else { bool success = Enum.TryParse(traitRefIncrementalTypeValue.ToString(), out CdmIncrementalPartitionType traitRefIncrementalType); if (success) { update = traitRefIncrementalType == incrementalType; } else { update = false; Logger.Error(patternOrPartitionObj.Ctx, Tag, nameof(ShouldCallFileStatusCheck), patternOrPartitionObj.AtCorpusPath, CdmLogCode.ErrEnumConversionFailure, traitRefIncrementalTypeValue, nameof(CdmIncrementalPartitionType), $"parameter 'type' of trait '{Constants.IncrementalTraitName}' from '{patternOrPartitionObj.FetchObjectDefinitionName()}'"); } } } return(update); }