本文整理汇总了C#中Microsoft.JScript.Vsa.VsaEngine.GetGlobalScope方法的典型用法代码示例。如果您正苦于以下问题:C# VsaEngine.GetGlobalScope方法的具体用法?C# VsaEngine.GetGlobalScope怎么用?C# VsaEngine.GetGlobalScope使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.JScript.Vsa.VsaEngine
的用法示例。
在下文中一共展示了VsaEngine.GetGlobalScope方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PartialTrustEvaluationStrategy
public PartialTrustEvaluationStrategy(string expression, VsaEngine engine)
: base(engine)
{
//
// Following is equivalent to declaring a "var" in JScript
// at the level of the Global object.
//
_scope = (GlobalScope)engine.GetGlobalScope().GetObject();
_contextField = _scope.AddField("$context");
_expression = expression;
}
示例2: CreateEngineForDebugger
internal static VsaEngine CreateEngineForDebugger(){
VsaEngine engine = new VsaEngine(true);
engine.InitVsaEngine("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa", new DefaultVsaSite());
GlobalScope scope = (GlobalScope)engine.GetGlobalScope().GetObject();
scope.globalObject = engine.Globals.globalObject;
return engine;
}
示例3: CreateEngineWithType
// This factory method is called by DLL code only
public static VsaEngine CreateEngineWithType(RuntimeTypeHandle callingTypeHandle){
Type callingType = Type.GetTypeFromHandle(callingTypeHandle);
Assembly callingAssembly = callingType.Assembly;
Object o = System.Runtime.Remoting.Messaging.CallContext.GetData("JScript:" + callingAssembly.FullName);
if (o != null){
VsaEngine e = o as VsaEngine;
if (e != null)
return e;
}
VsaEngine engine = new VsaEngine(callingAssembly);
engine.InitVsaEngine("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa", new DefaultVsaSite());
GlobalScope scope = (GlobalScope)engine.GetGlobalScope().GetObject();
scope.globalObject = engine.Globals.globalObject;
// for every global class generated in this assembly make an instance and call the global code method
int i = 0;
Type globalClassType = null;
do{
String globalClassName = "JScript " + i.ToString();
globalClassType = callingAssembly.GetType(globalClassName, false);
if (globalClassType != null){
engine.SetEnclosingContext(new WrappedNamespace("", engine));
ConstructorInfo globalScopeConstructor = globalClassType.GetConstructor(new Type[]{typeof(GlobalScope)});
MethodInfo globalCode = globalClassType.GetMethod("Global Code");
Object globalClassInstance = globalScopeConstructor.Invoke(new Object[]{scope});
globalCode.Invoke(globalClassInstance, new Object[0]);
}
i++;
}while (globalClassType != null);
if (o == null)
System.Runtime.Remoting.Messaging.CallContext.SetData("JScript:" + callingAssembly.FullName, engine);
return engine;
}
示例4: CreateEngineAndGetGlobalScope
public static GlobalScope CreateEngineAndGetGlobalScope(bool fast, String[] assemblyNames){
VsaEngine engine = new VsaEngine(fast);
engine.InitVsaEngine("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa", new DefaultVsaSite());
engine.doPrint = true;
engine.SetEnclosingContext(new WrappedNamespace("", engine));
foreach (String assemblyName in assemblyNames){
VsaReference r = (VsaReference)engine.vsaItems.CreateItem(assemblyName, VsaItemType.Reference, VsaItemFlag.None);
r.AssemblyName = assemblyName;
}
VsaEngine.exeEngine = engine;
GlobalScope scope = (GlobalScope)engine.GetGlobalScope().GetObject();
scope.globalObject = engine.Globals.globalObject;
return scope;
}
示例5: CreateEngineAndGetGlobalScopeWithType
public static GlobalScope CreateEngineAndGetGlobalScopeWithType(bool fast, String[] assemblyNames, RuntimeTypeHandle callingTypeHandle){
VsaEngine engine = new VsaEngine(fast);
engine.InitVsaEngine("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa", new DefaultVsaSite());
engine.doPrint = true;
engine.SetEnclosingContext(new WrappedNamespace("", engine));
foreach (String assemblyName in assemblyNames){
VsaReference r = (VsaReference)engine.vsaItems.CreateItem(assemblyName, VsaItemType.Reference, VsaItemFlag.None);
r.AssemblyName = assemblyName;
}
// Put the engine in the CallContext so that calls to CreateEngineWithType will return this engine
Type callingType = Type.GetTypeFromHandle(callingTypeHandle);
Assembly callingAssembly = callingType.Assembly;
System.Runtime.Remoting.Messaging.CallContext.SetData("JScript:" + callingAssembly.FullName, engine);
// Get and return the global scope
GlobalScope scope = (GlobalScope)engine.GetGlobalScope().GetObject();
scope.globalObject = engine.Globals.globalObject;
return scope;
}
示例6: CreateEngineWithType
// This factory method is called by DLL code only
public static VsaEngine CreateEngineWithType(RuntimeTypeHandle callingTypeHandle){
Type callingType = Type.GetTypeFromHandle(callingTypeHandle);
Assembly callingAssembly = callingType.Assembly;
Object o = System.Runtime.Remoting.Messaging.CallContext.GetData("JScript:" + callingAssembly.FullName);
if (o != null){
VsaEngine e = o as VsaEngine;
if (e != null)
return e;
}
VsaEngine engine = new VsaEngine(callingAssembly);
engine.InitVsaEngine("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa", new DefaultVsaSite());
GlobalScope scope = (GlobalScope)engine.GetGlobalScope().GetObject();
scope.globalObject = engine.Globals.globalObject;
// for every global class generated in this assembly make an instance and call the global code method
int i = 0;
Type globalClassType = null;
do{
String globalClassName = "JScript " + i.ToString(CultureInfo.InvariantCulture);
globalClassType = callingAssembly.GetType(globalClassName, false);
if (globalClassType != null){
engine.SetEnclosingContext(new WrappedNamespace("", engine));
ConstructorInfo globalScopeConstructor = globalClassType.GetConstructor(new Type[]{typeof(GlobalScope)});
MethodInfo globalCode = globalClassType.GetMethod("Global Code");
try{
Object globalClassInstance = globalScopeConstructor.Invoke(new Object[]{scope});
globalCode.Invoke(globalClassInstance, new Object[0]);
}catch(SecurityException){
// [stesty] Due to bug 337909, if a JScript assembly is strongly-named but partially-trusted, it will
// not succeed here unless it also has the AllowPartiallyTrustedCallersAttribute. We do not
// want to run this constructor with elevated permissions, so we work around by abandoning
// the attempt, thus disabling eval in this scenario.
break;
}
}
i++;
}while (globalClassType != null);
if (o == null)
System.Runtime.Remoting.Messaging.CallContext.SetData("JScript:" + callingAssembly.FullName, engine);
return engine;
}
示例7: CreateEngineAndGetGlobalScope
public static GlobalScope CreateEngineAndGetGlobalScope (bool fast, string [] assembly_names)
{
int i, n;
GlobalScope scope;
VsaEngine engine = new VsaEngine (fast);
engine.InitVsaEngine ("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa",
new DefaultVsaSite ());
n = assembly_names.Length;
for (i = 0; i < n; i++) {
string assembly_name = assembly_names [i];
VsaReferenceItem r = (VsaReferenceItem) engine.Items.CreateItem (assembly_name,
VsaItemType.Reference,
VsaItemFlag.None);
r.AssemblyName = assembly_name;
}
scope = (GlobalScope) engine.GetGlobalScope ().GetObject ();
return scope;
}
示例8: CreateEngineWithType
public static VsaEngine CreateEngineWithType(RuntimeTypeHandle callingTypeHandle)
{
Assembly runtimeAssembly = Type.GetTypeFromHandle(callingTypeHandle).Assembly;
object data = System.Runtime.Remoting.Messaging.CallContext.GetData("JScript:" + runtimeAssembly.FullName);
if (data != null)
{
VsaEngine engine = data as VsaEngine;
if (engine != null)
{
return engine;
}
}
VsaEngine engine2 = new VsaEngine(runtimeAssembly);
engine2.InitVsaEngine("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa", new DefaultVsaSite());
GlobalScope scope = (GlobalScope) engine2.GetGlobalScope().GetObject();
scope.globalObject = engine2.Globals.globalObject;
int num = 0;
Type type = null;
do
{
string name = "JScript " + num.ToString(CultureInfo.InvariantCulture);
type = runtimeAssembly.GetType(name, false);
if (type != null)
{
engine2.SetEnclosingContext(new WrappedNamespace("", engine2));
ConstructorInfo constructor = type.GetConstructor(new Type[] { typeof(GlobalScope) });
MethodInfo method = type.GetMethod("Global Code");
try
{
object obj3 = constructor.Invoke(new object[] { scope });
method.Invoke(obj3, new object[0]);
}
catch (SecurityException)
{
break;
}
}
num++;
}
while (type != null);
if (data == null)
{
System.Runtime.Remoting.Messaging.CallContext.SetData("JScript:" + runtimeAssembly.FullName, engine2);
}
return engine2;
}
示例9: CreateEngineAndGetGlobalScopeWithTypeAndRootNamespace
public static GlobalScope CreateEngineAndGetGlobalScopeWithTypeAndRootNamespace(bool fast, string[] assemblyNames, RuntimeTypeHandle callingTypeHandle, string rootNamespace)
{
VsaEngine engine = new VsaEngine(fast);
engine.InitVsaEngine("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa", new DefaultVsaSite());
engine.doPrint = true;
engine.SetEnclosingContext(new WrappedNamespace("", engine));
if (rootNamespace != null)
{
engine.SetEnclosingContext(new WrappedNamespace(rootNamespace, engine));
}
foreach (string str in assemblyNames)
{
VsaReference reference = (VsaReference) engine.vsaItems.CreateItem(str, JSVsaItemType.Reference, JSVsaItemFlag.None);
reference.AssemblyName = str;
}
Assembly assembly = Type.GetTypeFromHandle(callingTypeHandle).Assembly;
System.Runtime.Remoting.Messaging.CallContext.SetData("JScript:" + assembly.FullName, engine);
GlobalScope scope = (GlobalScope) engine.GetGlobalScope().GetObject();
scope.globalObject = engine.Globals.globalObject;
return scope;
}
示例10: Evaluator
public Evaluator(Evaluator theEvaluator)
{
ICodeCompiler compiler;
compiler = new JScriptCodeProvider().CreateCompiler();
CompilerParameters parameters;
parameters = new CompilerParameters();
parameters.GenerateInMemory = true;
CompilerResults results;
results = compiler.CompileAssemblyFromSource(parameters, _jscriptSource);
Assembly assembly = results.CompiledAssembly;
_evaluatorType = assembly.GetType("EvaluatorNS.Evaluator");
//_evaluatorCtxType = assembly.GetType("Evaluator.Context");
_evaluator = Activator.CreateInstance(_evaluatorType);
// create a new form instance
// _scriptableForm = new ScriptableForm();
// create a new set of hosts
lock (hosts)
{
string rootMoniker = string.Format("{0}://{1}", rootHostName, Guid.NewGuid().ToString());
_host = new VsaScriptingHost(VsaScriptingLanguages.JScript, "Evaluator", rootMoniker,
_evaluatorType.Namespace, true);
Engine = (VsaEngine)(object)_host.Engine;
globalScope = Engine.GetGlobalScope();
thisGlobalObj = Microsoft.JScript.Eval.JScriptEvaluate("this;", Engine) as GlobalScope;
hosts.Add(_host);
_host.AddType(typeof(System.Object));
_host.AddType(typeof(System.String));
AddGlobalItem("$engine", Engine);
AddGlobalItem("$superE", theEvaluator);
// hosts.AddRange(HostFactory.Create(@"MyScriptingHost", @"Scripting", true, Environment.CurrentDirectory));
}
// wire up to the events of each host
foreach (VsaScriptingHost host in hosts)
{
host.AssemblyReferencesNeeded += new ScriptingHostEventHandler(OnAssemblyReferencesNeeded);
host.CompilerException += new ScriptingHostCompilerExceptionEventHandler(OnCompilerException);
host.GlobalItemsNeeded += new ScriptingHostEventHandler(OnGlobalItemsNeeded);
}
// execute the hosts
foreach (VsaScriptingHost host in hosts)
host.Execute();
// show the form
//_scriptableForm.ShowDialog();
}