コード例 #1
0
ファイル: Program.cs プロジェクト: surya-rakanta/EPJsDeOb
        static void ProcessScript(String sFunc, String sHdrFile, String sDtlFile)
        {
            String sFileResult = Path.GetFileNameWithoutExtension(sDtlFile) + "-result.js";
            String sHdrScript  = File.ReadAllText(sHdrFile);
            String sRScript    = File.ReadAllText(sDtlFile);

            V8ScriptEngine v8       = new V8ScriptEngine();
            V8Script       myScript = v8.Compile(sHdrScript);

            v8.Execute(myScript);

            String          sRegex    = "(" + sFunc + @"\(\'0[xX][0-9A-Fa-f]+\'\))";
            MatchCollection arMatches = Regex.Matches(sRScript, sRegex);
            int             nI;
            String          sMatchVal, sRes;

            for (nI = 0; nI < arMatches.Count; nI++)
            {
                sMatchVal = arMatches[nI].Value;
                Console.WriteLine("Processing " + sMatchVal + " ...");
                sRes     = v8.ExecuteCommand(sMatchVal);
                sRScript = sRScript.Replace(arMatches[nI].Value, "\"" + sRes + "\"");
            }
            v8.Dispose();
            File.WriteAllText(sFileResult, sRScript);
            return;
        }
コード例 #2
0
 public void Dispose()
 {
     RaiseEventAsync("dispose").ContinueWith((task) =>
     {
         engine.Dispose();
     });
 }
コード例 #3
0
ファイル: JSPlayer.cs プロジェクト: newmind/GoldMine
 public void Dispose()
 {
     if (engin != null)
     {
         engin.Dispose();
     }
 }
コード例 #4
0
        public void Evaluating4000Records_ExpectedTime_200ms()
        {
            // Arrange
            var engine = new V8ScriptEngine();

            var exprected_time  = TimeSpan.FromMilliseconds(200);
            var exprected_count = 4000;

            var actual_time    = new TimeSpan();
            var actual_results = new Stack <int>(4000);

            // Act
            try
            {
                actual_time = Estimator.Estimate(() =>
                {
                    for (int i = 0; i < 4000; i++)
                    {
                        actual_results.Push((int)engine.Evaluate("1+1"));
                    }
                });
            }
            finally
            {
                engine.Dispose();
            }

            // Expect
            Assert.AreEqual(exprected_count, actual_results.Count);
            Assert.That(actual_time, Is.LessThanOrEqualTo(exprected_time));
        }
コード例 #5
0
 public void Cleanup()
 {
     if (_scriptEngine != null)
     {
         _scriptEngine.Dispose();
         _scriptEngine = null;
     }
 }
コード例 #6
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                channels.Clear();
                _engine.Dispose();
                _engine = null;

                disposedValue = true;
            }
        }
コード例 #7
0
 public override void Dispose()
 {
     if (_disposedFlag.Set())
     {
         if (_jsEngine != null)
         {
             _jsEngine.Dispose();
             _jsEngine = null;
         }
     }
 }
コード例 #8
0
ファイル: GameEngine.cs プロジェクト: punio7/DungeonCrawler2
 public void Dispose()
 {
     if (executeScript != null)
     {
         executeScript.Dispose();
     }
     if (scriptEngine != null)
     {
         scriptEngine.Dispose();
     }
 }
コード例 #9
0
        public override void Dispose()
        {
            if (!_disposed)
            {
                _disposed = true;

                if (_jsEngine != null)
                {
                    _jsEngine.Dispose();
                    _jsEngine = null;
                }
            }
        }
コード例 #10
0
        public void Dispose()
        {
            if (m_tcpClient != null)
            {
                m_tcpClient.Close();
            }

            if (m_scriptEngine != null)
            {
                m_scriptEngine.Interrupt();
                //m_scriptEngine.CollectGarbage(true);
                m_scriptEngine.Dispose();
                m_scriptEngine = null;
            }
        }
コード例 #11
0
        static void Main(string[] args)
        {
            string s = string.Empty;

            try
            {
                string url = "https://zingnews.vn";
                if (args.Length > 0)
                {
                    url = args[0];
                }

                //V8ScriptEngine engine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging);
                V8ScriptEngine engine = new V8ScriptEngine(V8ScriptEngineFlags.DisableGlobalMembers);
                //engine.Execute(Script_Text);
                engine.AddCOMType("XMLHttpRequest", "MSXML2.XMLHTTP");
                //object returnedVal = _v8Engine.Script.Execute();
                //return returnedVal;
                //engine.AddCOMType("XMLHttpRequest", "MSXML2.XMLHTTP");
                engine.Execute(@"
    function get(url) {
        var xhr = new XMLHttpRequest();
        xhr.open('GET', url, false);
        xhr.send();
        if (xhr.status == 200)
            return xhr.responseText;
        return '';
    }
");

                s = engine.Script.get(url);
                engine.Dispose();
            }
            catch (Exception e)
            {
                s = "ERROR: " + e.Message;
            }

            Console.OutputEncoding = System.Text.Encoding.UTF8;

            Console.WriteLine(s);

            //Force garbage collection.
            GC.Collect();
            // Wait for all finalizers to complete before continuing.
            GC.WaitForPendingFinalizers();
        }
コード例 #12
0
        public void Evaluated_ExpectedResult_2()
        {
            // Arrange
            var engine   = new V8ScriptEngine();
            int actual   = 0;
            int expected = 2;

            // Act
            try
            {
                actual = (int)engine.Evaluate("1+1");
            }
            finally
            {
                engine.Dispose();
            }

            // Expect
            Assert.AreEqual(expected, actual);
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: surya-rakanta/EPJsDeOb
        static void Testing()
        {
            Console.WriteLine("Testing Here");
            V8ScriptEngine v8       = new V8ScriptEngine();
            String         sScript  = File.ReadAllText("header.js");
            String         sRScript = File.ReadAllText("detail.js");
            String         sFunc    = "_0xfec0";
            //Console.WriteLine(sScript);
            V8Script myScript = v8.Compile(sScript);

            v8.Execute(myScript);

            //find certain pattern in the
            String sTest = v8.ExecuteCommand("_0xfec0('0x0')");

            Console.WriteLine("OK " + sTest);
            sTest = v8.ExecuteCommand("_0xfec0('0x1')");
            Console.WriteLine("OK " + sTest);
            sTest = v8.ExecuteCommand("_0xfec0('0x2')");
            Console.WriteLine("OK " + sTest);
            v8.Dispose();
        }
コード例 #14
0
        public void Dispose()
        {
            if (m_debuggerClient != null)
            {
                m_debuggerClient.ExceptionEvent  -= debuggerClient_ExceptionEvent;
                m_debuggerClient.BreakpointEvent -= m_debuggerClient_BreakpointEvent;
                m_debuggerClient = null;
            }

            if (m_debuggerConnection != null)
            {
                m_debuggerConnection.Close();
                m_debuggerConnection.Dispose();
                m_debuggerConnection = null;
            }

            if (m_scriptEngine != null)
            {
                m_scriptEngine.Interrupt();
                m_scriptEngine.Dispose();
                m_scriptEngine = null;
            }
        }
コード例 #15
0
 public void Dispose()
 {
     _engine.Dispose();
 }
コード例 #16
0
 public void Dispose()
 {
     _context.Dispose();
 }
コード例 #17
0
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     _engine?.Dispose();
 }
コード例 #18
0
        public void V8ScriptEngine_General_Precompiled_Dual()
        {
            engine.Dispose();
            using (var runtime = new V8Runtime())
            {
                using (var script = runtime.Compile(generalScript))
                {
                    engine = runtime.CreateScriptEngine();
                    using (var console = new StringWriter())
                    {
                        var clr = new HostTypeCollection(type => type != typeof(Console), "mscorlib", "System", "System.Core");
                        clr.GetNamespaceNode("System").SetPropertyNoCheck("Console", console);

                        engine.AddHostObject("host", new ExtendedHostFunctions());
                        engine.AddHostObject("clr", clr);

                        engine.Evaluate(script);
                        Assert.AreEqual(MiscHelpers.FormatCode(generalScriptOutput), console.ToString().Replace("\r\n", "\n"));

                        console.GetStringBuilder().Clear();
                        Assert.AreEqual(string.Empty, console.ToString());

                        engine.Evaluate(script);
                        Assert.AreEqual(MiscHelpers.FormatCode(generalScriptOutput), console.ToString().Replace("\r\n", "\n"));
                    }

                    engine.Dispose();
                    engine = runtime.CreateScriptEngine();
                    using (var console = new StringWriter())
                    {
                        var clr = new HostTypeCollection(type => type != typeof(Console), "mscorlib", "System", "System.Core");
                        clr.GetNamespaceNode("System").SetPropertyNoCheck("Console", console);

                        engine.AddHostObject("host", new ExtendedHostFunctions());
                        engine.AddHostObject("clr", clr);

                        engine.Evaluate(script);
                        Assert.AreEqual(MiscHelpers.FormatCode(generalScriptOutput), console.ToString().Replace("\r\n", "\n"));

                        console.GetStringBuilder().Clear();
                        Assert.AreEqual(string.Empty, console.ToString());

                        engine.Evaluate(script);
                        Assert.AreEqual(MiscHelpers.FormatCode(generalScriptOutput), console.ToString().Replace("\r\n", "\n"));
                    }
                }
            }
        }
コード例 #19
0
ファイル: ScriptEngine.cs プロジェクト: 0x5b25/RTSPrototype
 public void Dispose()
 {
     runtime?.Dispose();
 }
コード例 #20
0
 internal void Close()
 {
     engine.Dispose();
     sw.Stop();
     Console.WriteLine("Engine {4}#{0,-3} Thread {3,-3} disposed.", SerialNumber, 0, 0, Thread.CurrentThread.ManagedThreadId, PoolName);
 }
コード例 #21
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;
            }
        }
コード例 #22
0
 public void TestCleanup()
 {
     engine.Dispose();
     BaseTestCleanup();
 }
コード例 #23
0
ファイル: ScriptRT.cs プロジェクト: dp0001/AutumnBox
 public void Dispose()
 {
     engine?.Dispose();
 }
コード例 #24
0
 public void Dispose()
 {
     v8ScriptEngine?.Dispose();
 }
コード例 #25
0
        public void Restart()
        {
            // Find available port
            _engineDebugPort = -1;
            for (var p = DebugPortStart; p <= DebugPortEnd; p++)
            {
                if (Proxy.IsPortAvailable(p))
                {
                    _engineDebugPort = p;
                    break;
                }
            }

            // Dispose old engine
            if (_engine != null)
            {
                _engine.Dispose();
            }

            // Clear queues
            _callbacks = new ConcurrentQueue <Callback>();
            _timeouts  = new List <TimeOut>();
            _requests  = new ConcurrentQueue <Request>();

            // Clear XDoc callback
            API.XDoc.ResetHooks();

            if (_engineDebugPort != -1)
            {
                // Enable debugging on port "port"
                _engine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging, _engineDebugPort);
            }
            else
            {
                // Create engine without debugging because no port is open
                // (this should never happen since there are a lot of ports in the range)
                _engine = new V8ScriptEngine();
            }

            // Clear the list of required files
            _required.Clear();

            // Define the NetJS API
            AddHostType(typeof(API.HTTP));
            AddHostType(typeof(API.SQLAPI));
            AddHostType(typeof(API.IO));
            AddHostType(typeof(API.Log));
            AddHostType(typeof(API.Application));
            AddHostType(typeof(API.Session));
            AddHostType(typeof(API.XDoc));
            AddHostType(typeof(API.Base64));
            AddHostType(typeof(API.Buffer));
            AddHostType(typeof(API.Windows));
            AddHostType(typeof(API.DLL));
            AddHostType(typeof(API.XML));
            AddHostType(typeof(API.MongoDBAPI));
            AddHostFunctions(typeof(API.Functions));

            // Initialize the tool functions
            Tool.Init(_engine);

            // Call the after start callback
            _afterStart(this);
        }
コード例 #26
0
 public void Dispose()
 {
     V8.Dispose();
 }
コード例 #27
0
ファイル: AddIn.cs プロジェクト: wdatasci/WDS-ModelSpec
 public void AutoClose()
 {
     lScriptEngine.Dispose();
 }