private static ScriptRuntimeSetup ReadScriptRuntimeSetupFromConfiguration()
        {
            string assemblyFile = AssemblyUtils.GetFriendlyAssemblyLocation(typeof(DLRTestDriver).Assembly);
            string configFile   = assemblyFile + ".config";

            return(ScriptRuntimeSetup.ReadConfiguration(configFile));
        }
Exemple #2
0
        public void ReadConfiguration_Multiple()
        {
            string configFile = GetTempConfigFile(new[] { LangSetup.Python });
            var    srs        = ScriptRuntimeSetup.ReadConfiguration(configFile);

            Assert.AreEqual(1, srs.LanguageSetups.Count);

            var sr = new ScriptRuntime(srs);

            Assert.AreEqual(1, sr.Setup.LanguageSetups.Count);

            //create a config file, srs and runtime with 2 langsetups
            configFile = GetTempConfigFile(new[] { LangSetup.Python, LangSetup.Ruby });
            var srs2 = ScriptRuntimeSetup.ReadConfiguration(configFile);

            Assert.AreEqual(2, srs2.LanguageSetups.Count);

            var sr2 = new ScriptRuntime(srs2);

            Assert.AreEqual(2, sr2.Setup.LanguageSetups.Count);

            //older ones still have only 1 lang
            Assert.AreEqual(1, srs.LanguageSetups.Count);
            Assert.AreEqual(1, sr.Setup.LanguageSetups.Count);
        }
Exemple #3
0
        public TestRuntime(Driver /*!*/ driver, TestCase /*!*/ testCase)
        {
            _driver   = driver;
            _testName = testCase.Name;

            if (_driver.IsDebug)
            {
                Environment.SetEnvironmentVariable("DLR_AssembliesFileName", _testName);
            }

            var           runtimeSetup  = ScriptRuntimeSetup.ReadConfiguration();
            LanguageSetup langaugeSetup = null;

            foreach (var language in runtimeSetup.LanguageSetups)
            {
                if (language.TypeName == typeof(RubyContext).AssemblyQualifiedName)
                {
                    langaugeSetup = language;
                    break;
                }
            }

            // TODO: dynamic modules with symbols are not available in partial trust
            runtimeSetup.DebugMode = !driver.PartialTrust;
            langaugeSetup.Options["InterpretedMode"] = _driver.Interpret;
            langaugeSetup.Options["Verbosity"]       = 2;
            langaugeSetup.Options["Compatibility"]   = testCase.Compatibility;

            _env     = Ruby.CreateRuntime(runtimeSetup);
            _engine  = Ruby.GetEngine(_env);
            _context = Ruby.GetExecutionContext(_engine);
        }
Exemple #4
0
        public static void Scenario_RemoteEvaluation()
        {
            ScriptRuntime runtime = ScriptRuntime.CreateRemote(
                AppDomain.CreateDomain("remote domain"),
                ScriptRuntimeSetup.ReadConfiguration()
                );

            ScriptEngine     engine = runtime.GetEngine("python");
            ObjectOperations ops    = engine.Operations;

            ObjectHandle classC = engine.ExecuteAndWrap(@"
class C(object):
  def __init__(self, value):
    self.value = value
    
  def __int__(self):
    return self.value

C
");

            ObjectHandle result    = ops.CreateInstance(classC, 17);
            int          intResult = ops.Unwrap <int>(result);

            Console.WriteLine(intResult);
        }
Exemple #5
0
        protected override ScriptRuntime /*!*/ CreateRuntime()
        {
            string        root              = IronRubyToolsPackage.Instance.IronRubyBinPath;
            string        configPath        = IronRubyToolsPackage.Instance.IronRubyExecutable + ".config";
            LanguageSetup existingRubySetup = null;
            LanguageSetup rubySetup         = Ruby.CreateRubySetup();

            if (File.Exists(configPath))
            {
                try {
                    existingRubySetup = GetSetupByName(ScriptRuntimeSetup.ReadConfiguration(configPath), "IronRuby");
                } catch {
                    // TODO: report the error
                }
            }

            if (existingRubySetup != null)
            {
                var options = new RubyOptions(existingRubySetup.Options);
                rubySetup.Options["StandardLibraryPath"] = NormalizePaths(root, new[] { options.StandardLibraryPath })[0];
                rubySetup.Options["RequiredPaths"]       = NormalizePaths(root, options.RequirePaths);
                rubySetup.Options["SearchPaths"]         = NormalizePaths(root, options.SearchPaths);
            }

            var runtimeSetup = new ScriptRuntimeSetup();

            runtimeSetup.LanguageSetups.Add(rubySetup);
            return(RemoteScriptFactory.CreateRuntime(runtimeSetup));
        }
Exemple #6
0
        public static void Scenario_RemoteEvaluationInSandbox()
        {
            // creates a sandbox:
            Evidence e = new Evidence();

            e.AddHostEvidence(new Zone(SecurityZone.Internet));
            AppDomainSetup setup = new AppDomainSetup();

            setup.ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var       ps      = SecurityManager.GetStandardSandbox(e);
            AppDomain sandbox = AppDomain.CreateDomain("Tests", null, setup, ps);

            // creates a remote runtime:
            var runtime = ScriptRuntime.CreateRemote(sandbox, ScriptRuntimeSetup.ReadConfiguration());
            var engine  = runtime.GetEngine("python");

            ObjectHandle exception;

            engine.CreateScriptSourceFromString(@"raise TypeError('this is wrong')").ExecuteAndWrap(out exception);

            if (exception != null)
            {
                string message, typeName;
                engine.GetService <ExceptionOperations>().GetExceptionMessage(exception, out message, out typeName);
                Console.WriteLine(typeName);
                Console.WriteLine(message);
            }
        }
Exemple #7
0
        /// <summary>
        /// Creates a new script runtime configured using .NET configuration files.
        /// If the .NET configuration doesn't include IronRuby a default IronRuby configuration is added.
        /// </summary>
        public static ScriptRuntime /*!*/ CreateRuntime()
        {
            var setup = ScriptRuntimeSetup.ReadConfiguration();

            setup.AddRubySetup();
            return(new ScriptRuntime(setup));
        }
Exemple #8
0
        public TestRuntime(Driver /*!*/ driver, TestCase /*!*/ testCase)
        {
            _driver   = driver;
            _testName = testCase.Name;

            if (testCase.Options.NoRuntime)
            {
                return;
            }

            if (_driver.SaveToAssemblies)
            {
                Environment.SetEnvironmentVariable("DLR_AssembliesFileName", _testName);
            }

            var runtimeSetup  = ScriptRuntimeSetup.ReadConfiguration();
            var languageSetup = runtimeSetup.AddRubySetup();

            runtimeSetup.DebugMode      = _driver.IsDebug;
            runtimeSetup.PrivateBinding = testCase.Options.PrivateBinding;
            runtimeSetup.HostType       = typeof(TestHost);
            runtimeSetup.HostArguments  = new object[] { testCase.Options };
            languageSetup.Options["NoAdaptiveCompilation"] = _driver.NoAdaptiveCompilation;
            languageSetup.Options["CompilationThreshold"]  = _driver.CompilationThreshold;
            languageSetup.Options["Verbosity"]             = 2;

            _runtime = Ruby.CreateRuntime(runtimeSetup);
            _engine  = Ruby.GetEngine(_runtime);
            _context = (RubyContext)HostingHelpers.GetLanguageContext(_engine);
        }
Exemple #9
0
        public void RubyHosting5()
        {
            // app-domain creation:
            if (_driver.PartialTrust)
            {
                return;
            }

            AppDomain domain = AppDomain.CreateDomain("foo");

            var           rs = ScriptRuntimeSetup.ReadConfiguration();
            LanguageSetup ls = rs.GetRubySetup();

            Debug.Assert(ls.Names.IndexOf("IronRuby") != -1);

            var newSetup = new ScriptRuntimeSetup();

            newSetup.AddRubySetup((s) => {
                s.Options["LibraryPaths"] = ls.Options["LibraryPaths"];
            });

            ScriptRuntime runtime = ScriptRuntime.CreateRemote(domain, newSetup);
            ScriptEngine  engine  = runtime.GetRubyEngine();

            Assert(engine.RequireFile("fcntl") == true);
            Assert(engine.Execute <bool>("Object.constants.include?(:Fcntl)") == true);
        }
Exemple #10
0
        private void initRuby()
        {
            ScriptRuntimeSetup runtimeSetup = ScriptRuntimeSetup.ReadConfiguration();
            var languageSetup = IronRuby.RubyHostingExtensions.AddRubySetup(runtimeSetup);

            runtimeSetup.DebugMode      = false;
            runtimeSetup.PrivateBinding = false;
            runtimeSetup.HostType       = typeof(RhoHost);

            languageSetup.Options["NoAdaptiveCompilation"] = false;
            languageSetup.Options["CompilationThreshold"]  = 0;
            languageSetup.Options["Verbosity"]             = 2;

            m_runtime = IronRuby.Ruby.CreateRuntime(runtimeSetup);
            m_engine  = IronRuby.Ruby.GetEngine(m_runtime);
            m_context = (RubyContext)Microsoft.Scripting.Hosting.Providers.HostingHelpers.GetLanguageContext(m_engine);

            m_context.ObjectClass.SetConstant("RHO_WP7", 1);
            m_context.Loader.LoadAssembly("RhoRubyLib", "rho.rubyext.rubyextLibraryInitializer", true, true);

            System.Collections.ObjectModel.Collection <string> paths = new System.Collections.ObjectModel.Collection <string>();
            paths.Add("lib");
            paths.Add("apps/app");
            m_engine.SetSearchPaths(paths);
        }
Exemple #11
0
        public static ScriptRuntimeSetup CreateSetup()
        {
            var configFile = TestHelpers.StandardConfigFile;

            Debug.Assert(File.Exists(configFile), configFile);
            return(ScriptRuntimeSetup.ReadConfiguration(configFile));
        }
Exemple #12
0
        private void initRuby()
        {
            ScriptRuntimeSetup runtimeSetup = ScriptRuntimeSetup.ReadConfiguration();
            var languageSetup = IronRuby.RubyHostingExtensions.AddRubySetup(runtimeSetup);

            runtimeSetup.DebugMode      = false;
            runtimeSetup.PrivateBinding = false;
            runtimeSetup.HostType       = typeof(RhoHost);

            //runtimeSetup.HostArguments = new object[] { testCase.Options };
            languageSetup.Options["NoAdaptiveCompilation"] = false;
            languageSetup.Options["CompilationThreshold"]  = 0;
            languageSetup.Options["Verbosity"]             = 2;

            _runtime = IronRuby.Ruby.CreateRuntime(runtimeSetup);
            _engine  = IronRuby.Ruby.GetEngine(_runtime);

            System.Collections.ObjectModel.Collection <string> paths = new System.Collections.ObjectModel.Collection <string>();
            paths.Add("lib");
            paths.Add("apps/app");
            _engine.SetSearchPaths(paths);

            //IronRuby.Runtime.Loader
            //context.Loader.LoadAssembly(assemblyName.ConvertToString(), initializer, true, true);
            //IronRuby.Libraries
            //IronRuby.StandardLibrary.StringScanner.StringScannerLibraryInitializer
        }
 private ScriptRuntime GetScriptRuntime()
 {
     if (_scriptRuntime == null)
     {
         _scriptRuntime = new ScriptRuntime(ScriptRuntimeSetup.ReadConfiguration());
     }
     return(_scriptRuntime);
 }
Exemple #14
0
        public void ReadConfiguration_EmptyConfigEntries()
        {
            string configFile = GetTempConfigFile(new[] { new LangSetup() });
            var    srs        = ScriptRuntimeSetup.ReadConfiguration(configFile);

            var sr = new ScriptRuntime(srs);

            Assert.Fail("some exception should have been thrown");
        }
Exemple #15
0
        public void ReadConfiguration_EmptyTypeName()
        {
            LangSetup py2 = new LangSetup(LangSetup.Python.Names, LangSetup.Python.Extensions, LangSetup.Python.DisplayName,
                                          "", LangSetup.Python.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py2 });
            var    srs        = ScriptRuntimeSetup.ReadConfiguration(configFile);
            var    eng        = new ScriptRuntime(srs).GetEngine("py");

            Assert.AreEqual(LangSetup.Python.Names[0], eng.Setup.DisplayName);
        }
Exemple #16
0
        public void Configuration_MutateAndCheck()
        {
            string configFile = GetTempConfigFile(new[] { LangSetup.Python });

            var sr      = new ScriptRuntime(ScriptRuntimeSetup.ReadConfiguration(configFile));
            var config1 = sr.Setup;

            config1 = null;

            Assert.IsNotNull(sr.Setup);
        }
Exemple #17
0
        void Start()
        {
            ButtonObj.gameObject.SetActive(false);

            var config = Resources.Load <TextAsset>(ConfigName).bytes;

            _setup = ScriptRuntimeSetup.ReadConfiguration(new MemoryStream(config));
            _ex   += "\n 配置加载结束 --- IronPython 版本:" + _setup.LanguageSetups[0].DisplayName;

            StartCoroutine(_startCopy());
        }
Exemple #18
0
        public void ReadConfiguration_DuplicateLang()
        {
            string configFile = GetTempConfigFile(new[] { LangSetup.Python, LangSetup.Python });
            var    srs        = ScriptRuntimeSetup.ReadConfiguration(configFile);

            Assert.AreEqual(1, srs.LanguageSetups.Count);

            var sr = new ScriptRuntime(srs);

            Assert.AreEqual(1, sr.Setup.LanguageSetups.Count);
        }
Exemple #19
0
        public void ReadConfiguration_EmptyExtensions()
        {
            LangSetup py1 = LangSetup.Python;
            LangSetup py2 = new LangSetup(py1.Names, new[] { "", "" }, py1.DisplayName,
                                          py1.TypeName, py1.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py2 });
            var    srs        = ScriptRuntimeSetup.ReadConfiguration(configFile);
            var    runtime    = new ScriptRuntime(srs);

            Assert.AreEqual(5, runtime.GetEngine("py").Execute("2+3"));
        }
Exemple #20
0
    protected override ScriptRuntimeSetup CreateRuntimeSetup()
    {
        ScriptRuntimeSetup srs = ScriptRuntimeSetup.ReadConfiguration();

        foreach (var langSetup in srs.LanguageSetups)
        {
            if (langSetup.FileExtensions.Contains(".py"))
            {
                langSetup.Options["SearchPaths"] = new string[0];
            }
        }
        return(srs);
    }
        protected override ScriptRuntimeSetup CreateRuntimeSetup()
        {
            ScriptRuntimeSetup setup = ScriptRuntimeSetup.ReadConfiguration();

            foreach (LanguageSetup setup2 in setup.LanguageSetups)
            {
                if (setup2.FileExtensions.Contains(".py"))
                {
                    setup2.Options["SearchPaths"] = new string[0];
                }
            }
            return(setup);
        }
Exemple #22
0
        public void Configuration_MutateAndCheck2()
        {
            string configFile = GetTempConfigFile(new[] { LangSetup.Python });

            var srs = ScriptRuntimeSetup.ReadConfiguration(configFile);
            var sr  = new ScriptRuntime(srs);

            var config1 = sr.Setup;
            var config2 = new ScriptRuntime(ScriptRuntimeSetup.ReadConfiguration(GetTempConfigFile(new[] { LangSetup.Ruby }))).Setup;

            Assert.AreEqual(LangSetup.Python.DisplayName, config1.LanguageSetups[0].DisplayName);
            TestHelpers.AreEqualArrays(LangSetup.Python.Names, config1.LanguageSetups[0].Names);
        }
Exemple #23
0
        public void Configuration_MutateAndCheck3()
        {
            string configFile = GetTempConfigFile(new[] { LangSetup.Python });

            var sr  = new ScriptRuntime(ScriptRuntimeSetup.ReadConfiguration(configFile));
            var eng = sr.GetEngine("py");

            var config = eng.Setup;

            config = null;

            Assert.IsNotNull(eng.Setup);
        }
Exemple #24
0
        public ScriptEngine CreateRubyEngine()
        {
            var runtimeSetup = ScriptRuntimeSetup.ReadConfiguration();
            var languageSetup = runtimeSetup.AddRubySetup();

            runtimeSetup.PrivateBinding = true;
            runtimeSetup.HostType = typeof(TmpHost);
            runtimeSetup.HostArguments = new object[] { new OptionsAttribute() };

            languageSetup.Options["Verbosity"] = 2;

            var runtime = Ruby.CreateRuntime(runtimeSetup);
            return Ruby.GetEngine(runtime);
        }
Exemple #25
0
        public void ReadConfiguration_MissingAssembly()
        {
            LangSetup lang = new LangSetup(new[] { "SomeName" }, new[] { ".sn" }, "Somename",
                                           "SomeLang.Runtime.LangContext",
                                           "SomeLang, Version=8.0.0.5050, Culture=neutral, PublicKeyToken=31345fgsd4344e35");

            string configFile = GetTempConfigFile(new[] { lang });
            var    srs        = ScriptRuntimeSetup.ReadConfiguration(configFile);

            //this should throw..error message should be meaningful
            var sr = new ScriptRuntime(srs);

            Assert.Fail("some exception should have been thrown");
        }
Exemple #26
0
        public void ReadConfiguration_IncorrectType()
        {
            LangSetup py1 = LangSetup.Python;
            LangSetup py2 = new LangSetup(py1.Names, py1.Extensions, py1.DisplayName,
                                          "IronPython.Runtime.PythonBuffer", py1.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py2 });
            var    srs        = ScriptRuntimeSetup.ReadConfiguration(configFile);

            var sr  = new ScriptRuntime(srs);
            var eng = sr.GetEngine("py");

            Assert.Fail("some exception should have been thrown");
        }
Exemple #27
0
        public void ReadConfiguration_DuplicateNames()
        {
            LangSetup py1 = LangSetup.Python;
            LangSetup py2 = new LangSetup(LangSetup.Ruby.Names, py1.Extensions, py1.DisplayName,
                                          py1.TypeName, py1.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py2, LangSetup.Ruby });
            var    srs        = ScriptRuntimeSetup.ReadConfiguration(configFile);

            Assert.AreEqual(2, srs.LanguageSetups.Count);

            var sr = new ScriptRuntime(srs);

            Assert.Fail("some exception should have been thrown");
        }
Exemple #28
0
        public void ReadConfiguration_1Lang()
        {
            string configFile = GetTempConfigFile(new[] { LangSetup.Python });

            var srs = ScriptRuntimeSetup.ReadConfiguration(configFile);

            Assert.AreEqual(1, srs.LanguageSetups.Count);

            var sr = new ScriptRuntime(srs);

            Assert.AreEqual(1, sr.Setup.LanguageSetups.Count);

            var pythonEngine = sr.GetEngine("py");

            Assert.IsTrue(pythonEngine.IsValidPythonEngine());
        }
        public Action Cleanup;  // A function delegate that will be called when the script is completed to allow any cleanup actions to take place.

        public DialPlanExecutingScript(SIPMonitorLogDelegate logDelegate)
        {
            ScriptNumber = ++ScriptCounter % Int32.MaxValue;
            Id           = Guid.NewGuid();

            var setup         = ScriptRuntimeSetup.ReadConfiguration();
            var scriptRuntime = Ruby.CreateRuntime(setup);

            DialPlanScriptEngine = Ruby.GetEngine(scriptRuntime);

            //DialPlanScriptEngine = Ruby.CreateEngine();

            DialPlanScriptScope = DialPlanScriptEngine.CreateScope();

            LogDelegate = logDelegate;
        }
Exemple #30
0
        public void ReadConfiguration_Multi_SameTypeDifferentName()
        {
            LangSetup py1 = LangSetup.Python;
            LangSetup py2 = new LangSetup(new[] { "NewPython" }, py1.Extensions, py1.DisplayName,
                                          py1.TypeName, py1.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py1, py2 });
            var    srs        = ScriptRuntimeSetup.ReadConfiguration(configFile);

            Assert.AreEqual(1, srs.LanguageSetups.Count);

            var sr = new ScriptRuntime(srs);

            Assert.AreEqual(1, sr.Setup.LanguageSetups.Count);
            Assert.AreEqual("NewPython", sr.Setup.LanguageSetups[0].Names[0]);
        }