本文整理汇总了C#中ScriptEngine.ExecuteFile方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptEngine.ExecuteFile方法的具体用法?C# ScriptEngine.ExecuteFile怎么用?C# ScriptEngine.ExecuteFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScriptEngine
的用法示例。
在下文中一共展示了ScriptEngine.ExecuteFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadAllTasks
public static ICollection<string> ReadAllTasks(string path)
{
var list = new List<string>();
if (path.EndsWith(".ts"))
{
path = path.Replace(".ts", ".js").Replace(".coffee",".js");
}
if (!File.Exists(path))
{
return list;
}
// executes the gulpfile with some little additions :)
try
{
var engine = new ScriptEngine();
engine.Execute(Resources.gulpInit);
engine.ExecuteFile(path);
// reads the evaluated tasks
ArrayInstance names = (ArrayInstance)engine.Evaluate("tasks");
foreach (var elem in names.ElementValues)
{
list.Add((string)elem);
}
}
catch (Exception)
{
list.Add("Cannot parse gulpfile");
}
return list.Distinct().ToList();
}
示例2: Execute
public override void Execute(ScriptEngine scriptEngine)
{
if (scriptEngine == null)
throw new ArgumentNullException("scriptEngine");
scriptEngine.ExecuteFile(_scriptPath);
}
示例3: InitEngine
protected void InitEngine()
{
JSEngine = new Jurassic.ScriptEngine();
FileToExecute = FileToExecute.Select(i => filePath + "\\" + i).ToList();
FileToExecute.ForEach(file => JSEngine.ExecuteFile(file));
}
示例4: Execute
public override void Execute(ScriptEngine engine, ScriptScope scope)
{
if (!string.IsNullOrEmpty(Path))
{
engine.ExecuteFile(Path, scope);
}
}
示例5: ReadAllTasks
/// <summary>
/// Reads all the defined tasks in a Gruntfile whose path is passed as parameter
/// </summary>
/// <param name="path">The path of the file to examine</param>
/// <returns>A list of tasks</returns>
public static ICollection<string> ReadAllTasks(string path)
{
var list = new List<string>();
//executes the gruntfile with some little additions :)
try
{
var engine = new ScriptEngine();
engine.Execute(Resources.Init);
engine.ExecuteFile(path);
engine.Execute("module.exports(grunt);");
//reads the evaluated tasks
ArrayInstance names = (ArrayInstance)engine.Evaluate("names");
foreach (var elem in names.ElementValues)
{
list.Add((string)elem);
}
}
catch (Exception) {
list.Add("Cannot parse Gruntfile");
}
return list;
}
示例6: LoadHtmlTemplateScriptsIntoEngine
static ScriptEngine LoadHtmlTemplateScriptsIntoEngine(HtmlTemplateBundle bundle)
{
var output = bundle.OpenStream().ReadToEnd();
var scriptEngine = new ScriptEngine();
scriptEngine.ExecuteFile("hogan.js");
scriptEngine.Execute(output);
return scriptEngine;
}
示例7: BigNumber
public void BigNumber()
{
var engine = new ScriptEngine();
engine.SetGlobalValue("console", new Jurassic.Library.FirebugConsole(engine));
engine.ExecuteFile(@"..\..\..\Unit Tests\Real-world\Files\bignumber.js");
engine.EnableDebugging = true;
Assert.AreEqual("129963294281830400", engine.Evaluate(@"new BigNumber('129963294281830401').subtract(1).toString()"));
}
示例8: Script
public Script(string path)
{
_engine = Python.CreateEngine();
_engine.Runtime.LoadAssembly(Assembly.GetExecutingAssembly());
_path = Path.Combine("Content/Scripts/", path + ".py");
_scope = _engine.CreateScope();
_scope.owner = this;
_engine.ExecuteFile(_path, _scope);
_scriptClass = _engine.Operations.CreateInstance(_scope.GetVariable("Script"));
_engine.Operations.InvokeMember(_scriptClass, "initialize");
}
示例9: Construct
/// <summary>
/// Creates and configures a Jurassic ScriptEngine
/// </summary>
/// <param name="context">The request/response context to process</param>
/// <returns>A RaptorJS-configured Jurassic ScriptEngine instance</returns>
public static ScriptEngine Construct(HttpListenerContext context)
{
ScriptEngine engine = new ScriptEngine();
engine.SetGlobalValue("Request", new RequestInstance(engine, context.Request));
engine.SetGlobalValue("Response", new ResponseInstance(engine, context.Response));
engine.SetGlobalValue("console", new ConsoleInstance(engine));
engine.SetGlobalValue("file", new FileSystemInstance(engine));
engine.SetGlobalFunction("require", new Action<string>((path) => engine.ExecuteFile(path)));
engine.SetGlobalFunction("require", new Func<string, object>((path) => engine.Evaluate(new FileScriptSource(path))));
return engine;
}
示例10: GaudiPythonPlugin
public GaudiPythonPlugin(string plugin)
{
try
{
iPy = Python.CreateEngine();
iPy.CreateScope();
iPy.ExecuteFile(String.Format("{0}.py", plugin));
}
catch (Exception ex)
{
PrintError(String.Format("Script error - {0}.", ex.Message));
LogDump(ex.Message);
}
}
示例11: CanCompileHoganTemplate
public void CanCompileHoganTemplate()
{
var compiler = new HoganCompiler();
var result = compiler.Compile("Hello {{world}}", new CompileContext());
var engine = new ScriptEngine();
engine.ExecuteFile("hogan.js");
var source = @"
(function(){
var template = new Hogan.Template();
template.r = " + result.Output + @";
return template.render({world:'Andrew'});
}());";
var templateRender = engine.Evaluate<string>(source);
templateRender.ShouldEqual("Hello Andrew");
}
示例12: CanCompileHandlebarsTemplate
public void CanCompileHandlebarsTemplate()
{
var settings = new HandlebarsSettings { KnownHelpersOnly = false, KnownHelpers = new List<string> { "t" } };
var compiler = new HandlebarsCompiler(settings);
var result = compiler.Compile("Hello {{world}}", new CompileContext());
var engine = new ScriptEngine();
engine.ExecuteFile("handlebars.js");
var source = @"
(function(){
var template = new Hogan.template(" + result.Output + @");
return template({world:'Andrew'});
}());";
var templateRender = engine.Evaluate<string>(source);
templateRender.ShouldEqual("Hello Andrew");
}
示例13: Setup
public void Setup()
{
engine = new ScriptEngine { EnableDebugging = true };
engine.SetGlobalValue("nativeModule", new NativeModuleInstance(engine));
engine.SetGlobalValue("console", new FirebugConsole(engine));
engine.SetGlobalFunction("native_require", new Func<string, ObjectInstance>(identifier =>
{
switch (identifier)
{
case "nativeModule":
return new NativeModuleInstance(engine);
default:
throw new ArgumentOutOfRangeException(string.Format("Unsupported module name: {0}", identifier));
}
}));
engine.ExecuteFile("./Builtin/require.js");
}
示例14: EngineRun
private void EngineRun() {
lock(_pyLock) {
_pyEngine = Python.CreateEngine();
_pyEngine.Runtime.IO.SetOutput(_engineOutput, new StreamWriter(_engineOutput, System.Text.Encoding.UTF8));
ICollection<string> paths = _pyEngine.GetSearchPaths();
string path = Path.GetDirectoryName(_filePath);
_logger.Log(path);
paths.Add(path);
_pyEngine.SetSearchPaths(paths);
_pyScope = _pyEngine.CreateScope();
}
_logger.Log("Engine started. Initializing TerminalOS.");
try {
_pyEngine.ExecuteFile(_filePath, _pyScope);
}
catch (Exception e) {
_logger.Log(e.Message + e.StackTrace);
}
_logger.Log("TerminalOS has stopped.");
}
示例15: TestFoo
public TestFoo()
{
#if SILVERLIGHT
var setup = DynamicApplication.CreateRuntimeSetup();
#else
var setup = Python.CreateRuntimeSetup(new Dictionary<string, object>());
#endif
setup.DebugMode = System.Diagnostics.Debugger.IsAttached;
var runtime = new ScriptRuntime(setup);
engine = Python.GetEngine(runtime);
var file = "test_example.py";
#if SILVERLIGHT
var filepath = file;
#else
var assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var filepath = Path.Combine(assemblyPath, file);
#endif
module = engine.ExecuteFile(filepath);
klass = engine.Operations.GetMember(module, "TestFoo");
klassInstance = ((dynamic)klass)();
}