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 ); }
private async Task SearchBooks( List<BookInstruction> ItemList, ProcPassThru PPass, ProcConvoy KnownBook, string Content ) { ProcFind.RegItem RegParam = new ProcFind.RegItem( ItemPattern, ItemParam, true ); if ( !RegParam.Validate() ) return; MatchCollection matches = RegParam.RegExObj.Matches( Content ); foreach ( Match match in matches ) { if ( HasSubProcs && RegParam.Valid ) { string FParam = string.Format( RegParam.Format , match.Groups .Cast<Group>() .Select( g => g.Value ) .ToArray() ); ProcConvoy ItemConvoy = await ItemProcs.CreateSpider().Crawl( new ProcConvoy( PPass, FParam ) ); string Id = await GetId( ItemConvoy ); if ( string.IsNullOrEmpty( Id ) ) { ProcManager.PanelMessage( this, () => { StringResources stx = new StringResources( "Error" ); return stx.Str( "NoIdForBook" ); }, LogType.WARNING ); continue; } ItemConvoy = ProcManager.TracePackage( ItemConvoy, ( P, C ) => C.Payload is BookInstruction ); if ( !( ItemConvoy == null || ItemConvoy == KnownBook ) ) { BookInstruction BInst = ( BookInstruction ) ItemConvoy.Payload; ItemList.Add( BInst ); if ( HasBookSpider ) BInst.PlaceDefs( Id, BookSpider ); } else { ProcManager.PanelMessage( this, () => { StringResources stx = new StringResources( "Error" ); return stx.Str( "NotABook" ); }, LogType.WARNING ); } } } }