public async Task <IActionResult> Post()
        {
            Task task;

            task = Task.Run(() =>
            {
                Stream stream = this.Request.Body;

                using (ProgressWrappedStream inputStream = new ProgressWrappedStream(stream))
                {
                    using (ProgressWrappedStream outputStream = new ProgressWrappedStream(System.IO.File.Create(Path.Combine("d:\\", $"api-post-{Guid.NewGuid().ToString("N")}.json"))))
                    {
                        inputStream.CopyTo(outputStream);
                    }
                }
            });

            await task;

            if (task.IsCompletedSuccessfully)
            {
                return(this.Ok());
            }
            else
            {
                return(this.StatusCode(500));
            }
        }
Пример #2
0
        /// <summary>
        /// https://blogs.msdn.microsoft.com/henrikn/2012/02/16/push-and-pull-streams-using-httpclient/
        /// </summary>
        /// <param name="stream"> </param>
        /// <param name="records"> </param>
        /// <returns> </returns>
        private void SerializeRecordsToStream(Stream stream, IAsyncEnumerable <IRecord> records)
        {
            Type serializationStrategyType;
            Type compressionStrategyType;

            ISerializationStrategy serializationStrategy;
            ICompressionStrategy   compressionStrategy;

            if ((object)stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            this.AssertValidConfiguration();

            RestfulWebApiConnectorSpecificConfiguration fsConfig = this.Configuration.StageSpecificConfiguration;

            serializationStrategyType = fsConfig.GetSerializationStrategyType();

            if ((object)serializationStrategyType == null)
            {
                throw new InvalidOperationException(nameof(serializationStrategyType));
            }

            serializationStrategy = (ISerializationStrategy)Activator.CreateInstance(serializationStrategyType);

            if ((object)serializationStrategy == null)
            {
                throw new InvalidOperationException(nameof(serializationStrategy));
            }

            compressionStrategyType = fsConfig.GetCompressionStrategyType();

            if ((object)compressionStrategyType == null)
            {
                throw new InvalidOperationException(nameof(compressionStrategyType));
            }

            compressionStrategy = (ICompressionStrategy)Activator.CreateInstance(compressionStrategyType);

            if ((object)compressionStrategy == null)
            {
                throw new InvalidOperationException(nameof(compressionStrategy));
            }

            stream = compressionStrategy.ApplyStreamWrap(stream);
            stream = new ProgressWrappedStream(stream);             // uncompressed
            serializationStrategy.SetObjectToStream(stream, records);
        }
        public async Task <IActionResult> Post()
        {
            Stream stream = this.Request.Body;
            string file   = null;

            using (ProgressWrappedStream inputStream = new ProgressWrappedStream(stream))
            {
                using (ProgressWrappedStream outputStream =                 /*new ProgressWrappedStream(Stream.Null)*/
                                                            new ProgressWrappedStream(System.IO.File.Create(Path.Combine("d:\\", file = $"api-post-{Guid.NewGuid().ToString("N")}.json")))
                       )
                {
                    await inputStream.CopyToAsync(outputStream);
                }
            }

            Console.WriteLine(file);

            return(this.Created(file, ""));
        }
Пример #4
0
 public Stream ApplyStreamWrap(Stream stream)
 {
     stream = new ProgressWrappedStream(stream);             // compressesed
     stream = new GZipStream(stream, CompressionLevel.Optimal);
     return(stream);
 }