/// <summary>
        /// Stops the script engine at the current point.
        /// </summary>
        /// <returns></returns>
        public async Task Interrupt()
        {
            try
            {
                m_scriptEngine.Interrupt();
            }
            catch (Exception)
            {
                throw;
            }

            await ResetScriptEngine();
        }
Exemplo n.º 2
0
 public void Cleanup()
 {
     if (_scriptEngine != null)
     {
         _scriptEngine.Interrupt();
         _scriptEngine.Dispose();
         _scriptEngine = null;
     }
 }
Exemplo n.º 3
0
        public void Run(string script, ViewModels.LogStream log, CancellationToken cancel)
        {
            var utils = new ScriptUtils(log, cancel);

            try
            {
                engine?.Interrupt();

                engine = new V8ScriptEngine();
                engine.AddHostObject("utils", utils);
                engine.AddHostObject("client", this.client);

                var evalResult = engine.Evaluate("script", script);
            }
            catch (ScriptEngineException e)
            {
                utils.WriteLine(e.ErrorDetails);
            }
            catch (ScriptInterruptedException e)
            {
                utils.WriteLine(e.ErrorDetails);
            }
        }
Exemplo n.º 4
0
        private async Task Navigate(Uri uri)
        {
            controlsGrid.IsEnabled = false;
            try
            {
                string url = uri.ToString();
                urlBar.Text = url;

                if (engine != null)
                {
                    engine.Interrupt();
                    engine.Dispose();
                }

                engine = new V8ScriptEngine();
                engine.AddHostObject("window", this);
                engine.AddHostType(typeof(MessageBox));
                engine.AddHostType(typeof(Console));

                foreach (var t in availableTypesLazy.Value)
                {
                    engine.AddHostType(t);
                }

                ParserContext parserContext = new ParserContext();
                parserContext.XmlnsDictionary["s"] = "clr-namespace:DynamicWPF.Scripting;assembly=DynamicWPF";

                try
                {
                    var resp = await client.GetAsync(uri);

                    uri         = resp.RequestMessage.RequestUri;
                    url         = uri.ToString();
                    urlBar.Text = url;

                    parserContext.BaseUri = new Uri(url.Remove(url.LastIndexOf('/') + 1));

                    Page obj = null;

                    if (resp.IsSuccessStatusCode)
                    {
                        try
                        {
                            obj = (Page)XamlReader.Load(await resp.Content.ReadAsStreamAsync(), parserContext);
                        }
                        catch
                        {
                            Process.Start(url);
                        }
                    }
                    else
                    {
                        try
                        {
                            obj = (Page)XamlReader.Load(await resp.Content.ReadAsStreamAsync(), parserContext);
                        }
                        catch
                        {
                            resp.EnsureSuccessStatusCode();
                        }
                    }

                    if (obj != null)
                    {
                        contentFrame.Navigate(obj);
                        foreach (var link in (obj.Content as DependencyObject).FindVisualChildren <Hyperlink>())
                        {
                            link.RequestNavigate += async(o, ev) =>
                            {
                                ev.Handled = true;
                                var u = (o as Hyperlink).NavigateUri;

                                await Navigate(u.IsAbsoluteUri?u : new Uri(parserContext.BaseUri, u));
                            };
                        }

                        engine.AddHostObject("content", obj);
                        foreach (var s in ScriptManager.GetScripts(obj))
                        {
                            try
                            {
                                var str = await client.GetStringAsync(s.Source.IsAbsoluteUri?s.Source : new Uri(parserContext.BaseUri, s.Source));

                                engine.Execute(str);
                            }
                            catch { }
                        }
                    }
                }
                catch (Exception ex)
                {
                    contentFrame.Navigate(new ErrorPage(ex));
                }
            }
            finally
            {
                controlsGrid.IsEnabled = true;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Stops the script engine at the current point.
        /// </summary>
        /// <returns></returns>
        public async Task Interrupt()
        {
            m_scriptEngine.Interrupt();

            await ResetScriptEngine();
        }