Example #1
0
        /// <summary>
        /// Navigate to detail page
        /// </summary>
        private void GridView_ItemClick(object sender, PointerRoutedEventArgs e)
        {
            var item       = sender as StackPanel;
            var dataToPass = item.DataContext as BookSummary;

            if (NetworkGet.IsValidID(dataToPass.ID))
            {
                switch ((BookSummaryCollectionType)item.Tag)
                {
                case BookSummaryCollectionType.NewBooks:
                    NBGrid.PrepareConnectedAnimation(Util.TO_BOOK_DETAIL, dataToPass, "NBImage");
                    break;

                case BookSummaryCollectionType.TopBooks:
                    TBGrid.PrepareConnectedAnimation(Util.TO_BOOK_DETAIL, dataToPass, "TBImage");
                    break;

                case BookSummaryCollectionType.PersonalRecommands:
                    PRGrid.PrepareConnectedAnimation(Util.TO_BOOK_DETAIL, dataToPass, "PRImage");
                    break;

                default:
                    return;
                }
                this._navigateType = (BookSummaryCollectionType)item.Tag;
                this._navigateItem = dataToPass;
                Util.MainElem.NavigateToBookDetail(dataToPass, typeof(BookDetailPage));
            }
        }
Example #2
0
        private void SaveBook(DownloadItemDataModel item, BookSummary bookSummary, IBookSummaryParser previewGenerator, IsolatedStorageFile storeForApplication)
        {
            using (var imageStorageFileStream = new IsolatedStorageFileStream(CreateImagesPath(item), FileMode.Create, storeForApplication))
            {
                previewGenerator.SaveImages(imageStorageFileStream);
            }

            previewGenerator.SaveCover(item.BookID.ToString());

            var book = CreateBook(item, bookSummary);

            try
            {
                _bookService.Add(book);
                TokensTool.SaveTokens(book, previewGenerator);
                book.Hidden = book.Trial;
                _bookService.Save(book);
                IsolatedStorageSettings.ApplicationSettings.Save();
            }
            catch (Exception)
            {
                _bookService.Remove(book.BookID);
                throw;
            }
        }
Example #3
0
        /// <summary>
        /// searchBooks: search for books (author, publisher or keyword)
        /// </summary>
        /// <remarks>
        /// This peforms a traditional search returning the results as a dynamic array.
        /// The results are parsed into a list of book summaries using regular extractions.
        /// </remarks>
        /// <param name="searchType"></param>
        /// <param name="searchData"></param>
        /// <param name="list"></param>
        /// <returns></returns>
        public Boolean searchBooks(int searchType, String searchData, BookSummaryList list)
        {
            String      subrName = String.Empty;
            String      errText  = String.Empty;
            UniDynArray results  = null;

            list.Clear();

            switch (searchType)
            {
            case 0:     // author
                subrName = "u2_getBooksForAuthor";
                break;

            case 1:     // publisher
                subrName = "u2_getBooksForPublisher";
                break;

            case 2:
                subrName = "u2_getBooks";
                break;

            default:
                ShowError("Not a recognized search type");
                return(false);
            }

            searchData = searchData + FM_STR + moneyFormat.ToString();

            try {
                lock (_syncCall) {
                    UniSubroutine s = _sess.CreateUniSubroutine(subrName, 3);
                    s.SetArg(0, searchData);
                    s.Call();
                    errText = s.GetArg(2);
                    results = s.GetArgDynArray(1);

                    if (String.IsNullOrEmpty(results.StringValue) == false)
                    {
                        int dc = results.Dcount(BookConst.BOOKSUMMARY_BOOKID);
                        for (int i = 1; i <= dc; i++)
                        {
                            BookSummary b = new BookSummary();
                            b.BookId     = results.Extract(BookConst.BOOKSUMMARY_BOOKID, i).StringValue;
                            b.Title      = results.Extract(BookConst.BOOKSUMMARY_TITLE, i).StringValue;
                            b.AuthorName = results.Extract(BookConst.BOOKSUMMARY_AUTHORNAME, i).StringValue;
                            b.ISBN       = results.Extract(BookConst.BOOKSUMMARY_ISBN, i).StringValue;
                            b.SalesPrice = Convert.ToDouble(results.Extract(BookConst.BOOKSUMMARY_SALESPRICE, i).StringValue); // TBD
                            b.Media      = results.Extract(BookConst.BOOKSUMMARY_MEDIA, i).StringValue;
                            list.Add(b);
                        }
                    }
                }
            } catch (Exception ex) {
                ShowError(ex.Message);
                return(false);
            }
            return(true);
        }
Example #4
0
        internal static async Task <bool> GetBookSummaryContents(BookSummaryCollection collection, int[] ids)
        {
            foreach (int id in ids)
            {
                var book = new BookSummary(id);
                await GetBookSummary(book);

                collection.Books.Add(book);
            }
            return(true);
        }
Example #5
0
 public override BookSummary GetBookPreview()
 {
     XElement info = _root
         .Elements(_ns + "description")
         .Elements(_ns + "title-info")
         .FirstOrDefault();
     var preview = new BookSummary();
     if (info == null)
         return preview;
     
     preview.Title = PrepareBookTitle(info);
     preview.AuthorName = PrepareBookAuthor(info);
     preview.Description = PrepareAnnotation(info);
     preview.Language = PrepareLanguage(info);
     preview.UniqueID = PrepareUniqueID();
     return preview;
 }
Example #6
0
            public void TableIsSplitIntoTwoEntities()
            {
                var dbConnectionString = DbConnectionString.Create(nameof(ConfiguringRelationships), GetCallerName());

                using var context =
                          dbConnectionString
                          .AsSqlConnectionString <BookStoreContext>()
                          .EnsureDb()
                          .BuildDbContext()
                          .StartLogging(_testOutput.AsLineWriter());

                var newDetail = new BookDetail {
                    Price = 49M
                };
                var newSummary = new BookSummary {
                    Title = "Entity Framework Core IN ACTION", Details = newDetail
                };

                context.Add(newSummary);
                context.SaveChanges();

                context
                .BookSummaries
                .Single()
                .Title
                .Should().Contain("Entity Framework");

                var aloneSummary = new BookSummary {
                    Title = "C# 8.0 in a Nutshell"
                };

                context.Add(aloneSummary);
                context.Invoking(ctx => ctx.SaveChanges()).Should().NotThrow <Exception>("because not all parts of a split table must be saved at once");

                context.Invoking(ctx =>
                {
                    ctx
                    .BookSummaries
                    .Include(bs => bs.Details)
                    .Where(bs => bs.Title.ToLower().Contains("c#"))
                    .Select(bs => bs.Details.Price)
                    .Single();
                }).Should().NotThrow("because EF Core returns the default values in this case");
            }
        public override BookSummary GetBookPreview()
        {
            XElement info = _root
                            .Elements(_ns + "description")
                            .Elements(_ns + "title-info")
                            .FirstOrDefault();
            var preview = new BookSummary();

            if (info == null)
            {
                return(preview);
            }

            preview.Title       = PrepareBookTitle(info);
            preview.AuthorName  = PrepareBookAuthor(info);
            preview.Description = PrepareAnnotation(info);
            preview.Language    = PrepareLanguage(info);
            preview.UniqueID    = PrepareUniqueID();
            return(preview);
        }
Example #8
0
        private static void ParseTitleInfo(BookSummary bookSummary)
        {
            var document = bookSummary.Document;

            var genres = document
                         .Find("genre")
                         .Where(x => x.ParentNode != null && x.ParentNode.TagName == "title-info")
                         .Select(x => x.Text)
                         .ToList();

            bookSummary.Genres.AddRange(genres);

            var authors = document
                          .Find("author")
                          .Where(x => x.ParentNode != null && x.ParentNode.TagName == "title-info")
                          .Select(x => new
            {
                FirstName = x.Children.FirstOrDefault(y => y is HtmlElementNode {
                    TagName: "first-name"
                })?.Text,
Example #9
0
        private static BookModel CreateBook(DownloadItemDataModel item, BookSummary bookSummary)
        {
            var book = new BookModel
            {
                BookID        = item.BookID.ToString(),
                Title         = bookSummary.Title.SafeSubstring(1024),
                Author        = bookSummary.AuthorName.SafeSubstring(1024),
                Type          = item.Type,
                Hidden        = true,
                Trial         = item.IsTrial,
                Deleted       = false,
                CreatedDate   = DateTime.Now.ToFileTimeUtc(),
                UniqueID      = bookSummary.UniqueID.SafeSubstring(1024),
                Description   = bookSummary.Description,
                Language      = bookSummary.Language,
                Url           = item.Path,
                CatalogItemId = item.CatalogItemId
            };

            return(book);
        }
Example #10
0
        private void DeleteUnnecessaryInfo(DownloadItemDataModel item, BookSummary bookSummary)
        {
            _bookService.Remove(item.BookID.ToString());
            if (string.IsNullOrEmpty(bookSummary.UniqueID))
            {
                return;
            }

            var bookModel = _bookService.GetBookByUniqueId(bookSummary.UniqueID);

            if (bookModel == null)
            {
                return;
            }

            try
            {
                item.BookID = Guid.Parse(bookModel.BookID);
            }
            catch (Exception)
            {
            }
        }
Example #11
0
        public static async Task GetBookSummary(BookSummary book)
        {
            var query = new QueryObject("GetBookSummary")
            {
                BookId = book.ID
            };

            if (Storage.Test)
            {
                book.BookCover = new Windows.UI.Xaml.Media.Imaging.BitmapImage(
                    new Uri("https://gss0.baidu.com/7LsWdDW5_xN3otqbppnN2DJv/doc/pic/item/6159252dd42a283478df074e58b5c9ea15cebf7d.jpg"));
                book.BookFullName = RandomName();
                book.BookName     = book.BookFullName.CutString();
                book.AuthorName   = "松浦彌太郎";
                return;
            }

            var recv = await Connection.SendAndReceive.GlobalLock(query);

            book.BookCover    = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri(recv.BookCoverUrl));
            book.BookFullName = recv.BookName;
            book.BookName     = book.BookFullName.CutString();
            book.AuthorName   = recv.AuthorName;
        }
Example #12
0
        internal override void Parse(XElement element)
        {
            Id            = element.ElementAsInt("id");
            Header        = element.ElementAsString("header");
            LikesCount    = element.ElementAsInt("likes_count");
            CommentsCount = element.ElementAsInt("comments_count");
            Liked         = element.ElementAsBool("liked");
            CreatedAt     = element.ElementAsDateTime("created_at");
            UpdatedAt     = element.ElementAsDateTime("updated_at");
            Status        = element.ElementAsString("status");
            ReviewId      = element.ElementAsInt("review_id");

            var book = element.Element("book");

            if (book != null)
            {
                Book = new BookSummary();
                Book.Parse(book);
            }

            var comments = element.Element("comments");

            if (comments != null)
            {
                Comments = new PaginatedList <Comment>();
                Comments.Parse(comments);
            }

            var user = element.Element("user");

            if (user != null)
            {
                User = new Actor();
                User.Parse(user);
            }
        }