public static string SerializeJson(oEmbed response) { try { var serializer = new JavaScriptSerializer(); serializer.RegisterConverters(new[] {new oEmbedJavaScriptConverter()}); return serializer.Serialize(response); } catch { return null; } }
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 string SerializeXml(oEmbed response) { try { var memoryStream = new MemoryStream(); var serializer = new XmlSerializer(typeof (oEmbedXmlForSerialization)); var xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8); serializer.Serialize(xmlTextWriter, new oEmbedXmlForSerialization(response)); memoryStream = (MemoryStream) xmlTextWriter.BaseStream; return Encoding.UTF8.GetString(memoryStream.ToArray()); } catch { return null; } }
public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer) { if (type == typeof (oEmbed)) { var obj = new oEmbed(); if (dictionary.ContainsKey("version")) obj.Version = serializer.ConvertToType<string>(dictionary["version"]); if (dictionary.ContainsKey("title")) obj.Title = serializer.ConvertToType<string>(dictionary["title"]); if (dictionary.ContainsKey("type")) obj.Type = serializer.ConvertToType<oEmbedType>(dictionary["type"]); if (dictionary.ContainsKey("author_name")) obj.AuthorName = serializer.ConvertToType<string>(dictionary["author_name"]); if (dictionary.ContainsKey("author_url")) obj.AuthorUrl = serializer.ConvertToType<string>(dictionary["author_url"]); if (dictionary.ContainsKey("provider_name")) obj.ProviderName = serializer.ConvertToType<string>(dictionary["provider_name"]); if (dictionary.ContainsKey("provider_url")) obj.ProviderUrl = serializer.ConvertToType<string>(dictionary["provider_url"]); if (dictionary.ContainsKey("cache_age")) obj.CacheAge = serializer.ConvertToType<int>(dictionary["cache_age"]); if (dictionary.ContainsKey("thumbnail_url")) obj.ThumbnailUrl = serializer.ConvertToType<string>(dictionary["thumbnail_url"]); if (dictionary.ContainsKey("thumbnail_width")) obj.ThumbnailWidth = serializer.ConvertToType<int?>(dictionary["thumbnail_width"]); if (dictionary.ContainsKey("thumbnail_height")) obj.ThumbnailHeight = serializer.ConvertToType<int?>(dictionary["thumbnail_height"]); if (dictionary.ContainsKey("url")) obj.Url = serializer.ConvertToType<string>(dictionary["url"]); if (dictionary.ContainsKey("width") && dictionary["width"] != null) obj.Width = serializer.ConvertToType<int>(dictionary["width"]); if (dictionary.ContainsKey("height") && dictionary["height"] != null) obj.Height = serializer.ConvertToType<int>(dictionary["height"]); if (dictionary.ContainsKey("html")) obj.Html = serializer.ConvertToType<string>(dictionary["html"]); return obj; } return null; }
public oEmbedXmlForSerialization(oEmbed oEmbed) { Version = oEmbed.Version; Type = oEmbed.Type; Title = oEmbed.Title; AuthorName = oEmbed.AuthorName; AuthorUrl = oEmbed.AuthorUrl; ProviderName = oEmbed.ProviderName; ProviderUrl = oEmbed.ProviderUrl; CacheAge = oEmbed.CacheAge; ThumbnailUrl = oEmbed.ThumbnailUrl; ThumbnailWidth = oEmbed.ThumbnailWidth; ThumbnailHeight = oEmbed.ThumbnailHeight; Url = oEmbed.Url; Width = oEmbed.Width; Height = oEmbed.Height; Html = oEmbed.Html; }
public abstract Stream WriteResponse(oEmbed oembed, oEmbedFormat format, string callback);
public abstract Stream WriteResponse(oEmbed oembed, oEmbedFormat format);
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); }