Example #1
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
                    );
            }
        }
Example #2
0
        public void LoadIntro(BookItem b, bool useCache = true)
        {
            if (b.IsSpider())
            {
                return;
            }

            CurrentBook = b;

            if (!useCache || string.IsNullOrEmpty(b.Info.LongDescription))
            {
                X.Instance <IRuntimeCache>(XProto.WRuntimeCache).InitDownload(
                    b.ZItemId
                    , X.Call <XKey[]>(XProto.WRequest, "GetBookIntro", b.ZItemId)
                    , SaveIntro, IntroFailed, false
                    );
            }
        }
Example #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
                        );
                }
            }
        }
Example #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);
        }
Example #5
0
        private void BookLoadComplete(BookItem Book)
        {
            BookLoading = false;

            var j = Dispatcher.RunIdleAsync(x =>
            {
                if (Book.IsSpider())
                {
                    ImageSrv           = ImageService.GetProvider(Book);
                    bool ServiceExists = ImageSrv.Exists();

                    ImageBrowserBtn.IsEnabled
                          = ImageCoverBtn.IsEnabled
                          = ServiceExists;

                    bool ServiceAvail = ServiceExists || string.IsNullOrEmpty(Book.Info.CoverSrcUrl);

                    UseImageSearch.Foreground = new SolidColorBrush(ServiceExists ? GRConfig.Theme.ColorMinor : GRConfig.Theme.SubtleColor);
                    UseImageSearch.IsEnabled  = ServiceAvail;
                }

                CacheStateStory.Stop();
            });
        }