Ejemplo n.º 1
0
        public void SerializationTest()
        {
            // TODO: Update Portable.Xaml
            var expected = new EmbedData()
            {
                // Description = "{NotBinding}",
                CacheAge = null,
                // AuthorName = "{}{Author}"
            };

            using (var sw = new StringWriter())
            {
                XamlServices.Save(sw, expected);

                var xml = sw.ToString();
                using (var sr = new StringReader(xml))
                {
                    var obj = XamlServices.Load(sr);
                    Assert.IsType <EmbedData>(obj);

                    var actual = (EmbedData)obj;

                    Assert.Equal(expected.Description, actual.Description);
                    Assert.Equal(expected.CacheAge, actual.CacheAge);
                    Assert.Equal(expected.AuthorName, actual.AuthorName);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Writes a EmbedData to the specified writer.
        /// </summary>
        /// <param name="writer">The writer to write.</param>
        /// <param name="obj">The <see cref="EmbedData" />.</param>
        /// <param name="hash">The URL hash to append.</param>
        public static async Task WriteEmbedDataAsync(this IResponseWriter writer, EmbedData obj, string hash = null)
        {
            writer.WriteStartResponse();

            writer.WritePropertyIfNeeded("type", obj.Type);
            writer.WritePropertyIfNeeded("url", obj.Url + hash);
            writer.WritePropertyIfNeeded("title", obj.Title);
            writer.WritePropertyIfNeeded("description", obj.Description);
            writer.WritePropertyIfNeeded("author_name", obj.AuthorName);
            writer.WritePropertyIfNeeded("author_url", obj.AuthorUrl);
            writer.WritePropertyIfNeeded("provider_name", obj.ProviderName);
            writer.WritePropertyIfNeeded("provider_url", obj.ProviderUrl);
            writer.WritePropertyIfNeeded("cache_age", obj.CacheAge);
            writer.WriteStartObjectProperty("metadata_image");
            writer.WritePropertyIfNeeded("type", obj.MetadataImage?.Type);
            writer.WritePropertyIfNeeded("restriction_policy", obj.MetadataImage?.RestrictionPolicy);
            writer.WritePropertyIfNeeded("raw_url", obj.MetadataImage?.RawUrl);
            writer.WritePropertyIfNeeded("location", obj.MetadataImage?.Location);
            writer.WriteStartObjectProperty("thumbnail");
            writer.WritePropertyIfNeeded("url", obj.MetadataImage?.Thumbnail?.Url);
            writer.WritePropertyIfNeeded("width", obj.MetadataImage?.Thumbnail?.Width);
            writer.WritePropertyIfNeeded("height", obj.MetadataImage?.Thumbnail?.Height);
            writer.WriteEndObjectProperty();
            writer.WriteEndObjectProperty();
            writer.WritePropertyIfNeeded("restriction_policy", obj.RestrictionPolicy);

            if (obj.Medias.Count > 0)
            {
                writer.WriteStartArrayProperty("medias");
                foreach (var media in obj.Medias)
                {
                    writer.WriteStartObject("media");
                    writer.WriteProperty("type", media.Type.ToString());
                    if (media.Thumbnail != null)
                    {
                        writer.WriteStartObjectProperty("thumbnail");
                        writer.WritePropertyIfNeeded("url", media.Thumbnail.Url);
                        writer.WritePropertyIfNeeded("width", media.Thumbnail.Width);
                        writer.WritePropertyIfNeeded("height", media.Thumbnail.Height);
                        writer.WriteEndObjectProperty();
                    }
                    writer.WritePropertyIfNeeded("raw_url", media.RawUrl);
                    writer.WritePropertyIfNeeded("location", media.Location);
                    writer.WritePropertyIfNeeded("restriction_policy", media.RestrictionPolicy);
                    writer.WriteEndObject();
                }
                writer.WriteEndArrayProperty();
            }

            await writer.WriteEndResponseAsync();
        }