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


C# ScriptEngine.CreateScriptSourceFromFile方法代码示例

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


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

示例1: Main

        /// <summary>
        /// Main method
        /// </summary>
        /// <param name="args">Command line args.</param>
        public static void Main(string[] args)
        {
            engine = Python.CreateEngine();
            scope = engine.CreateScope();

            engine.Runtime.LoadAssembly(typeof(TurntableBot).Assembly);
            engine.Runtime.LoadAssembly(typeof(JObject).Assembly);
            engine.Runtime.IO.RedirectToConsole();

            ScriptSource source = null;

            if (File.Exists(Script))
            {
                source = engine.CreateScriptSourceFromFile(Script);
            }
            else
            {
                Console.WriteLine("File not found");
            }

            if (source != null)
            {
                try
                {
                    source.Execute(scope);
                }
                catch (Exception e)
                {
                    ExceptionOperations ops = engine.GetService<ExceptionOperations>();
                    Console.WriteLine(ops.FormatException(e));
                }
            }

            Console.ReadLine();
        }
开发者ID:nmalaguti,项目名称:Turntable-API-sharp,代码行数:39,代码来源:Program.cs

示例2: PythonController

 public PythonController(ScriptEngine engine,string path)
 {
     this.Name = System.IO.Path.GetFileNameWithoutExtension(path);
     this.Engine = engine;
     var scriptSource = engine.CreateScriptSourceFromFile(path, Encoding.UTF8, Microsoft.Scripting.SourceCodeKind.File);
     _compiledCode = scriptSource.Compile();
 }
开发者ID:yaozd,项目名称:YOYOFx,代码行数:7,代码来源:PythonController.cs

示例3: Load

        public override IEnumerable<Kbtter4Plugin> Load(Kbtter instance, IList<string> filenames)
        {
            var files = filenames.Where(p => p.EndsWith(".py"));
            var ret = new List<Kbtter4IronPythonPlugin>();

            engine = Python.CreateEngine();

            var context = HostingHelpers.GetLanguageContext(engine) as PythonContext;
            var path = context.GetSearchPaths();
            path.Add(Environment.CurrentDirectory + "\\");
            engine.SetSearchPaths(path);

            engine.Runtime.LoadAssembly(typeof(Status).Assembly);

            foreach (var i in files)
            {
                try
                {
                    var scope = engine.CreateScope();
                    scope.SetVariable("Kbtter4", new Kbtter4PluginProvider(instance));
                    var src = engine.CreateScriptSourceFromFile(i);
                    var code = src.Compile();
                    code.Execute(scope);
                    var p = new Kbtter4IronPythonPlugin(scope,instance);
                    ret.Add(p);
                }
                catch (Exception e)
                {
                    instance.LogError(String.Format("プラグイン読み込み中にエラーが発生しました : {0}\n{1}", i, e.Message));

                }
            }

            return ret;
        }
开发者ID:kb10uy,项目名称:Kbtter4,代码行数:35,代码来源:Kbtter4IronPythonPlugin.cs

示例4: Communicate

 public Communicate(string python, Jardin jardin)
 {
     //création du lien avec le script python
     engine = Python.CreateEngine();
     script = engine.CreateScriptSourceFromFile(python);
     scope = engine.CreateScope();
     this.jardin = jardin;
 }
开发者ID:sandra-laduranti,项目名称:psar,代码行数:8,代码来源:Communicate.cs

示例5: Form1

 public Form1()
 {
     InitializeComponent();
     imp_dir = Directory.GetCurrentDirectory();
     myPen = new System.Drawing.Pen(System.Drawing.Color.Red);
     formGraphics = pictureBox1.CreateGraphics();
     pictureBox1.BackColor = Color.White;
     myBrush = new System.Drawing.SolidBrush(Color.Red);
     m_engine = Python.CreateEngine();
     m_scope = m_engine.CreateScope();
     source = m_engine.CreateScriptSourceFromFile("center_iron.py");
 }
开发者ID:esse,项目名称:Graph-Center,代码行数:12,代码来源:Form1.cs

示例6: pyDissector

 public pyDissector(string fileName)
 {
     engine = Python.CreateEngine();
     scope = engine.CreateScope();
     var runtime = engine.Runtime;
     runtime.LoadAssembly(typeof(PacketDotNet.Packet).Assembly);
     runtime.LoadAssembly(typeof(pyDissector).Assembly);
     src = engine.CreateScriptSourceFromFile(fileName);
     program = src.Compile();
     var result = program.Execute(scope);
     var filterString = scope.GetVariable<string>("nativeFilterString");
     myFilter = filterGen.genFilter(filterString);
     parseFunc = scope.GetVariable<Func<Packet, HLPacket>>("parsePacket");
 }
开发者ID:Ronald-Liu,项目名称:visualSniffer,代码行数:14,代码来源:pythonDissector.cs

示例7: 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

示例8: InitScripting

        private void InitScripting(string scriptName)
        {
            this.engine = Python.CreateEngine();
            this.engine.Runtime.LoadAssembly(typeof(string).Assembly);
            this.engine.Runtime.LoadAssembly(typeof(DiagnosticMonitor).Assembly);
            this.engine.Runtime.LoadAssembly(typeof(RoleEnvironment).Assembly);
            this.engine.Runtime.LoadAssembly(typeof(Microsoft.WindowsAzure.CloudStorageAccount).Assembly);

            this.scope = this.engine.CreateScope();
            engine.CreateScriptSourceFromFile(scriptName).Execute(scope);

            if (scope.ContainsVariable("start"))
                this.pyStart = scope.GetVariable<Func<bool>>("start");

            this.pyRun = scope.GetVariable<Action>("run");

            if (scope.ContainsVariable("stop"))
                this.pyStop = scope.GetVariable<Action>("stop");
        }
开发者ID:AdamStrojek,项目名称:IronPythonAzure,代码行数:19,代码来源:PyRoleEntryPoint.cs

示例9: LoadPlugin

        static void LoadPlugin(string PluginFile, ScriptEngine Engine)
        {
            try
            {
                ScriptSource PluginSource;
                CompiledCode CompiledPlugin;

                fileName = PluginFile.Substring(PluginFile.LastIndexOf('\\') + 1);
                if(StartUp) IronUI.ShowLoadMessage("Loading Plugin - " + fileName);
                if (PluginFile.EndsWith(".py", StringComparison.CurrentCultureIgnoreCase))
                {
                    Engine.Runtime.TryGetEngine("py", out Engine);
                    PluginSource = Engine.CreateScriptSourceFromFile(PluginFile);
                    CompiledPlugin = PluginSource.Compile();
                    PluginSource.ExecuteProgram();
                }
                else if (PluginFile.EndsWith(".rb", StringComparison.CurrentCultureIgnoreCase))
                {
                    Engine.Runtime.TryGetEngine("rb", out Engine);
                    PluginSource = Engine.CreateScriptSourceFromFile(PluginFile);
                    CompiledPlugin = PluginSource.Compile();
                    PluginSource.ExecuteProgram();
                }
            }
            catch (Exception Exp)
            {
                IronException.Report("Error loading plugin - " + PluginFile, Exp.Message, Exp.StackTrace);
            }
            finally
            {
                fileName = "";
            }
        }
开发者ID:welias,项目名称:IronWASP,代码行数:33,代码来源:PluginStore.cs

示例10: createScriptSource

 private ScriptSource createScriptSource(string fileName)
 {
     currentEngine = runtime.GetEngineByFileExtension(Path.GetExtension(fileName));
     return currentEngine.CreateScriptSourceFromFile(fileName);
 }
开发者ID:schuster-rainer,项目名称:DLR_Hosting_Playground,代码行数:5,代码来源:ScriptFactory.cs

示例11: LoadModule

        internal static Module LoadModule(Module M)
        {
            try
            {
                string FullName = string.Format("{0}\\modules\\{1}\\{2}", Config.RootDir, M.Name, M.FileName);
                if (M.FileName.EndsWith(".dll"))
                {
                    Assembly MA = System.Reflection.Assembly.LoadFile(FullName);
                    Module NewModule = (Module) Activator.CreateInstance(MA.GetTypes()[0]);
                    Module.Add(NewModule.GetInstance());
                }
                else
                {
                    Engine = PluginEngine.GetScriptEngine();

                    if (M.FileName.EndsWith(".py"))
                        Engine.Runtime.TryGetEngine("py", out Engine);
                    else
                        Engine.Runtime.TryGetEngine("rb", out Engine);
                    List<string> ModulePaths = new List<string>();
                    foreach (Module ModuleFromXml in ModuleListFromXml)
                    {
                        ModulePaths.Add(string.Format("{0}\\modules\\{1}\\", Config.RootDir, ModuleFromXml.Name));
                    }
                    Engine.SetSearchPaths(ModulePaths);
                    if (M.FileName.Length == 0)
                        throw new Exception("Module is missing script files");
                    ScriptSource ModuleSource = Engine.CreateScriptSourceFromFile(FullName);
                    ScriptErrorReporter CompileErrors = new ScriptErrorReporter();
                    string ErrorMessage = "";
                    CompiledCode CompiledModule = ModuleSource.Compile(CompileErrors);
                    ErrorMessage = CompileErrors.GetErrors();
                    if (M.FileName.EndsWith(".py"))
                    {
                        string IndentError = PluginEditor.CheckPythonIndentation(ModuleSource.GetCode())[1];
                        if (IndentError.Length > 0)
                        {
                            ErrorMessage = string.Format("{0}\r\n{1}", IndentError, ErrorMessage);
                        }
                    }
                    if (ErrorMessage.Length == 0)
                    {
                        ModuleSource.ExecuteProgram();
                    }
                    else
                    {
                        throw new Exception(string.Format("Syntax error in module file:{0}\r\n{1}", M.FileName, ErrorMessage));
                    }
                }
            }
            catch(Exception Exp)
            {
                 ModuleStartPromptForm PF = GetPromptWindow(M);
                 if (PF != null) PF.ShowError("Error Loading Module.");
                 IronException.Report(string.Format("Error Loading Module - {0}", M.Name), Exp);
                 return null;
            }
            IronUI.BuildPluginTree();
            ModuleStartPromptForm UsedPF = RemovePromptWindowFromList(M);
            if (UsedPF != null)
            {
                try
                {
                    if (!UsedPF.IsClosed)
                        UsedPF.CloseForm();
                }
                catch { }
            }
            return Get(M.Name);
        }
开发者ID:0ks3ii,项目名称:IronWASP,代码行数:70,代码来源:Module.cs

示例12: Compile

        private CompiledCode Compile(string scriptLink, FileAndDate scriptItem, ScriptEngine engine)
        {
            string cacheName = "script_" + scriptItem.LastUpdate.Ticks;
            KeyValuePair<DateTime, CompiledCode>? compiledItem = (KeyValuePair<DateTime, CompiledCode>?) HttpRuntime.Cache.Get(cacheName);

            // not in cache or not matching modificaction datetime of script from repository
            if (compiledItem == null || compiledItem.Value.Key != scriptItem.LastUpdate)
            {
                ScriptSource source = engine.CreateScriptSourceFromFile(scriptLink, Encoding.UTF8, SourceCodeKind.File);
                compiledItem = new KeyValuePair<DateTime, CompiledCode>(scriptItem.LastUpdate,
                    source.Compile());
                HttpRuntime.Cache.Insert(cacheName, compiledItem, null, DateTime.Now.AddDays(1), Cache.NoSlidingExpiration);
            }

            return compiledItem.Value.Value;
        }
开发者ID:NAVERTICA,项目名称:SPTools,代码行数:16,代码来源:DLRExecute.cs

示例13: LoadPlugin

        static void LoadPlugin(string PluginFile, ScriptEngine Engine)
        {
            try
            {
                ScriptSource PluginSource;
                CompiledCode CompiledPlugin;
                ScriptErrorReporter CompileErrors = new ScriptErrorReporter();
                string ErrorMessage = "";

                fileName = PluginFile.Substring(PluginFile.LastIndexOf('\\') + 1);
                if(StartUp) IronUI.LF.ShowLoadMessage("Loading Plugin - " + fileName);
                if (PluginFile.EndsWith(".py", StringComparison.CurrentCultureIgnoreCase))
                {
                    Engine.Runtime.TryGetEngine("py", out Engine);
                    PluginSource = Engine.CreateScriptSourceFromFile(PluginFile);
                    string IndentError = PluginEditor.CheckPythonIndentation(PluginSource.GetCode())[1];
                    if (IndentError.Length > 0)
                    {
                        string UpdatedCode =  PluginEditor.FixPythonIndentation(PluginSource.GetCode());
                        PluginSource = Engine.CreateScriptSourceFromString(UpdatedCode);
                        //ErrorMessage = string.Format("{0}\r\n{1}", IndentError, ErrorMessage);
                    }
                    CompiledPlugin = PluginSource.Compile(CompileErrors);
                    ErrorMessage = CompileErrors.GetErrors();
                    if (ErrorMessage.Length > 0 && IndentError.Length > 0)
                    {
                        ErrorMessage = string.Format("{0}\r\n{1}", IndentError, ErrorMessage);
                    }
                    if (ErrorMessage.Length == 0)
                    {
                        PluginSource.ExecuteProgram();
                    }
                }
                else if (PluginFile.EndsWith(".rb", StringComparison.CurrentCultureIgnoreCase))
                {
                    Engine.Runtime.TryGetEngine("rb", out Engine);
                    PluginSource = Engine.CreateScriptSourceFromFile(PluginFile);
                    CompiledPlugin = PluginSource.Compile(CompileErrors);
                    ErrorMessage = CompileErrors.GetErrors();
                    if (ErrorMessage.Length == 0)
                    {
                        PluginSource.ExecuteProgram();
                    }
                }
                if (ErrorMessage.Length > 0)
                {
                    IronException.Report("Syntax error in Plugin - " + PluginFile, ErrorMessage);
                }
            }
            catch (Exception Exp)
            {
                IronException.Report("Error loading plugin - " + PluginFile, Exp.Message, Exp.StackTrace);
            }
            finally
            {
                fileName = "";
            }
        }
开发者ID:0ks3ii,项目名称:IronWASP,代码行数:58,代码来源:PluginEngine.cs

示例14: initPython

        private void initPython()
        {
            if (pyEngine == null)
            {
                pyEngine = Python.CreateEngine();
                pyScope = pyEngine.CreateScope();

                ScriptSource src = pyEngine.CreateScriptSourceFromFile("scripts.py");

                src.Execute(pyScope);
            }
        }
开发者ID:tolachhoeun,项目名称:CSharpWoTReplayParserPoC,代码行数:12,代码来源:WOTParser.cs


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