示例#1
0
        private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            await Browser.WaitForInitializationAsync();

            SubscriptionResult = Bus.SubscribeAsync("subscriptionId", GetLogic(node => Logger.Information("{@Node}", node),
                                                                               url => Task.FromResult(Browser.LoadPage(url)),
                                                                               script =>
            {
                string result             = null;
                AutoResetEvent waitHandle = new AutoResetEvent(false);

                Task.Run(async() =>
                {
                    await Dispatcher.Invoke(async() =>
                    {
                        result = await Browser.EvaluateScriptWithReturnAsync(script);
                        waitHandle.Set();
                    });
                });

                waitHandle.WaitOne();

                return(Task.FromResult(result));
            },
                                                                               async node => await Bus.PublishAsync(node),
                                                                               async node => await Bus.PublishAsync(new Result {
                Node = node
            }),
                                                                               async node =>
            {
                Logger.Error("{@Node}", node);
                await Bus.PublishAsync(new ErrorResult {
                    Node = node
                });
            },
                                                                               node => {}));
        }