Пример #1
0
 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;
        }
Пример #3
0
 ///<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;
 }
Пример #4
0
 public static dynamic ExecuteCompiledCode(CompiledCode code, ICompiledCodeContext context)
 {
     var scope = CurrentScriptEngine.CreateScope();
     EvaluateContext(scope, context);
     return code.Execute(scope);
 }
Пример #5
0
 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));
 }
Пример #7
0
 public RemoteCompiledCode(CompiledCode compiledCode)
 {
     _compiledCode = compiledCode;
 }
Пример #8
0
 internal TypeWithEventsBuildResult(CompiledCode compiledCode, string scriptVirtualPath)
     : base(compiledCode, scriptVirtualPath)
 {
 }
Пример #9
0
 public BuildResult(CompiledCode compiledCode, string scriptVirtualPath)
 {
     _scriptVirtualPath = scriptVirtualPath;
     _compiledCode = compiledCode;
 }
Пример #10
0
 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;
     }
 }
Пример #11
0
 internal static void ExecuteCompiledCode(CompiledCode compiledExpression, ScriptScope module)
 {
     try {
         compiledExpression.Execute(module);
     } catch (Exception e) {
         if (!ProcessRuntimeException(compiledExpression.Engine, e, null))
             throw;
     }
 }
Пример #12
0
 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;
 }
Пример #13
0
 public Script(string Value)
 {
     code = ExecuteCore.CompileScript(Value);
 }
Пример #14
0
        /// <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();
        }
Пример #15
0
 public void Dispose()
 {
     _compiledCode = null;
 }
Пример #16
0
 internal GlobalAsaxBuildResult(ScriptEngine engine, CompiledCode compiledCode, string scriptVirtualPath)
     : base(compiledCode, scriptVirtualPath)
 {
     _engine = engine;
 }
Пример #17
0
 public static ScriptCode FromCompiledCode(CompiledCode compiledCode) {
     Contract.RequiresNotNull(compiledCode, "compiledCode");
     return compiledCode.ScriptCode;
 }
Пример #18
0
 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(); });
        }
Пример #20
0
 public ScriptChangedEventArgs(object reference, string script, CompiledCode code)
 {
     Reference = reference;
      Script = script;
      Code = code;
 }
Пример #21
0
        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;
            }
        }
Пример #22
0
 public void OnDestroy()
 {
     CallMethod("OnDestroy");
     code = null;
     engine = null;
     scope = null;
 }
Пример #23
0
 public RemoteCompiledCode(CompiledCode compiledCode) {
     _compiledCode = compiledCode;
 }
Пример #24
0
        /// <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;
        }
Пример #25
0
            private Hashtable _compiledSnippets; // <string, CompiledCode>

            internal TemplateControlBuildResult(CompiledCode compiledCode, string scriptVirtualPath)
                : base(compiledCode, scriptVirtualPath) { }
Пример #26
0
 public virtual object Run()
 {
     if (Source != null)
     {
         CCode = Source.Compile();
         return CCode.Execute(Scope);
     }
     else
     {
         MessageBox.Show("No Script Source Loaded !");
         return null;
     }
 }