예제 #1
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;
        }
예제 #2
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)
            {
            }
        }
예제 #3
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;
            }
        }