示例#1
0
 public Task ImportAsync(byte[] content)
 {
     if (_type == ThumbnailType.Album)
     {
         return(ThumbnailManager.AddAsync(_originalArtist, _originalAlbum, content, true));
     }
     else
     {
         return(ThumbnailManager.AddAsync(_originalArtist, content, true));
     }
 }
示例#2
0
        public async Task <bool> DownloadSelected()
        {
            var selected = SearchCandidates[SelectedIndex].Thumbnail;

            if (selected == null)
            {
                ResultText = CommonSharedStrings.NoValidThumbnailPrompt;
                return(false);
            }
            IsBusy = true;
            try
            {
                using (var client = new HttpClient())
                {
                    using (var response = await client.GetAsync(selected))
                    {
                        response.EnsureSuccessStatusCode();
                        response.Content.Headers.TryGetValues("Content-Length", out var ctlength);
                        var lengthValue = ctlength.FirstOrDefault();

                        if (lengthValue == null ||
                            !ulong.TryParse(lengthValue, out ulong length))
                        {
                            length = 0;
                        }

                        if (length <= 10 * 1024 * 1024)
                        {
                            var content = await response.Content.ReadAsByteArrayAsync();

                            if (content.Length >= (int)length)
                            {
                                if (_type == ThumbnailType.Album)
                                {
                                    await ThumbnailManager.AddAsync(_originalArtist, _originalAlbum, content, true);
                                }
                                else
                                {
                                    await ThumbnailManager.AddAsync(_originalArtist, content, true);
                                }
                                return(true);
                            }
                            else
                            {
                                ResultText = CommonSharedStrings.DownloadFailedPrompt;
                                return(false);
                            }
                        }
                        else
                        {
                            ResultText = CommonSharedStrings.FileSizeLimitPrompt;
                            return(false);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ResultText = string.Format(CommonSharedStrings.SearchError, ex.Message);
                return(false);
            }
            finally
            {
                IsBusy = false;
            }
        }