Esempio n. 1
0
        /// <summary>
        /// Create a Type Attribute
        /// </summary>
        /// <returns></returns>
        public CdmTypeAttributeDefinition CreateTypeAttribute(string attributeName, string dataType, string purpose)
        {
            CdmDataTypeReference dataTypeRef = Corpus.MakeRef <CdmDataTypeReference>(CdmObjectType.DataTypeRef, dataType, simpleNameRef: false);

            CdmPurposeReference purposeRef = Corpus.MakeRef <CdmPurposeReference>(CdmObjectType.PurposeRef, purpose, simpleNameRef: false);

            CdmTypeAttributeDefinition attribute = Corpus.MakeObject <CdmTypeAttributeDefinition>(CdmObjectType.TypeAttributeDef, nameOrRef: attributeName, simpleNameRef: false);

            attribute.DataType = dataTypeRef;
            attribute.Purpose  = purposeRef;

            return(attribute);
        }
        public static CdmPurposeReference FromData(CdmCorpusContext ctx, JToken obj)
        {
            if (obj == null)
            {
                return(null);
            }

            bool    simpleReference = true;
            bool?   optional        = null;
            dynamic purpose;

            if (obj is JValue)
            {
                purpose = obj;
            }
            else
            {
                simpleReference = false;

                if (obj["optional"] != null)
                {
                    if (bool.TryParse(obj["optional"].ToString(), out bool optVal))
                    {
                        optional = optVal;
                    }
                }

                if (obj["purposeReference"] is JValue)
                {
                    purpose = (string)obj["purposeReference"];
                }
                else
                {
                    purpose = PurposePersistence.FromData(ctx, obj["purposeReference"]);
                }
            }

            CdmPurposeReference purposeReference = ctx.Corpus.MakeRef <CdmPurposeReference>(CdmObjectType.PurposeRef, purpose, simpleReference);

            if (optional != null)
            {
                purposeReference.Optional = optional;
            }

            if (!(obj is JValue))
            {
                Utils.AddListToCdmCollection(purposeReference.AppliedTraits, Utils.CreateTraitReferenceList(ctx, obj["appliedTraits"]));
            }

            return(purposeReference);
        }
        public static CdmPurposeReference FromData(CdmCorpusContext ctx, JToken obj)
        {
            if (obj == null)
            {
                return(null);
            }

            bool    simpleReference = true;
            dynamic purpose         = null;
            List <CdmTraitReference> appliedTraits = null;

            if (obj is JValue)
            {
                purpose = obj;
            }
            else
            {
                simpleReference = false;
                if (obj["purposeReference"] is JValue)
                {
                    purpose = (string)obj["purposeReference"];
                }
                else
                {
                    purpose = PurposePersistence.FromData(ctx, obj["purposeReference"]);
                }
            }

            CdmPurposeReference purposeReference = ctx.Corpus.MakeRef <CdmPurposeReference>(CdmObjectType.PurposeRef, purpose, simpleReference);

            if (!(obj is JValue))
            {
                appliedTraits = Utils.CreateTraitReferenceList(ctx, obj["appliedTraits"]);
            }

            Utils.AddListToCdmCollection(purposeReference.AppliedTraits, appliedTraits);

            return(purposeReference);
        }
Esempio n. 4
0
        /// <summary>
        /// Create an purpose reference instance which points to `meaningOfRelationshipVerbPhrases` which is defined in public standards.
        /// </summary>
        /// <param name="cdmCorpus"> The CDM corpus. </param>
        /// <returns> The instance of purpose reference. </returns>
        private static CdmPurposeReference CreateRelationshipMeanings(CdmCorpusDefinition cdmCorpus, string customMessage)
        {
            // The purpose "meaningOfRelationshipVerbPhrases" is from /samples/example-public-standards/foundations.cdm.json
            // With the use of this purpose, two additional traits ("means.relationship.verbPhrase" and "means.relationship.inverseVerbPhrase") will be added by default
            // as they are attached to the purpose definition.
            CdmPurposeReference purposeRef = cdmCorpus.MakeRef <CdmPurposeReference>(CdmObjectType.PurposeRef, "meaningOfRelationshipVerbPhrases", false);

            // You can add your own argument to the additional traits
            // The trait "means.relationship.verbPhrase" is also from /samples/example-public-standards/foundations.cdm.json
            // This trait states that the data type it requires is an entity "localizedTable", which allow you to define phrases in different languages
            CdmTraitReference forwardPurposeTraitReference = cdmCorpus.MakeObject <CdmTraitReference>(CdmObjectType.TraitRef, "means.relationship.verbPhrase", false);

            List <List <string> > forwardDescriptions = new List <List <string> > {
                new List <string>()
                {
                    "en", $"{customMessage} - Forwards"
                },
                new List <string>()
                {
                    "cn", "正向"
                }
            };

            var forwardConstEntDef = cdmCorpus.MakeObject <CdmConstantEntityDefinition>(CdmObjectType.ConstantEntityDef, null, false);

            forwardConstEntDef.ConstantValues = forwardDescriptions;

            // The entity "localizedTable" is from /samples/example-public-standards/foundations.cdm.json
            forwardConstEntDef.EntityShape = cdmCorpus.MakeRef <CdmEntityReference>(CdmObjectType.EntityRef, "localizedTable", true);
            forwardPurposeTraitReference.Arguments.Add(null, cdmCorpus.MakeRef <CdmEntityReference>(CdmObjectType.EntityRef, forwardConstEntDef, true));

            purposeRef.AppliedTraits.Add(forwardPurposeTraitReference);

            // You can also use the same way above to decorate the second trait "means.relationship.inverseVerbPhrase"
            // it is also available in /samples/example-public-standards/foundations.cdm.json

            return(purposeRef);
        }
 public static dynamic ToData(CdmPurposeReference instance, ResolveOptions resOpt, CopyOptions options)
 {
     return(CdmObjectRefPersistence.ToData(instance, resOpt, options));
 }