예제 #1
0
 public SimpleException(Exception e)
 {
     ExceptionType = e.GetType().FullName;
     Message = e.Message;
     StackTrace = e.StackTrace;
     if (e.InnerException != null)
     {
         InnerException = new SimpleException(e.InnerException);
     }
 }
예제 #2
0
 public SimpleException(Exception e)
 {
     ExceptionType = e.GetType().FullName;
     Message       = e.Message;
     StackTrace    = e.StackTrace;
     if (e.InnerException != null)
     {
         InnerException = new SimpleException(e.InnerException);
     }
 }
예제 #3
0
        public IronPythonResponse Run(IronPythonScript script)
        {
            object actual = null;
            SimpleException ex = null;
            MemoryStream outputStream = new MemoryStream();
            StringWriter outputWriter = new StringWriter();

            MemoryStream errorStream = new MemoryStream();
            StringWriter errorWriter = new StringWriter();

            try
            {
                var engine = Python.CreateEngine();

                if(SynchronizationContext.Current==null)
                    SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());

                AddAssemblyReferences(engine);
                engine.Runtime.IO.SetOutput(outputStream, outputWriter);
                engine.Runtime.IO.SetErrorOutput(errorStream, errorWriter);

                var scope = engine.CreateScope();
                scope.SetVariable("scenario", Scenario);

                if (ProjectHandler == null)
                {
                    ProjectHandler = ProjectManager.Instance.ProjectHandler;
                }
                scope.SetVariable("project_handler", ProjectHandler);
                var sourceCode = engine.CreateScriptSourceFromString(script.Script);
                actual = sourceCode.Execute<object>(scope);
                if (scope.ContainsVariable("result"))
                    actual = scope.GetVariable("result");
            }
            catch (Exception e)
            {
                ex = new SimpleException(e);
            }

            return new IronPythonResponse()
            {
                Response = AsKnownDataContract(actual),
                StandardError = errorWriter.ToString(),
                StandardOut = outputWriter.ToString(),
                Exception = ex
            };
        }