예제 #1
0
        /// <summary>
        /// Checks whether the supplied identity is a valid Curie and if so resolves it against the supplied namespace mappings
        /// </summary>
        /// <param name="identity"></param>
        /// <returns></returns>
        protected string ResolveIdentity(string identity)
        {
            var curie = new Curie(identity);

            if (curie.IsValidCurie && _namespaceMappings.ContainsKey(curie.Prefix))
            {
                return(Curie.ResolveCurie(curie, _namespaceMappings).ToString());
            }
            if (Uri.IsWellFormedUriString(identity, UriKind.Absolute))
            {
                return(identity);
            }
            throw new ArgumentException(Strings.InvalidDataObjectIdentity, "identity");
        }
예제 #2
0
        /// <summary>
        /// The string value can either be a valid absolute URI or a CURIE.
        /// </summary>
        /// <param name="identity">The URI or CURIE that identifies the DataObject</param>
        /// <exception cref="ArgumentException">Thrown if <paramref name="identity"/> could not be parsed as a CURIE or a URI</exception>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="identity"/> is NULL</exception>
        /// <returns></returns>
        public IDataObject MakeDataObject(string identity)
        {
            if (identity == null)
            {
                throw new ArgumentNullException("identity");
            }
            var curie = new Curie(identity);

            if (curie.IsValidCurie && _namespaceMappings.ContainsKey(curie.Prefix))
            {
                return(RegisterDataObject(new DataObject(this, Curie.ResolveCurie(new Curie(identity), _namespaceMappings).ToString())));
            }

            Uri uri;
            var validUri = Uri.TryCreate(identity, UriKind.Absolute, out uri);

            if (validUri)
            {
                return(RegisterDataObject(new DataObject(this, identity)));
            }

            throw new ArgumentException(Strings.InvalidDataObjectIdentity, "identity");
        }