Beispiel #1
0
        private void OpenBook(BookItem Book)
        {
            ThisBook           = Book;
            Shared.CurrentBook = Book;

            PageProcessor.ReadSecondaryTile(Book);

            CacheStateStory.Begin();

            BookLoading = true;

            if (Book.IsEx())
            {
                Book.XSetProp("Mode", X.Const <string>(XProto.WProtocols, "ACTION_BOOK_META"));
            }

            BookLoader BL = new BookLoader(BookLoadComplete);

            BL.Load(Book, true);
            BL.LoadIntro(Book, true);
            BL.LoadCover(Book, true);

            SyncAnchors();
            SetContext();
        }
Beispiel #2
0
        public async void Load(BookItem b, bool useCache = true)
        {
            // b is null when back button is pressed before BookLoader load
            if (b == null)
            {
                return;
            }

            Shared.LoadMessage("LoadingVolumes");
            CurrentBook = b;

            if (b.Volumes == null)
            {
                b.Entry.Volumes = await Shared.BooksDb.LoadCollectionAsync(b.Entry, x => x.Volumes, x => x.Index);
            }

            if (b.IsLocal() || (useCache && !b.NeedUpdate && b.Volumes.Any()))
            {
                foreach (Volume Vol in b.Volumes)
                {
                    if (Vol.Chapters == null)
                    {
                        Vol.Chapters = await Shared.BooksDb.LoadCollectionAsync(Vol, x => x.Chapters, x => x.Index);
                    }
                }

                OnComplete(b);
            }
            else if (b.IsSpider())
            {
                var j = Task.Run(() => LoadInst(( BookInstruction )b));
            }
            else if (b.IsEx())
            {
                IRuntimeCache wCache = X.Instance <IRuntimeCache>(XProto.WRuntimeCache);
                // This occurs when tapping pinned book but cache is cleared
                wCache.InitDownload(
                    b.ZItemId
                    , X.Call <XKey[]>(XProto.WRequest, "GetBookTOC", b.ZItemId)
                    , (DRequestCompletedEventArgs e, string id) =>
                {
                    b.XCall("ParseVolume", e.ResponseString);
                    OnComplete(b);
                }
                    , (string RequestURI, string id, Exception ex) =>
                {
                    OnComplete(b);
                }
                    , false
                    );
            }
        }
Beispiel #3
0
        public void Load(BookItem b, bool useCache = false)
        {
            CurrentBook = b;

            if (b.IsLocal())
            {
                OnComplete(b);
            }
            else if (b.IsSpider())
            {
                Task.Run(() => LoadInstruction(( BookInstruction )b, useCache));
            }
            else if (CurrentBook.IsEx())
            {
                string BookId = b.ZItemId;
                string Mode   = CurrentBook.XField <string>("Mode");

                if (useCache && b.Info.Flags.Contains(Mode))
                {
                    OnComplete(b);
                }
                else
                {
                    b.Info.Flags.Add(Mode);
                    X.Instance <IRuntimeCache>(XProto.WRuntimeCache)
                    .InitDownload(
                        BookId, X.Call <XKey[]>(XProto.WRequest, "DoBookAction", Mode, BookId)
                        , (e, id) =>
                    {
                        CurrentBook.XCall("ParseXml", e.ResponseString);
                        CurrentBook.LastCache = DateTime.Now;
                        CurrentBook.SaveInfo();
                        OnComplete(CurrentBook);
                    }
                        , (cache, id, ex) =>
                    {
                        b.Info.Flags.Remove(Mode);
                        OnComplete(null);
                    }, true
                        );
                }
            }
        }
Beispiel #4
0
        private void ToggleAppBar()
        {
            StringResources stx = StringResources.Load("AppBar", "AppResources", "ContextMenu");

            if (ThisBook.IsEx())
            {
                VoteButton.Visibility = Visibility.Visible;

                AuthorBtn        = UIAliases.CreateAppBarBtn(Symbol.ContactPresence, stx.Str("Author"));
                AuthorBtn.Click += SearchAuthor;

                CommentBtn.Click += OpenExComments;

                MajorControls = new ICommandBarElement[] { FavBtn, AuthorBtn, CommentBtn, TOCBtn };
            }
            else if (ThisBook.IsSpider())
            {
                HSBtn        = UIAliases.CreateAppBarBtn(SegoeMDL2.HomeGroup, stx.Text("ScriptDetails", "AppResources"));
                HSBtn.Click += OpenHSComments;

                FavBtn        = UIAliases.CreateAppBarBtn(SegoeMDL2.Pin, stx.Text("PinToStart", "ContextMenu"));
                FavBtn.Click += PinSpider;

                CommentBtn.Click += OpenTwitter;

                MajorControls = new ICommandBarElement[] { FavBtn, HSBtn, CommentBtn, TOCBtn };
            }
            else
            {
                CommentBtn.Click += OpenTwitter;

                MajorControls = new ICommandBarElement[] { FavBtn, CommentBtn, TOCBtn };
            }

            ControlChanged?.Invoke(this);
        }
Beispiel #5
0
        public async Task <bool> LoadCoverAsync(BookItem B, bool Cache)
        {
            if (Cache && B.CoverExist)
            {
                return(true);
            }

            if (!CoverProcess.AcquireLock(B.Entry, out var QToken))
            {
                goto AwaitToken;
            }

            if (B.IsEx())
            {
                X.Instance <IRuntimeCache>(XProto.WRuntimeCache).InitDownload(
                    B.ZItemId, X.Call <XKey[]>(XProto.WRequest, "GetBookCover", B.ZItemId)
                    , (e, id) =>
                {
                    B.SaveCover(e.ResponseBytes);
                    QToken.TrySetResult(true);
                }
                    , (c, i, ex) => QToken.TrySetResult(false)
                    , false
                    );

                goto AwaitToken;
            }

            if (string.IsNullOrEmpty(B.Info.CoverSrcUrl))
            {
                // Use bing service
                string ThumbUrl = await ImageService.GetProvider(B).GetImage();

                if (string.IsNullOrEmpty(ThumbUrl))
                {
                    QToken.TrySetResult(false);
                    goto AwaitToken;
                }

                B.Info.CoverSrcUrl = ThumbUrl;
            }

            // Set the referer, as it is required by some site such as fanfiction.net
            new RuntimeCache(a =>
            {
                HttpRequest R = new WHttpRequest(a)
                {
                    EN_UITHREAD = false
                };

                if (!string.IsNullOrEmpty(B.Info.OriginalUrl))
                {
                    R.RequestHeaders.Referrer = new Uri(B.Info.OriginalUrl);
                }

                return(R);
            }).GET(new Uri(B.Info.CoverSrcUrl)
                   , (e, id) =>
            {
                B.SaveCover(e.ResponseBytes);
                QToken.TrySetResult(true);
            }
                   , (c, i, ex) => QToken.TrySetResult(false)
                   , false);

AwaitToken:
            return(await QToken.Task);
        }