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 ); }
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 ) ) ); }
void Dispose() { if ( Disposed ) return; Disposed = true; foreach ( Action p in RegKey ) p(); ClockStop(); NavigationHandler.OnNavigatedBack -= OnBackRequested; Window.Current.SizeChanged -= Current_SizeChanged; App.ViewControl.PropertyChanged -= VC_PropertyChanged; CurrentBook = null; CurrentChapter = null; ContentView?.Dispose(); ContentView = null; ES = null; ContentPane = null; }
public void OpenBook( Chapter C, bool Reload = false, int Anchor = -1 ) { if ( OpenLock ) return; if ( C == null ) { Logger.Log( ID, "Oops, Chapter is null. Can't open nothing.", LogType.WARNING ); return; } if ( !Reload && C.Equals( CurrentChapter ) ) { if ( Anchor != -1 ) { ContentView.UserStartReading = false; ContentView.GotoIndex( Anchor ); } return; } ClosePane(); OpenMask(); CurrentChapter = C; OpenLock = true; // Throw this into background as it is resources intensive Task.Run( () => { if ( CurrentBook == null || C.aid != CurrentBook.Id ) { Shared.LoadMessage( "BookConstruct" ); if ( C is SChapter ) { CurrentBook = new BookInstruction( C as SChapter ); } else { CurrentBook = X.Instance<BookItem>( XProto.BookItemEx, C ); } } BookLoader BL = new BookLoader( BookLoaded ); BL.Load( CurrentBook, true ); // Fire up Episode stepper, used for stepping next episode if ( ES == null || ES.Chapter.aid != C.aid ) { Shared.LoadMessage( "EpisodeStepper" ); VolumeLoader VL = new VolumeLoader( ( BookItem b ) => { ES = new EpisodeStepper( new VolumesInfo( b ) ); SetInfoTemplate(); } ); VL.Load( CurrentBook ); } else { Worker.UIInvoke( () => SetInfoTemplate() ); } ReloadReader = () => { ContentFrame.Content = null; Shared.LoadMessage( "RedrawingContent" ); ContentView?.Dispose(); ContentView = new ReaderContent( this, Anchor ); SetLayoutAware(); ContentFrame.Content = ContentView; // Load Content at the very end ContentView.Load( false ); }; // Override reload here since // Since the selected index just won't update if ( Reload ) { ChapterLoader CL = new ChapterLoader( CurrentBook, x => { OpenLock = false; Redraw(); } ); // if book is local, use the cache CL.Load( CurrentChapter, CurrentBook.IsLocal ); } else { Worker.UIInvoke( () => { // Lock should be released before redrawing start OpenLock = false; Redraw(); } ); } } ); }
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; }