Example #1
0
        public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext)
        {
            return(Task.Factory.StartNew(() =>
            {
                StreamWriter writer = new StreamWriter(writeStream);
                JsonWriter jsonwriter = new JsonTextWriter(writer);
                if (type == typeof(OperationOutcome))
                {
                    Resource resource = (Resource)value;
                    FhirSerializer.SerializeResource(resource, jsonwriter);
                }
                else if (type == typeof(ResourceEntry))
                {
                    ResourceEntry entry = (ResourceEntry)value;
                    FhirSerializer.SerializeResource(entry.Resource, jsonwriter);
                    content.Headers.SetFhirTags(entry.Tags);
                }
                else if (type == typeof(Bundle))
                {
                    FhirSerializer.SerializeBundle((Bundle)value, jsonwriter);
                }
                else if (type == typeof(TagList))
                {
                    FhirSerializer.SerializeTagList((TagList)value, jsonwriter);
                }

                writer.Flush();
            }));
        }
Example #2
0
        public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext)
        {
            return(Task.Factory.StartNew(() =>
            {
                XmlWriter writer = new XmlTextWriter(writeStream, Encoding.UTF8);
                // todo: klopt het dat Bundle wel en <?xml ...> header heeft een Resource niet?
                // follow up: is now ticket in FhirApi. Check later.

                if (type == typeof(OperationOutcome))
                {
                    Resource resource = (Resource)value;
                    FhirSerializer.SerializeResource(resource, writer);
                }
                else if (type == typeof(ResourceEntry))
                {
                    ResourceEntry entry = (ResourceEntry)value;
                    FhirSerializer.SerializeResource(entry.Resource, writer);

                    content.Headers.SetFhirTags(entry.Tags);
                }

                else if (type == typeof(Bundle))
                {
                    FhirSerializer.SerializeBundle((Bundle)value, writer);
                }
                else if (type == typeof(TagList))
                {
                    FhirSerializer.SerializeTagList((TagList)value, writer);
                }

                writer.Flush();
            }));
        }