public async Task<ProcConvoy> Crawl( ProcConvoy Convoy = null ) { if ( ProcList.Count() == 0 ) { ProcManager.PanelMessage( ID, () => Res.RSTR( "EmptyCrawling" ), LogType.INFO ); return Convoy; } ProcConvoy Conveying = Convoy; foreach ( Procedure Proc in ProcList ) { ProcManager.PanelMessage( ID, () => Res.RSTR( "Running" ) + ": " + Proc.Name, LogType.INFO ); try { Proc.Running = true; ProcConvoy Received = await Proc.Run( Conveying ); Conveying = Received; Proc.Running = false; } catch ( Exception ex ) { ProcManager.PanelMessage( ID, () => Res.RSTR( "Faulted", Proc.Name, ex.Message ), LogType.ERROR ); Proc.Running = false; Proc.Faulted = true; Conveying = null; break; } } ProcManager.PanelMessage( ID, () => Res.RSTR( "RunComplete" ), LogType.INFO ); return Conveying; }
private void MessageBus_OnDelivery(Message Mesg) { ProcConvoy Convoy = Mesg.Payload as ProcConvoy; if (Mesg.Content == "RUN_RESULT" && Convoy != null && Convoy.Dispatcher == EditTarget) { TempInst = Convoy.Payload as BookInstruction; ProcConvoy ProcCon = ProcManager.TracePackage(Convoy, (P, C) => P is ProcParameter); if (ProcCon != null) { ProcParameter PPClone = new ProcParameter(); PPClone.ReadParam(ProcCon.Dispatcher.ToXParam()); ProcCon = new ProcConvoy(PPClone, null); } TempInst.PackVolumes(ProcCon); Preview.Navigate( typeof(TableOfContents) , new Tuple <Volume[], SelectionChangedEventHandler>(TempInst.GetVolInsts().Remap(x => x.ToVolume(TempInst.Entry)), PreviewContent) ); Preview.BackStack.Clear(); TestRunning.IsActive = false; } }
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 void MessageBus_OnDelivery(Message Mesg) { ProcConvoy Convoy = Mesg.Payload as ProcConvoy; if (Mesg.Content == "RUN_RESULT" && Convoy != null && Convoy.Dispatcher == EditTarget) { TestRunning.IsActive = false; BookInstruction BookInst = Convoy.Payload as BookInstruction; if (BookInst != null) { var j = ViewTestResult(BookInst); } } }
private async void TestDef(object sender, RoutedEventArgs e) { if (TestRunning.IsActive) { return; } string Url = UrlInput.Text.Trim(); TestRunning.IsActive = true; if (string.IsNullOrEmpty(Url)) { MessageBus.SendUI(typeof(ProceduresPanel), "RUN", EditTarget); return; } try { if (PreviewFile == null) { PreviewFile = await MCrawler.DownloadSource(Url); } // The resulting convoy may not be the book instruction originally created ProcConvoy Convoy = await new ProceduralSpider(new Procedure[] { EditTarget }) .Crawl(new ProcConvoy(new ProcDummy(), PreviewFile)); // So we trackback the Book Convoy Convoy = ProcManager.TracePackage(Convoy, (D, C) => C.Payload is BookInstruction); if (Convoy == null) { throw new Exception("Unable to find the generated book convoy"); } await ViewTestResult(( BookInstruction )Convoy.Payload); } catch (Exception ex) { ProcManager.PanelMessage(ID, ex.Message, LogType.INFO); } 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); }
private void MessageBus_OnDelivery(Message Mesg) { ProcConvoy Convoy = Mesg.Payload as ProcConvoy; if (Mesg.Content == "RUN_RESULT" && Convoy != null && Convoy.Dispatcher == EditTarget) { TestRunning.IsActive = false; Convoy = ProcManager.TracePackage(Convoy, (P, C) => Convoy.Payload is IEnumerable <BookInstruction>); if (Convoy == null) { throw new Exception("Unable to find the generated book convoy"); } else { var j = ViewTestResult((IEnumerable <BookInstruction>)Convoy.Payload); } } }
public static ProcConvoy TracePackage( ProcConvoy Start, Func<Procedure, ProcConvoy, bool> Verifier ) { if ( Start == null ) return null; Procedure Disp = Start.Dispatcher; ProcConvoy Convoy = Start; while ( Convoy != null ) { if( Verifier( Disp, Convoy ) ) { return Convoy; } // Dispatcher's Convoy Convoy = Disp.Convoy; if ( Disp.Convoy == null ) break; // Dispatcher's Convoy's Dispatcher... Disp = Disp.Convoy.Dispatcher; } return null; }
public async Task <IList <T> > NextPage(uint ExpectedCount = 30) { TaskCompletionSource <T[]> Ts = new TaskCompletionSource <T[]>(); try { ProcPassThru RunMode; if (FirstLoad) { FirstLoad = false; RunMode = new ProcPassThru(); } else { RunMode = new ProcPassThru(ProcType.FEED_RUN); } ProcConvoy Convoy = await Spider.Crawl(new ProcConvoy( RunMode, FeedParams )); string FeedParam = ""; if (Convoy.Payload is IEnumerable <IStorageFile> ) { FeedParam = await((IEnumerable <IStorageFile>)Convoy.Payload).FirstOrDefault()?.ReadString(); } else if (Convoy.Payload is IEnumerable <string> ) { FeedParam = ((IEnumerable <string>)Convoy.Payload).FirstOrDefault(); } else if (Convoy.Payload is IStorageFile) { FeedParam = await(( IStorageFile )Convoy.Payload).ReadString(); } else if (Convoy.Payload is string) { FeedParam = ( string )Convoy.Payload; } FeedParams = FeedParam.Split('\n'); Convoy = ProcManager.TracePackage(Convoy, (P, C) => C.Payload is IEnumerable <T>); if (Convoy != null) { IEnumerable <T> Items = (IEnumerable <T>)Convoy.Payload; Ts.SetResult(Items.ToArray()); } else { Ts.TrySetResult(new T[0]); } } catch (Exception ex) { Ts.TrySetResult(new T[0]); Logger.Log(ID, ex.Message, LogType.WARNING); } T[] Cs = await Ts.Task; PageEnded = (Cs.Length == 0); return(Cs); }