//OnWriteToStreamAsync(Type type, object value, Stream stream, HttpContentHeaders contentHeaders, FormatterContext formatterContext, TransportContext transportContext)
        public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext)
        {
            string uri = HttpContext.Current.Request.Url.Query;
            string method = HttpContext.Current.Request.HttpMethod;
            if(HttpContext.Current.Request.HttpMethod =="GET")
            {

                return Task.Factory.StartNew(() =>
                {
                    var writer = new StreamWriter(writeStream);
                    var query = HttpUtility.ParseQueryString(uri);
                    string callback = query[CallbackQueryParameter];
                    writer.Write(callback + "(");
                    writer.Flush();

                    base.WriteToStreamAsync(type, value, writeStream, content, transportContext).Wait();

                    writer.Write(")");
                    writer.Flush();
                });
            }
            else
            {
                return base.WriteToStreamAsync(type, value, writeStream, content, transportContext);
            }
        }
Exemplo n.º 2
0
 public override System.Threading.Tasks.Task WriteToStreamAsync(Type type, object value, Stream stream, HttpContent content, TransportContext transportContext)
 {
     return new TaskFactory().StartNew(() =>
                                                   {
                                                       new StreamWriter(stream).Write((string)value);
                                                   });
 }
Exemplo n.º 3
0
 protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
 {
     _problemStream.CopyTo(stream);  // Because this is likely a small document there is no advantage to switching threads to do this copy.
     var tcs = new TaskCompletionSource<object>();
     tcs.SetResult(null);
     return tcs.Task;
 }
Exemplo n.º 4
0
        public async Task StreamVideo(Stream stream, HttpContent content, TransportContext transport)
        {
            try
            {
                var buffer = new byte[65536];
                var filename = Path.Combine(String.Format("{0}{1}video.{2}", System.Web.HttpContext.Current.Server.MapPath("~"), Constants.FilePath, _fileExtension));
                using (var file = File.Open(filename, FileMode.Open, FileAccess.Read))
                {
                    var videoLength = (int)file.Length;
                    var placeInFile = 1;

                    while (videoLength > 0 && placeInFile > 0)
                    {
                        placeInFile = file.Read(buffer, 0, Math.Min(videoLength, buffer.Length));
                        await stream.WriteAsync(buffer, 0, placeInFile);
                        videoLength -= placeInFile;
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.InnerException);
            }
            finally
            {
                stream.Close();
            }
        }
Exemplo n.º 5
0
        public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext)
        {
            
            return Task.Factory.StartNew(() =>
            {
                XmlWriter writer = new XmlTextWriter(writeStream, new UTF8Encoding(false));
                bool summary = requestMessage.RequestSummary();

                if (type == typeof(OperationOutcome)) 
                {
                    Resource resource = (Resource)value;
                    FhirSerializer.SerializeResource(resource, writer, summary);
                }
                else if (type.IsAssignableFrom(typeof(Resource)))
                {
                    Resource resource = (Resource)value;
                    FhirSerializer.SerializeResource(resource, writer, summary);
                    
                    content.Headers.ContentLocation = resource.ExtractKey().ToUri();
                }
                else if (type == typeof(FhirResponse))
                {
                    FhirResponse response = (value as FhirResponse);
                    if (response.HasBody)
                    FhirSerializer.SerializeResource(response.Resource, writer, summary);
                }
                
                writer.Flush();
            });
        }
Exemplo n.º 6
0
 public override async Task WriteToStreamAsync(Type type, object value, Stream stream, HttpContent content, TransportContext transportContext)
 {
     using (stream)
     {
         Encoding encoding = SelectCharacterEncoding(content.Headers);
         using (var writer = new StreamWriter(stream, encoding))
         {
             var individuals = value as IEnumerable<Individual>;
             if (individuals != null)
             {
                 foreach (var individu in individuals)
                 {
                     await writer.WriteLineAsync(String.Format("{0,-10};{1,-10};{2,-10}", individu.Id, individu.FirstName, individu.LastName));
                 }
                 await writer.FlushAsync();
             }
             var individual = value as Individual;
             if (individual != null)
             {
                 await writer.WriteLineAsync(String.Format("{0,-10};{1,-10};{2,-10}", individual.Id, individual.FirstName, individual.LastName));
                 await writer.FlushAsync();
             }
         }
     }
 }
Exemplo n.º 7
0
        protected override Task OnWriteToStreamAsync(Type type, object value, Stream stream,
                                                     HttpContentHeaders contentHeaders,
                                                     FormatterContext formatterContext,
                                                     TransportContext transportContext)
        {
            var serializer = JsonSerializer.Create(jsonSerializerSettings);
            var tcs = new TaskCompletionSource<object>();

            try
            {
                using (var streamWriter = new StreamWriter(stream, Encoding))
                {
                    using (var jsonTextWriter = new JsonTextWriter(streamWriter))
                    {
                        serializer.Serialize(jsonTextWriter, value);
                        tcs.SetResult(null);
                    }
                }
            }
            catch (Exception ex)
            {
                tcs.SetException(ex);
            }

            return tcs.Task;
        }
Exemplo n.º 8
0
        protected override Task OnWriteToStreamAsync(Type type, object value, Stream stream,
                                               HttpContentHeaders contentHeaders,
                                               FormatterContext formatterContext,
                                               TransportContext transportContext)
        {
            string callback;

               if (IsJsonpRequest(formatterContext.Response.RequestMessage, out callback))
               {
            return Task.Factory.StartNew(() =>
            {
             var writer = new StreamWriter(stream);
             writer.Write(callback + "(");
             writer.Flush();

             base.OnWriteToStreamAsync(type, value, stream, contentHeaders,
                             formatterContext, transportContext).Wait();

             writer.Write(")");
             writer.Flush();
            });
               }
               else
               {
            return base.OnWriteToStreamAsync(type, value, stream, contentHeaders, formatterContext, transportContext);
               }
        }
Exemplo n.º 9
0
        async void WriteToStream(Stream outputStream, HttpContent content, TransportContext context)
        {
            try
            {
                var buffer = new byte[_chunkSize];
                using (var inputStream = OpenInputStream())
                {
                    var length = (int)inputStream.Length;
                    var bytesRead = 1;

                    while (length > 0 && bytesRead > 0)
                    {
                        bytesRead = inputStream.Read(buffer, 0, Math.Min(length, buffer.Length));
                        await outputStream.WriteAsync(buffer, 0, bytesRead);
                        length -= bytesRead;
                    }
                }
            }
            catch (HttpException)
            {
            }
            finally
            {
                outputStream.Close();
                outputStream.Dispose();
            }
        }
Exemplo n.º 10
0
        public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content,
                                                TransportContext transportContext)
        {
            var callback = GetCallbackName();

            if (!String.IsNullOrEmpty(callback))
            {
                // select the correct encoding to use.
                Encoding encoding = SelectCharacterEncoding(content.Headers);

                // write the callback and opening paren.
                return Task.Factory.StartNew(() =>
                {
                    var bytes = encoding.GetBytes(callback + "(");
                    writeStream.Write(bytes, 0, bytes.Length);
                })
                    // then we do the actual JSON serialization...
                .ContinueWith(t => base.WriteToStreamAsync(type, value, writeStream, content, transportContext))

                // finally, we close the parens.
                .ContinueWith(t =>
                {
                    var bytes = encoding.GetBytes(")");
                    writeStream.Write(bytes, 0, bytes.Length);
                });
            }
            return base.WriteToStreamAsync(type, value, writeStream, content, transportContext);
        }
Exemplo n.º 11
0
 protected override Task SerializeToStreamAsync(
                                         Stream stream,
                                         TransportContext context) {
         var tcs = new TaskCompletionSource<object>();
         tcs.SetResult(null);
         return tcs.Task;
 }
Exemplo n.º 12
0
        public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, System.Net.Http.HttpContent content, TransportContext transportContext)
        {
            if (type == null) throw new ArgumentNullException("type");
            if (writeStream == null) throw new ArgumentNullException("writeStream");

            var tcs = new TaskCompletionSource<object>();
            try
            {
                if (_writerSettings == null)
                {
                    this._writerSettings = new XmlWriterSettings()
                    {
                        OmitXmlDeclaration = true,
                        Indent = true,
                        Encoding = SelectCharacterEncoding(content != null ? content.Headers : null),
                        CloseOutput = false
                    };
                }
                using (XmlWriter writer = XmlWriter.Create(writeStream, _writerSettings))
                {
                    XmlSerializer xmlSerializer = new XmlSerializer(type);
                    xmlSerializer.Serialize(writer, value, _namespaces);
                    tcs.SetResult(null);
                }
            }
            catch (Exception e)
            {
                tcs.SetException(e);
            }
            return tcs.Task;
        }
        public override async Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)
        {
            if (type == typeof (AdminProject))
            {
                var project = (AdminProject)value;
                await WriteAsync(project, writeStream, cancellationToken);
            }
            else if (typeof (IEnumerable<AdminProject>).IsAssignableFrom(type))
            {
                var projects = (IEnumerable<AdminProject>)value;
                foreach (AdminProject project in projects)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        return;
                    }

                    await WriteAsync(project, writeStream, cancellationToken);
                }
            }
            else
            {
                throw new NotSupportedException("Cannot serialize type");
            }
        }
Exemplo n.º 14
0
        protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
        {
            if (HasNoData())
                return new CompletedTask<bool>(true);

            using ( var undisposableStream = new UndisposableStream(stream) )
            using ( var bufferedStream = new BufferedStream(undisposableStream))
            {
                var writer = new StreamWriter(bufferedStream, DefaultEncoding);
                if (string.IsNullOrEmpty(Jsonp) == false)
                {
                    writer.Write(Jsonp);
                    writer.Write("(");
                }

                Data.WriteTo(new JsonTextWriter(writer)
                {
                    Formatting = IsOutputHumanReadable ? Formatting.Indented : Formatting.None,
                }, Default.Converters);

                if (string.IsNullOrEmpty(Jsonp) == false)
                    writer.Write(")");

                writer.Flush();
            }

            return new CompletedTask<bool>(true);
        }
Exemplo n.º 15
0
		protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
		{
		    if (HasNoData())
		        return new CompletedTask<bool>(true);

			if (string.IsNullOrEmpty(Jsonp))
				Headers.ContentType = new MediaTypeHeaderValue("application/json") {CharSet = "utf-8"};
			else
				Headers.ContentType = new MediaTypeHeaderValue("application/javascript") {CharSet = "utf-8"};

			var writer = new StreamWriter(stream, DefaultEncoding);
			if (string.IsNullOrEmpty(Jsonp) == false)
			{
				writer.Write(Jsonp);
				writer.Write("(");
			}

			Data.WriteTo(new JsonTextWriter(writer)
			{
				Formatting = IsOutputHumanReadable ? Formatting.Indented : Formatting.None,
			}, Default.Converters);

			if (string.IsNullOrEmpty(Jsonp) == false)
				writer.Write(")");

			writer.Flush();
            return new CompletedTask<bool>(true);
		}
Exemplo n.º 16
0
        private void OnStreamAvailable(Stream stream, HttpContent content, System.Net.TransportContext context)
        {
            var client  = new StreamWriter(stream);
            var subInfo = AddSubscriber(client);

            content.Headers.Add("ClientSessionGuid", subInfo.ClientSessionGuid.ToString());
        }
Exemplo n.º 17
0
        protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
        {
            using (var uncloseableStream = new UndisposableStream(stream))
            using (var bufferedStream = new BufferedStream(uncloseableStream))
            {
                Stream compressedStream = null;

                if (encodingType == "gzip")
                {
                    compressedStream = new GZipStream(bufferedStream, CompressionMode.Compress, leaveOpen: true);
                }
                else if (encodingType == "deflate")
                {
                    compressedStream = new DeflateStream(bufferedStream, CompressionMode.Compress, leaveOpen: true);
                }
                else throw new InvalidOperationException("This shouldn't happen, ever.");

                await originalContent.CopyToAsync(compressedStream);

                if (compressedStream != null)
                {
                    compressedStream.Dispose();
                }
            }
        }
Exemplo n.º 18
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();
            });
        }
        public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext)
        {
            if (ReferenceEquals(value, null)) {
                return _baseFormatter.WriteToStreamAsync(typeof (HalModel), new HalModel(), writeStream, content, transportContext);
            }

            var valType = value.GetType();
            if (valType != typeof(HalModel))
            {
                if (valType.IsArray || value is IEnumerable<object>)
                {
                    var data = value as IEnumerable<object>;
                    value = new HalModel(new { Count = data.Count() })
                        .AddLinks(new HalLink("self", RequestPath))
                        .AddEmbeddedCollection("values", data);
                }
                else
                {
                    value = new HalModel(value);
                }
                type = typeof(HalModel);
            }

            var model = value as HalModel;
            model.Config.IsRoot = true;
            model.Config.RequestPathBase = RequestPathBase;
            model.Config.Expands = Expands;

            return _baseFormatter.WriteToStreamAsync(type, model, writeStream, content, transportContext);
        }
Exemplo n.º 20
0
 public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext)
 {
     return Task.Factory.StartNew(() =>
     {
         WriteHTMLOutput(type, value, writeStream);
     });
 }
Exemplo n.º 21
0
			protected override Task SerializeToStreamAsync (Stream stream, TransportContext context)
			{
				if (OnSerializeToStreamAsync != null)
					OnSerializeToStreamAsync ();

				return base.SerializeToStreamAsync (stream, context);
			}
Exemplo n.º 22
0
 /// <summary>
 /// Serialize the HTTP content to a stream as an asynchronous operation.
 /// </summary>
 /// <param name="stream">The target stream.</param>
 /// <param name="context">Information about the transport (channel binding token, for example). This parameter may be null.</param>
 /// <returns>
 /// Returns <see cref="T:System.Threading.Tasks.Task" />.The task object representing the asynchronous operation.
 /// </returns>
 protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
 {
     using (Stream compressedStream = new GZipStream(stream, CompressionMode.Compress, true))
     {
         await this._originalContent.CopyToAsync(compressedStream);
     }
 }
Exemplo n.º 23
0
 public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content,
     TransportContext transportContext)
 {
     dynamic obj = Convert.ChangeType(value, type);
     value = BuildEntity(obj);
     return base.WriteToStreamAsync(value.GetType(), value, writeStream, content, transportContext);
 }
Exemplo n.º 24
0
 public override Task WriteToStreamAsync(Type type, object value, Stream output, HttpContent content, TransportContext transportContext)
 {
     var writer = new StreamWriter(output);
     JSON.Serialize(value, writer, _options);
     writer.Flush();
     return Done;
 }
Exemplo n.º 25
0
        public async void WriteToStream(Stream outputStream, HttpContent content, TransportContext context)
        {
            try
            {
                var buffer = new byte[65536];

                using (var media = File.Open(_filename, FileMode.Open, FileAccess.Read))
                {
                    var length = (int)media.Length;
                    var bytesRead = 1;

                    while (length > 0 && bytesRead > 0)
                    {
                        bytesRead = media.Read(buffer, 0, Math.Min(length, buffer.Length));
                        await outputStream.WriteAsync(buffer, 0, bytesRead);
                        length -= bytesRead;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new BlogException(ex.Message, ex);
            }
            finally
            {
                outputStream.Close();
            }
        }
Exemplo n.º 26
0
        public static void OnStreamAvailable1(Stream stream, HttpContent headers, TransportContext context)
        {
            StreamWriter streamwriter = new StreamWriter(stream);
            //_streammessage.TryAdd(_streammessage.Count+1,streamwriter);

            StartWriting(streamwriter);
        }
Exemplo n.º 27
0
        public async void WriteToStream(Stream outputStream, HttpContent content, TransportContext context)
        {
            try
            {
                var buffer = new byte[65536];

                using (var video = new MemoryStream(this.videoData))
                {
                    var length = (int)video.Length;
                    var bytesRead = 1;

                    while (length > 0 && bytesRead > 0)
                    {
                        bytesRead = video.Read(buffer, 0, Math.Min(length, buffer.Length));
                        await outputStream.WriteAsync(buffer, 0, bytesRead);
                        length -= bytesRead;
                    }
                }
            }
            catch (Exception ex)
            {
                return;
            }
            finally
            {
                outputStream.Close();
            }
        }
Exemplo n.º 28
0
        public async void WriteToStream(Stream outputStream, HttpContent content, TransportContext context)
        {
            try
            {

              var channelBinding=   context.GetChannelBinding(ChannelBindingKind.Endpoint);

                var buffer = new byte[65536];
                using (var video = File.Open(_filename, FileMode.Open, FileAccess.Read))
                {
                    var length = (int)video.Length;
                    var bytesRead = 1;
                    while (length > 0 && bytesRead > 0)
                    {
                        bytesRead = video.Read(buffer, 0, Math.Min(length, buffer.Length));
                        await outputStream.WriteAsync(buffer, 0, bytesRead);
                        length -= bytesRead;
                    }
                }
            }
            catch (HttpResponseException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            finally
            {
                outputStream.Close();
            }
        }
Exemplo n.º 29
0
		protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
		{
			using (var writer = new StreamWriter(stream))
			{
                await writer.WriteAsync("data: { \"Type\": \"Heartbeat\" }\r\n\r\n");
				await writer.FlushAsync();
							
				while (Connected)
				{
					try
					{
						var result = await manualResetEvent.WaitAsync(5000);
						if (Connected == false)
							return;

						if (result == false)
						{
                            await writer.WriteAsync("data: { \"Type\": \"Heartbeat\" }\r\n\r\n");
							await writer.FlushAsync();

                            if (lastMessageEnqueuedAndNotSent != null)
                            {
								await SendMessage(lastMessageEnqueuedAndNotSent, writer);
                            }
							continue;
						}

						manualResetEvent.Reset();

						object message;
						while (msgs.TryDequeue(out message))
						{
							if (CoolDownWithDataLossInMiliseconds > 0 && Environment.TickCount - lastMessageSentTick < CoolDownWithDataLossInMiliseconds)
                            {
                                lastMessageEnqueuedAndNotSent = message;
                                continue;
                            }

							await SendMessage(message, writer);
						}
					}
					catch (Exception e)
					{
						Connected = false;
						log.DebugException("Error when using events transport", e);
						Disconnected();
						try
						{
							writer.WriteLine(e.ToString());
						}
						catch (Exception)
						{
							// try to send the information to the client, okay if they don't get it
							// because they might have already disconnected
						}

					}
				}
			}
		}
        public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (writeStream == null)
            {
                throw new ArgumentNullException("writeStream");
            }

            CheckForIEnumerable(ref type, ref value);

            var completion = new TaskCompletionSource<bool>();

            if (cancellationToken.IsCancellationRequested)
            {
                completion.SetCanceled();
            }
            else
            {
                try
                {
                    WriteValue(type, value, writeStream, content);
                    completion.SetResult(true);
                }
                catch (Exception ex)
                {
                    completion.SetException(ex);
                }
            }

            return completion.Task;
        }
Exemplo n.º 31
0
            protected override Task SerializeToStreamAsync(Stream stream, System.Net.TransportContext context)
            {
                _Stream.CopyTo(stream);

                var tcs = new TaskCompletionSource <object>();

                tcs.SetResult(null);
                return(tcs.Task);
            }
Exemplo n.º 32
0
        /// <summary>
        /// When this method is called, it calls the action provided in the constructor with the output
        /// stream to write to. Once the action has completed its work it closes the stream which will
        /// close this content instance and complete the HTTP request or response.
        /// </summary>
        /// <param name="stream">The <see cref="Stream"/> to which to write.</param>
        /// <param name="context">The associated <see cref="TransportContext"/>.</param>
        /// <returns>A <see cref="Task"/> instance that is asynchronously serializing the object's content.</returns>
        protected override async Task SerializeToStreamAsync(Stream stream, System.Net.TransportContext context)
        {
            TaskCompletionSource <bool> serializeToStreamTask = new TaskCompletionSource <bool>();

            Stream wrappedStream = new CompleteTaskOnCloseStream(stream, serializeToStreamTask);

            await _onStreamAvailable(wrappedStream, this, context);

            // wait for wrappedStream.Close/Dispose to get called.
            await serializeToStreamTask.Task;
        }
        public override Task WriteToStreamAsync
        (
            Type type, object value,
            Stream stream,
            System.Net.Http.HttpContent content,
            System.Net.TransportContext transportContext
        )
        {
            string callback;

            /*
             * if (IsJsonpRequest(formatterContext.Response.RequestMessage, out callback))
             * {
             *  return Task.Factory.StartNew
             *  (
             *      () =>
             *      {
             *          var writer = new StreamWriter(stream);
             *          writer.Write(string.Format("callback{0}", "("));
             *          writer.Flush();
             *          base.OnWriteToStreamAsync
             *              (
             *                  type,
             *                  value,
             *                  stream,
             *                  contentHeaders,
             *                  formatterContext,
             *                  transportContext
             *              ).Wait();
             *
             *          writer.Write(")");
             *          writer.Flush();
             *
             *      }
             *  );
             * }
             * else
             * {
             *  return base.OnWriteToStreamAsync
             *              (
             *                  type,
             *                  value,
             *                  stream,
             *                  contentHeaders,
             *                  formatterContext,
             *                  transportContext
             *              );
             * }
             */

            return(default(Task));
        }
 public override Task WriteToStreamAsync
 (
     Type type, object value,
     Stream stream,
     System.Net.Http.HttpContent content,
     System.Net.TransportContext transportContext
 )
 {
     return
         (new Task
          (
              () =>
     {
         StreamWriter writer = new StreamWriter(stream);
         writer.Write(value.ToString());
     }
          ));
 }
Exemplo n.º 35
0
        public override System.Threading.Tasks.Task WriteToStreamAsync(Type type, object value, System.IO.Stream writeStream, System.Net.Http.HttpContent content, System.Net.TransportContext transportContext)
        {
            var viewmodel = value as string;
            var sr        = new StreamWriter(writeStream);

            sr.Write(viewmodel);
            sr.Flush();
            var tcs = new TaskCompletionSource <Stream>();

            tcs.SetResult(writeStream);
            return(tcs.Task);
        }
        public override System.Threading.Tasks.Task WriteToStreamAsync(Type type, object value, System.IO.Stream writeStream, HttpContent content, System.Net.TransportContext transportContext)
        {
            if (value is ResourceEntry)
            {
                ResourceEntry re = (ResourceEntry)value;

                if (re.SelfLink != null)
                {
                    content.Headers.ContentLocation = re.SelfLink;
                }
                if (re.LastUpdated != null)
                {
                    content.Headers.LastModified = re.LastUpdated;
                }
            }

            return(base.WriteToStreamAsync(type, value, writeStream, content, transportContext));
        }
Exemplo n.º 37
0
 public override Task WriteToStreamAsync(Type type, object value, Stream stream, System.Net.Http.HttpContent content, System.Net.TransportContext transportContext)
 {
     return(Task.Factory.StartNew(() => WriteQrStream(type, value, stream, content.Headers)));
 }
Exemplo n.º 38
0
        public override System.Threading.Tasks.Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, System.Net.TransportContext transportContext)
        {
            Binary binary = (Binary)value;
            //var stream = new MemoryStream(binary.Content);
            var stream = new MemoryStream(binary.Data);

            content.Headers.ContentType = new MediaTypeHeaderValue(binary.ContentType);
            stream.CopyTo(writeStream);
            stream.Flush();

            return(System.Threading.Tasks.Task.CompletedTask);
        }
Exemplo n.º 39
0
 public Stream EndGetRequestStream(IAsyncResult asyncResult, ref TransportContext context)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 40
0
    public override Task WriteToStreamAsync(Type type, object?value, Stream writeStream, HttpContent content, System.Net.TransportContext transportContext, System.Threading.CancellationToken cancellationToken)
    {
        if (value == null)
        {
            return(Task.CompletedTask);
        }
        var buff = System.Text.Encoding.UTF8.GetBytes(value.ToString() !);

        return(writeStream.WriteAsync(buff, 0, buff.Length, cancellationToken));
    }
Exemplo n.º 41
0
 public Stream GetRequestStream(out TransportContext context)
 {
     context = null;
     return(GetRequestStream());
 }
Exemplo n.º 42
0
 public Stream GetRequestStream(ref TransportContext context)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 43
0
 public Stream EndGetRequestStream(IAsyncResult asyncResult, out TransportContext context)
 {
     context = null;
     return(EndGetRequestStream(asyncResult));
 }
Exemplo n.º 44
-1
 public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext)
 {
     var writer = new StreamWriter(writeStream);
     JSON.Serialize(value, writer, _options);
     writer.Flush();
     return Task.FromResult(writeStream);
 }