/// <summary> /// Loads all script from a directory and optionally it's sub directorys /// </summary> /// <param name="scriptAssemblyType">Needs to inherit IScriptAssembly</param> /// <param name="getsubdirs">if true it will search sub directories</param> /// <param name="path">Path to scripts</param> /// <param name="error">returns the error if LoadScripts returns false</param> /// <returns>Returns true if no errors occured.</returns> public override bool LoadScripts(Type scriptAssemblyType, bool getsubdirs, string path, out string error) { error = string.Empty; if (scriptAssemblyType.GetInterface(typeof(IScriptAssembly).ToString()) == null) { error = scriptAssemblyType.ToString() + " does not implemented " + typeof(IScriptAssembly).ToString(); return(false); } DirectoryInfo dir; try { dir = new DirectoryInfo(path); } catch (ArgumentException e) { error = e.Message + " " + path; return(false); } if (dir.Exists == false) { return(true); } //string shortpath = path; string shortpath = dir.FullName; path = dir.FullName; if (getsubdirs) { if (!CheckPath(path, out error)) { return(false); } } else if (ScriptAssemblies.Contains(path)) { error = "There's already a script assembly on that path."; return(false); } IScriptAssembly asm = (IScriptAssembly)Activator.CreateInstance(scriptAssemblyType); int assemblies = 0; string[] assemblyfiles = GetFilesNoSub(shortpath, "*.dll"); foreach (string afile in assemblyfiles) { try { Assembly sassembly = Assembly.LoadFile(afile); asm.AddAssembly(sassembly); assemblies++; Console.WriteLine("SCRIPT: " + scriptAssemblyType.Name + " loaded the script assembly: " + afile); } catch (Exception e) { error = e.ToString(); return(false); } } //#region Old ScriptCode #if SUPPORT_CSHARP if (!AddAssembly(new Microsoft.CSharp.CSharpCodeProvider(), asm, shortpath, getsubdirs, out error)) { if (error != string.Empty) { return(false); } } else { assemblies++; } #endif #if SUPPORT_VB if (!AddAssembly(new Microsoft.VisualBasic.VBCodeProvider(), asm, shortpath, getsubdirs, out error)) { if (error != string.Empty) { return(false); } } else { assemblies++; } #endif #if SUPPORT_MCPP if (!AddAssembly(new Microsoft.MCpp.MCppCodeProvider(), asm, shortpath, getsubdirs, out error)) { if (error != string.Empty) { return(false); } } else { assemblies++; } #endif #if SUPPORT_VJSHARP if (!AddAssembly(new Microsoft.VJSharp.VJSharpCodeProvider(), asm, shortpath, getsubdirs, out error)) { if (error != string.Empty) { return(false); } } else { assemblies++; } #endif //#endregion if (assemblies > 0) { if (asm.Load(out error) == false) { return(false); } ScriptAssemblies[path] = asm; } return(true); }
/// <summary> /// Loads all script from a directory and optionally it's sub directorys /// </summary> /// <param name="scriptAssemblyType">Needs to inherit IScriptAssembly</param> /// <param name="getsubdirs">if true it will search sub directories</param> /// <param name="path">Path to scripts</param> /// <param name="error">returns the error if LoadScripts returns false</param> /// <returns>Returns true if no errors occured.</returns> public override bool LoadScripts(Type scriptAssemblyType, bool getsubdirs, string path, out string error) { error = string.Empty; if (scriptAssemblyType.GetInterface(typeof(IScriptAssembly).ToString()) == null) { error = scriptAssemblyType.ToString() + " does not implemented " + typeof(IScriptAssembly).ToString(); return(false); } DirectoryInfo dir; try { dir = new DirectoryInfo(path); } catch (ArgumentException e) { error = e.Message + " " + path; return(false); } if (dir.Exists == false) { return(true); } //string shortpath = path; string shortpath = dir.FullName; path = dir.FullName; if (getsubdirs) { if (!CheckPath(path, out error)) { return(false); } } else if (ScriptAssemblies.Contains(path)) { error = "There's already a script assembly on that path."; return(false); } IScriptAssembly asm = (IScriptAssembly)Activator.CreateInstance(scriptAssemblyType); int assemblies = 0; #if SUPPORT_CSHARP if (!AddAssembly(new Microsoft.CSharp.CSharpCodeProvider(), asm, shortpath, getsubdirs, out error)) { if (error != string.Empty) { return(false); } } else { assemblies++; } #endif #if SUPPORT_VB if (!AddAssembly(new Microsoft.VisualBasic.VBCodeProvider(), asm, shortpath, getsubdirs, out error)) { if (error != string.Empty) { return(false); } } else { assemblies++; } #endif #if SUPPORT_MCPP if (!AddAssembly(new Microsoft.MCpp.MCppCodeProvider(), asm, shortpath, getsubdirs, out error)) { if (error != string.Empty) { return(false); } } else { assemblies++; } #endif #if SUPPORT_VJSHARP if (!AddAssembly(new Microsoft.VJSharp.VJSharpCodeProvider(), asm, shortpath, getsubdirs, out error)) { if (error != string.Empty) { return(false); } } else { assemblies++; } #endif if (assemblies > 0) { if (asm.Load(out error) == false) { return(false); } ScriptAssemblies[path] = asm; } return(true); }