wenku8.Model.Loaders.ChapterLoader.LoadAsync C# (CSharp) Method

LoadAsync() public method

public LoadAsync ( Chapter C, bool Cache = true ) : System.Threading.Tasks.Task
C Chapter
Cache bool
return System.Threading.Tasks.Task
        public async Task LoadAsync( Chapter C, bool Cache = true )
        {
            if ( Cache && Shared.Storage.FileExists( C.ChapterPath ) )
            {
                OnComplete( C );
            }
            else if ( C is SChapter )
            {
                // if this belongs to the spider
                SChapter SC = C as SChapter;
                await SC.SubProcRun( Cache );

                if ( SC.TempFile != null )
                {
                    await new ContentParser().OrganizeBookContent(
                        await SC.TempFile.ReadString()
                        , SC
                    );
                }

                OnComplete( C );
            }
            else
            {
                if ( !ProtoMode ) throw new InvalidOperationException( "ChapterLoader is in Bare mode" );
                IRuntimeCache wCache = X.Instance<IRuntimeCache>( XProto.WRuntimeCache );

                // Cancel thread if there is same job downloading
                App.RuntimeTransfer.CancelThread( C.ChapterPath );

                // Initiate download, precache should not be done internally.
                wCache.InitDownload(
                    C.ChapterPath
                    , X.Call<XKey[]>( XProto.WRequest, "GetBookContent", CurrentBook.Id, C.cid )

                    , async ( DRequestCompletedEventArgs e, string path ) =>
                    {
                        await new ContentParser().OrganizeBookContent( e.ResponseString, C );
                        OnComplete( C );
                    }

                    , ( string Request, string path, Exception ex ) =>
                    {
                        Logger.Log( ID, ex.Message, LogType.ERROR );
                        System.Utils.ShowError( () => { return new ErrorMessage().DOWNLOAD; } );
                        // OnComplete( C );
                    }

                    , false
                );
            }
        }