Exemplo n.º 1
0
        // it may throw HttpClientException
        public async Task LoadImageAsync()
        {
            MyHttpClient        client   = new MyHttpClient(_uri);
            HttpResponseMessage response = await client.SendRequestAsync();

            _imageBuffer = await response.Content.ReadAsStreamAsync();
        }
Exemplo n.º 2
0
        internal static async Task <T> GetAsync <T>(string url, bool withoutMetadata = true) where T : Entities.Entity
        {
            MyHttpClient        httpClient = new MyHttpClient(url);
            HttpResponseMessage response   = await httpClient.SendRequestAsync();

            IBuffer responseBuffer = await response.Content.ReadAsBufferAsync();

            using (var stream = responseBuffer.AsStream())
            {
                var xml        = XDocument.Load(stream);
                var serializer = new XmlSerializer(typeof(T));

                //Add extension namespace:
                var ns = new XmlSerializerNamespaces();
                ns.Add("ext", "http://musicbrainz.org/ns/ext#-2.0");

                //check valid xml schema:
                if (xml.Root == null || xml.Root.Name.LocalName != "metadata")
                {
                    throw new NullReferenceException("Wrong Xml Format");
                }

                var node = withoutMetadata ? xml.Root.Elements().FirstOrDefault() : xml.Root;

                if (node == null)
                {
                    return(default(T));
                }

                return((T)serializer.Deserialize(node.CreateReader()));
            }
        }
Exemplo n.º 3
0
        internal static async Task <T> GetAsync <T>(string url)
        {
            var client = new MyHttpClient(url);
            HttpResponseMessage response = await client.SendRequestAsync();

            var responseBuffer = await response.Content.ReadAsStreamAsync();

            using (var stream = responseBuffer)
            {
                var serializer = new DataContractJsonSerializer(typeof(T));

                return((T)serializer.ReadObject(stream));
            }
        }
Exemplo n.º 4
0
 // it may throw HttpClientException
 public async Task LoadImageAsync()
 {
     MyHttpClient client = new MyHttpClient(_uri);
     HttpResponseMessage response = await client.SendRequestAsync();
     _imageBuffer = await response.Content.ReadAsStreamAsync();
 }