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(); }
public virtual bool CanExecute(object parameter) { try { code = source.Compile(); return true; } catch (SyntaxErrorException e) { string msg = "Syntax error in \"{0}\""; showError(msg, Path.GetFileName(source.Path), e); } catch (Exception e) { string msg = "Error executing file \"{0}\""; showError(msg, Path.GetFileName(source.Path), e); } return false; }
///<summary> ///</summary> ///<param name="fileCode"></param> ///<param name="fileName"></param> ///<param name="compiledCode"></param> public PythonFileInfo(string fileCode, string fileName, CompiledCode compiledCode) : base(fileCode, fileName) { _compiledCode = compiledCode; _type = ScriptType.Python; }
public static dynamic ExecuteCompiledCode(CompiledCode code, ICompiledCodeContext context) { var scope = CurrentScriptEngine.CreateScope(); EvaluateContext(scope, context); return code.Execute(scope); }
BuildResult IBuildProvider.CreateBuildResult(CompiledCode compiledCode, string scriptVirtualPath) { return new TemplateControlBuildResult(compiledCode, scriptVirtualPath); }
public object ExecuteWithResult(CompiledCode compiledCode, object[] values) { SetVariables(this.ScriptScope, values); return ExecuteSafely(() => compiledCode.Execute(this.ScriptScope)); }
public RemoteCompiledCode(CompiledCode compiledCode) { _compiledCode = compiledCode; }
internal TypeWithEventsBuildResult(CompiledCode compiledCode, string scriptVirtualPath) : base(compiledCode, scriptVirtualPath) { }
public BuildResult(CompiledCode compiledCode, string scriptVirtualPath) { _scriptVirtualPath = scriptVirtualPath; _compiledCode = compiledCode; }
internal static void ExecuteCode(ScriptScope scope, CompiledCode compiledCode, string virtualPath) { try { compiledCode.Execute(scope); } catch (SyntaxErrorException e) { EngineHelper.ThrowSyntaxErrorException(e); } catch (Exception e) { if (!EngineHelper.ProcessRuntimeException(compiledCode.Engine, e, virtualPath)) throw; } }
internal static void ExecuteCompiledCode(CompiledCode compiledExpression, ScriptScope module) { try { compiledExpression.Execute(module); } catch (Exception e) { if (!ProcessRuntimeException(compiledExpression.Engine, e, null)) throw; } }
internal static object EvaluateCompiledCode(CompiledCode compiledExpression, ScriptScope scope, string defaultVirtualPath, int lineOffset) { try { return compiledExpression.Execute(scope); } catch (Exception e) { if (!ProcessRuntimeException(compiledExpression.Engine, e, defaultVirtualPath, lineOffset)) throw; } return null; }
public Script(string Value) { code = ExecuteCore.CompileScript(Value); }
/// <summary> /// Parse a script /// </summary> /// <param name="container">Script container</param> /// <returns>An array of errors, if no errors then empty</returns> public ScriptError[] Parse(ScriptContainer container) { ScriptErrorListener listener = new ScriptErrorListener(); try { foreach (AssemblyName name in container.ReferencedNames) { _engine.Runtime.LoadAssembly(Assembly.Load(name)); } if (container.EnableDebug) { string newFile = Path.GetTempFileName(); ScriptUtils.AddTempFile(newFile); File.WriteAllText(newFile, container.Script); _source = _engine.CreateScriptSourceFromFile(newFile); } else { _source = _engine.CreateScriptSourceFromString(container.Script); } _code = _source.Compile(listener); if (listener.Errors.Count == 0) { // Just create the global scope, don't execute it yet _scope = _engine.CreateScope(); _scope.SetVariable("CANAPEScriptContainer", new ScriptContainer(container)); } } catch (Exception ex) { listener.Errors.Add(new ScriptError(ex.Message, "FatalError", 0, 0)); } return listener.Errors.ToArray(); }
public void Dispose() { _compiledCode = null; }
internal GlobalAsaxBuildResult(ScriptEngine engine, CompiledCode compiledCode, string scriptVirtualPath) : base(compiledCode, scriptVirtualPath) { _engine = engine; }
public static ScriptCode FromCompiledCode(CompiledCode compiledCode) { Contract.RequiresNotNull(compiledCode, "compiledCode"); return compiledCode.ScriptCode; }
BuildResult IBuildProvider.CreateBuildResult(CompiledCode compiledCode, string scriptVirtualPath) { return new GlobalAsaxBuildResult(((IBuildProvider)this).GetScriptEngine(), compiledCode, scriptVirtualPath); }
private List<string> m_workerSIPEndPoints = new List<string>(); // Allow quick lookups to determine whether a remote end point is that of a worker process. public SIPCallDispatcher( SIPMonitorLogDelegate logDelegate, SIPTransport sipTransport, XmlNode callDispatcherNode, SIPEndPoint outboundProxy, string dispatcherScriptPath) { if (callDispatcherNode == null || callDispatcherNode.ChildNodes.Count == 0) { throw new ArgumentNullException("A SIPCallDispatcher cannot be created with an empty configuration node."); } SIPMonitorLogEvent_External = logDelegate; m_sipTransport = sipTransport; m_callDispatcherNode = callDispatcherNode; m_outboundProxy = outboundProxy; m_dispatcherScriptPath = dispatcherScriptPath; m_scriptLoader = new ScriptLoader(SIPMonitorLogEvent_External, m_dispatcherScriptPath); m_scriptLoader.ScriptFileChanged += (s, e) => { m_compiledScript = m_scriptLoader.GetCompiledScript(); }; m_compiledScript = m_scriptLoader.GetCompiledScript(); try { CallManagerPassThruServiceInstanceProvider callManagerPassThruSvcInstanceProvider = new CallManagerPassThruServiceInstanceProvider(this); m_callManagerPassThruSvcHost = new ServiceHost(typeof(CallManagerPassThruService)); m_callManagerPassThruSvcHost.Description.Behaviors.Add(callManagerPassThruSvcInstanceProvider); m_callManagerPassThruSvcHost.Open(); logger.Debug("SIPCallDispatcher CallManagerPassThru hosted service successfully started on " + m_callManagerPassThruSvcHost.BaseAddresses[0].AbsoluteUri + "."); } catch (Exception excp) { logger.Warn("Exception starting SIPCallDispatcher CallManagerPassThru hosted service. " + excp.Message); } foreach (XmlNode callDispatcherWorkerNode in callDispatcherNode.ChildNodes) { SIPCallDispatcherWorker callDispatcherWorker = new SIPCallDispatcherWorker(callDispatcherWorkerNode); m_callDispatcherWorkers.Add(callDispatcherWorker); m_workerSIPEndPoints.Add(callDispatcherWorker.AppServerEndpoint.ToString()); dispatcherLogger.Debug(" SIPCallDispatcher worker added for " + callDispatcherWorker.AppServerEndpoint.ToString() + " and " + callDispatcherWorker.CallManagerAddress.ToString() + "."); } ThreadPool.QueueUserWorkItem(delegate { SpawnWorkers(); }); ThreadPool.QueueUserWorkItem(delegate { ProbeWorkers(); }); }
public ScriptChangedEventArgs(object reference, string script, CompiledCode code) { Reference = reference; Script = script; Code = code; }
public SIPProxyCore( SIPMonitorLogDelegate proxyLogger, SIPTransport sipTransport, string scriptPath, string appServerEndPointsPath) { try { m_proxyLogger = proxyLogger ?? m_proxyLogger; m_scriptPath = scriptPath; m_sipTransport = sipTransport; if (!appServerEndPointsPath.IsNullOrBlank() && File.Exists(appServerEndPointsPath)) { m_sipCallDispatcherFile = new SIPCallDispatcherFile(SendMonitorEvent, appServerEndPointsPath); m_sipCallDispatcherFile.LoadAndWatch(); } else { logger.Warn("No call dispatcher file specified for SIP Proxy."); } m_proxyDispatcher = new SIPProxyDispatcher(new SIPMonitorLogDelegate(SendMonitorEvent)); GetAppServerDelegate getAppServer = (m_sipCallDispatcherFile != null) ? new GetAppServerDelegate(m_sipCallDispatcherFile.GetAppServer) : null; m_proxyScriptFacade = new SIPProxyScriptFacade( new SIPMonitorLogDelegate(SendMonitorEvent), // Don't use the m_proxyLogger delegate directly here as doing so caused stack overflow exceptions in the IronRuby engine. sipTransport, m_proxyDispatcher, getAppServer); m_scriptLoader = new ScriptLoader(SendMonitorEvent, m_scriptPath); m_scriptLoader.ScriptFileChanged += (s, e) => { m_compiledScript = m_scriptLoader.GetCompiledScript(); }; m_compiledScript = m_scriptLoader.GetCompiledScript(); // Events that pass the SIP requests and responses onto the Stateless Proxy Core. m_sipTransport.SIPTransportRequestReceived += GotRequest; m_sipTransport.SIPTransportResponseReceived += GotResponse; } catch (Exception excp) { logger.Error("Exception SIPProxyCore (ctor). " + excp.Message); throw excp; } }
public void OnDestroy() { CallMethod("OnDestroy"); code = null; engine = null; scope = null; }
/// <summary> /// Starts the $PythonBehaviour /// </summary> /// <param name="classname">Name of the Script</param> public bool Awakening(String classname) { scope = engine.CreateScope(); scope.SetVariable("this", this); scope.SetVariable("gameObject", gameObject); scope.SetVariable("transform", transform); scope.SetVariable("enabled", enabled); scope.SetVariable("useAPI", new Action(UseAPI)); scope.SetVariable("disableAPI", new Action(DisableAPI)); if (Settings.useAPI) { Besiege.SetUp(); scope.SetVariable("besiege", Besiege._besiege); } spaar.ModLoader.Game.OnSimulationToggle += GameOnOnSimulationToggle; spaar.ModLoader.Game.OnLevelWon += GameOnOnLevelWon; foreach (string @ref in refs.Where(@ref => !String.IsNullOrEmpty(@ref))) { try { #region OBSOLETE /* Assembly assembly = Assembly.Load(@ref); var namespaces = assembly.GetTypes() .Select(t => t.Namespace) .Distinct(); String[] lines = Util.splitStringAtNewline(sauce); for (int i = 0; i < lines.Length; i++) { if (!lines[i].Contains("import") && !String.IsNullOrEmpty(lines[i])) { foreach (string ns in namespaces) { if (!String.IsNullOrEmpty(ns)) { if (lines[i].Contains((ns + "."))) { lines[i] = Regex.Replace(lines[i], ns + ".", string.Empty); } } } } lines[i] += Util.getNewLine(); } lines = lines.Where(x => !string.IsNullOrEmpty(x) && !x.Equals("\r\n") && !x.Equals("\r") && !x.Equals("\n") && !String.IsNullOrEmpty(x.Trim())).ToArray(); sauce = String.Concat(lines); */ #endregion engine.Runtime.LoadAssembly(Assembly.Load(@ref)); } catch (Exception ex) { Debug.LogException(ex); return false; } } ScriptSource source = engine.CreateScriptSourceFromString(sauce); ErrorListener error = new ErrorSinkProxyListener(ErrorSink.Default); code = source.Compile(error); if (code == null) { Debug.LogError(error); return false; } code.Execute(scope); pythonClass = engine.Operations.Invoke(scope.GetVariable(classname)); CallMethod("Awake"); return true; }
private Hashtable _compiledSnippets; // <string, CompiledCode> internal TemplateControlBuildResult(CompiledCode compiledCode, string scriptVirtualPath) : base(compiledCode, scriptVirtualPath) { }
public virtual object Run() { if (Source != null) { CCode = Source.Compile(); return CCode.Execute(Scope); } else { MessageBox.Show("No Script Source Loaded !"); return null; } }