public MethodBasedOperation(IObjectBinderLocator binderLocator, IType ownerType, IMethod method) { _method = method; _ownerType = ownerType; _parameterBinders = method.InputMembers.ToDictionary(x => x, x => binderLocator.GetBinder(x)); Inputs = _parameterBinders.Select(x => new InputMember(x.Key, x.Value, x.Key.IsOptional)); ExtendedProperties = new NullBehaviorDictionary <object, object>(); }
IDictionary <string, IList <IMultipartHttpEntity> > PreLoadAllParts(IHttpEntity source) { var multipartReader = new MultipartReader(source.ContentType.Boundary, source.Stream) { Log = Log }; var formData = new NullBehaviorDictionary <string, IList <IMultipartHttpEntity> >(StringComparer.OrdinalIgnoreCase); foreach (var requestPart in multipartReader.GetParts()) { if (requestPart.Headers.ContentDisposition != null && requestPart.Headers.ContentDisposition.Disposition.EqualsOrdinalIgnoreCase("form-data")) { var memoryStream = new MemoryStream(); int totalRead = 0, lastRead; while ((lastRead = requestPart.Stream.Read(_buffer, 0, _buffer.Length)) > 0) { totalRead += lastRead; if (totalRead > REQUEST_LENGTH_TRESHOLD) { string filePath; using (var fileStream = CreateTempFile(out filePath)) { memoryStream.Position = 0; memoryStream.CopyTo(fileStream); fileStream.Write(_buffer, 0, lastRead); requestPart.Stream.CopyTo(fileStream); } memoryStream = null; requestPart.SwapStream(filePath); break; } memoryStream.Write(_buffer, 0, lastRead); } if (memoryStream != null) { memoryStream.Position = 0; requestPart.SwapStream(memoryStream); } var listOfEntities = formData[requestPart.Headers.ContentDisposition.Name] ?? (formData[requestPart.Headers.ContentDisposition.Name] = new List <IMultipartHttpEntity>()); if (requestPart.ContentType == null) { requestPart.ContentType = MediaType.TextPlain; } listOfEntities.Add(requestPart); } } return(formData); }
IDictionary<string, IList<IMultipartHttpEntity>> PreLoadAllParts(IHttpEntity source) { var multipartReader = new MultipartReader(source.ContentType.Boundary, source.Stream) { Log = Log }; var formData = new NullBehaviorDictionary<string, IList<IMultipartHttpEntity>>(StringComparer.OrdinalIgnoreCase); foreach (var requestPart in multipartReader.GetParts()) { if (requestPart.Headers.ContentDisposition != null && requestPart.Headers.ContentDisposition.Disposition.EqualsOrdinalIgnoreCase("form-data")) { var memoryStream = new MemoryStream(); int totalRead = 0, lastRead; while ((lastRead = requestPart.Stream.Read(_buffer, 0, _buffer.Length)) > 0) { totalRead += lastRead; if (totalRead > REQUEST_LENGTH_TRESHOLD) { string filePath; using (var fileStream = CreateTempFile(out filePath)) { memoryStream.Position = 0; var memoryStreamLength = memoryStream.CopyTo(fileStream); fileStream.Write(_buffer, 0, lastRead); var leftoverLength = requestPart.Stream.CopyTo(fileStream); } memoryStream = null; requestPart.SwapStream(filePath); break; } memoryStream.Write(_buffer, 0, lastRead); } if (memoryStream != null) { memoryStream.Position = 0; requestPart.SwapStream(memoryStream); } var listOfEntities = formData[requestPart.Headers.ContentDisposition.Name] ?? (formData[requestPart.Headers.ContentDisposition.Name] = new List<IMultipartHttpEntity>()); if (requestPart.ContentType == null) requestPart.ContentType = MediaType.TextPlain; listOfEntities.Add(requestPart); } } return formData; }