本文整理汇总了C#中ScriptScope类的典型用法代码示例。如果您正苦于以下问题:C# ScriptScope类的具体用法?C# ScriptScope怎么用?C# ScriptScope使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ScriptScope类属于命名空间,在下文中一共展示了ScriptScope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartServer
/// <summary>
/// Publish objects so that the host can use it, and then block indefinitely (until the input stream is open).
///
/// Note that we should publish only one object, and then have other objects be accessible from it. Publishing
/// multiple objects can cause problems if the client does a call like "remoteProxy1(remoteProxy2)" as remoting
/// will not be able to know if the server object for both the proxies is on the same server.
/// </summary>
/// <param name="remoteRuntimeChannelName">The IPC channel that the remote console expects to use to communicate with the ScriptEngine</param>
/// <param name="scope">A intialized ScriptScope that is ready to start processing script commands</param>
internal static void StartServer(string remoteRuntimeChannelName, ScriptScope scope) {
Debug.Assert(ChannelServices.GetChannel(remoteRuntimeChannelName) == null);
IpcChannel channel = CreateChannel("ipc", remoteRuntimeChannelName);
LifetimeServices.LeaseTime = GetSevenDays();
LifetimeServices.LeaseManagerPollTime = GetSevenDays();
LifetimeServices.RenewOnCallTime = GetSevenDays();
LifetimeServices.SponsorshipTimeout = GetSevenDays();
ChannelServices.RegisterChannel(channel, false);
try {
RemoteCommandDispatcher remoteCommandDispatcher = new RemoteCommandDispatcher(scope);
RemotingServices.Marshal(remoteCommandDispatcher, CommandDispatcherUri);
// Let the remote console know that the startup output (if any) is complete. We use this instead of
// a named event as we want all the startup output to reach the remote console before it proceeds.
Console.WriteLine(RemoteCommandDispatcher.OutputCompleteMarker);
// Block on Console.In. This is used to determine when the host process exits, since ReadLine will return null then.
string input = System.Console.ReadLine();
Debug.Assert(input == null);
} finally {
ChannelServices.UnregisterChannel(channel);
}
}
示例2: Execute
public object Execute(CompiledCode compiledCode, ScriptScope scope) {
Debug.Assert(_executingThread == null);
_executingThread = Thread.CurrentThread;
try {
object result = compiledCode.Execute(scope);
Console.WriteLine(RemoteCommandDispatcher.OutputCompleteMarker);
return result;
} catch (ThreadAbortException tae) {
KeyboardInterruptException pki = tae.ExceptionState as KeyboardInterruptException;
if (pki != null) {
// Most exceptions get propagated back to the client. However, ThreadAbortException is handled
// differently by the remoting infrastructure, and gets wrapped in a RemotingException
// ("An error occurred while processing the request on the server"). So we filter it out
// and raise the KeyboardInterruptException
Thread.ResetAbort();
throw pki;
} else {
throw;
}
} finally {
_executingThread = null;
}
}
示例3: Execute
public override void Execute(ScriptEngine engine, ScriptScope scope)
{
if (!string.IsNullOrEmpty(Expression))
{
engine.Execute(Expression, scope);
}
}
示例4: SendMethodToModules
public static void SendMethodToModules(string methodName, ScriptScope scope)
{
var engine = scope.Engine;
var snippet = String.Format(RecompileSnippet, methodName);
var source = engine.CreateScriptSourceFromString(snippet, SourceCodeKind.Statements);
source.Execute(scope);
}
示例5: RenderView
private void RenderView(ScriptScope scope, ViewContext context, TextWriter writer)
{
scope.SetVariable("view_data", context.ViewData);
scope.SetVariable("model", context.ViewData.Model);
scope.SetVariable("context", context);
scope.SetVariable("response", context.HttpContext.Response);
scope.SetVariable("url", new RubyUrlHelper(context.RequestContext));
scope.SetVariable("html", new RubyHtmlHelper(context, new Container(context.ViewData)));
scope.SetVariable("ajax", new RubyAjaxHelper(context, new Container(context.ViewData)));
var script = new StringBuilder();
Template.ToScript("render_page", script);
if (_master != null)
_master.Template.ToScript("render_layout", script);
else
script.AppendLine("def render_layout; yield; end");
script.AppendLine("def view_data.method_missing(methodname); get_Item(methodname.to_s); end");
script.AppendLine("render_layout { |content| render_page }");
try
{
_rubyEngine.ExecuteScript(script.ToString(), scope);
}
catch (Exception e)
{
writer.Write(e.ToString());
}
}
示例6: PythonSingleLayer
public PythonSingleLayer(PythonScriptHost host, string code, string name)
{
Name = name;
Code = code;
Host = host;
string[] codeWithoutWhitespace = code.Split(new char[] { ' ', '\n' }, StringSplitOptions.RemoveEmptyEntries);
string alltokens = "";
foreach (string token in codeWithoutWhitespace)
{
alltokens += token;
}
_id = alltokens.GetHashCode().ToString();
_scope = host.CreateScriptSource(code, name);
if (_scope.ContainsVariable(_processannotations))
{
_processAnnotationsFunc = _scope.GetVariable(_processannotations);
}
if (_scope.ContainsVariable(_interpret))
{
_interpretFunc = _scope.GetVariable(_interpret);
}
}
示例7: 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();
}
示例8: PythonScriptReader
public PythonScriptReader()
{
_engine = Python.CreateEngine();
_escope = _engine.CreateScope();
var reader = new StreamReader(new FileStream(@"Scripts\Script.py", FileMode.Open, FileAccess.Read));
string scriptText = reader.ReadToEnd();
reader.Close();
_engine.Execute(scriptText, _escope);
if (!_escope.TryGetVariable("GeneratorFunc", out _randomGenerator))
{
MessageBox.Show("Error Occurred in Executing python script! - GeneratorFunc", "Error");
throw new Exception("Error Occurred in Executing python script!");
}
if (!_escope.TryGetVariable("userDefinedFunc", out _userDefinedMethod))
{
MessageBox.Show("Error Occurred in Executing python script! - userDefinedFunc", "Error");
throw new Exception("Error Occurred in Executing python script!");
}
if (!_escope.TryGetVariable("LifeSpanMapper", out _lifeTimeMapper))
{
MessageBox.Show("Error Occurred in Executing python script! - LifeSpanMapper", "Error");
throw new Exception("Error Occurred in Executing python script!");
}
if (!_escope.TryGetVariable("DelayMapper", out _delayTimeMapper))
{
MessageBox.Show("Error Occurred in Executing python script! - DelayMapper", "Error");
throw new Exception("Error Occurred in Executing python script!");
}
}
示例9: PythonLanguage
public PythonLanguage()
{
_scope = Python.CreateEngine().CreateScope();
_scope.Engine.Runtime.LoadAssembly(typeof(string).Assembly);
_scope.Engine.Runtime.LoadAssembly(typeof(Uri).Assembly);
_scope.Engine.Runtime.LoadAssembly(typeof(SPList).Assembly);
}
示例10: Engine
public Engine()
{
Dictionary<String,Object> options = new Dictionary<string,object>();
options["DivisionOptions"] = PythonDivisionOptions.New;
engine = Python.CreateEngine(options);
scope = engine.CreateScope();
}
示例11: InitialzeInterpreter
/// <summary>
/// 初始化解释器
/// </summary>
public void InitialzeInterpreter()
{
pythonEngine = Python.CreateEngine();
pythonScope = pythonEngine.CreateScope();
string initialString =
@"
import clr, sys
import System.Collections.Generic.List as List
clr.AddReference('Clover')
from Clover import *
# 获取CloverController的实例
clover = CloverController.GetInstance();
# 取出所有的函数指针
FindFacesByVertex = clover.FindFacesByVertex
GetVertex = clover.GetVertex
CutFaces = clover.AnimatedCutFaces
_CutFaces = clover.CutFaces
_RotateFaces = clover.RotateFaces
RotateFaces = clover.AnimatedRotateFaces
Undo = clover.Undo
Redo = clover.Redo
";
pythonEngine.Execute(initialString, pythonScope);
}
示例12: PyInterpretUtility
public PyInterpretUtility()
{
_engine = Python.CreateEngine();
_stdout = new MemoryStream();
_engine.Runtime.IO.SetOutput(_stdout, Encoding.ASCII);
_scope = null;
}
示例13: Load
public override void Load(string code = "")
{
Engine = IronPython.Hosting.Python.CreateEngine();
Scope = Engine.CreateScope();
Scope.SetVariable("Commands", chatCommands);
Scope.SetVariable("DataStore", DataStore.GetInstance());
Scope.SetVariable("Find", Find.GetInstance());
Scope.SetVariable("GlobalData", GlobalData);
Scope.SetVariable("Plugin", this);
Scope.SetVariable("Server", Pluton.Server.GetInstance());
Scope.SetVariable("ServerConsoleCommands", consoleCommands);
Scope.SetVariable("Util", Util.GetInstance());
Scope.SetVariable("Web", Web.GetInstance());
Scope.SetVariable("World", World.GetInstance());
try {
Engine.Execute(code, Scope);
Class = Engine.Operations.Invoke(Scope.GetVariable(Name));
Globals = Engine.Operations.GetMemberNames(Class);
object author = GetGlobalObject("__author__");
object about = GetGlobalObject("__about__");
object version = GetGlobalObject("__version__");
Author = author == null ? "" : author.ToString();
About = about == null ? "" : about.ToString();
Version = version == null ? "" : version.ToString();
State = PluginState.Loaded;
} catch (Exception ex) {
Logger.LogException(ex);
State = PluginState.FailedToLoad;
}
PluginLoader.GetInstance().OnPluginLoaded(this);
}
示例14: RubyHelper
public RubyHelper()
{
Scope = Engine.CreateScope();
Engine.SetSearchPaths
LoadRubyFiles();
}
示例15: EditorDocument
public EditorDocument(string input = "")
{
if (input == "")
{
Title = "Untitled";
SavedBefore = false;
}
else
{
Title = Path.GetFileName(input);
SavedBefore = true;
InputFile = input;
}
_ruby = Settings.RubyTemplate;
_scope = Settings.ScopeTemplate;
var editor = Settings.ScintillaTemplate;
if (input != "")
editor.Text = File.ReadAllText(input);
Content = new WindowsFormsHost
{
Child = editor
};
}