Exemplo n.º 1
0
        // TODO: This shouldn't modify curbook
        public async Task <bool> GetPageCountAsync(BookInfo curBook, CancellationToken cancellationToken = default)
        {
            var bookPage = await _httpClient.GetPageAsync(curBook.DataUrl, cancellationToken);

            var pagesNode = bookPage.DocumentNode.SelectSingleNode("//div[@id='details']");

            if (pagesNode == null)
            {
                return(false);
            }
            var match = Regex.Match(pagesNode.InnerText, @"((\d+)|(\d+,\d+)) pages");

            if (match.Success)
            {
                var minutes = int.Parse(match.Groups[1].Value, NumberStyles.AllowThousands) * 1.2890625;
                var span    = TimeSpan.FromMinutes(minutes);
                // Functions.Pluralize($"{BookList[i].editions:edition}")
                _logger.Log(string.Format("Typical time to read: {0}, {1}, and {2} ({3} pages)",
                                          PluralUtil.Pluralize($"{span.Days:day}"),
                                          PluralUtil.Pluralize($"{span.Hours:hour}"),
                                          PluralUtil.Pluralize($"{span.Minutes:minute}"),
                                          match.Groups[1].Value));
                curBook.PagesInBook    = int.Parse(match.Groups[1].Value);
                curBook.ReadingHours   = span.Hours;
                curBook.ReadingMinutes = span.Minutes;
                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        private void cbResults_SelectedIndexChanged(object sender, EventArgs e)
        {
            var i = cbResults.SelectedIndex == -1 ? 0 : cbResults.SelectedIndex;

            pbCover.Image    = _bookList[i].CoverImage ?? Resources.missing_image;
            lblTitle.Text    = _bookList[i].Title;
            lblAuthor.Text   = $"by {_bookList[i].Author}";
            lblRating.Text   = $"{_bookList[i].AmazonRating:#.#} average rating " + PluralUtil.Pluralize($"({_bookList[i].Reviews:rating})");
            lblEditions.Text = PluralUtil.Pluralize($"{_bookList[i].Editions:edition}");
            linkID.Text      = _bookList[i].GoodreadsId;
            _toolTip1.SetToolTip(linkID, $"http://www.goodreads.com/book/show/{linkID.Text}");
        }
Exemplo n.º 3
0
        public string GetFormattedReadingTime(int pageCount)
        {
            if (pageCount == 0)
            {
                return(null);
            }

            var readingTime = GetReadingTime(pageCount);

            var days    = PluralUtil.Pluralize($"{readingTime.Days:day}");
            var hours   = PluralUtil.Pluralize($"{readingTime.Hours:hour}");
            var minutes = PluralUtil.Pluralize($"{readingTime.Minutes:minute}");

            return($"Typical time to read: {(readingTime.Days > 1 ? $"{days}, " : string.Empty)}{(readingTime.Hours > 1 ? $"{hours}" : string.Empty)}{(readingTime.Hours > 1 ? " and " : ", ")}{(readingTime.Minutes > 1 ? $"{minutes}" : string.Empty)} ({pageCount} pages)");
        }
Exemplo n.º 4
0
        public async Task Populate(string inputFile, CancellationToken cancellationToken = default)
        {
            var startActions = Functions.JsonDeserializeFile <StartActions>(inputFile);

            ilOtherBooks.Images.Clear();
            dgvOtherBooks.Rows.Clear();

            if (startActions.Data.SeriesPosition != null)
            {
                var seriesInfo = startActions.Data.SeriesPosition;
                lblSeries.Text = $"This is book {seriesInfo.PositionInSeries} of {seriesInfo.TotalInSeries} in {seriesInfo.SeriesName}";
                if (seriesInfo.PositionInSeries == 1)
                {
                    pbPreviousCover.Visible    = false;
                    lblPreviousHeading.Visible = false;
                    lblPreviousTitle.Visible   = false;
                    lblSeries.Left             = 12;
                    lblSeries.Width            = 312;
                }
                else
                {
                    lblSeries.Left             = 80;
                    lblSeries.Width            = 244;
                    pbPreviousCover.Visible    = true;
                    lblPreviousHeading.Visible = true;
                    lblPreviousTitle.Visible   = true;
                }
            }
            else
            {
                lblSeries.Text             = "This book is not part of a series...";
                pbPreviousCover.Image      = Resources.missing_image;
                lblPreviousHeading.Visible = false;
                lblPreviousTitle.Visible   = false;
            }

            // TODO: Enums or something for language
            var highlights = startActions.Data.PopularHighlightsText?.LocalizedText?.GetOrDefault("en-US");

            if (highlights != null)
            {
                var popularHighlightsText = _regexHighlights.Match(highlights);
                if (popularHighlightsText.Success)
                {
                    lblHighlights.Text = popularHighlightsText.Groups["text"].Value;
                }
            }

            if (startActions.Data.BookDescription != null)
            {
                var bookDescription = startActions.Data.BookDescription;
                lblTitle.Text       = bookDescription.Title;
                lblAuthor.Text      = bookDescription.Authors.FirstOrDefault() ?? "";
                lblDescription.Text = bookDescription.Description;
                if (bookDescription.AmazonRating.HasValue)
                {
                    pbRating.Image = (Image)Resources.ResourceManager.GetObject($"STAR{bookDescription.AmazonRating}");
                }
                lblVotes.Text = $"({bookDescription.NumberOfReviews ?? 0} {PluralUtil.Pluralize($"{bookDescription.NumberOfReviews ?? 0:vote}")})";
            }

            var author = startActions.Data.AuthorBios?.Authors?.FirstOrDefault();

            if (author != null)
            {
                var imageUrl = author.ImageUrl;
                if (!string.IsNullOrEmpty(imageUrl))
                {
                    pbAuthorImage.Image = await _httpClient.GetImageAsync(imageUrl, true, cancellationToken);
                }
                lblBiography.Text = author.Bio;
            }

            if (startActions.Data.AuthorRecs != null || startActions.Data.AuthorFeaturedRecs != null)
            {
                var recommendations = startActions.Data.AuthorRecs ?? startActions.Data.AuthorFeaturedRecs;
                foreach (var rec in recommendations.Recommendations)
                {
                    var imageUrl = rec.ImageUrl;
                    if (!string.IsNullOrEmpty(imageUrl))
                    {
                        ilOtherBooks.Images.Add(await _httpClient.GetImageAsync(imageUrl, true, cancellationToken));
                    }
                    dgvOtherBooks.Rows.Add(ilOtherBooks.Images[ilOtherBooks.Images.Count - 1], $"{rec.Title}\n{rec.Authors.FirstOrDefault() ?? ""}");
                }
            }

            if (startActions.Data.ReadingTime != null)
            {
                lblReadingTime.Text = $"{startActions.Data.ReadingTime.Hours} hours and {startActions.Data.ReadingTime.Minutes} minutes to read";
                if (startActions.Data.ReadingPages != null)
                {
                    lblReadingTime.Text = $"{lblReadingTime.Text} ({startActions.Data.ReadingPages.PagesInBook} pages)";
                }
            }

            if (startActions.Data.PreviousBookInTheSeries != null)
            {
                lblPreviousTitle.Text = startActions.Data.PreviousBookInTheSeries.Title;
                var imageUrl = startActions.Data.PreviousBookInTheSeries.ImageUrl;
                if (!string.IsNullOrEmpty(imageUrl))
                {
                    pbPreviousCover.Image = await _httpClient.GetImageAsync(imageUrl, true, cancellationToken);
                }
            }
        }
Exemplo n.º 5
0
        public XRayPanel(string type, string name, string mentions, string description)
        {
            BorderStyle = BorderStyle.None;
            Name        = "XRayPanel";
            Size        = new Size(460, 72);
            BackColor   = Color.FromArgb(240, 240, 240);

            var pbType = new PictureBox
            {
                Image    = type == "character" ? Resources.character : Resources.setting,
                Location = new Point(5, 5),
                Size     = new Size(16, 16),
                SizeMode = PictureBoxSizeMode.StretchImage
            };

            var lblName = new Label
            {
                Font         = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point, 0),
                AutoSize     = false,
                AutoEllipsis = true,
                TextAlign    = ContentAlignment.MiddleLeft,
                Location     = new Point(22, 5),
                Size         = new Size(335, 15),
                Text         = name
            };

            var lblMentions = new Label
            {
                Font      = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point, 0),
                AutoSize  = false,
                TextAlign = ContentAlignment.MiddleRight,
                Location  = new Point(304, 5),
                Size      = new Size(150, 15),
                Text      = PluralUtil.Pluralize($"{int.Parse(mentions):mention}")
            };

            var lblDescription = new Label
            {
                Font         = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point, 0),
                AutoSize     = false,
                AutoEllipsis = true,
                TextAlign    = ContentAlignment.TopLeft,
                Location     = new Point(22, 24),
                Size         = new Size(435, 40),
                Text         = description
            };

            var pbSeperator = new PictureBox
            {
                Location  = new Point(0, 71),
                Size      = new Size(460, 1),
                SizeMode  = PictureBoxSizeMode.StretchImage,
                BackColor = Color.FromArgb(214, 214, 214)
            };

            Controls.Add(lblName);
            Controls.Add(lblMentions);
            Controls.Add(lblDescription);
            Controls.Add(pbType);
            Controls.Add(pbSeperator);
        }
Exemplo n.º 6
0
        public async Task Populate(string inputFile, CancellationToken cancellationToken = default)
        {
            var startActions = JsonUtil.DeserializeFile <StartActions>(inputFile);

            ilOtherBooks.Images.Clear();
            lvOtherBooks.Clear();

            _asin = startActions.BookInfo.Asin;

            if (startActions.Data.SeriesPosition != null)
            {
                var seriesInfo = startActions.Data.SeriesPosition;
                if (seriesInfo.PositionInSeries > 1)
                {
                    lblSeries.Text             = $@"This is book {seriesInfo.PositionInSeries} of {seriesInfo.TotalInSeries} in {seriesInfo.SeriesName}";
                    lblPreviousHeading.Visible = true;
                    lblPreviousTitle.Visible   = true;
                }
            }
            else
            {
                lblPreviousTitle.Text      = @"This book is not part of a series…";
                pbPreviousCover.Image      = Resources.missing_cover_small;
                lblSeries.Visible          = false;
                lblPreviousHeading.Visible = false;
                lblPreviousTitle.Visible   = true;
            }

            // TODO: Enums or something for language
            var highlights = startActions.Data.PopularHighlightsText?.LocalizedText?.GetOrDefault("en-US");

            if (highlights != null)
            {
                var popularHighlightsText = _regexHighlights.Match(highlights);
                if (popularHighlightsText.Success)
                {
                    lblHighlightsCount.Text = !popularHighlightsText.Groups["text"].Value.StartsWith("0") ? popularHighlightsText.Groups["text"].Value : "No popular highlights were found for this book.";
                }
            }
            else
            {
                lblHighlightsCount.Text = "No popular highlights were found for this book.";
            }

            if (startActions.Data.BookDescription != null)
            {
                var bookDescription = startActions.Data.BookDescription;
                lblTitle.Text           = bookDescription.Title;
                lblAuthor.Text          = bookDescription.Authors.FirstOrDefault() ?? "";
                lblAboutAuthorName.Text = bookDescription.Authors.FirstOrDefault() ?? "";
                lblDescription.Text     = bookDescription.Description;
                if (bookDescription.AmazonRating.HasValue)
                {
                    pbRating.Image = (Image)Resources.ResourceManager.GetObject($"STAR{Math.Floor((decimal) bookDescription.AmazonRating)}");
                }
                lblVotes.Text = $@"({PluralUtil.Pluralize($"{bookDescription.NumberOfReviews ?? 0:vote}")})";
            }

            var author = startActions.Data.AuthorBios?.Authors?.FirstOrDefault();

            if (author != null)
            {
                var imageUrl = author.ImageUrl;
                if (!string.IsNullOrEmpty(imageUrl))
                {
                    pbAuthorImage.Image = await _httpClient.GetImageAsync(imageUrl, MaxImageSize, false, cancellationToken);
                }
                lblBiography.Text = author.Bio;
            }

            if (startActions.Data.AuthorRecs != null || startActions.Data.AuthorFeaturedRecs != null)
            {
                var recommendations = startActions.Data.AuthorRecs ?? startActions.Data.AuthorFeaturedRecs;
                Width = recommendations.Recommendations.Length < 15 ? 665 : 691;
                foreach (var rec in recommendations.Recommendations)
                {
                    var imageUrl = rec.ImageUrl;
                    if (!string.IsNullOrEmpty(imageUrl))
                    {
                        ilOtherBooks.Images.Add(await _httpClient.GetImageAsync(imageUrl, MaxImageSize, false, cancellationToken));
                    }
                }
                ListViewItem_SetSpacing(lvOtherBooks, 60 + 10, 90 + 10);
                for (var i = 0; i < ilOtherBooks.Images.Count; i++)
                {
                    var item = new ListViewItem {
                        ImageIndex = i
                    };
                    lvOtherBooks.Items.Add(item);
                }
            }

            if (startActions.Data.ReadingTime != null)
            {
                lblReadingTime.Text = $@"{startActions.Data.ReadingTime.Hours} hours and {startActions.Data.ReadingTime.Minutes} minutes to read";
                if (startActions.Data.ReadingPages != null)
                {
                    lblReadingTime.Text = $@"{lblReadingTime.Text} ({startActions.Data.ReadingPages.PagesInBook} pages)";
                }
            }

            if (startActions.Data.PreviousBookInTheSeries != null)
            {
                lblPreviousTitle.Text = startActions.Data.PreviousBookInTheSeries.Title;
                var imageUrl = startActions.Data.PreviousBookInTheSeries.ImageUrl;
                if (!string.IsNullOrEmpty(imageUrl))
                {
                    pbPreviousCover.Image = await _httpClient.GetImageAsync(imageUrl, MaxImageSize, false, cancellationToken);
                }
            }
        }