예제 #1
0
        public static async Task <LocalEntity> ToData(CdmEntityDefinition instance, ResolveOptions resOpt, CopyOptions options, CdmCorpusContext ctx)
        {
            var result = new LocalEntity
            {
                Name        = instance.EntityName,
                Description = instance.Description,
                Type        = "LocalEntity"
            };

            await Utils.ProcessAnnotationsToData(instance.Ctx, result, instance.ExhibitsTraits);

            if (instance.Attributes != null)
            {
                result.Attributes = new List <Attribute>();
                foreach (dynamic element in instance.Attributes)
                {
                    // TODO: handle when attribute is something else other than CdmTypeAttributeDefinition.
                    var attribute = await TypeAttributePersistence.ToData(element as CdmTypeAttributeDefinition, resOpt, options);

                    if (attribute != null)
                    {
                        result.Attributes.Add(attribute);
                    }
                    else
                    {
                        Logger.Error(nameof(EntityPersistence), (ResolveContext)ctx, "There was an error while trying to convert model.json attribute to cdm attribute.");

                        return(null);
                    }
                }
            }

            return(result);
        }
예제 #2
0
        public static async Task <LocalEntity> ToData(CdmEntityDefinition instance, ResolveOptions resOpt, CopyOptions options, CdmCorpusContext ctx)
        {
            var result = new LocalEntity
            {
                Name        = instance.EntityName,
                Description = instance.GetProperty("description"),
                Type        = "LocalEntity"
            };

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

            if (instance.Attributes != null)
            {
                result.Attributes = new List <Attribute>();
                foreach (CdmAttributeItem element in instance.Attributes)
                {
                    if (element.ObjectType != CdmObjectType.TypeAttributeDef)
                    {
                        Logger.Error(nameof(EntityPersistence), (ResolveContext)ctx, "Saving a manifest, with an entity containing an entity attribute, to model.json format is currently not supported.");

                        return(null);
                    }

                    // TODO: handle when attribute is something else other than CdmTypeAttributeDefinition.
                    var attribute = await TypeAttributePersistence.ToData(element as CdmTypeAttributeDefinition, resOpt, options);

                    if (attribute != null)
                    {
                        result.Attributes.Add(attribute);
                    }
                    else
                    {
                        Logger.Error(nameof(EntityPersistence), (ResolveContext)ctx, "There was an error while trying to convert model.json attribute to cdm attribute.");

                        return(null);
                    }
                }
            }

            return(result);
        }
예제 #3
0
        public static async Task <LocalEntity> ToData(CdmEntityDefinition instance, ResolveOptions resOpt, CopyOptions options, CdmCorpusContext ctx)
        {
            var result = new LocalEntity
            {
                Name        = instance.EntityName,
                Description = instance.GetProperty("description"),
                Type        = "LocalEntity"
            };

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

            if (instance.Attributes != null)
            {
                result.Attributes = new List <Attribute>();
                foreach (CdmAttributeItem element in instance.Attributes)
                {
                    if (element.ObjectType != CdmObjectType.TypeAttributeDef)
                    {
                        Logger.Error((ResolveContext)ctx, Tag, nameof(ToData), element.AtCorpusPath, CdmLogCode.ErrPersistModelJsonEntityAttrError);
                        return(null);
                    }

                    // TODO: handle when attribute is something else other than CdmTypeAttributeDefinition.
                    var attribute = await TypeAttributePersistence.ToData(element as CdmTypeAttributeDefinition, resOpt, options);

                    if (attribute != null)
                    {
                        result.Attributes.Add(attribute);
                    }
                    else
                    {
                        Logger.Error((ResolveContext)ctx, Tag, nameof(ToData), element.AtCorpusPath, CdmLogCode.ErrPersistModelJsonFromAttrConversionFailure);
                        return(null);
                    }
                }
            }

            return(result);
        }