/// <summary> /// Creates a new language specific engine based upon the language specified /// </summary> /// <param name="language">The language that the engine should support</param> /// <returns></returns> protected VsaEngine CreateLanguageSpecificEngine(VsaScriptingLanguages language) { VsaEngine engine = null; switch (language) { //case VsaScriptingLanguages.VBScript: // use the vbscript engine provided in the assembly Microsoft.VisualBasic.Vsa.dll // engine = new Microsoft.VisualBasic.Vsa.VsaEngine(); // break; case VsaScriptingLanguages.JScript: // use the jscript engine provided in the assembly Microsoft.JScript.dll engine = new Microsoft.JScript.Vsa.VsaEngine(); break; default: // the language specified is not supported throw new VsaScriptingLanguageNotSupportedException(language); }; return engine; }
/// <summary> /// Selects the appropriate language based upon the file extension /// </summary> /// <param name="info"></param> /// <param name="language"></param> /// <returns></returns> public bool SelectLanguageBasedOnExtension(FileInfo info, out VsaScriptingLanguages language) { // default the language type to none language = VsaScriptingLanguages.None; if (string.Compare(info.Extension, @".js", true) == 0) { language = VsaScriptingLanguages.JScript; return true; } else if (string.Compare(info.Extension, @".vb", true) == 0) { language = VsaScriptingLanguages.VBScript; return true; } return false; }
/// <summary>a /// Initializes a new instance of the VsaScriptingHost class /// </summary> /// <param name="language">The language used by this scripting host</param> /// <param name="name">The name of the engine used by the scripting host</param> /// <param name="rootMoniker">The root moniker of the engine used by the scripting host</param> /// <param name="rootNamespace">The root namespace of the engine used by the scripting host</param> /// <param name="generateDebugInfo">A flag that indicates whether the engine should generate debugging information</param> public VsaScriptingHost(VsaScriptingLanguages language, string name, string rootMoniker, string rootNamespace, bool generateDebugInfo) { // create a new hashtable for storing global items so that we can look them up as needed _globalItemLookupTable = new Hashtable(); _language = language; // create an engine aligned to the language specified (currently only JScript and VBScript are supported) _engine = ((object)this.CreateLanguageSpecificEngine(language)) as IVsaEngine; _engine.RootMoniker = rootMoniker; SetEngine(_engine); SetUpEngine(name, rootMoniker, rootNamespace, generateDebugInfo); }
/// <summary> /// Initializes a new instance of the VsaScriptingLanguageNotSupportedException class /// </summary> /// <param name="language"></param> public VsaScriptingLanguageNotSupportedException(VsaScriptingLanguages language) : base(string.Format("The language '{0}' is not supported.", language.ToString())) { _language = language; }