当前位置: 首页>>代码示例>>C#>>正文


C# ScriptRuntime.LoadAssembly方法代码示例

本文整理汇总了C#中Microsoft.Scripting.Hosting.ScriptRuntime.LoadAssembly方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptRuntime.LoadAssembly方法的具体用法?C# ScriptRuntime.LoadAssembly怎么用?C# ScriptRuntime.LoadAssembly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Scripting.Hosting.ScriptRuntime的用法示例。


在下文中一共展示了ScriptRuntime.LoadAssembly方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: loadRunTime

        private void loadRunTime()
        {
            m_output = new MemoryStream();
            m_runTime = ScriptRuntime.CreateFromConfiguration();

            m_runTime.IO.SetOutput(m_output, new StreamWriter(m_output));
            m_runTime.IO.SetErrorOutput(m_output, new StreamWriter(m_output));

            Assembly pluginsAssembly = Assembly.LoadFile(IO.IOHelper.MapPath(IO.SystemDirectories.Bin + "/umbraco.dll"));
            m_runTime.LoadAssembly(pluginsAssembly);

            m_runTime.LoadAssembly(typeof(String).Assembly);
            m_runTime.LoadAssembly(typeof(Uri).Assembly);
            m_runTime.LoadAssembly(typeof(umbraco.presentation.nodeFactory.Node).Assembly);
        }
开发者ID:elrute,项目名称:Triphulcas,代码行数:15,代码来源:ScriptEngine.cs

示例2: AnalysisModule

        public AnalysisModule()
        {
            var t = Directory.GetCurrentDirectory();
            SourcePath = t + "\\Analysis";
            if (!Directory.Exists(SourcePath))
            {
                Directory.CreateDirectory(SourcePath);
            }

            ASRT = new ScriptRuntime(ScriptRuntimeSetup.ReadConfiguration(t+"\\NSCore.dll.config"));
            ASRT.LoadAssembly(Assembly.GetAssembly(typeof(IDevice)));
            ASRT.LoadAssembly(Assembly.GetAssembly(typeof(Marshal)));

            Scope = ASRT.CreateScope();
        }
开发者ID:babaq,项目名称:NeuSys,代码行数:15,代码来源:AnalysisModule.cs

示例3: PyFilter

        /// <summary>
        /// Initialize static scripting API objects
        /// </summary>
        static PyFilter()
        {
            _setup = ScriptRuntimeSetup.ReadConfiguration();
            _runtime = new ScriptRuntime(_setup);

            //make System and the current assembly availible to the scripts
            _runtime.LoadAssembly(Assembly.GetExecutingAssembly());
            _runtime.LoadAssembly(Assembly.GetAssembly(typeof(DateTime)));

            //assume default of App_Data/filters.py, but allow for overwriting
            string path = RootPath ?? HttpContext.Current.Server.MapPath("~/App_Data/");
            ScriptEngine engine = _runtime.GetEngine("IronPython");
            engine.SetSearchPaths(new string[] { path });
            engine.ExecuteFile(Path.Combine(path, ScriptFile ?? "filters.py"), _runtime.Globals);
        }
开发者ID:mdrubin,项目名称:codevoyeur-samples,代码行数:18,代码来源:PyFilter.cs

示例4: Page

        public Page()
        {
            InitializeComponent();
            string code = @"
            def function(string):
            return string.upper()";

            ScriptRuntimeSetup setup = Python.CreateRuntimeSetup(null);
            setup.HostType = typeof(Microsoft.Scripting.Silverlight.BrowserScriptHost);
            setup.Options["SearchPaths"] = new string[] { string.Empty };

            ScriptRuntime runtime = new ScriptRuntime(setup);
            ScriptEngine pe = Python.GetEngine(runtime);

            // load platform assemblies so you don't need to call LoadAssembly in script code.
            foreach (string name in new string[] { "mscorlib", "System", "System.Windows", "System.Windows.Browser", "System.Net" })
            {
                runtime.LoadAssembly(runtime.Host.PlatformAdaptationLayer.LoadAssembly(name));
            }

            ScriptScope scope = pe.CreateScope();
            ScriptSource source = pe.CreateScriptSourceFromString(code, SourceCodeKind.Statements);
            source.Execute(scope);

            Func<string, string> func = scope.GetVariable<Func<string, string>>("function");

            string result = func("hello world!");
            textblock.Text = result;
        }
开发者ID:rachmatg,项目名称:ironpython,代码行数:29,代码来源:Page.xaml.cs

示例5: startPythonEngine

        private void startPythonEngine()
        {
            m_engine = Python.CreateEngine();
            m_runtime = m_engine.Runtime;
            m_scope = m_engine.CreateScope();

            m_runtime.LoadAssembly(GetType().Assembly);
        }
开发者ID:Didoman87,项目名称:RayTracer_Lecture5_Kontrolna,代码行数:8,代码来源:SceneLoaderPython.cs

示例6: IronPythonScriptEngine

        public IronPythonScriptEngine()
        {
            runtime = engine.Runtime;
            runtime.LoadAssembly(Assembly.GetAssembly(typeof(Mogre.Vector3)));
            scope = runtime.CreateScope();

            // install built-in scripts
            install(new Script(builtin));
        }
开发者ID:agustinsantos,项目名称:mogregis3d,代码行数:9,代码来源:IronPythonScriptEngine.cs

示例7: PyControllerFactory

        static PyControllerFactory()
        {
            _setup = ScriptRuntimeSetup.ReadConfiguration();
            _runtime = new ScriptRuntime(_setup);

            _runtime.LoadAssembly(Assembly.GetExecutingAssembly());

            string path = HttpContext.Current.Server.MapPath("~/App_Data/Controllers.py");
            _runtime.GetEngine("IronPython").ExecuteFile(path, _runtime.Globals);
        }
开发者ID:mdrubin,项目名称:codevoyeur-samples,代码行数:10,代码来源:PyControllerFactory.cs

示例8: IPyEngine

 /// <summary>
 /// Creates new instance of IPy engine with given stream
 /// </summary>
 /// <param name="iostream">stream object to be used for I/O</param>
 /// <remarks></remarks>
 public IPyEngine(System.IO.Stream iostream, bool AddExecutingAssembly = true)
 {
     this.Engine = Python.CreateEngine();
     Runtime = this.Engine.Runtime;
     EngineScope = this.Engine.CreateScope();
     _io = iostream;
     SetStreams(_io);
     if (AddExecutingAssembly)
     {
         Runtime.LoadAssembly(Assembly.GetExecutingAssembly());
     }
 }
开发者ID:devsprasad,项目名称:DociPy,代码行数:17,代码来源:IPyWrapperNamespace.cs

示例9: GetObject

        public object GetObject(string objectName)
        {
            Dictionary<string, object> instances = new Dictionary<string, object>();

            ScriptRuntimeSetup setup = ScriptRuntimeSetup.ReadConfiguration();
            ScriptRuntime runtime = new ScriptRuntime(setup);
            runtime.LoadAssembly(Assembly.GetExecutingAssembly());

            ScriptEngine engine = runtime.GetEngine("IronPython");
            runtime.Globals.SetVariable("instances", instances);
            engine.ExecuteFile("Objects.py", runtime.Globals);

            return instances[objectName];
        }
开发者ID:mdrubin,项目名称:codevoyeur-samples,代码行数:14,代码来源:PyCrust.cs

示例10: Engine

 public Engine(string filePath,Inventor.PlanarSketch oSketch,Inventor.Application oApp, double slotHeight, double slotWidth)
 {
     _engine = Python.CreateEngine(new Dictionary<string, object>() { {"Frames", true}, {"FullFrames", true}});
     _runtime = _engine.Runtime;
     Assembly invAssembly = Assembly.LoadFile(@"C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Autodesk.Inventor.Interop\v4.0_17.0.0.0__d84147f8b4276564\Autodesk.Inventor.interop.dll");
     _runtime.LoadAssembly(invAssembly);
     _scope = _engine.CreateScope();
     //Make variable names visible within the python file.  These string names will be used an arguments in the python file.
     _scope.SetVariable("oPlanarSketch",oSketch);
     _scope.SetVariable("oApp",oApp);
     _scope.SetVariable("slotHeight",slotHeight);
     _scope.SetVariable("slotWidth",slotWidth);
     ScriptSource _script = _engine.CreateScriptSourceFromFile(filePath);
     _code = _script.Compile();
 }
开发者ID:frankfralick,项目名称:InventorAddIns,代码行数:15,代码来源:Engine.cs

示例11: InitializeDLR

    private static void InitializeDLR(StreamResourceInfo xap, List<Assembly> assemblies) {
        DynamicApplication.XapFile = xap;

        var setup = DynamicApplication.CreateRuntimeSetup(assemblies);
        setup.DebugMode = true;
        var runtime = new ScriptRuntime(setup);
        
        // Load default silverlight assemblies for the script to have access to
        DynamicApplication.LoadDefaultAssemblies(runtime);

        // Load the assemblies into the runtime, giving the script access to them 
        assemblies.ForEach((a) => runtime.LoadAssembly(a));
        
        _engine = IronRuby.Ruby.GetEngine(runtime);
        _scope = _engine.CreateScope();
    }
开发者ID:joshholmes,项目名称:ironruby,代码行数:16,代码来源:Eggs.cs

示例12: DlrHost

        public DlrHost()
        {
            this._Runtime = new Lazy<ScriptRuntime>(() => {
                var setup = new ScriptRuntimeSetup();
                setup.DebugMode = true;

                setup.LanguageSetups.Add(Python.CreateLanguageSetup(null));
                setup.AddRubySetup();

                var runtime = new ScriptRuntime(setup);
                AppDomain.CurrentDomain.GetAssemblies().ForEach(assm => runtime.LoadAssembly(assm));
                return runtime;
            });

            this._Scope = new Lazy<ScriptScope>(() => {
                var scope = this._Runtime.Value.CreateScope();
                return scope;
            });

            this._Extensions = new Lazy<ISet<string>>(() => {
                return new HashSet<string>(this._Runtime.Value.Setup.LanguageSetups.SelectMany(lang => lang.FileExtensions), StringComparer.OrdinalIgnoreCase);
            });
        }
开发者ID:catwalkagogo,项目名称:Heron,代码行数:23,代码来源:DlrHost.cs

示例13: ConstructObject

        protected object ConstructObject(ContainedObject co)
        {
            if (_staticObjects.ContainsKey(co.Name)) {
                return _staticObjects[co.Name];
            } else {

                //in the full CodeVoyeur version, this is cached!
                ScriptRuntimeSetup setup = ScriptRuntimeSetup.ReadConfiguration();
                ScriptRuntime runtime = new ScriptRuntime(setup);
                runtime.LoadAssembly(Assembly.GetExecutingAssembly());

                ScriptScope scope = runtime.CreateScope("IronPython");
                ScriptSource source = scope.Engine.CreateScriptSourceFromString("from HostedIronPython.Model import *", SourceCodeKind.SingleStatement);
                source.Execute(scope);

                scope.SetVariable("instance", new object());

                scope.SetVariable("reference", new Func<string, object>
                    (
                        delegate(string refName) {
                            if (_staticObjects.ContainsKey(refName))
                                return _staticObjects[refName];
                            else
                                return GetFilling(refName);
                        }
                    ));

                ScriptSource configSource = scope.Engine.CreateScriptSourceFromString(co.Script, SourceCodeKind.Statements);
                configSource.Execute(scope);

                if (co.IsStatic)
                    return _staticObjects[co.Name] = scope.GetVariable("instance");
                else
                    return scope.GetVariable("instance");
            }
        }
开发者ID:mdrubin,项目名称:codevoyeur-samples,代码行数:36,代码来源:PyCrust.cs

示例14: InitialiseScriptingEnvironment

        internal static void InitialiseScriptingEnvironment()
        {
            ScriptRuntimeSetup Setup = new ScriptRuntimeSetup();
            Setup.LanguageSetups.Add(IronRuby.Ruby.CreateRubySetup());
            Setup.LanguageSetups.Add(IronPython.Hosting.Python.CreateLanguageSetup(null));
            RunTime = new ScriptRuntime(Setup);
            Engine = RunTime.GetEngine("py");
            Scope = RunTime.CreateScope();

            RunTime.IO.SetOutput(ShellOutStream, Encoding.UTF8);
            RunTime.IO.SetErrorOutput(ShellOutStream, Encoding.UTF8);

            Assembly MainAssembly = Assembly.GetExecutingAssembly();
            string RootDir = Directory.GetParent(MainAssembly.Location).FullName;
            string HAGPath = Path.Combine(RootDir, "HtmlAgilityPack.dll");
            Assembly HAGAssembly = Assembly.LoadFile(HAGPath);

            RunTime.LoadAssembly(MainAssembly);
            RunTime.LoadAssembly(HAGAssembly);
            RunTime.LoadAssembly(typeof(String).Assembly);
            RunTime.LoadAssembly(typeof(Uri).Assembly);
            RunTime.LoadAssembly(typeof(XmlDocument).Assembly);

            Engine.Runtime.TryGetEngine("py", out Engine);
            List<string> PySearchPaths = new List<string>();
            foreach (string PyPath in PyPaths)
            {
                PySearchPaths.Add(PyPath.Replace("$ROOTDIR", RootDir));
            }
            try
            {
                Engine.SetSearchPaths(PySearchPaths);
            }
            catch(Exception Exp)
            {
                IronException.Report("Unable to set PyPaths", Exp.Message, Exp.StackTrace);
            }

            foreach (string PyCommand in PyCommands)
            {
                try
                {
                    ExecuteStartUpCommand(PyCommand);
                }
                catch(Exception Exp)
                {
                    IronException.Report("Unable to execute Python startup command - " + PyCommand, Exp.Message, Exp.StackTrace);
                }
            }

            Engine.Runtime.TryGetEngine("rb", out Engine);

            List<string> RbSearchPaths = new List<string>();

            foreach (string RbPath in RbPaths)
            {
                RbSearchPaths.Add(RbPath.Replace("$ROOTDIR", RootDir));
            }
            Engine.SetSearchPaths(RbSearchPaths);

            foreach (string RbCommand in RbCommands)
            {
                try
                {
                    ExecuteStartUpCommand(RbCommand);
                }
                catch (Exception Exp)
                {
                    IronException.Report("Unable to execute Ruby startup command" + RbCommand, Exp.Message, Exp.StackTrace);
                }
            }

            Engine.Runtime.TryGetEngine("py", out Engine);
            ExecuteStartUpCommand("print 123");
            ShellOutText = new StringBuilder();
            IronUI.ResetInteractiveShellResult();
        }
开发者ID:moon2l,项目名称:IronWASP,代码行数:77,代码来源:IronScripting.cs

示例15: PythonObject

        public PythonObject(string[] args)
        {
            ScriptRuntimeSetup runtimeSetup = ScriptRuntimeSetup.ReadConfiguration();
            ConsoleHostOptions options = new ConsoleHostOptions();
            _optionsParser = new ConsoleHostOptionsParser(options, runtimeSetup);

            string provider = GetLanguageProvider(runtimeSetup);

            LanguageSetup languageSetup = null;
            foreach (LanguageSetup language in runtimeSetup.LanguageSetups) {
                if (language.TypeName == provider) {
                    languageSetup = language;
                }
            }
            if (languageSetup == null) {
                // the language doesn't have a setup -> create a default one:
                languageSetup = new LanguageSetup(Provider.AssemblyQualifiedName, Provider.Name);
                runtimeSetup.LanguageSetups.Add(languageSetup);
            }

            // inserts search paths for all languages (/paths option):
            InsertSearchPaths(runtimeSetup.Options, Options.SourceUnitSearchPaths);

            _languageOptionsParser = new OptionsParser<ConsoleOptions>();

            try {
                _languageOptionsParser.Parse(Options.IgnoredArgs.ToArray(), runtimeSetup, languageSetup, PlatformAdaptationLayer.Default);
            } catch (InvalidOptionException e) {
                Console.Error.WriteLine(e.Message);
            }

            _runtime = new ScriptRuntime(runtimeSetup);

            try {
                _engine = _runtime.GetEngineByTypeName(provider);
            } catch (Exception e) {
                Console.Error.WriteLine(e.Message);
            }
            _runtime.LoadAssembly(System.Reflection.Assembly.GetExecutingAssembly());
            _runtime.LoadAssembly(provider.GetType().Assembly);
            _runtime.LoadAssembly(PythonStringIO.StringIO().GetType().Assembly);
            _scope= _engine.CreateScope();
            RunCommandLine(args);
        }
开发者ID:turkowski,项目名称:museum,代码行数:44,代码来源:PythonObject.cs


注:本文中的Microsoft.Scripting.Hosting.ScriptRuntime.LoadAssembly方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。