Exemplo n.º 1
0
        internal static async Task ProcessAnnotationsFromData(CdmCorpusContext ctx, MetadataObject obj, CdmTraitCollection traits)
        {
            var multiTraitAnnotations = new List <NameValuePair>();

            if (obj.Annotations != null)
            {
                foreach (var element in obj.Annotations)
                {
                    if (!ShouldAnnotationGoIntoASingleTrait(element.Name))
                    {
                        NameValuePair cdmElement = new NameValuePair()
                        {
                            Name  = element.Name,
                            Value = element.Value
                        };
                        multiTraitAnnotations.Add(cdmElement);
                    }
                    else
                    {
                        var innerTrait = ctx.Corpus.MakeObject <CdmTraitReference>(CdmObjectType.TraitRef, ConvertAnnotationToTrait(element.Name));
                        innerTrait.Arguments.Add(await ArgumentPersistence.FromData(ctx, element));
                        traits.Add(innerTrait);
                    }
                }

                if (multiTraitAnnotations.Count > 0)
                {
                    var trait = ctx.Corpus.MakeRef <CdmTraitReference>(CdmObjectType.TraitRef, "is.modelConversion.otherAnnotations", false);
                    trait.IsFromProperty = false;
                    var annotationsArgument = new CdmArgumentDefinition(ctx, "annotations")
                    {
                        Value = multiTraitAnnotations
                    };
                    trait.Arguments.Add(annotationsArgument);
                    traits.Add(trait);
                }
            }

            if (obj.Traits != null)
            {
                foreach (var trait in obj.Traits)
                {
                    var trToken = JToken.FromObject(trait);

                    if (!(trToken is JValue) && trToken["traitGroupReference"] != null)
                    {
                        traits.Add(CdmFolder.TraitGroupReferencePersistence.FromData(ctx, trToken));
                    }
                    else
                    {
                        traits.Add(CdmFolder.TraitReferencePersistence.FromData(ctx, trToken));
                    }
                }
            }
        }
Exemplo n.º 2
0
        internal static async Task ProcessAnnotationsFromData(CdmCorpusContext ctx, MetadataObject obj, CdmTraitCollection traits)
        {
            var multiTraitAnnotations = new List <Annotation>();

            if (obj.Annotations != null)
            {
                foreach (var element in obj.Annotations)
                {
                    if (!ShouldAnnotationGoIntoASingleTrait(element.Name))
                    {
                        multiTraitAnnotations.Add(element);
                    }
                    else
                    {
                        var innerTrait = ctx.Corpus.MakeObject <CdmTraitReference>(CdmObjectType.TraitRef, ConvertAnnotationToTrait(element.Name));
                        innerTrait.Arguments.Add(await ArgumentPersistence.FromData(ctx, element));
                        traits.Add(innerTrait);
                    }
                }

                var trait = ctx.Corpus.MakeRef <CdmTraitReference>(CdmObjectType.TraitRef, "is.modelConversion.otherAnnotations", false);
                trait.IsFromProperty = true;
                var annotationsArgument = new CdmArgumentDefinition(ctx, "annotations")
                {
                    Value = multiTraitAnnotations
                };
                trait.Arguments.Add(annotationsArgument);
                traits.Add(trait);
            }

            if (obj.Traits != null)
            {
                foreach (var trait in obj.Traits)
                {
                    var traitInstance = CdmFolder.TraitReferencePersistence.FromData(ctx, JToken.FromObject(trait));
                    traits.Add(traitInstance);
                }
            }
        }