private async void PreviewContent(object sender, SelectionChangedEventArgs e) { if (e.AddedItems.Count == 0 || TestRunning.IsActive) { return; } TestRunning.IsActive = true; TOCItem Item = ( TOCItem )e.AddedItems[0]; Chapter Ch = Item.Ch; if (Ch == null) { ProcManager.PanelMessage(ID, "Chapter is not available", LogType.INFO); return; } string VId = Ch.Volume.Meta[AppKeys.GLOBAL_VID]; string CId = Ch.Meta[AppKeys.GLOBAL_CID]; EpInstruction EpInst = TempInst.GetVolInsts().First(x => x.VId == VId).EpInsts.Cast <EpInstruction>().First(x => x.CId == CId); IEnumerable <ProcConvoy> Convoys = await EpInst.Process(); StorageFile TempFile = await AppStorage.MkTemp(); StringResources stx = StringResources.Load("LoadingMessage"); foreach (ProcConvoy Konvoi in Convoys) { ProcConvoy Convoy = ProcManager.TracePackage( Konvoi , (d, c) => c.Payload is IEnumerable <IStorageFile> || c.Payload is IStorageFile ); if (Convoy == null) { continue; } if (Convoy.Payload is IStorageFile) { await TempFile.WriteFile(( IStorageFile )Convoy.Payload, true, new byte[] { ( byte )'\n' }); } else if (Convoy.Payload is IEnumerable <IStorageFile> ) { foreach (IStorageFile ISF in ((IEnumerable <IStorageFile>)Convoy.Payload)) { ProcManager.PanelMessage(ID, string.Format(stx.Str("MergingContents"), ISF.Name), LogType.INFO); await TempFile.WriteFile(ISF, true, new byte[] { ( byte )'\n' }); } } } ShowSource(TempFile); TestRunning.IsActive = false; }
private async void LoadChapterInst(Chapter C) { BookInstruction BkInst = ( BookInstruction )CurrentBook ?? new BookInstruction(C.Book); XRegistry Settings = SpiderBook.GetSettings(BkInst.ZoneId, BkInst.ZItemId); EpInstruction Inst = new EpInstruction(C, Settings); IEnumerable <ProcConvoy> Convoys = await Inst.Process(); string ChapterText = ""; foreach (ProcConvoy Konvoi in Convoys) { ProcConvoy Convoy = ProcManager.TracePackage( Konvoi , (d, c) => c.Payload is IEnumerable <IStorageFile> || c.Payload is IStorageFile ); if (Convoy == null) { continue; } if (Convoy.Payload is IStorageFile) { ChapterText += await(( IStorageFile )Convoy.Payload).ReadString(); } else if (Convoy.Payload is IEnumerable <IStorageFile> ) { foreach (IStorageFile ISF in ((IEnumerable <IStorageFile>)Convoy.Payload)) { Shared.LoadMessage("MergingContents", ISF.Name); ChapterText += (await ISF.ReadString()) + "\n"; } } } await new ContentParser().ParseAsync(ChapterText, C); OnComplete(C); }
public override async Task<ProcConvoy> Run( ProcConvoy Convoy ) { Convoy = await base.Run( Convoy ); ProcConvoy UsableConvoy; if ( !TryGetConvoy( out UsableConvoy, ( P, C ) => { if ( P.Type.HasFlag( ProcType.FIND ) || P.Type.HasFlag( ProcType.URLLIST ) ) { return C.Payload is IEnumerable<IStorageFile>; } return false; } ) ) return Convoy; IInstructionSet SpTOC = null; // Search for the closest Instruction Set ProcConvoy SpiderInst = ProcManager.TracePackage( Convoy , ( P, C ) => { return C.Payload is IInstructionSet; } ); if( SpiderInst != null ) { SpTOC = SpiderInst.Payload as IInstructionSet; } if( SpTOC == null ) { SpTOC = new BookInstruction(); } IEnumerable<IStorageFile> ISFs = UsableConvoy.Payload as IEnumerable<IStorageFile>; bool VTitleAddOnce = false; ProcPassThru PPass = new ProcPassThru( new ProcConvoy( this, SpTOC ) ); foreach( IStorageFile ISF in ISFs ) { string Content = await ISF.ReadString(); ProcFind.RegItem RegTitle = new ProcFind.RegItem( VolPattern, VolTitle, true ); ProcFind.RegItem RegParam = new ProcFind.RegItem( VolPattern, VolParam, true ); if ( !( RegTitle.Validate() || RegParam.Validate() ) ) continue; MatchCollection matches = RegTitle.RegExObj.Matches( Content ); foreach ( Match match in matches ) { if ( VTitleAddOnce ) break; VolInstruction VInst = null; if( RegTitle.Valid ) { string FTitle = string.Format( RegTitle.Format , match.Groups .Cast<Group>() .Select( g => g.Value ) .ToArray() ); if( string.IsNullOrEmpty( RegTitle.Pattern ) ) { VTitleAddOnce = true; } VInst = new VolInstruction( VTitleAddOnce ? SpTOC.LastIndex : match.Index , FTitle.ToCTrad() ); VInst.ProcMan = VolProcs; SpTOC.PushInstruction( VInst ); } else { ProcManager.PanelMessage( this, () => Res.RSTR( "InvalidPattern" ), LogType.WARNING ); continue; } if ( HasVolProcs && RegParam.Valid ) { string FParam = string.Format( RegParam.Format , match.Groups .Cast<Group>() .Select( g => g.Value ) .ToArray() ); if( VolAsync ) { VInst.SetProcId( VolProcs.GUID ); VInst.PushConvoyParam( FParam ); } else { ProcConvoy VolConvoy = await VolProcs.CreateSpider().Crawl( new ProcConvoy( PPass, VInst ) ); } } } RegTitle = new ProcFind.RegItem( EpPattern, EpTitle, true ); RegParam = new ProcFind.RegItem( EpPattern, EpParam, true ); if ( !( RegTitle.Validate() || RegParam.Validate() ) ) continue; matches = RegTitle.RegExObj.Matches( Content ); foreach ( Match match in matches ) { EpInstruction EInst = null; if( RegTitle.Valid ) { string FTitle = string.Format( RegTitle.Format , match.Groups .Cast<Group>() .Select( g => g.Value ) .ToArray() ); EInst = new EpInstruction( VTitleAddOnce ? SpTOC.LastIndex : match.Index , FTitle.ToCTrad() ); EInst.ProcMan = EpProcs; SpTOC.PushInstruction( EInst ); } else { ProcManager.PanelMessage( this, () => Res.RSTR( "InvalidPattern" ), LogType.WARNING ); continue; } if ( HasEpProcs && RegParam.Valid ) { string FParam = string.Format( RegParam.Format , match.Groups .Cast<Group>() .Select( g => g.Value ) .ToArray() ); if( EpAsync ) { EInst.SetProcId( EpProcs.GUID ); EInst.PushConvoyParam( FParam ); } else { ProcConvoy EpConvoy = await EpProcs.CreateSpider().Crawl( new ProcConvoy( PPass, FParam ) ); } } } } return new ProcConvoy( this, SpTOC ); }