Beispiel #1
0
        private async void StepAutomation()
        {
            ES = new EpisodeStepper( new VolumesInfo( ThisBook ) );

            if ( AutoLimit < CurrentCount )
            {
                DispLog( string.Format( "Error: Limit Reached {0}/{1}", CurrentCount - 1, AutoLimit ) );
                return;
            }

            try
            {
                bool NotCached = false;
                for ( ES.Rewind(); ES.NextStepAvailable(); ES.StepNext() )
                {
                    Chapter C = new Chapter( ES.EpTitle, ThisBook.Id, ES.Vid, ES.Cid );
                    if ( !C.IsCached )
                    {
                        if ( !NotCached ) CurrentCount++;

                        NotCached = true;
                        // Register backgrountd transfer
                        await Task.Delay( TimeSpan.FromMilliseconds( 80 ) );

                        XKey[] Request = X.Call<XKey[]>( XProto.WRequest, "GetBookContent", ThisBook.Id, ES.Cid );

                        DispLog( ES.VolTitle + "[" + ES.EpTitle + "]" );
                        App.RuntimeTransfer.RegisterRuntimeThread(
                            Request
                            , C.ChapterPath, Guid.NewGuid()
                            , Uri.EscapeDataString( ThisBook.Title ) + "&" + Uri.EscapeDataString( ES.VolTitle ) + "&" + Uri.EscapeDataString( ES.EpTitle )
                            , C.IllustrationPath
                        );
                    }
                }
            }
            catch ( Exception ex )
            {
                global::System.Diagnostics.Debugger.Break();
                Logger.Log( ID, ex.Message, LogType.ERROR );
            }

            App.RuntimeTransfer.StartThreadCycle( LoadComplete );
            DispLog( "Complete" );

            OnComplete( ThisBook );
        }
Beispiel #2
0
        private async void GoToContentReader( BookItem b )
        {
            TOCData = new TOCSection( b );
            if ( TOCData.AnchorAvailable )
            {
                await Dispatcher.RunAsync(
                    CoreDispatcherPriority.Normal
                    , () => Frame.Navigate( typeof( ContentReader ), TOCData.AutoAnchor )
                );
                return;
            }

            EpisodeStepper ES = new EpisodeStepper( new VolumesInfo( b ) );
            ES.StepNext();

            await OneDriveRsync();
            await Dispatcher.RunAsync(
                CoreDispatcherPriority.Normal
                , () => Frame.Navigate(
                    typeof( ContentReader )
                    , new Chapter( ES.EpTitle, b.Id, ES.Vid, ES.Cid )
                )
            );
        }
Beispiel #3
0
        private async Task<AsyncTryOut<Chapter>> TryFoundIllustration()
        {
            VolumesInfo VF = new VolumesInfo( ReaderPage.CurrentBook );
            EpisodeStepper ES = new EpisodeStepper( VF );

            ES.SetCurrentPosition( ReaderPage.CurrentChapter, true );

            List<Chapter> Chs = new List<Chapter>();

            bool NeedDownload = false;

            string Vid = ReaderPage.CurrentChapter.vid;
            while ( ES.Vid == Vid )
            {
                Chapter Ch = ES.Chapter;
                Chs.Add( Ch );

                if ( !Ch.IsCached ) NeedDownload = true;
                if( Ch.HasIllustrations )
                {
                    return new AsyncTryOut<Chapter>( true, Ch );
                }
                if ( !ES.StepNext() ) break;
            }

            if ( !NeedDownload )
            {
                Message.Text = "No Image for this volume";
                return new AsyncTryOut<Chapter>();
            }

            NeedDownload = false;

            StringResources stm = new StringResources( "Message" );
            MessageDialog Msg = new MessageDialog( "Not enough information to see if there were any illustrations within this volume. Download this volume?" );

            Msg.Commands.Add(
                new UICommand( stm.Str( "Yes" ), ( x ) => NeedDownload = true )
            );

            Msg.Commands.Add( new UICommand( stm.Str( "No" ) ) );

            await Popups.ShowDialog( Msg );

            if ( !NeedDownload )
            {
                Message.Text = "Not enough information for finding illustrations. Consider downloading a specific chapter";
                return new AsyncTryOut<Chapter>();
            }

            // Really, this desperate?
            TaskCompletionSource<AsyncTryOut<Chapter>> TCSChapter = new TaskCompletionSource<AsyncTryOut<Chapter>>();
            Volume V = ReaderPage.CurrentBook.GetVolumes().First( x => x.vid == ReaderPage.CurrentChapter.vid );
            ChapterList.ItemsSource = V.ChapterList;

            WRuntimeTransfer.DCycleCompleteHandler CycleComp = null;

            CycleComp = delegate ( object sender, DCycleCompleteArgs e )
            {
                App.RuntimeTransfer.OnCycleComplete -= CycleComp;
                bool AllSet = V.ChapterList.All( x => x.IsCached );

                Chapter C = V.ChapterList.FirstOrDefault( x => x.HasIllustrations );

                if ( C == null )
                {
                    if ( AllSet ) Worker.UIInvoke( () => Message.Text = "No Illustration available" );
                    TCSChapter.TrySetResult( new AsyncTryOut<Chapter>() );
                    return;
                }

                TCSChapter.TrySetResult( new AsyncTryOut<Chapter>( true, C ) );
            };

            if ( ReaderPage.CurrentBook is BookInstruction )
            {
                foreach( SChapter C in V.ChapterList.Cast<SChapter>() )
                {
                    await new ChapterLoader().LoadAsync( C );
                    C.UpdateStatus();
                }

                // Fire the event myself
                CycleComp( this, new DCycleCompleteArgs() );
            }
            else
            {
                App.RuntimeTransfer.OnCycleComplete += CycleComp;
                AutoCache.DownloadVolume( ReaderPage.CurrentBook, V );
            }

            return await TCSChapter.Task;
        }