This is what I have been doing:
string[] commonNamespaces =
{
"System",
"System.Collections",
"System.ComponentModel",
"System.Data",
"System.Drawing",
"System.Windows.Forms",
"System.Xml",
"Ico.Gwx"
//"System.Drawing.Drawing2D",
//"System.Drawing.Imaging",
//"System.Globalization",
//"System.IO",
//"System.Reflection",
//"System.Text",
//"System.Text.RegularExpressions",
//"System.Threading"
};
string[] commonAssemblies =
{
"mscorlib",
"System",
"System.Data",
"System.Drawing",
"System.Windows.Forms",
"System.Xml",
"GwxRuntimeCore",
"GwxRuntimeCoreCommands",
"GwxRuntimeViewControl",
"GwxConfigCore"
};
private Microsoft.JScript.GlobalScope jscriptGlobalScope = null;
private void UninitializeJScriptDotNetEngine()
{
if (jscriptGlobalScope != null)
jscriptGlobalScope.engine.Close();
jscriptGlobalScope = null;
}
private void InitializeJScriptDotNetEngine()
{
if (jscriptGlobalScope == null)
{
try
{
jscriptGlobalScope =
Microsoft.JScript.Vsa.VsaEngine.CreateEngineAndGetGlobalScope(false,
commonAssemblies);
}
catch {}
foreach (string ns in commonNamespaces)
{
try
{
if ((ns != null) && (ns != String.Empty))
Microsoft.JScript.Import.JScriptImport(ns, jscriptGlobalScope.engine);
}
catch {}
}
}
}
After initializing the engine you can call
Object retVal=Microsoft.JScript.Eval.JScriptEvaluate(jscriptCode, "unsafe",
jscriptGlobalScope.engine);
it will evaluate your code using the assembly and namespaces that you
declared
[quoted text, click to view] "bruce barker" <nospam_brubar@safeco.com> wrote in message
news:OuFTbaj1EHA.1144@TK2MSFTNGP09.phx.gbl...
> the vsa engine has an Items (IVsaItems) collections, to which you can add
> references.
>
> -- bruce (sqlwork.com)
>
>
> "Kolo San" <write2kolo@hotmail.com> wrote in message
> news:ShWpd.7690$3U4.233365@news02.tsnz.net...
> | Hi,
> |
> | I am trying to add a JScript Evaluation to a Page Template parser in C#
> for
> | a CMS port from ASP that I am doing. VBscript (for ASP) has an Eval
> | function which we have used to allow some measure of scripting within
page
> | templates (allowing some of our other developers to extend our pages
> without
> | playing with the base scripts).
> |
> | The Evaluation works in C# for actual JScript.Net classes (like Math,
etc)
> | but I am having problems loading (or referencing) Net Managed assemblies
> | (like System, or classes which we have created) into the script engine.
> |
> | The somewhat prototypical code I am using for this is (in a Parse.dll
> | assembly which the aspx page 'uses'):
> |
> | <code>
> |
> | Microsoft.JScript.Vsa.VsaEngine scriptEngine =
> | Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
> | try{
> | // Ok, now evaluate the expression using the script file where
necessary.
> | result = Microsoft.JScript.Eval.JScriptEvaluate(fullscriptfile,
> | scriptEngine).ToString();
> | }catch(Exception ex){
> | result = ex.ToString();
> | }
> | return result;
> |
> | </code>
> |
> | where the script file is loaded into the string 'fullscriptfile'.
> |
> | Is there any way I can add C# assemblies into the scriptEngine before
> | Evaluating.
> |
> | I tried the Microsoft.JScript.Import(name, Engine) method but I cant
find
> | any information on what string it requires for the 'name' parameter...is
> it
> | the assembly name, path to the dll or something else (I have tried both
> | these options without success)? Could it be a security issue?
> |
> | Hoping someone can help as there is not a lot on the Net or MSDN about
> this.
> |
> | Mark
> |
> |
>
>