Exemplo n.º 1
0
 public void sample_contains_two_parts()
 {
     var data = new MultiPartStream(MultiPartFormDataSample.Boundry);
     var parts = 0;
     data.PartReady += (s, e) => ++parts;
     data.Read(MultiPartFormDataSample.CreateSampleStream());
     Verify.That(() => parts == 2);
 }
Exemplo n.º 2
0
 void ParseMultiPart(IRequestStream request)
 {
     var multiPartStream = new MultiPartStream(GetBoundary(request.ContentType));
     multiPartStream.PartReady += (sender, e) => {
         var disposition = e.Part["Content-Disposition"];
         var name = NamePattern.Match(disposition).Groups["name"].Value;
         var hasFileName = FilenamePattern.Match(disposition);
         if(hasFileName.Success)
             files.Add(name, new BasicHttpPostedFile(
                 hasFileName.Groups["filename"].Value,
                 e.Part["Content-Type"],
                 e.Part.Body));
         else
             fields.Add(name, e.Part.GetBodyText(Encoding.UTF8));
     };
     multiPartStream.Read(request.InputStream, request.ContentLength);
 }