示例#1
0
        public WbooruImageInfo(ImageInfo raw_info, string gallery_name)
        {
            Rating      = raw_info.Rating;
            GalleryName = gallery_name;

            GalleryItemID            = raw_info.Id.ToString();
            PreviewImageSize         = new ImageSize(raw_info.ThumbnailImageUrl.ImageWidth, raw_info.ThumbnailImageUrl.ImageHeight);
            PreviewImageDownloadLink = raw_info.ThumbnailImageUrl.Url;
            DetailLink       = raw_info.DetailUrl;
            DownloadFileName = $"{raw_info.Id} {string.Join(" ", raw_info.Tags)}";

            GalleryDetail = new GalleryImageDetail()
            {
                Author                 = raw_info.Author,
                CreateDate             = raw_info.CreateDateTime,
                ID                     = raw_info.Id.ToString(),
                Rate                   = raw_info.Rating.ToString(),
                Resolution             = raw_info.ImageUrls.OrderByDescending(x => x.FileLength).Select(x => new Size(x.ImageWidth, x.ImageHeight)).FirstOrDefault(),
                Score                  = raw_info.Score.ToString(),
                Source                 = raw_info.Source,
                Tags                   = raw_info.Tags,
                DownloadableImageLinks = raw_info.ImageUrls.Select(x => new DownloadableImageLink()
                {
                    Description  = x.UrlDescription,
                    DownloadLink = x.Url,
                    FileLength   = x.FileLength,
                    FullFileName = WebUtility.UrlDecode(Path.GetFileName(x.Url)),
                    Size         = new Size(x.ImageWidth, x.ImageHeight)
                }).ToArray()
            };
        }
        private void DisplayDetailInfo(GalleryImageDetail detail)
        {
            var type = detail.GetType();

            var displayable_props = type.GetProperties()
                                    .Select(x => new { PropertyInfo = x, x.GetCustomAttribute <Models.Gallery.Annotation.DisplayNameAttribute>()?.Name, Order = x.GetCustomAttribute <DisplayOrderAttribute>()?.Order ?? 0, Value = x.GetValue(detail) })
                                    .Where(x => !string.IsNullOrWhiteSpace(x.Name))
                                    .Where(x => x.PropertyInfo.GetCustomAttribute <DisplayAutoIgnoreAttribute>() == null || !string.IsNullOrWhiteSpace(x.Value?.ToString()))
                                    .OrderBy(x => x.Order)
                                    .ToArray();

            var grid = new Grid();

            grid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = GridLength.Auto
            });
            grid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });

            grid.RowDefinitions.Clear();

            foreach (var _ in displayable_props)
            {
                grid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });
            }

            var generated_controls = displayable_props.Select(x => (x.Name, GenerateDisplayControl(detail, x.PropertyInfo, x.Value))).ToList();

            for (int i = 0; i < generated_controls.Count; i++)
            {
                var(name, control) = generated_controls[i];

                Grid.SetRow(control, i);
                Grid.SetColumn(control, 1);

                TextBlock text = new TextBlock()
                {
                    FontSize            = 16,
                    Text                = name,
                    Foreground          = Brushes.Gray,
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Right
                };

                Grid.SetRow(text, i);

                grid.Children.Add(text);
                grid.Children.Add(control);
            }

            DetailContentGrid.Children.Add(grid);
        }
        private UIElement GenerateDisplayControl(GalleryImageDetail detail, PropertyInfo propertyInfo, object value)
        {
            var string_value  = (value?.ToString() ?? string.Empty).Trim();
            var custom_action = propertyInfo.GetCustomAttribute <DisplayClickActionAttribute>();

            Label block = new Label();

            block.Margin     = new Thickness(10, 5, 0, 5);
            block.FontSize   = 16;
            block.Foreground = Brushes.White;

            if (string_value.StartsWith("https://") || string_value.StartsWith("http://") || custom_action != null)
            {
                var hyper = new Hyperlink()
                {
                    NavigateUri = new Uri("https://github.com/Wbooru/Wbooru")//nothing
                };

                hyper.RequestNavigate += (_, e) =>
                {
                    e.Handled = true;

                    if (!(custom_action?.RemoteCallBack(detail, value) ?? false))
                    {
                        Process.Start(string_value);
                    }
                };

                hyper.Foreground = block.Foreground;
                hyper.Inlines.Add(string_value);
                block.Content = hyper;
            }
            else
            {
                block.Content = string_value;

                if (!string.IsNullOrWhiteSpace(string_value))
                {
                    block.MouseDown += (_, __) =>
                    {
                        Clipboard.SetText(string_value);
                        Toast.ShowMessage("已复制");
                    };
                }
            }

            return(block);
        }
        private async void ChangeDetailPicture(GalleryImageDetail galleryImageDetail)
        {
            if (galleryImageDetail == null)
            {
                return;
            }

            DisplayDetailInfo(galleryImageDetail);

            var pick_download = PickSuitableImageURL(galleryImageDetail.DownloadableImageLinks);

            if (pick_download == null)
            {
                //notice error;
                ExceptionHelper.DebugThrow(new Exception("No image."));
                Toast.ShowMessage("没图片可显示");
                return;
            }

            await DisplayImage(pick_download);
        }
示例#5
0
 public static string GetFileNameWithoutExtName(GalleryImageDetail detail)
 {
     return(FilterFileName($"{detail.ID} {string.Join(" ",detail.Tags)}"));
 }
示例#6
0
        private async void ChangeDetailPicture(GalleryImageDetail galleryImageDetail)
        {
            //clean.
            DetailImageBox.ImageSource = null;

            if (galleryImageDetail == null)
            {
                return;
            }

            RefreshButton.IsBusy = true;

            const string notify_content = "加载图片中......";

            using (var notify = LoadingStatus.BeginBusy(notify_content))
            {
                var(pick_download, is_new) = await PickSuitableImageURL(galleryImageDetail.DownloadableImageLinks);

                if (pick_download == null)
                {
                    //notice error;
                    ExceptionHelper.DebugThrow(new Exception("No image."));
                    Toast.ShowMessage("没图片可显示");
                    return;
                }

                if (is_new)
                {
                    //force update
                    var d = DownloadList.DataContext;
                    DownloadList.DataContext = this;
                    DownloadList.DataContext = d;
                }

                var downloader = Container.Default.GetExportedValue <ImageFetchDownloadScheduler>();

                System.Drawing.Image image;

                do
                {
                    image = await ImageResourceManager.RequestImageAsync(pick_download.FullFileName, async() =>
                    {
                        return(await downloader.GetImageAsync(pick_download.DownloadLink, null, d =>
                        {
                            (long cur, long total) = d;
                            notify.Description = $"({cur * 1.0 / total * 100:F2}%) {notify_content}";
                        }));
                    });
                } while (image == null);

                var source = image.ConvertToBitmapImage();
                RefreshButton.IsBusy = false;

                if (PictureDetailInfo == galleryImageDetail)
                {
                    DetailImageBox.ImageSource = source;
                }
                else
                {
                    Log <PictureDetailViewPage> .Debug($"Picture info mismatch.");
                }
            };