コード例 #1
0
ファイル: PageCompositor.cs プロジェクト: karbazol/FBReaderCS
 public PageCompositor(BookModel book, int fontSize, Size pageSize, IList<BookImage> images)
 {
     _book = book;
     _fontSize = fontSize;
     _pageSize = pageSize;
     _images = images;
 }
コード例 #2
0
        public async Task UploadBook(BookModel book)
        {
            _book = book;
            
            try
            {
                if(_cancellationTokenSource != null)
                    _cancellationTokenSource.Cancel();

                _cancellationTokenSource = new CancellationTokenSource();
                _publicUri = await _skyDriveService.UploadAsync(_book, _cancellationTokenSource.Token);
                if (string.IsNullOrEmpty(_publicUri))
                    return;

                _cancellationTokenSource.Token.ThrowIfCancellationRequested();
                EventWaitHandle waitHandle = new AutoResetEvent(false);
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                              {
                                                                  ShowShareMethodSelector = 
                                                                      true && 
                                                                      !_cancellationTokenSource.IsCancellationRequested;
                                                                  waitHandle.Set();
                                                              });
                await Task.Factory.StartNew(() => waitHandle.WaitOne());
            }
            catch (FileUploadException)
            {
                _notificationsService.ShowAlert(UINotifications.General_ErrorCaption,
                                                UINotifications.ShareBook_UploadError);
            }
            catch (OperationCanceledException)
            {

            }
        }
コード例 #3
0
 public void Add(BookModel book)
 {
     using (BookDataContext context = BookDataContext.Connect())
     {
         context.Books.InsertOnSubmit(book);
         context.SubmitChanges();
     }
 }
コード例 #4
0
 public void Save(BookModel book)
 {
     using (BookDataContext context = BookDataContext.Connect())
     {
         context.Books.Attach(book);
         context.Refresh(0, book);
         context.SubmitChanges();
     }
 }
コード例 #5
0
        protected override void OnInitialize()
        {
            base.OnInitialize();

            if (TransientStorage.Contains(CatalogBookItemKey))
                CatalogBookItemModel = TransientStorage.Get<CatalogBookItemModel>(CatalogBookItemKey);

            _book = _bookRepository.Get(BookId, false);

            DisplayName = string.Format(UIStrings.SearchInBookPage_Title, _book.Title).ToUpper();
        }
コード例 #6
0
ファイル: ReadController.cs プロジェクト: karbazol/FBReaderCS
 public ReadController(IBookView page, string bookId, IBookRepository bookRepository, int offset = 0)
 {
     _data = new BookData(bookId);
     _bookView = page;
     _offset = offset;
     _bookRepository = bookRepository;
     _bookModel = _bookRepository.Get(bookId);
     _images = _data.LoadImages().ToList();
     _pageLoader = new PageCompositor(_bookModel, (int)(AppSettings.Default.FontSettings.FontSize), new Size(page.GetSize().Width - AppSettings.Default.Margin.Left - AppSettings.Default.Margin.Right, page.GetSize().Height - AppSettings.Default.Margin.Top - AppSettings.Default.Margin.Bottom), _images);
     BookId = bookId;
 }
コード例 #7
0
ファイル: BookTool.cs プロジェクト: karbazol/FBReaderCS
 public Stream GetOriginalBook(BookModel book)
 {
     var destinationStream = new MemoryStream();
     using (var file = FileStorage.Instance.GetFile(book.GetBookPath()))
     {
         using (file.Lock())
         {
             file.Reader.BaseStream.CopyTo(destinationStream);
         }
     }
     destinationStream.Seek(0, SeekOrigin.Begin);
     return destinationStream;
 }
コード例 #8
0
ファイル: TokensTool.cs プロジェクト: karbazol/FBReaderCS
        public static void SaveTokens(BookModel book, IBookSummaryParser parser)
        {
            var tokens = parser.GetTokenParser().GetTokens().ToList();
            var positions = SaveTokensWithPosition(book.GetTokensPath(), tokens);

            SaveTokenPosition(book.GetTokensRefPath(), positions);

            book.TokenCount = positions.Count;
            book.WordCount = tokens.Count(t => t is TextToken);
            book.CurrentTokenID = Math.Min(tokens.Count() - 1, book.CurrentTokenID);

            parser.BuildChapters();

            SaveAnchors(book.BookID, parser.Anchors, tokens);
            SaveChapters(book.BookID, parser.Chapters, tokens);
        }
コード例 #9
0
ファイル: BookSearch.cs プロジェクト: karbazol/FBReaderCS
        public Task<List<BookSearchResult>> Search(BookModel book, string query, int count)
        {
            if (string.IsNullOrEmpty(query) || book == null)
                return Task<List<BookSearchResult>>.Factory.StartNew(() => new List<BookSearchResult>());

            if (_bookTokenIterator != null)
            {
                _bookTokenIterator.Dispose();
            }

            _book = book;
            _bookTokenIterator = new BookTokenIterator(_book.GetTokensPath(), TokensTool.GetTokens(_book.BookID));

            _query = PrepareQuery(query);

            return Task<List<BookSearchResult>>
                .Factory.StartNew(() => Load(_bookTokenIterator, _query, count));
        }
コード例 #10
0
ファイル: BookTool.cs プロジェクト: karbazol/FBReaderCS
        public string GetText(BookModel book, int tokenOffset, int wordsCount, out int lastTokenId)
        {
            lastTokenId = -1;
            var result = new List<string>();

            using (var tokenIterator = new BookTokenIterator(book.GetTokensPath(), TokensTool.GetTokens(book.BookID)))
            {
                int words = 0;
                tokenIterator.MoveTo(tokenOffset);
                while (tokenIterator.MoveNext() && words < wordsCount)
                {
                    if(tokenIterator.Current is NewPageToken && result.Count > 0)
                        break;

                    var textToken = tokenIterator.Current as TextToken;
                    if(textToken == null)
                        continue;
                    lastTokenId = textToken.ID;
                    result.Add(textToken.Text);
                    words++;
                }
            }
            return string.Join(" ", result);
        }
コード例 #11
0
 public BookRemoved(BookModel book)
 {
     Book = book;
 }
コード例 #12
0
 public void NavigateToItem(BookModel model)
 {
     _navigationService.UriFor<ReadPageViewModel>()
                       .WithParam(vm => vm.BookId, model.BookID)
                       .WithParam(vm => vm.TokenOffset, model.CurrentTokenID)
                       .Navigate();
 }
コード例 #13
0
 public static string GetBookPath(this BookModel model)
 {
     return(Path.Combine(model.BookID, ModelConstants.BOOK_FILE_DATA_PATH));
 }
コード例 #14
0
 public static string GetTokensPath(this BookModel model)
 {
     return(Path.Combine(model.BookID, ModelConstants.BOOK_TOKENS_PATH));
 }
コード例 #15
0
 private string GetFileName(BookModel book)
 {
     var name = string.Format("{0} - {1}.{2}", book.Author, book.Title, book.BookID);
     var invalidChars = Path.GetInvalidFileNameChars();
     var cleanFileName = new string(name.Where(m => !invalidChars.Contains(m)).ToArray());
     return string.Format("{0}.{1}", cleanFileName, book.Type);
 }
コード例 #16
0
        public async Task<string> UploadAsync(BookModel book, CancellationToken cancellationToken)
        {

            LiveConnectClient skyDrive;

            try
            {
                skyDrive = await _liveLogin.Login();
                if (skyDrive == null)
                    return null;

                var catalog = _catalogRepository.GetAll().Single(c => c.Type == CatalogType.SkyDrive);
                catalog.AccessDenied = false;
                _catalogRepository.Save(catalog);

            }
            catch (LiveAuthException e)
            {
                if (e.ErrorCode != "access_denied")
                {
                    throw;
                }
                return null;
            }
            catch (Exception e)
            {
                throw new FileUploadException(e.Message, e);
            }

            cancellationToken.ThrowIfCancellationRequested();

            try
            {
                var root = (List<dynamic>) (await skyDrive.GetAsync("me/skydrive/files")).Result["data"];
                dynamic folder = root.SingleOrDefault(f => f.type == "folder" && f.name == SkyDriveFolder);
                string folderId;
                if (folder != null)
                {
                    folderId = folder.id;
                }
                else
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    var folderData = new Dictionary<string, object> {{"name", SkyDriveFolder}};
                    var createFolderData = await skyDrive.PostAsync("me/skydrive", folderData);
                    var createFolderResult = createFolderData.Result;
                    folderId = (string) createFolderResult["id"];
                }

                cancellationToken.ThrowIfCancellationRequested();

                string fileId;

                var fileName = GetFileName(book);
                var files = (List<dynamic>) (await skyDrive.GetAsync(folderId + "/files")).Result["data"];
                dynamic file = files.SingleOrDefault(f => f.type == "file" && f.name == fileName);
                if (file != null)
                {
                    fileId = file.id;
                }
                else
                {
                    using (Stream fileStream = _bookTool.GetOriginalBook(book))
                    {
                        dynamic fileUploadResult = (await skyDrive.UploadAsync(folderId, GetFileName(book), fileStream,
                                                        OverwriteOption.DoNotOverwrite, cancellationToken, null)).Result;
                        fileId = fileUploadResult.id;
                    }
                }

                cancellationToken.ThrowIfCancellationRequested();

                LiveOperationResult operationResult = await skyDrive.GetAsync(fileId + "/shared_read_link");
                dynamic result = operationResult.Result;




                return GetDirectLink(result.link);

            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new FileUploadException(e.Message, e);
            }
        }
コード例 #17
0
 private void ShareInSocialNetworks(BookModel book, string url)
 {
     try
     {
         var shareLink = new ShareLinkTask();
         shareLink.LinkUri = new Uri(url);
         shareLink.Title = book.Author + " " + book.Title;
         shareLink.Show();
     }
     catch (Exception)
     {
     }
 }
コード例 #18
0
        private void SendEmail(BookModel book, string url)
        {

            try
            {
                var email = new EmailComposeTask();
                email.Subject = book.Author + " " + book.Title;
                email.Body = url;

                email.Show();
            }
            catch (Exception)
            {
            }
        }
コード例 #19
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;
        }