Пример #1
0
        public override async Task <AppIcon> DownloadIconAsync(AppMetadata meta)
        {
            if (string.IsNullOrEmpty(meta.IconUrl))
            {
                throw new ArgumentException("Metadata has empty icon url", nameof(meta));
            }
            var result     = new AppIcon();
            var httpResult = await _client.GetAsync(new Uri(meta.IconUrl));

            if (httpResult.Content == null)
            {
                return(result);
            }
            result.ContentType = httpResult.Content?.Headers?.ContentType?.MediaType;
            if (result.ContentType?.Equals("image/jpeg", StringComparison.OrdinalIgnoreCase) == false)
            {
                //todo: need to find System.Drawing alternative for .Net Core
                var imgStream = await httpResult.Content.ReadAsStreamAsync();

                var color = GetBgColor(meta);
                result.Content = AddBackgroundColor(color, imgStream);
                meta.AddValue("BgColorUsed", color);
                //result.Content = await httpResult.Content.ReadAsByteArrayAsync();
            }
            else
            {
                result.Content = await httpResult.Content.ReadAsByteArrayAsync();
            }
            return(result);
        }
 public override async Task<AppIcon> DownloadIconAsync(AppMetadata meta)
 {
     if (string.IsNullOrEmpty(meta.IconUrl))
         throw new ArgumentException("Metadata has empty icon url", nameof(meta));
     var result = new AppIcon();
     var httpResult = await _client.GetAsync(new Uri(meta.IconUrl));
     if (httpResult.Content != null)
     {
         result.ContentType = httpResult.Content?.Headers?.ContentType?.MediaType;
         result.Content = await httpResult.Content.ReadAsByteArrayAsync();
     }
     return result;
 }
        public override async Task <AppIcon> DownloadIconAsync(AppMetadata meta)
        {
            if (string.IsNullOrEmpty(meta.IconUrl))
            {
                throw new ArgumentException("Metadata has empty icon url", nameof(meta));
            }
            var result     = new AppIcon();
            var httpResult = await _client.GetAsync(new Uri(meta.IconUrl));

            if (httpResult.Content != null)
            {
                result.ContentType = httpResult.Content?.Headers?.ContentType?.MediaType;
                result.Content     = await httpResult.Content.ReadAsByteArrayAsync();
            }
            return(result);
        }