public override Stream WriteResponse(oEmbed oembed, oEmbedFormat format,
                                      string callback)
 {
     if (oembed == null)
         return FileNotFound();
     string oEmbedString;
     switch (format)
     {
         case oEmbedFormat.Unspecified:
         case oEmbedFormat.Json:
             oEmbedString = oEmbedSerializer.SerializeJson(oembed);
             _response.ContentType = "application/json";
             break;
         case oEmbedFormat.Jsonp:
             oEmbedString = callback + "(" + oEmbedSerializer.SerializeJson(oembed) + ")";
             _response.ContentType = "application/javascript";
             break;
         case oEmbedFormat.Xml:
             oEmbedString = oEmbedSerializer.SerializeXml(oembed);
             _response.ContentType = "text/xml";
             break;
         default:
             throw new ArgumentOutOfRangeException("format");
     }
     var resultStream = ToStream(oEmbedString);
     _response.ContentLength = resultStream.Length;
     if (oembed.CacheAge > 0)
     {
         _response.Headers.Add(HttpResponseHeader.CacheControl, "max-age=" + oembed.CacheAge + ", public");
         _response.Headers.Add(HttpResponseHeader.Expires,
                               DateTime.UtcNow.AddSeconds(oembed.CacheAge).ToString("R",
                                                                                    CultureInfo.InvariantCulture));
     }
     return resultStream;
 }
        public override Stream WriteResponse(oEmbed oembed, oEmbedFormat format, string callback)
        {
            if (oembed == null)
                return FileNotFound();
            string oEmbedString;
            switch (format)
            {
                case oEmbedFormat.Unspecified:
                case oEmbedFormat.Json:
                    oEmbedString = oEmbedSerializer.SerializeJson(oembed);
                    _response.ContentType = "application/json";
                    break;
                case oEmbedFormat.Jsonp:
                    oEmbedString = callback + "(" + oEmbedSerializer.SerializeJson(oembed) + ")";
                    _response.ContentType = "application/javascript";
                    break;
                case oEmbedFormat.Xml:
                    oEmbedString = oEmbedSerializer.SerializeXml(oembed);
                    _response.ContentType = "text/xml";
                    break;
                default:
                    throw new ArgumentOutOfRangeException("format");
            }

            var resultStream = ToStream(oEmbedString);
            if (_response.Headers["Content-Length"] != null)
                _response.Headers.Remove("Content-Length");
            _response.AddHeader("Content-Length", resultStream.Length.ToString());
            return resultStream;
        }
 public oEmbedResponse Read(string api, string url, int? maxwidth, int? maxheight, oEmbedFormat format,
                            NameValueCollection queryParameters, string userAgent)
 {
     return
         Read(new oEmbedRequest(api, url, maxwidth, maxheight, format,
                                queryParameters ?? new NameValueCollection(), userAgent));
 }
 public oEmbedRequest(string api, string url, int? maxWidth, int? maxHeight, oEmbedFormat format, NameValueCollection queryParameters, string userAgent)
 {
     Api = api;
     Url = url;
     MaxWidth = maxWidth;
     MaxHeight = maxHeight;
     Format = format;
     QueryParameters = queryParameters??new NameValueCollection();
     UserAgent = userAgent;
 }
 public virtual string Write(oEmbed oembed, oEmbedFormat format, string callback)
 {
     switch (format)
     {
         case oEmbedFormat.Unspecified:
         case oEmbedFormat.Json:
             return oEmbedSerializer.SerializeJson(oembed);
         case oEmbedFormat.Jsonp:
             return callback + "(" + oEmbedSerializer.SerializeJson(oembed) + ")";
         case oEmbedFormat.Xml:
             return oEmbedSerializer.SerializeXml(oembed);
         default:
             throw new ArgumentOutOfRangeException("format");
     }
 }
 public static oEmbed Deserialize(string response, oEmbedFormat format)
 {
     oEmbed result = null;
     switch (format)
     {
         case oEmbedFormat.Unspecified:
             break;
         case oEmbedFormat.Json:
             result = DeserializeJson(response);
             break;
         case oEmbedFormat.Xml:
             result = DeserializeXml(response);
             break;
         default:
             throw new ArgumentOutOfRangeException();
     }
     return result;
 }
 public override Stream WriteResponse(oEmbed oembed, oEmbedFormat format)
 {
     if (format == oEmbedFormat.Jsonp)
         throw new ArgumentException("jsonp format requires a callback", "format");
     return WriteResponse(oembed, format, null);
 }
 public override Stream WriteResponse(oEmbed oembed, oEmbedFormat format, string callback)
 {
     throw new System.NotImplementedException();
 }
 public oEmbedResponse Read(string api, string url, int? maxwidth, int? maxheight, oEmbedFormat format,
                            NameValueCollection queryParameters)
 {
     return Read(api, url, maxwidth, maxheight, format, queryParameters, null);
 }
Пример #10
0
 public oEmbedResponse Read(string api, string url, int? maxwidth, int? maxheight, oEmbedFormat format)
 {
     return Read(api, url, maxwidth, maxheight, format, null);
 }
Пример #11
0
 public oEmbedResponse Read(string api, string url, oEmbedFormat format)
 {
     return Read(api, url, null, null, format);
 }
Пример #12
0
 private static IEnumerable<ValidationRule> ValidateFormat(oEmbedResponse response, oEmbedFormat requestFormat)
 {
     var brokenRules = new List<ValidationRule>();
     if (requestFormat != oEmbedFormat.Unspecified &&
         requestFormat != response.Format)
         brokenRules.Add(new ValidationRule("Format", "Requested format (" + requestFormat.ToString().ToLower() +
                                                      ") does not match response (" +
                                                      response.Format.ToString().ToLower() + ")"));
     return brokenRules;
 }
Пример #13
0
 private void ValidateResponse(oEmbedResponse response, int maxwidth, int maxheight, oEmbedFormat requestFormat)
 {
     response.BrokenRules.AddRange(ValidateBasic(response));
     if (!response.IsValid) return;
     response.BrokenRules.AddRange(ValidateThumbnail(response, maxheight, maxwidth));
     response.BrokenRules.AddRange(ValidateFormat(response, requestFormat));
     response.BrokenRules.AddRange(ValidateType(response, maxheight, maxwidth));
     response.BrokenRules.AddRange(ValidateSize(response, maxheight, maxwidth));
 }
Пример #14
0
 public abstract Stream WriteResponse(oEmbed oembed, oEmbedFormat format, string callback);
Пример #15
0
 public abstract Stream WriteResponse(oEmbed oembed, oEmbedFormat format);
Пример #16
0
 public virtual string Write(oEmbed oembed, oEmbedFormat format)
 {
     if (format == oEmbedFormat.Jsonp)
         throw new ArgumentException("jsonp format requires a callback", "format");
     return Write(oembed, format, null);
 }