Example #1
0
        private HttpWebRequest prepareRequest(string method, Uri uri, object data, IEnumerable <Tag> tags, bool expectBundleResponse)
        {
            byte[] body = null;

            Uri api = uri;

            if (UseFormatParam)
            {
                api = api.AddParam(HttpUtil.RESTPARAM_FORMAT, ContentType.BuildFormatParam(PreferredFormat));
            }

            var req = initializeRequest(api, method);

            if (!UseFormatParam)
            {
                req.Accept = ContentType.BuildContentType(PreferredFormat, forBundle: expectBundleResponse);
            }

            if (data is Binary)
            {
                var bin = (Binary)data;
                body            = bin.Content;
                req.ContentType = bin.ContentType;
            }
            else if (data is Resource)
            {
                body = PreferredFormat == ResourceFormat.Xml ?
                       FhirSerializer.SerializeResourceToXmlBytes((Resource)data) :
                       FhirSerializer.SerializeResourceToJsonBytes((Resource)data);

                req.ContentType = ContentType.BuildContentType(PreferredFormat, false);
            }
            else if (data is Bundle)
            {
                body = PreferredFormat == ResourceFormat.Xml ?
                       FhirSerializer.SerializeBundleToXmlBytes((Bundle)data) :
                       FhirSerializer.SerializeBundleToJsonBytes((Bundle)data);

                req.ContentType = ContentType.BuildContentType(PreferredFormat, true);
            }
            else if (data is TagList)
            {
                body = PreferredFormat == ResourceFormat.Xml ?
                       FhirSerializer.SerializeTagListToXmlBytes((TagList)data) :
                       FhirSerializer.SerializeTagListToJsonBytes((TagList)data);

                req.ContentType = ContentType.BuildContentType(PreferredFormat, false);
            }

            if (tags != null)
            {
                req.Headers[HttpUtil.CATEGORY] = HttpUtil.BuildCategoryHeader(tags);
            }

            if (body != null)
            {
                writeBody(req, body);
            }
            return(req);
        }
Example #2
0
        public void SetBody(TagList tagList, ResourceFormat format)
        {
            if (tagList == null)
            {
                throw Error.ArgumentNull("tagList");
            }

            _body = format == ResourceFormat.Xml ?
                    FhirSerializer.SerializeTagListToXmlBytes(tagList) :
                    FhirSerializer.SerializeTagListToJsonBytes(tagList);

            _contentType = ContentType.BuildContentType(format, forBundle: false);
        }
Example #3
0
 public static byte[] TagListBody(IEnumerable <Tag> tags, ContentType.ResourceFormat format)
 {
     return(serializeBody <IEnumerable <Tag> >(tags, format,
                                               t => FhirSerializer.SerializeTagListToXmlBytes(tags),
                                               t => FhirSerializer.SerializeTagListToJsonBytes(tags)));
 }