An immutable wrapper around our underlying content type representation which provides specialized processing for various processing like pretty printing and choosing correct file extensions.
示例#1
0
        /// <summary>
        /// Create a ResponseModel populated from an IRestResonse
        /// </summary>
        public ResponseModel(HttpResponseMessage response, DateTime start, DateTime end)
        {
            if (response == null)
            {
                throw new ArgumentNullException("response");
            }

            this.Status = string.Format("{0} {1}", (int)response.StatusCode, response.ReasonPhrase);

            Start = start;
            End   = end;

            var readContentBytesTask = response.Content.ReadAsByteArrayAsync();

            readContentBytesTask.Wait();
            this.ContentBytes = readContentBytesTask.Result;

            var readContentStringTask = response.Content.ReadAsStringAsync();

            readContentStringTask.Wait();
            this.Content = readContentStringTask.Result;

            var headers = response.Headers.Concat(response.Content.Headers);

            this.Headers = headers.Select(p => p.Key + ": " + p.Value.Coalesce().Join(", ")).Join(Environment.NewLine);

            var contentType = headers.FirstOrDefault(x => String.Equals(x.Key, "content-type", StringComparison.OrdinalIgnoreCase)).Value.Coalesce().Join(", ");

            this.ContentType = new IorContentType(contentType);

            this.ErrorMessage = null;

            initLazyFields(response.RequestMessage.RequestUri);
        }
示例#2
0
 private void initLazyFields(Uri requestUri)
 {
     this.prettyPrintedContent = new Lazy <string>(() => IorContentType.GetPrettyPrintedContent(this.ContentType.MediaTypeCategory, this.Content));
     this.contentFileExtension = new Lazy <string>(() => IorContentType.GetFileExtension(this.ContentType.MediaTypeCategory, this.ContentType.MediaType, requestUri));
     this.temporaryFile        = new Lazy <string>(() => FileUtils.CreateTempFile(this.ContentBytes, this.ContentFileExtension));
 }
示例#3
0
 /// <summary>
 /// Create an empty ResponseModel with ResponseStatus set to a loading message.
 /// </summary>
 public ResponseModel(string status = "")
 {
     this.Status      = status;
     this.ContentType = new IorContentType();
     initLazyFields(new Uri("http://localhost"));
 }
 /// <summary>
 /// Create an empty ResponseModel with ResponseStatus set to a loading message.
 /// </summary>
 public ResponseModel(string status = "")
 {
     this.Status      = status;
     this.ContentType = new IorContentType();
     initLazyFields();
 }
 public void default_ctor()
 {
     var ict = new IorContentType();
     ict.MediaType.Should().Be("application/octet-stream");
 }
 public void ctor_sets_category()
 {
     var ict = new IorContentType("text/xml");
     ict.MediaType.Should().Be("text/xml");
     ict.MediaTypeCategory.Should().Be(IorMediaTypeCategory.Xml);
 }
 public void ctor_forgive_illegal_content_type_fallback()
 {
     var ict = new IorContentType("R#O@IJ@#R");
     ict.MediaType.Should().Be("application/octet-stream");
 }
 public void ctor_forgives_illegal_comma_sep_content_type()
 {
     var ict = new IorContentType("text/xml, application/xml");
     ict.MediaType.Should().Be("text/xml");
 }