Exemplo n.º 1
0
        private Bundle.EntryComponent newEntry(Bundle.HTTPVerb method)
        {
            var newEntry = new Bundle.EntryComponent();
            newEntry.Request = new Bundle.RequestComponent();
            newEntry.Request.Method = method;

            return newEntry;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Identifies if this entry is a deleted transaction (entry.Transaction.Method == DELETE)
        /// </summary>
        /// <param name="entry"></param>
        /// <returns></returns>
        public static bool IsDeleted(this Bundle.EntryComponent entry)
        {
            if (entry.Request != null)
            {
                return(entry.Request.Method == Bundle.HTTPVerb.DELETE);
            }

            return(false);
        }
Exemplo n.º 3
0
        public static Bundle.EntryComponent AddResourceEntry(this Bundle b, Resource r, string fullUrl)
        {
            var newEntry = new Bundle.EntryComponent()
            {
                Resource = r, FullUrl = fullUrl
            };

            b.Entry.Add(newEntry);

            return(newEntry);
        }
Exemplo n.º 4
0
        internal static Bundle.EntryComponent ToBundleEntry(this HttpWebResponse response, byte[] body)
        {
            var result = new Bundle.EntryComponent();

            result.Response = new Bundle.ResponseComponent();
            result.Response.Status = ((int)response.StatusCode).ToString();
            result.Response.SetHeaders(response.Headers);

            var contentType = getContentType(response);
            var charEncoding = getCharacterEncoding(response);

            result.Response.Location = response.Headers[HttpUtil.LOCATION] ?? response.Headers[HttpUtil.CONTENTLOCATION];

#if PORTABLE45
            if (!String.IsNullOrEmpty(response.Headers[HttpUtil.LASTMODIFIED]))
                    result.Response.LastModified = DateTimeOffset.Parse(response.Headers[HttpUtil.LASTMODIFIED]);
#else
            result.Response.LastModified = response.LastModified;
#endif
            result.Response.Etag = getETag(response);                     

            if (body != null)
            {
                result.Response.SetBody(body);

                if (IsBinaryResponse(response.ResponseUri.OriginalString, contentType))
                {
                    result.Resource = makeBinaryResource(body, contentType);
                    if (result.Response.Location != null)
                    {
                        var ri = new ResourceIdentity(result.Response.Location);
                        result.Resource.Id = ri.Id;
                        result.Resource.Meta = new Meta();
                        result.Resource.Meta.VersionId = ri.VersionId;
                        result.Resource.ResourceBase = ri.BaseUri;
                    }
                }
                else
                {
                    var bodyText = DecodeBody(body, charEncoding);
                    var resource = parseResource(bodyText, contentType);
                    result.Resource = resource;

                    if (result.Response.Location != null)
                        result.Resource.ResourceBase = new ResourceIdentity(result.Response.Location).BaseUri;
                }
            }

            return result;
        }
Exemplo n.º 5
0
        public static Bundle.EntryComponent AddSearchEntry(this Bundle b, Resource r, string fullUrl, Bundle.SearchEntryMode searchEntryMode, decimal searchScore)
        {
            var newEntry = new Bundle.EntryComponent
            {
                Resource = r,
                FullUrl  = fullUrl,
                Search   = new Bundle.SearchComponent {
                    Mode = searchEntryMode, Score = searchScore
                }
            };

            b.Entry.Add(newEntry);

            return(newEntry);
        }
Exemplo n.º 6
0
        public static bool IsTargetOf(this Bundle.EntryComponent entry, string reference)
        {
            // From the spec: If the reference is version specific (either relative or absolute), then remove the version from the URL
            // before matching fullUrl, and then match the version based on Resource.meta.versionId.

            if (reference == null)
            {
                throw Error.ArgumentNull(nameof(reference));
            }
            if (!new Uri(reference, UriKind.RelativeOrAbsolute).IsAbsoluteUri)
            {
                throw Error.Argument(nameof(reference), "uri should be absolute");
            }

            string referencedVersion = ResourceIdentity.IsRestResourceIdentity(reference) ? (new ResourceIdentity(reference).VersionId) : null;

            reference = referencedVersion != null ? (new ResourceIdentity(reference).WithoutVersion().ToString()) : reference;
            var refRestUrl = new RestUrl(reference);

            return(refRestUrl.IsSameUrl(new RestUrl(entry.FullUrl)) &&
                   (referencedVersion == null || (entry.HasResource() && entry.Resource.VersionId == referencedVersion)));
        }
Exemplo n.º 7
0
 public static bool HasResource(this Bundle.EntryComponent entry)
 {
     return(entry.Resource != null);
 }
Exemplo n.º 8
0
 public static ResourceIdentity GetResourceLocation(this Bundle.EntryComponent entry, string baseUrl = null)
 {
     return(entry.FullUrl != null ?  new ResourceIdentity(entry.FullUrl) : null);
 }