/// <summary> /// Initializes a new instance of the <see cref="ActiveScriptEngine"/> class. /// </summary> /// <param name="scriptEngine"> The script engine. </param> /// <param name="language"> The scripting language. </param> private ActiveScriptEngine(object scriptEngine, ScriptLanguage language) { if (scriptEngine == null) throw new ArgumentNullException("scriptEngine"); this.language = language; this.engine = (IActiveScript)scriptEngine; this.engine.SetScriptSite(this); this.parser = (IActiveScriptParse)this.engine; this.parser.InitNew(); // Set properties. var activeScriptProperty = (IActiveScriptProperty)scriptEngine; // Indicate that we are not combining multiple script engines. object value = true; activeScriptProperty.SetProperty(SCRIPTPROP.ABBREVIATE_GLOBALNAME_RESOLUTION, IntPtr.Zero, ref value); // Upgrade the version of the script engine to 5.8 (IE 8). value = SCRIPTLANGUAGEVERSION.V5_8; activeScriptProperty.SetProperty(SCRIPTPROP.INVOKEVERSIONING, IntPtr.Zero, ref value); }
/// <summary> /// Parses the template directive from the specified fragment. /// </summary> /// <param name="fragment">The fragment.</param> private void ParseTemplateDirective(string fragment) { string language = ExtractDirectiveAttribute(fragment, Constants.LanguageAttributeName) ?? string.Empty; if (language.StartsWith(Constants.CSharpLanguageIdentifier, StringComparison.Ordinal)) { scriptLanguage = ScriptLanguage.CSharp; if (language.Length > 2) { scriptLanguageVersion = language.Substring(2); } } else if (language.StartsWith(Constants.VisualBasicLanguageIdentifier, StringComparison.Ordinal)) { scriptLanguage = ScriptLanguage.VisualBasic; if (language.Length > 2) { scriptLanguageVersion = language.Substring(2); } } else { throw new InvalidOperationException(InvalidOperationException_UnrecognizedLanguageIdentifier); } }
/// <summary> /// Initializes a new instance of the <see cref="InvalidScriptLanguageException"/> class. /// </summary> /// <param name="language">The unknown script language.</param> public InvalidScriptLanguageException(ScriptLanguage language) : this(string.Format( CultureInfo.InvariantCulture, Resources.Exceptions_Messages_InvalidScriptLanguage_WithLanguage, language)) { }
public NewFileDialog(ScriptLanguage Lang, StringCollection CreatedFileNames) { _Language = Lang; _CreatedFileNames = CreatedFileNames; InitializeComponent(); InitilizeListView(Lang); }
public object Any(EvalExpression request) { if (string.IsNullOrWhiteSpace(request.Expression)) { return(new EvalExpressionResponse()); } var args = new Dictionary <string, object>(); foreach (String name in Request.QueryString.AllKeys) { if (name.EqualsIgnoreCase("expression")) { continue; } var argExpr = Request.QueryString[name]; var argValue = JS.eval(argExpr); args[name] = argValue; } var scope = JS.CreateScope(args: args); var expr = JS.expression(request.Expression.Trim()); var response = new EvalExpressionResponse { Result = ScriptLanguage.UnwrapValue(expr.Evaluate(scope)), Tree = expr.ToJsAstString(), }; return(response); }
/// <summary> /// Initializes a new instance of the <see cref="ScriptDefinition"/> class. /// </summary> /// <param name="script">The script.</param> /// <param name="lang">The language.</param> /// <param name="imports">The imports.</param> /// <param name="references">The references.</param> public ScriptDefinition(string script, ScriptLanguage lang, string[] imports, string[] references) { Script = script; Lang = lang; Imports = imports; References = references; }
/// <summary> /// Adds script files to this ScriptCollection. /// </summary> /// <param name="scriptFiles">An IEnumerable of paths to the script files to load into this collection.</param> /// <param name="language">Language of the scripts.</param> /// <returns>Errors and warnings generated when compiling the scripts.</returns> CompilerErrorCollection AddScriptFiles(IEnumerable <string> scriptFiles, ScriptLanguage language) { // Check for files if (scriptFiles == null) { return(null); } scriptFiles = scriptFiles.ToImmutable(); if (scriptFiles.IsEmpty()) { return(null); } // Get the assembly CompilerErrorCollection errors = null; var asm = _scriptAssemblyCache.CreateInCache(scriptFiles, x => CompileCode(x, scriptFiles, language, out errors)); if (asm == null) { _compilationFailed = true; } else { // Add the new types var newTypes = asm.GetExportedTypes(); foreach (var newType in newTypes) { _types.Add(newType.Name, newType); } } return(errors); }
/// <summary> /// Creates a code DOM provider appropriate for the specified script language. /// </summary> /// <param name="scriptLanguage">The script language.</param> /// <param name="compilerVersion">The compiler version.</param> /// <returns>A code DOM provider.</returns> public static CodeDomProvider Create(ScriptLanguage scriptLanguage, string compilerVersion) { if (compilerVersion == null) { throw new ArgumentNullException("compilerVersion"); } else if (string.IsNullOrWhiteSpace(compilerVersion)) { throw new ArgumentException(InternalExceptionStrings.ArgumentException_EmptyOrWhitespaceString, "compilerVersion"); } CodeDomProvider instance; Dictionary<string, string> providerOptions = new Dictionary<string, string>() { { "CompilerVersion", compilerVersion } }; if (scriptLanguage == ScriptLanguage.CSharp) { instance = new CSharpCodeProvider(providerOptions); } else if (scriptLanguage == ScriptLanguage.VisualBasic) { instance = new VBCodeProvider(providerOptions); } else { throw new InvalidOperationException(InvalidOperationException_UnsupportedLanguage); } return instance; }
private void InitilizeListView(ScriptLanguage Lang) { if (_Language == ScriptLanguage.CSharp) { ListViewItem listViewItem1 = new ListViewItem("Class", "Code_ClassCS.ico"); listViewItem1.ToolTipText = "An empty class definiton."; ListViewItem listViewItem2 = new ListViewItem("Interface", "Code_CodeFileCS.ico"); listViewItem2.ToolTipText = "An empty interface definition."; listViewItem1.Selected = true; this.listView1.Items.AddRange(new ListViewItem[] { listViewItem1, listViewItem2 }); } else { ListViewItem listViewItem1 = new ListViewItem("Class", "CodeClass.ico"); listViewItem1.ToolTipText = "An empty class definiton."; ListViewItem listViewItem2 = new ListViewItem("Interface", "Code_CodeFile.ico"); listViewItem2.ToolTipText = "An empty interface definition."; listViewItem1.Selected = true; this.listView1.Items.AddRange(new ListViewItem[] { listViewItem1, listViewItem2 }); } }
/// <summary> /// Creates a code DOM provider appropriate for the specified script language. /// </summary> /// <param name="scriptLanguage">The script language.</param> /// <param name="compilerVersion">The compiler version.</param> /// <returns>A code DOM provider.</returns> public static CodeDomProvider Create(ScriptLanguage scriptLanguage, string compilerVersion) { if (compilerVersion == null) { throw new ArgumentNullException("compilerVersion"); } else if (string.IsNullOrWhiteSpace(compilerVersion)) { throw new ArgumentException(InternalExceptionStrings.ArgumentException_EmptyOrWhitespaceString, "compilerVersion"); } CodeDomProvider instance; Dictionary <string, string> providerOptions = new Dictionary <string, string>() { { "CompilerVersion", compilerVersion } }; if (scriptLanguage == ScriptLanguage.CSharp) { instance = new CSharpCodeProvider(providerOptions); } else if (scriptLanguage == ScriptLanguage.VisualBasic) { instance = new VBCodeProvider(providerOptions); } else { throw new InvalidOperationException(InvalidOperationException_UnsupportedLanguage); } return(instance); }
/// <summary> /// 构造函数 /// </summary> /// <param name="language">脚本类型</param> public Script(ScriptLanguage language, string codeBody) { this.msc = new ScriptControl(); this.msc.UseSafeSubset = true; this.msc.Language = language.ToString(); _codeBody = codeBody; }
private IExecuteScripts LoadExecutor(ScriptLanguage language, AppDomain scriptDomain, TextWriter outputChannel) { // Load the script runner into the AppDomain var launcher = Activator.CreateInstanceFrom( scriptDomain, typeof(ScriptDomainLauncher).Assembly.LocalFilePath(), typeof(ScriptDomainLauncher).FullName) .Unwrap() as ScriptDomainLauncher; m_ProjectsForScripts = Activator.CreateInstanceFrom( scriptDomain, typeof(ScriptFrontEndProjectHub).Assembly.LocalFilePath(), typeof(ScriptFrontEndProjectHub).FullName, false, BindingFlags.Default, null, new object[] { m_Projects }, null, null) .Unwrap() as ScriptFrontEndProjectHub; var executor = launcher.Launch(language, m_ProjectsForScripts, outputChannel); return(executor); }
public ISyntaxVerifier VerifySyntax(ScriptLanguage language) { var scriptDomain = m_AppDomainBuilder("ScriptVerificationDomain", AppDomainPaths.Core); var executor = LoadExecutor(language, scriptDomain, new ScriptOutputPipe()); return(new SyntaxVerifier(scriptDomain, executor)); }
/// <inheritdoc /> public async Task <IScript> CompileCodeAsync(string code, ScriptLanguage language) { if (string.IsNullOrEmpty(code)) { return(null); } switch (language) { case ScriptLanguage.NCScript: return(await parser.ParseAsync(code)); case ScriptLanguage.JavaScript: case ScriptLanguage.TypeScript: return(new Dto.Scripts.JavaScript(code, importservice, language)); case ScriptLanguage.Python: return(new PythonScript(pythonservice, code)); case ScriptLanguage.Lua: return(new LuaScript(code, luaservice)); default: throw new ArgumentException($"Unsupported script language '{language}'"); } }
public ExternalScriptExecuter(SqlConnection connection, ScriptLanguage scriptLanguage) { _connection = connection; _sqlCommand = _connection.CreateCommand(); _language = scriptLanguage.ToString(); }
public Assembly Compile(FileName scriptFileName, ScriptLanguage language = ScriptLanguage.BYEXTENSION) { if (language == ScriptLanguage.BYEXTENSION) { switch (scriptFileName.Extension) { case "cs": language = ScriptLanguage.CSHARP; break; case "vb": language = ScriptLanguage.VB; break; default: throw new Exception("Unknown script extension: '" + scriptFileName.Extension + "'"); } } switch (language) { case ScriptLanguage.VB: throw new Exception("VB scripts are not yet implemented."); case ScriptLanguage.CSHARP: return CompileCSharpScript(LoadCSharpScript(scriptFileName)); default: return null; } }
/// <summary> /// 编译指定脚本源码,返回编译结果 /// </summary> /// <param name="source">源码</param> /// <param name="language">语言</param> /// <param name="outputFile">输出程序集文件</param> /// <returns>ScriptAgent的编译结果对象(永不为null)</returns> public CompileResults CompileScript(string source, ScriptLanguage language, string outputFile) { CodeDomProvider provider = null; switch (language) { case ScriptLanguage.VBNET: provider = new Microsoft.VisualBasic.VBCodeProvider(); break; case ScriptLanguage.CSharp: provider = new Microsoft.CSharp.CSharpCodeProvider(); break; } CompilerParameters param = this.GetCompilerParameters(outputFile); if (param == null) { return(new CompileResults()); } string szAssemblyDescriptor = this.GetScriptAssemblyDescriptor(language); CompilerResults results = null; try { source = this.FormatScript(source, language); results = provider.CompileAssemblyFromSource(param, szAssemblyDescriptor, source); } catch (Exception ex) { LogManager.Instance.WriteLog("ScriptCompiler.CompileScript", ex); } return(this.GetCompileResults(results)); }
private string GetSchemaType(ScriptLanguage language) { if (Schema == null) { return(Type); } var result = Schema["$ref"]?.ToObject <string>() ?? null; if (result == null) { return(Type); } result = result?.Split('/')?.LastOrDefault() ?? null; if (Type == "array") { switch (language) { case ScriptLanguage.CSharp: return($"List<{QlikApiUtils.GetDotNetType(result)}>"); case ScriptLanguage.TypeScript: return($"{QlikApiUtils.GetTypeScriptType(result)}[]"); default: throw new Exception($"Unknown script language {language.ToString()}"); } } return(result); }
public void UpdateScriptLanguage(string szFileName) { this.m_scriptLang = ScriptLanguage.VBNET; if (this.m_szFilePath != null && this.m_szFilePath.EndsWith(".cs", StringComparison.OrdinalIgnoreCase)) { this.m_scriptLang = ScriptLanguage.CSharp; } }
/// <summary> /// 构造函数 /// </summary> /// <param name="language">脚本类型</param> public ScriptEngine(ScriptLanguage language) { this.msc = new ScriptControlClass { UseSafeSubset = true, Language = language.ToString() }; ((DScriptControlSource_Event)this.msc).Error += new DScriptControlSource_ErrorEventHandler(OnError); ((DScriptControlSource_Event)this.msc).Timeout += new DScriptControlSource_TimeoutEventHandler(OnTimeout); }
/// <summary> /// 运行Run方法 /// </summary> /// <param name="language">脚本语言</param> /// <param name="mainFunctionName">入口函数名称</param> /// <param name="parameters">参数</param> /// <param name="codeBody">函数体</param> /// <returns>返回值object</returns> public object Run(ScriptLanguage language, string mainFunctionName, object[] parameters, string codeBody) { if (this.Language != language) { this.Language = language; } return(Run(mainFunctionName, parameters, codeBody)); }
/// <summary> /// Initializes a new instance of the <see cref="InvalidScriptLanguageException"/> class. /// </summary> /// <param name="language">The unknown script language.</param> public InvalidScriptLanguageException(ScriptLanguage language) : this( string.Format( CultureInfo.InvariantCulture, Resources.Exceptions_Messages_InvalidScriptLanguage_WithLanguage, language)) { }
/// <summary> /// 构造函数 /// </summary> /// <param name="language">脚本类型</param> public ScriptEngine(ScriptLanguage language) { this.msc = new ScriptControl(); this.msc.UseSafeSubset = true; this.msc.Language = language.ToString(); ((DScriptControlSource_Event)this.msc).Error += new DScriptControlSource_ErrorEventHandler(ScriptEngine_Error); ((DScriptControlSource_Event)this.msc).Timeout += new DScriptControlSource_TimeoutEventHandler(ScriptEngine_Timeout); }
/// <summary> /// Resets this instance. /// </summary> /// <returns></returns> public ScriptBuilder <T> Reset() { _language = ScriptLanguage.None; _body = string.Empty; _references.Clear(); _imports.Clear(); return(this); }
/// <summary> /// 运行Eval方法 /// </summary> /// <param name="language">脚本语言</param> /// <param name="expression">表达式</param> /// <param name="codeBody">函数体</param> /// <returns>返回值object</returns> public object Eval(ScriptLanguage language, string expression, string codeBody) { if (this.Language != language) { this.Language = language; } return(Eval(expression, codeBody)); }
/// <summary> /// 运行Eval方法 /// </summary> /// <param name="expression">js表达式,</param> /// <param name="language">脚本语言</param> /// <returns>返回值object</returns> public object Eval(string expression, ScriptLanguage language) { msc.AddCode(_codeBody); if (this.msc.Language != language.ToString()) { this.msc.Language = language.ToString(); } return(Eval(expression)); }
public string GetRealType(ScriptLanguage language) { var result = GetArrayType(language); if (result == Type) { result = GetSchemaType(language); } return(result); }
/// <summary> /// 获取脚本程序集文件描述器脚本 /// </summary> /// <param name="language">脚本语言</param> /// <returns>返回属性脚本</returns> private string GetScriptAssemblyDescriptor(ScriptLanguage language) { if (language == ScriptLanguage.VBNET) { return(this.GetScriptAssemblyDescriptorVB()); } else { return(this.GetScriptAssemblyDescriptorCS()); } }
/// <summary> /// 格式化传入的原始脚本,这些脚本中是不包含类定义的 /// </summary> /// <param name="script">原始脚本</param> /// <param name="language">脚本语言</param> /// <returns>格式化后的脚本</returns> private string FormatScript(string script, ScriptLanguage language) { if (language == ScriptLanguage.VBNET) { return(this.FormatScriptVB(script)); } else { return(this.FormatScriptCS(script)); } }
/// <summary> /// 构造函数 /// </summary> /// <param name="language">脚本类型</param> public ScriptEngine(ScriptLanguage language) { this.msc = new ScriptControlClass(); this.msc.UseSafeSubset = true; //MessageBox.Show(language.ToString()); this.msc.Language = "JavaScript";// language.ToString(); ((DScriptControlSource_Event)this.msc).Error += new DScriptControlSource_ErrorEventHandler(ScriptEngine_Error); ((DScriptControlSource_Event)this.msc).Timeout += new DScriptControlSource_TimeoutEventHandler(ScriptEngine_Timeout); }
private void ResetParserLanguage(ScriptLanguage lang) { if (lang == ScriptLanguage.CSharp) { Parser.ProjectParser.Language = SupportedLanguage.CSharp; } else { Parser.ProjectParser.Language = SupportedLanguage.VBNet; } }
/// <summary> /// Creates a scripting engine host given a scripting language. /// </summary> /// <param name="engineName"> The language to host. </param> /// <returns> A ScriptEngine instance. </returns> public static ActiveScriptEngine FromLanguage(ScriptLanguage language) { switch (language) { case ScriptLanguage.JScript: return new ActiveScriptEngine(new JScriptEngine(), ScriptLanguage.JScript); case ScriptLanguage.VBScript: return new ActiveScriptEngine(new VBScriptEngine(), ScriptLanguage.VBScript); } throw new NotImplementedException(string.Format("The scripting language '{0}' is not supported.", language)); }
public AddWebReferenceDialog(IProject project, ScriptLanguage Lang, StringCollection CreatedFileNames) { _Language = Lang; _CreatedFileNames = CreatedFileNames; InitializeComponent(); txtName.Text = GenerateValidFileName(); AddMruList(); // fixes forum-16247: Add Web Reference dialog missing URL on 120 DPI AddWebReferenceDialogResize(null, null); this.project = project; }
/// <summary> /// Creates a scripting engine host given a scripting language. /// </summary> /// <param name="engineName"> The language to host. </param> /// <returns> A ScriptEngine instance. </returns> public static ActiveScriptEngine FromLanguage(ScriptLanguage language) { switch (language) { case ScriptLanguage.JScript: return(new ActiveScriptEngine(new JScriptEngine(), ScriptLanguage.JScript)); case ScriptLanguage.VBScript: return(new ActiveScriptEngine(new VBScriptEngine(), ScriptLanguage.VBScript)); } throw new NotImplementedException(string.Format("The scripting language '{0}' is not supported.", language)); }
//-- default constructor public ScriptInfo() { ServiceName = string.Empty; ScriptLanguage = ScriptLanguage.English; PinLength = 9; ScriptType = ScriptType.PhoneCard; AuthenticationType = ScriptAuthenticationType.Card; PromptType = BalancePromptType.Money; PerUnit = 0; NumberOfSubSessions = 1; RbrRoot = AppConstants.RbrRoot; }
/// <summary> /// Initializes a new instance of the <see cref="Script" /> class. /// </summary> /// <param name="Language">Language.</param> /// <param name="_Script">_Script (required).</param> public Script(ScriptLanguage Language = default(ScriptLanguage), string _Script = default(string)) { // to ensure "_Script" is required (not null) if (_Script == null) { throw new InvalidDataException("_Script is a required property for Script and cannot be null"); } else { this._Script = _Script; } this.Language = Language; }
public IExecuteScripts Launch(ScriptLanguage language, ILinkScriptsToProjects projects, TextWriter writer) { switch (language) { case ScriptLanguage.None: throw new InvalidScriptLanguageException(language); case ScriptLanguage.IronPython: return new RemoteScriptRunner(projects, writer, Python.CreateEngine()); case ScriptLanguage.IronRuby: throw new NotImplementedException(); case ScriptLanguage.PowerShell: throw new NotImplementedException(); default: throw new NotImplementedException(); } }
/// <summary> /// Creates a script builder appropriate for the specified script language. /// </summary> /// <param name="scriptLanguage">The script language.</param> /// <param name="namespaceName">The name of the namespace to use.</param> /// <param name="className">The name of the class to generate.</param> /// <returns>A script builder.</returns> public static ScriptBuilder Create(ScriptLanguage scriptLanguage, string namespaceName, string className) { if (namespaceName == null) { throw new ArgumentNullException("namespaceName"); } else if (string.IsNullOrWhiteSpace(namespaceName)) { throw new ArgumentException(InternalExceptionStrings.ArgumentException_EmptyOrWhitespaceString, "namespaceName"); } else if (className == null) { throw new ArgumentNullException("className"); } else if (string.IsNullOrWhiteSpace(className)) { throw new ArgumentException(InternalExceptionStrings.ArgumentException_EmptyOrWhitespaceString, "className"); } ScriptBuilder instance; if (scriptLanguage == ScriptLanguage.CSharp) { instance = new CSharpScriptBuilder(namespaceName, className); } else if (scriptLanguage == ScriptLanguage.VisualBasic) { instance = new VisualBasicScriptBuilder(namespaceName, className); } else { throw new InvalidOperationException(InternalExceptionStrings.InvalidOperationException_UnrecognizedLanguageIdentifier); } return instance; }
/// <summary> /// Compiles the specified source code. /// </summary> /// <param name="text">The text.</param> /// <param name="language">The language.</param> /// <returns>A result from the compilation</returns> public static CompileResult Compile ( string text, ScriptLanguage language ) { CodeDomProvider provider = null; switch ( language ) { case ScriptLanguage.CSharp: provider = CodeDomProvider.CreateProvider( "CSharp" ); break; case ScriptLanguage.VB: provider = CodeDomProvider.CreateProvider( "VisualBasic" ); break; case ScriptLanguage.JavaScript: throw new NotImplementedException( "This language interface has not been implemented yet." ); } if ( provider == null ) { throw new NotImplementedException( "You must have .net developer tools. (You need a visual studio)" ); } var compile = provider.CompileAssemblyFromSource( _settings, text ); if ( compile.Errors.Count > 0 ) { return new CompileResult( null, compile.Errors ); } var assembly = compile.CompiledAssembly; var list = new List<Command>(); foreach ( Command command in from type in assembly.GetTypes() where type.BaseType == typeof( Command ) select Activator.CreateInstance( type ) as Command ) { list.Add( command ); } return new CompileResult( list.ToArray(), null ); }
protected virtual void Init() { Language = ScriptLanguage.BYEXTENSION; dllList = new List<string>(); }
private IExecuteScripts LoadExecutor(ScriptLanguage language, AppDomain scriptDomain, TextWriter outputChannel) { // Load the script runner into the AppDomain var launcher = Activator.CreateInstanceFrom( scriptDomain, typeof(ScriptDomainLauncher).Assembly.LocalFilePath(), typeof(ScriptDomainLauncher).FullName) .Unwrap() as ScriptDomainLauncher; m_ProjectsForScripts = Activator.CreateInstanceFrom( scriptDomain, typeof(ScriptFrontEndProjectHub).Assembly.LocalFilePath(), typeof(ScriptFrontEndProjectHub).FullName, false, BindingFlags.Default, null, new object[] { m_Projects }, null, null) .Unwrap() as ScriptFrontEndProjectHub; var executor = launcher.Launch(language, m_ProjectsForScripts, outputChannel); return executor; }
public ActiveScriptHost(ScriptLanguage language) { scriptLanguage = language; }
internal static string GetExtensionFromScaffoldLanguage(ScriptLanguage language) { switch (language) { case ScriptLanguage.CSharp: return ".csproj"; case ScriptLanguage.VisualBasic: return ".vbproj"; default: throw new NotSupportedException(); } }
public Script(string file, ScriptLanguage lang, string triggerName, SysEvent triggerEvent) : this(file, lang) { TriggerEvent = triggerEvent; TriggerName = triggerName; }
public Script(string file, ScriptLanguage lang) { FilePath = file; Language = lang; }
public System.Tuple<Task, CancellationTokenSource> Execute(ScriptLanguage language, string scriptCode, TextWriter outputChannel) { // If there is an existing runner then nuke that one if (m_CurrentlyRunningScript != null) { throw new CannotInterruptRunningScriptException(); } if ((m_CurrentLanguageDomainPair != null) && (m_CurrentLanguageDomainPair.Item1 != language)) { // Different language requested so nuke the domain UnloadCurrentScriptDomain(); } if (m_CurrentLanguageDomainPair == null) { var scriptDomain = m_AppDomainBuilder("ScriptDomain", AppDomainPaths.Core); m_CurrentLanguageDomainPair = new System.Tuple<ScriptLanguage, AppDomain>(language, scriptDomain); } IExecuteScripts executor = LoadExecutor(language, m_CurrentLanguageDomainPair.Item2, outputChannel); var source = new CancellationTokenSource(); var token = new CancelScriptToken(source.Token); var result = Task.Factory.StartNew( () => { try { executor.Execute(scriptCode, token); } finally { m_CurrentlyRunningScript = null; if (m_CurrentToken != null) { m_CurrentToken.Dispose(); m_CurrentToken = null; } } }, source.Token, TaskCreationOptions.LongRunning, m_Scheduler); m_CurrentlyRunningScript = result; m_CurrentToken = source; return new System.Tuple<Task, CancellationTokenSource>(result, source); }
/// <summary> /// 运行Run方法 /// </summary> /// <param name="language">脚本语言</param> /// <param name="mainFunctionName">入口函数名称</param> /// <param name="parameters">参数</param> /// <param name="codeBody">函数体</param> /// <returns>返回值object</returns> public object Run(ScriptLanguage language, string mainFunctionName, object[] parameters, string codeBody) { if (this.Language != language) this.Language = language; return Run(mainFunctionName, parameters, codeBody); }
/// <summary> /// 运行Eval方法 /// </summary> /// <param name="language">脚本语言</param> /// <param name="expression">表达式</param> /// <param name="codeBody">函数体</param> /// <returns>返回值object</returns> public object Eval(ScriptLanguage language, string expression, string codeBody) { if (this.Language != language) this.Language = language; return Eval(expression, codeBody); }
/// <summary> /// Parses the template directive from the specified fragment. /// </summary> /// <param name="fragment">The fragment.</param> private void ParseTemplateDirective(string fragment) { string language = ExtractDirectiveAttribute(fragment, Constants.LanguageAttributeName) ?? string.Empty; if (language.StartsWith(Constants.CSharpLanguageIdentifier, StringComparison.Ordinal)) { scriptLanguage = ScriptLanguage.CSharp; if (language.Length > 2) { scriptLanguageVersion = language.Substring(2); } } else if (language.StartsWith(Constants.VisualBasicLanguageIdentifier, StringComparison.Ordinal)) { scriptLanguage = ScriptLanguage.VisualBasic; if (language.Length > 2) { scriptLanguageVersion = language.Substring(2); } } else { throw new InvalidOperationException(InvalidOperationException_UnrecognizedLanguageIdentifier); } }
public ISyntaxVerifier VerifySyntax(ScriptLanguage language) { var scriptDomain = m_AppDomainBuilder("ScriptVerificationDomain", AppDomainPaths.Core); var executor = LoadExecutor(language, scriptDomain, new ScriptOutputPipe()); return new SyntaxVerifier(scriptDomain, executor); }