Example #1
0
        public virtual Stream ProcessAsynchronously(Stream requestStream)
        {
            DateTime now        = DateTime.Now;
            string   asyncToken = now.Ticks.ToString(CultureInfo.InvariantCulture);

            AsyncTask asyncTask = null;

            if (requestStream == null)
            {
                asyncTask = new AsyncTask(this, this.CreateRequestMessage(null), now.AddSeconds(AsyncTask.DefaultDuration));
            }
            else
            {
                StreamPipe requestPipe = new StreamPipe();
                using (requestPipe.WriteStream)
                {
                    requestStream.CopyTo(requestPipe.WriteStream); // read the input stream to memory
                }

                var requestMessage = this.CreateRequestMessage(requestPipe.ReadStream);
                asyncTask = new AsyncTask(this, requestMessage, now.AddSeconds(AsyncTask.DefaultDuration));
            }
            AsyncTask.AddTask(asyncToken, asyncTask);

            StreamPipe responsePipe    = new StreamPipe();
            var        responseMessage = new ODataResponseMessage(responsePipe.WriteStream, 202); //202 Accepted

            responseMessage.PreferenceAppliedHeader().RespondAsync = true;
            ResponseWriter.WriteAsyncPendingResponse(responseMessage, asyncToken);
            return(responsePipe.ReadStream);
        }