Example #1
0
        /// <summary>
        /// Create a CoRAL link from the parameters
        /// </summary>
        /// <param name="relation">Cori value containing the relation - IRI</param>
        /// <param name="uriTarget">Absolute or relative CIRI for the target</param>
        /// <param name="body">attributes about the target</param>
        public CoralLink(Cori relation, Cori uriTarget, CoralBody body = null)
        {
            if (!relation.IsAbsolute())
            {
                throw new ArgumentException("Relation must be an absolute IRI", nameof(relation));
            }

            RelationType = relation;
            Target       = uriTarget;
            Body         = body;
        }
Example #2
0
        public CoralLink(CBORObject node, CoralDictionary dictionary)
        {
            if (node[0].AsInt32() != 2)
            {
                throw new ArgumentException("Not an encoded CoRAL link");
            }

            RelationType = dictionary.Reverse(node[1]).AsString();
            Target       = dictionary.Reverse(node[2]);
            if (node.Count == 4)
            {
                Body = new CoralBody(node[3], dictionary);
            }
        }
Example #3
0
        /// <summary>
        /// Create a CoRAL link from the parameters
        /// </summary>
        /// <param name="relation">Cori version of the relation - IRI</param>
        /// <param name="target">Value of the target - Not a URI!!!</param>
        /// <param name="body">attributes about the target</param>
        public CoralLink(Cori relation, CBORObject target, CoralBody body = null)
        {
            if (!IsLiteral(target))
            {
                throw new ArgumentException("Value must be a literal value", nameof(target));
            }

            if (!relation.IsAbsolute())
            {
                throw new ArgumentException("Relation must be an absolute IRI", nameof(relation));
            }

            RelationType = relation;
            Value        = target;
            Body         = body;
        }
Example #4
0
 public CoralForm(string formRef, string target, CoralBody body)
 {
     _operationType = formRef;
     _target        = target;
     Body           = body;
 }
Example #5
0
 public CoralLink(string relation, CBORObject target, CoralBody body)
 {
     RelationType = relation;
     Target       = target;
     Body         = body;
 }
Example #6
0
 /// <summary>
 /// Create a CoRAL link from the parameters
 /// </summary>
 /// <param name="relation">string containing the relation - IRI</param>
 /// <param name="target">Value of the target - Not a URI!!!</param>
 /// <param name="body">attributes about the target</param>
 public CoralLink(string relation, CBORObject target, CoralBody body = null) : this(new Cori(relation), target, body)
 {
 }
Example #7
0
        /// <summary>
        /// Decode a CBOR encoded CoRAL link into the object for working with
        /// </summary>
        /// <param name="node">CBOR object to be decoded</param>
        /// <param name="baseCori">a URI to make things relative to</param>
        /// <param name="dictionary">dictionary to use for decoding</param>
        public CoralLink(CBORObject node, Cori baseCori, CoralDictionary dictionary)
        {
            if (node[0].AsInt32() != 2)
            {
                throw new ArgumentException("Not an encoded CoRAL link");
            }

            if (dictionary == null)
            {
                throw new ArgumentNullException(nameof(dictionary));
            }

            CBORObject o = (CBORObject)dictionary.Reverse(node[1], false);

            if (o == null)
            {
                RelationTypeInt = node[1].AsInt32();
            }
            else if (o.Type == CBORType.Array)
            {
                RelationType = new Cori(o);
                if (node[1].Type == CBORType.Integer)
                {
                    RelationTypeInt = node[1].AsInt32();
                }
            }
            else
            {
                throw  new ArgumentException("Invalid relation in CoRAL link");
            }

            CBORObject value = (CBORObject)dictionary.Reverse(node[2], true);

            if (value == null)
            {
                if (!node[2].HasOneTag(CoralDictionary.DictionaryTag))
                {
                    throw new ArgumentException("Invalid tagging on value");
                }
                TargetInt = node[2].Untag().AsInt32();
            }
            else if (value.Type == CBORType.Array)
            {
                Target = new Cori(value).ResolveTo(baseCori);
                if (node[2].Type == CBORType.Integer)
                {
                    TargetInt = node[2].Untag().AsInt32();
                }

                baseCori = Target;
            }
            else
            {
                if (node[2].IsTagged && node[2].Type == CBORType.Integer)
                {
                    TargetInt = node[2].Untag().AsInt32();
                }
                Value = value;
            }

            if (node.Count == 4)
            {
                Body = new CoralBody(node[3], baseCori, dictionary);
            }
        }
Example #8
0
 public CoralLink(string relation, string target, CoralBody body = null) : this(relation, CBORObject.FromObject(target), body)
 {
 }
Example #9
0
 /// <summary>
 /// Create a CoRAL link from the parameters
 /// </summary>
 /// <param name="relation">string containing the relation - IRI</param>
 /// <param name="uriTarget">Absolute or relative CIRI for the target</param>
 /// <param name="body">attributes about the target</param>
 public CoralLink(string relation, Cori uriTarget, CoralBody body = null) : this(new Cori(relation), uriTarget, body)
 {
 }