public async void Buy()
        {
            IsBusy = true;

            var catalog = _catalogRepository.Get(CatalogId);

            if (catalog.Type != CatalogType.Litres)
            {
                _navigationService.UriFor <WebBrowserPageViewModel>()
                .WithParam(vm => vm.WebBrowserUrl, CatalogBookItemModel.AcquisitionLink.Url)
                .WithParam(vm => vm.CatalogBookItemKey, TransientStorage.Put(CatalogBookItemModel))
                .WithParam(vm => vm.CatalogId, CatalogId)
                .Navigate();
                return;
            }

            if (string.IsNullOrEmpty(catalog.AuthorizationString))
            {
                _navigationService.UriFor <AuthorizationPageViewModel>()
                .WithParam(vm => vm.CatalogTitle, _catalogController.GetCatalogTitle(catalog).ToLower())
                .WithParam(vm => vm.Path, AUTHORIZATION_URL)
                .WithParam(vm => vm.CatalogId, catalog.Id)
                .WithParam(vm => vm.CatalogType, catalog.Type)
                .WithParam(vm => vm.CatalogBookItemKey, TransientStorage.Put(CatalogBookItemModel))
                .Navigate();
                return;
            }

            await PerformLitresAcqusition(catalog);
        }
Example #2
0
        private void BookDownloaderOnDownloadCompleted(object sender, DownloadItemDataModel downloadItemDataModel)
        {
            _eventAggregator.Publish(new BookDownloaded(downloadItemDataModel));


            var catalogBookItemModel = new CatalogBookItemModel();

            catalogBookItemModel.Id          = downloadItemDataModel.CatalogItemId;
            catalogBookItemModel.Title       = downloadItemDataModel.Name;
            catalogBookItemModel.Author      = downloadItemDataModel.Author;
            catalogBookItemModel.Description = downloadItemDataModel.Description;
            if (!string.IsNullOrWhiteSpace(downloadItemDataModel.AcquisitionUrl))
            {
                catalogBookItemModel.AcquisitionLink = new BookAcquisitionLinkModel
                {
                    Url    = downloadItemDataModel.AcquisitionUrl,
                    Type   = downloadItemDataModel.AcquisitionType,
                    Prices = BookAcquisitionLinkModel.ParsePrices(downloadItemDataModel.AcquisitionPrices)
                };
            }
            if (downloadItemDataModel.IsTrial)
            {
                catalogBookItemModel.TrialLink = new BookDownloadLinkModel
                {
                    Url  = downloadItemDataModel.Path,
                    Type = downloadItemDataModel.Type
                };
            }

            _notificationsService.ShowToast(UIStrings.BookDownloader_Success, downloadItemDataModel.Name, _navigationService.UriFor <ReadPageViewModel>()
                                            .WithParam(vm => vm.BookId, downloadItemDataModel.BookID.ToString())
                                            .WithParam(vm => vm.CatalogId, downloadItemDataModel.DataSourceID)
                                            .WithParam(vm => vm.CatalogBookItemKey, TransientStorage.Put(catalogBookItemModel))
                                            .WithParam(vm => vm.TokenOffset, 0).BuildUri());
        }
 public void GoToBookInfo()
 {
     _navigationService.UriFor <BookInfoPageViewModel>()
     .WithParam(vm => vm.BookId, BookId)
     .WithParam(vm => vm.CatalogId, CatalogId)
     .WithParam(vm => CatalogBookItemKey, TransientStorage.Put(CatalogBookItemModel))
     .Navigate();
 }
        private async Task PerformLitresAcqusition(CatalogModel catalog)
        {
            try
            {
                _busyOverlay.Closable = true;
                _busyOverlay.Closing += GoBack;
                await _busyOverlay.Start(false);

                // only for litres
                var buyService   = _acquisitionServiceFactory.GetAcquisitionService(catalog.Type);
                var downloadLink = await buyService.BuyBook(CatalogBookItemModel, catalog.AuthorizationString);

                CatalogBookItemModel.Links = new List <BookDownloadLinkModel>
                {
                    new BookDownloadLinkModel {
                        Type = ".fb2.zip", Url = downloadLink
                    }
                };

                if (!_downloadController.DownloadBook(CatalogBookItemModel, CatalogId))
                {
                    _busyOverlay.Stop();
                    _busyOverlay.Closing -= GoBack;
                    IsBusy = false;
                }
            }
            catch (CatalogAuthorizationException exception)
            {
                _navigationService.UriFor <AuthorizationPageViewModel>()
                .WithParam(vm => vm.CatalogTitle, _catalogController.GetCatalogTitle(catalog).ToLower())
                .WithParam(vm => vm.Path, exception.Path)
                .WithParam(vm => vm.CatalogId, catalog.Id)
                .WithParam(vm => vm.CatalogType, catalog.Type)
                .WithParam(vm => vm.CatalogBookItemKey, TransientStorage.Put(CatalogBookItemModel))
                .Navigate();
            }
            catch (ReadCatalogException)
            {
                ShowReadCatalogError();
                StopOverlay();
                IsBusy = false;
            }
            catch (CatalogNotEnoughMoneyException exception)
            {
                StopOverlay();
                IsBusy = false;
                _navigationService.UriFor <WebBrowserPageViewModel>()
                .WithParam(vm => vm.WebBrowserUrl, exception.PayMoneyUrl)
                .Navigate();
            }
            catch (CatalogBookAlreadyBoughtException)
            {
                _notificationsService.ShowMessage(UINotifications.General_AttentionCaption,
                                                  UINotifications.BuyBook_AlradyBoughtMessage);
                StopOverlay();
                IsBusy = false;
            }
        }
        protected override void OnInitialize()
        {
            base.OnInitialize();

            if (TransientStorage.Contains(CatalogBookItemKey))
            {
                CatalogBookItemModel = TransientStorage.Get <CatalogBookItemModel>(CatalogBookItemKey);
            }
        }
 public void GoToChapter(ChapterDataModel chapter)
 {
     _navigationService.UriFor <ReadPageViewModel>()
     .WithParam(vm => vm.BookId, BookId)
     .WithParam(vm => vm.TokenOffset, chapter.TokenId)
     .WithParam(vm => vm.CatalogId, CatalogId)
     .WithParam(vm => vm.CatalogBookItemKey, TransientStorage.Put(CatalogBookItemModel))
     .Navigate();
 }
 public void OnBookmarkClick(BookmarkItemDataModel itemDataModel)
 {
     _navigationService
     .UriFor <ReadPageViewModel>()
     .WithParam(vm => vm.BookId, itemDataModel.Bookmark.BookID)
     .WithParam(vm => vm.TokenOffset, itemDataModel.Bookmark.TokenID)
     .WithParam(vm => CatalogId, CatalogId)
     .WithParam(vm => vm.CatalogBookItemKey, TransientStorage.Put(CatalogBookItemModel))
     .Navigate();
 }
 public void OnItemClick(SearchInBookResultItemDataModel item)
 {
     _navigationService
     .UriFor <ReadPageViewModel>()
     .WithParam(vm => vm.BookId, item.BookId)
     .WithParam(vm => vm.TokenOffset, item.TokenId)
     .WithParam(vm => vm.CatalogId, CatalogId)
     .WithParam(vm => vm.CatalogBookItemKey, TransientStorage.Put(CatalogBookItemModel))
     .Navigate();
 }
 public void NavigateToItem(CatalogBookItemModel model)
 {
     _navigationService
     .UriFor <BookInfoPageViewModel>()
     .WithParam(vm => vm.Title, model.Title.ToUpper())
     .WithParam(vm => vm.Description, model.Description)
     .WithParam(vm => vm.ImageUrl, model.ImageUrl)
     .WithParam(vm => vm.CatalogId, GetCatalogId(model.GetHashCode()))
     .WithParam(vm => vm.CatalogBookItemKey, TransientStorage.Put(model))
     .Navigate();
 }
        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();
        }
Example #11
0
        public override Uri MapUri(Uri uri)
        {
            var navigationService = IoC.Get <INavigationService>();
            var catalogRepository = IoC.Get <ICatalogRepository>();

            string tempUri = uri.ToString();

            // File association launch
            if (tempUri.Contains("/FileTypeAssociation"))
            {
                // Get the file ID (after "fileToken=").
                int    fileIDIndex = tempUri.IndexOf("fileToken=", StringComparison.InvariantCulture) + 10;
                string fileID      = tempUri.Substring(fileIDIndex);

                // Get the file name.
                string incomingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);

                // Get the file extension.
// ReSharper disable PossibleNullReferenceException
                string incomingFileType = Path.GetExtension(incomingFileName).ToLower();
// ReSharper restore PossibleNullReferenceException


                var catalog = catalogRepository.GetAll().Single(c => c.Type == CatalogType.StorageFolder);

                var bookItemModel = new CatalogBookItemModel
                {
                    Title       = Path.GetFileNameWithoutExtension(incomingFileName),
                    Description = string.Empty,
                    Author      = string.Empty,
                    Links       = new List <BookDownloadLinkModel>
                    {
                        new BookDownloadLinkModel {
                            Type = incomingFileType, Url = fileID
                        }
                    },
                    Id = fileID
                };

                return(navigationService
                       .UriFor <BookInfoPageViewModel>()
                       .WithParam(vm => vm.Title, bookItemModel.Title.ToUpper())
                       .WithParam(vm => vm.Description, bookItemModel.Description)
                       .WithParam(vm => vm.CatalogId, catalog.Id)
                       .WithParam(vm => vm.CatalogBookItemKey, TransientStorage.Put(bookItemModel))
                       .BuildUri());
            }
            // Otherwise perform normal launch.
            return(uri);
        }
Example #12
0
        public void NavigateToItem(CatalogItemModel model)
        {
            if (IsBusy)
            {
                return;
            }

            // hack for improving performance. If we skip this thing, app will take a lot of time to generate exception and catch it.
            if (CheckForUnauthorizedLitresAccess(model))
            {
                NavigateToAuthorizationPage("http://robot.litres.ru/pages/catalit_authorise/");
                return;
            }

            var treeReader = CatalogReader as ITreeCatalogReader;

            if (treeReader == null)
            {
                return;
            }


            var itemModel = model as CatalogBookItemModel;

            if (itemModel != null)
            {
                var bookItemModel = itemModel;

                _navigationService
                .UriFor <BookInfoPageViewModel>()
                .WithParam(vm => vm.Title, bookItemModel.Title.ToUpper())
                .WithParam(vm => vm.Description, bookItemModel.Description)
                .WithParam(vm => vm.ImageUrl, bookItemModel.ImageUrl)
                .WithParam(vm => vm.CatalogId, treeReader.CatalogId)
                .WithParam(vm => vm.CatalogBookItemKey, TransientStorage.Put(bookItemModel))
                .Navigate();

                return;
            }

            if (!string.IsNullOrEmpty(model.OpdsUrl))
            {
                treeReader.GoTo(model);
                LoadItems();
            }
            else if (!string.IsNullOrEmpty(model.HtmlUrl))
            {
                NavigateToWebBrowser(model);
            }
        }
        public void Read()
        {
            if (string.IsNullOrEmpty(BookId) || Book == null)
            {
                return;
            }

            _navigationService
            .UriFor <ReadPageViewModel>()
            .WithParam(vm => vm.BookId, BookId)
            .WithParam(vm => vm.ToLastReadPage, true)
            .WithParam(vm => vm.CatalogId, CatalogId)
            .WithParam(vm => vm.CatalogBookItemKey, TransientStorage.Put(CatalogBookItemModel))
            .Navigate();
        }
        protected override void OnInitialize()
        {
            base.OnInitialize();

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

            _thisBookBookmarksViewModel.BookId               = BookId;
            _thisBookBookmarksViewModel.CatalogId            = CatalogId;
            _thisBookBookmarksViewModel.CatalogBookItemModel = CatalogBookItemModel;
            Items.Add(_thisBookBookmarksViewModel);
            Items.Add(_allBooksBookmarksViewModel);
        }
        public void GoToSearch()
        {
            var navigateUri = _navigationService
                              .UriFor <BookmarkSearchPageViewModel>();

            if (ActiveItem is ThisBookBookmarksViewModel)
            {
                var activeItem = (ThisBookBookmarksViewModel)ActiveItem;
                navigateUri.WithParam(vm => vm.BookId, activeItem.BookId);
            }
            navigateUri.WithParam(vm => vm.SearchBookSubtitle, ActiveItem.DisplayName)
            .WithParam(vm => vm.CatalogId, CatalogId)
            .WithParam(vm => vm.CatalogBookItemKey, TransientStorage.Put(CatalogBookItemModel))
            .Navigate();
        }
        private async Task CheckForDownloadItem(string url)
        {
            var link = await GetDownloadLink(url);

            if (link != null)
            {
                if (!string.IsNullOrEmpty(CatalogBookItemKey) && TransientStorage.Contains(CatalogBookItemKey))
                {
                    var catalogBookItem = TransientStorage.Get <CatalogBookItemModel>(CatalogBookItemKey);
                    catalogBookItem.Links = new List <BookDownloadLinkModel> {
                        link
                    };

                    _navigationService
                    .UriFor <BookInfoPageViewModel>()
                    .WithParam(vm => vm.Title, catalogBookItem.Title.ToUpper())
                    .WithParam(vm => vm.Description, catalogBookItem.Description)
                    .WithParam(vm => vm.ImageUrl, catalogBookItem.ImageUrl)
                    .WithParam(vm => vm.CatalogId, CatalogId)
                    .WithParam(vm => vm.StartDownload, true)
                    .WithParam(vm => vm.CatalogBookItemKey, TransientStorage.Put(catalogBookItem))
                    .Navigate();
                    _navigated = true;
                }
                else
                {
                    var catalogBookItemModel = new CatalogBookItemModel
                    {
                        Links = new List <BookDownloadLinkModel> {
                            link
                        },
                        Title = Title,
                        Id    = Guid.NewGuid().ToString()
                    };
                    _downloadController.DownloadBook(catalogBookItemModel, CatalogId);
                    _catalogItemId = catalogBookItemModel.Id;
                }
            }
        }
        protected override void OnInitialize()
        {
            base.OnInitialize();

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

            if (!string.IsNullOrEmpty(BookId))
            {
                InitializeBook();
            }
            else
            {
                if (CatalogBookItemModel != null)
                {
                    if (CheckIsDownloaded())
                    {
                        return;
                    }

                    if (CheckForExistingTrial())
                    {
                        InitializeBook();
                    }
                    else
                    {
                        Title               = !string.IsNullOrEmpty(CatalogBookItemModel.Title) ? CatalogBookItemModel.Title : null;
                        Author              = CatalogBookItemModel.Author;
                        Description         = CatalogBookItemModel.Description;
                        IsBookFree          = CatalogBookItemModel.AcquisitionLink == null;
                        ApplicationBarIndex = 1;
                    }
                }
                ShowOverlayIfBookDownloading();
            }
        }
        protected override void OnInitialize()
        {
            base.OnInitialize();

            Book = _bookRepository.Get(BookId);
            if (Book == null)
            {
                _navigationService.GoBack();
                return;
            }

            if (ToLastReadPage)
            {
                TokenOffset = Book.CurrentTokenID;
            }

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

            UpdateIsFavouriteBook();
        }
        public async void Login()
        {
            try
            {
                if (string.IsNullOrEmpty(_userName) || string.IsNullOrEmpty(_password))
                {
                    _notificationsService.ShowAlert(UINotifications.General_AttentionCaption, UINotifications.AuthorizationPage_WrongPasswordOrUserName);
                    return;
                }

                StartBusiness();

                var authorizationService = _authorizationFactory.GetAuthorizationService(new CatalogModel {
                    Id = CatalogId, Type = CatalogType
                });
                var authorizationString = await authorizationService.Authorize(_userName, _password, Path);

                if (!string.IsNullOrEmpty(authorizationString))
                {
                    var catalog = _catalogRepository.Get(CatalogId);
                    catalog.AuthorizationString = EncryptService.Encrypt(authorizationString);
                    _catalogRepository.Save(catalog);

                    if (!string.IsNullOrEmpty(CatalogBookItemKey))
                    {
                        var catalogBookItemModel = TransientStorage.Get <CatalogBookItemModel>(CatalogBookItemKey);

                        _navigationService
                        .UriFor <BookInfoPageViewModel>()
                        .WithParam(vm => vm.Title, catalogBookItemModel.Title.ToUpper())
                        .WithParam(vm => vm.Description, catalogBookItemModel.Description)
                        .WithParam(vm => vm.ImageUrl, catalogBookItemModel.ImageUrl)
                        .WithParam(vm => vm.CatalogId, CatalogId)
                        .WithParam(vm => vm.CatalogBookItemKey, TransientStorage.Put(catalogBookItemModel))
                        .Navigate();
                    }
                    else
                    {
                        _navigationService.UriFor <CatalogPageViewModel>()
                        .WithParam(vm => vm.CatalogId, catalog.Id)
                        .WithParam(vm => vm.DisplayName, _catalogController.GetCatalogTitle(catalog).ToUpper())
                        .WithParam(vm => vm.IsSearchEnabled, !string.IsNullOrEmpty(catalog.SearchUrl) ||
                                   catalog.Type == CatalogType.SDCard ||
                                   catalog.Type == CatalogType.SkyDrive)
                        .WithParam(vm => vm.CanRefresh, catalog.Type != CatalogType.SDCard)
                        .Navigate();
                    }
                }
                else
                {
                    StopBusiness();
                    _notificationsService.ShowAlert(UINotifications.General_AttentionCaption, UINotifications.AuthorizationPage_WrongPasswordOrUserName);
                }
            }
            catch (Exception exception)
            {
                _errorHandler.Handle(exception);
            }
            finally
            {
                StopBusiness();
            }
        }