|
using System;
using SynapticEffect.Forms;
namespace vsedebug
{
public class Script
{
/*
* The script host object that will do all our processing for us
*/
private Scripting.VsaScriptHost scripthost;
System.Reflection.Assembly builtassembly;
System.Reflection.MethodInfo IsSupportedTypeFunc;
System.Reflection.MethodInfo EvaluateTypeFunc;
public Script()
{
}
public Script(string lines)
{
LoadScript(lines);
}
/*
* Loads the script into memory given the text of the source and compiles it
*/
public bool LoadScript(String text)
{
scripthost = new Scripting.VsaScriptHost("JScript.NET", "vsedebug://scripts/", "vsedebug");
scripthost.scriptSrc = text;
//the references that are mine need paths
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(
"Software\\Microsoft\\VisualStudio\\7.0\\AddIns\\vsedebug.Connect");
if(key == null)
{
return false;
}
string basepath = (string)key.GetValue("SatelliteDLLPath");
//add a reference to EnvDTE
scripthost.AddReference("mscorlib", "mscorlib.dll");
//add a reference to EnvDTE
scripthost.AddReference("EnvDTE", "envdte.dll");
//add a reference to our very own vsedebug dll
scripthost.AddReference("vsedebug", basepath + "vsedebug.dll");
//add a reference to the synaptic effect stuff
scripthost.AddReference("SynapticEffect.Forms", basepath + "SynapticEffect.Forms.dll");
scripthost.AddReference("System.Windows.Forms", "System.Windows.Forms.dll");
//now, we need to attempt to compile it
try
{
scripthost.Compile();
}
catch
{
return false;
}
System.Type type;
builtassembly = scripthost.CompiledAssembly;
try
{
type = builtassembly.GetType("vsedebug.parser", true, true);
}
catch
{
return false;
}
IsSupportedTypeFunc = type.GetMethod("IsSupportedTypeFunc");
if(IsSupportedTypeFunc == null)
{
return false;
}
EvaluateTypeFunc = type.GetMethod("EvaluateType");
if(EvaluateTypeFunc == null)
{
return false;
}
return true;
}
/*
* This function returns whether the current script supports the type that is being queried for
*/
public bool ScriptSupportsType(String typename)
{
object[] parameters = {typename};
bool returnvalue = false;
if(IsSupportedTypeFunc == null)
{
return false;
}
try
{
returnvalue = (bool)IsSupportedTypeFunc.Invoke(null, parameters);
}
catch
{
returnvalue = false;
}
return returnvalue;
}
/*
* This function calls the script for the current type. Returns true if the script could be run and if the script returns true
*/
public TreeListNode EvaluateType(String currentexpression,
String currenttype,
String correctname,
TreeListNode parentnode,
TreeListNode currentnode,/*current node in the sense that we can replace the data of this node with other data*/
VSEDebugEvaluator.EvaluateAction action,
EnvDTE.Debugger debugger/*The debugger object for convience purposes*/)
{
object[] parameters = {currentexpression,
currenttype,
correctname,
parentnode,
currentnode,
action,
debugger};
TreeListNode returnvalue = null;
if(EvaluateTypeFunc == null)
{
return null;
}
try
{
returnvalue = (TreeListNode)EvaluateTypeFunc.Invoke(null, parameters);
}
catch
{
returnvalue = null;
}
return returnvalue;
}
}
/*
* The VSEDebugScript class wraps around the script host and does the loading and compiling of available scripts on the system,
* as well as providing information about what each script does
*/
public class VSEDebugScript
{
System.Collections.ArrayList Scripts;
public VSEDebugScript()
{
Scripts = new System.Collections.ArrayList();
LoadAllScripts();
}
/*
* Loads all the scripts into memory and compiles them, returns false if something goes wrong
*/
private bool LoadAllScripts()
{
//first we need to load the key for the directory that the add-in is installed in
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(
"Software\\Microsoft\\VisualStudio\\7.0\\AddIns\\vsedebug.Connect");
if(key == null)
{
return false;
}
string basepath = (string)key.GetValue("SatelliteDLLPath");
//now we need to open the scripts directory that is located inside this dir
if(!basepath.EndsWith("\\"))
{
basepath += "\\";
}
basepath += "scripts\\";
//now attempt to open this directory
if(!System.IO.Directory.Exists(basepath))
{
return false;
}
System.IO.DirectoryInfo scriptsdir = new System.IO.DirectoryInfo(basepath);
System.IO.FileInfo[] files = scriptsdir.GetFiles("*.vsedebug");
//now go through each file and build a script info
Script curscript;
foreach (System.IO.FileInfo curfile in files)
{
curscript = BuildScriptInfo(curfile.FullName);
if(curscript == null)
{
//don't close, just attempt to load the next script
continue;
}
Scripts.Add(curscript);
}
return true;
}
/*
* Grabs the script source and builds a script engine out of it, and compiles it
*/
private Script BuildScriptInfo(String filename)
{
String alllines;
System.IO.StreamReader filereader = new System.IO.StreamReader(filename);
alllines = filereader.ReadToEnd();
Script newscript = new Script();
if(!newscript.LoadScript(alllines))
{
System.Windows.Forms.MessageBox.Show("Error occured in file: " + filename);
return null;
}
return newscript;
}
/*
* Returns the Script object that can support the given type, null otherwise
*/
public Script GetTypeScript(String typename)
{
foreach(Script s in Scripts)
{
if(s.ScriptSupportsType(typename))
{
return s;
}
}
return null;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
I'm a student at the University of Florida studying computer engineering.
You may find additional information about vsedebug at http://vsedebug.sourceforge.net