Пример #1
0
        /// <summary>
        /// Parses the entity identifier.
        /// </summary>
        /// <returns>EntityIdSegment contained absolute Uri representing $id</returns>
        public EntityIdSegment ParseEntityId()
        {
            if (this.entityIdSegment != null)
            {
                return(this.entityIdSegment);
            }

            string idQuery = queryOptions.GetQueryOptionValue(UriQueryConstants.IdQueryOption);

            if (idQuery == null)
            {
                return(null);
            }

            Uri idUri = new Uri(idQuery, UriKind.RelativeOrAbsolute);

            if (!idUri.IsAbsoluteUri)
            {
                if (!this.fullUri.IsAbsoluteUri)
                {
                    Uri baseUri = UriUtils.CreateMockAbsoluteUri();
                    Uri c       = new Uri(UriUtils.CreateMockAbsoluteUri(this.fullUri), idUri);
                    idUri = baseUri.MakeRelativeUri(c);
                }
                else
                {
                    idUri = new Uri(this.fullUri, idUri);
                }
            }

            this.entityIdSegment = new EntityIdSegment(idUri);
            return(this.entityIdSegment);
        }
Пример #2
0
        /// <summary>
        /// Parses the entity identifier.
        /// </summary>
        /// <returns>EntityIdSegment contained absolute Uri representing $id</returns>
        public EntityIdSegment ParseEntityId()
        {
            if (this.entityIdSegment != null)
            {
                return(this.entityIdSegment);
            }

            InitQueryOptionDic();
            string idQuery = null;

            if (!this.Resolver.EnableCaseInsensitive)
            {
                if (!this.queryOptionDic.TryGetValue(UriQueryConstants.IdQueryOption, out idQuery))
                {
                    return(null);
                }
            }
            else
            {
                var list = this.queryOptionDic
                           .Where(pair => string.Equals(UriQueryConstants.IdQueryOption, pair.Key, StringComparison.OrdinalIgnoreCase))
                           .ToList();

                if (list.Count == 0)
                {
                    return(null);
                }
                else if (list.Count == 1)
                {
                    idQuery = list.First().Value;
                }
                else
                {
                    throw new ODataException(Strings.QueryOptionUtils_QueryParameterMustBeSpecifiedOnce(UriQueryConstants.IdQueryOption));
                }
            }

            Uri idUri = new Uri(idQuery, UriKind.RelativeOrAbsolute);

            if (!idUri.IsAbsoluteUri)
            {
                if (!this.fullUri.IsAbsoluteUri)
                {
                    Uri baseUri = UriUtils.CreateMockAbsoluteUri();
                    Uri c       = new Uri(UriUtils.CreateMockAbsoluteUri(this.fullUri), idUri);
                    idUri = baseUri.MakeRelativeUri(c);
                }
                else
                {
                    idUri = new Uri(this.fullUri, idUri);
                }
            }

            this.entityIdSegment = new EntityIdSegment(idUri);
            return(this.entityIdSegment);
        }