本文整理汇总了C#中ScriptEngine.GetService方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptEngine.GetService方法的具体用法?C# ScriptEngine.GetService怎么用?C# ScriptEngine.GetService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScriptEngine
的用法示例。
在下文中一共展示了ScriptEngine.GetService方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
private void Parse(ScriptEngine engine, Exception exc)
{
var service = engine.GetService<Microsoft.Scripting.Hosting.ExceptionOperations>();
string briefMessage;
string errorTypeName;
service.GetExceptionMessage(exc, out briefMessage, out errorTypeName);
var formattedMessage = service.FormatException(exc);
/*
var stackFrames = service.GetStackFrames(exc);
var ctxt = Microsoft.Scripting.Hosting.Providers.HostingHelpers.GetLanguageContext(engine);
var sink = ctxt.GetCompilerErrorSink();
var rubyContext = (IronRuby.Runtime.RubyContext)ctxt;
RubyExceptionData data = RubyExceptionData.GetInstance(exc);
IronRuby.Builtins.RubyArray backtrace = data.Backtrace;
var s = 12;
*/
switch (errorTypeName)
{
case "TypeInitializationException":
MessageType = "Sorry - Iron7 is unable to use dynamic ruby delegates";
break;
default:
MessageType = errorTypeName;
break;
}
MessageBrief = briefMessage;
var lines = formattedMessage.Replace("\r","").Split('\n');
AttemptParseLineNumber(lines);
CaptureRelevantStack(lines);
}
示例2: Main
/// <summary>
/// Main method
/// </summary>
/// <param name="args">Command line args.</param>
public static void Main(string[] args)
{
engine = Python.CreateEngine();
scope = engine.CreateScope();
engine.Runtime.LoadAssembly(typeof(TurntableBot).Assembly);
engine.Runtime.LoadAssembly(typeof(JObject).Assembly);
engine.Runtime.IO.RedirectToConsole();
ScriptSource source = null;
if (File.Exists(Script))
{
source = engine.CreateScriptSourceFromFile(Script);
}
else
{
Console.WriteLine("File not found");
}
if (source != null)
{
try
{
source.Execute(scope);
}
catch (Exception e)
{
ExceptionOperations ops = engine.GetService<ExceptionOperations>();
Console.WriteLine(ops.FormatException(e));
}
}
Console.ReadLine();
}
示例3: DlrClassifier
internal DlrClassifier(DlrClassifierProvider provider, ScriptEngine engine, ITextBuffer buffer)
{
buffer.Changed += BufferChanged;
buffer.ContentTypeChanged += BufferContentTypeChanged;
_tokenCache = new TokenCache();
_categorizer = engine.GetService<TokenCategorizer>();
_engine = engine;
_provider = provider;
_buffer = buffer;
}
示例4: RunRawCode
public void RunRawCode(InputImage[] images, string rawCode)
{
string pythonCode = this.GetFunctionCode(rawCode);
dynamic scope = engine.CreateScope();
try
{
engine.Execute(pythonCode, scope);
}
catch (SyntaxErrorException ex)
{
engine = null;
scope = null;
ExceptionOperations eo = engine.GetService<ExceptionOperations>();
MessageBox.Show(eo.FormatException(ex));
}
if (engine == null || scope == null)
{
throw new Exception("Cannot create Python engine!");
}
ImageExtensions.SaveAction = saveCallback;
foreach (var inputImage in images)
{
Image imageCopy = new Image(inputImage.SourceImage);
try
{
scope.ProcessImage(imageCopy);
}
catch (Exception ex)
{
throw new Exception("Error processing " + inputImage.SourceImage.Filename + ": " + ex.Message);
}
}
}
示例5: Execute
private string Execute(ScriptEngine engine, ScriptScope scope, string script)
{
stdout = new MemoryStream();
stdoutwriter = new StreamWriter(stdout);
stdoutreader = new StreamReader(stdout);
engine.Runtime.IO.SetOutput(stdout, stdoutwriter);
try
{
m_Core.Renderer.SetExceptionCatching(true);
dynamic ret = engine.CreateScriptSourceFromString(script).Execute(scope);
m_Core.Renderer.SetExceptionCatching(false);
if (ret != null)
{
stdoutwriter.Write(ret.ToString() + Environment.NewLine);
stdoutwriter.Flush();
}
}
catch (Exception ex)
{
m_Core.Renderer.SetExceptionCatching(false);
// IronPython throws so many exceptions, we don't want to kill the application
// so we just swallow Exception to cover all the bases
string exstr = engine.GetService<ExceptionOperations>().FormatException(ex);
stdoutwriter.Write(exstr);
stdoutwriter.Write(Environment.NewLine);
stdoutwriter.Flush();
}
stdout.Seek(0, SeekOrigin.Begin);
string output = stdoutreader.ReadToEnd();
stdoutreader.Dispose();
stdout = null;
stdoutreader = null;
stdoutwriter = null;
return output;
}
示例6: UnhandledException
protected virtual void UnhandledException(ScriptEngine engine, Exception e) {
Console.Error.Write("Unhandled exception");
Console.Error.WriteLine(':');
ExceptionOperations es = engine.GetService<ExceptionOperations>();
Console.Error.WriteLine(es.FormatException(e));
}
示例7: TestCategorizer
public void TestCategorizer(ScriptEngine engine, string src, int charCount, params TokenInfo[] expected) {
if (charCount == -1) charCount = src.Length;
TokenCategorizer categorizer = engine.GetService<TokenCategorizer>();
categorizer.Initialize(null, engine.CreateScriptSourceFromString(src), SourceLocation.MinValue);
IEnumerable<TokenInfo> actual = categorizer.ReadTokens(charCount);
int i = 0;
foreach (TokenInfo info in actual) {
Assert(i < expected.Length);
if (!info.Equals(expected[i])) {
Assert(false);
}
i++;
}
Assert(i == expected.Length);
}
示例8: MacroScriptEngine
internal MacroScriptEngine(string scriptType)
{
loadRunTime();
m_engine = m_runTime.GetEngine(scriptType);
m_exceptionOperations = m_engine.GetService<ExceptionOperations>();
}
示例9: GetPythonService
private static PythonService/*!*/ GetPythonService(ScriptEngine/*!*/ engine) {
return engine.GetService<PythonService>(engine);
}
示例10: ProcessRuntimeException
internal static bool ProcessRuntimeException(ScriptEngine engine, Exception e, string defaultVirtualPath, int lineOffset)
{
var frames = engine.GetService<ExceptionOperations>().GetStackFrames(e);
if (frames.Count == 0)
return false;
DynamicStackFrame frame = frames[0];
int line = frame.GetFileLineNumber();
// Get the physical path of the file where the exception occured, and attempt to get a
// virtual path from it
string physicalPath = frame.GetFileName();
string virtualPath = Misc.GetVirtualPathFromPhysicalPath(physicalPath);
// If we couldn't get one, use the passed in one, and adjust the line number
if (virtualPath == null) {
virtualPath = defaultVirtualPath;
line += lineOffset;
}
Misc.ThrowException(e.Message, e, virtualPath, line);
return true;
}