protected IMohidTask LoadScript(FileName script_file_path) { ScriptInfo si = scripts.Find(delegate(ScriptInfo info) { return info.ScriptFile.FullPath == script_file_path.FullPath; }); if (si != null) { si.Interface.Reset(); return si.Interface; } else { ScriptCompiler sc = new ScriptCompiler(); Assembly ass = sc.Compile(script_file_path); si = new ScriptInfo(); si.ScriptFile = script_file_path; si.Interface = (IMohidTask)sc.FindScriptInterface("IMohidTask", ass); return si.Interface; } }
protected IMohidTask LoadScript(FileName script_file_path) { ScriptInfo si = scripts.Find(delegate(ScriptInfo info) { return info.ScriptFile.FullPath == script_file_path.FullPath; }); if (si != null) { si.Interface.Reset(); return si.Interface; } else { ScriptCompiler sc = new ScriptCompiler(); Assembly ass; try { ass = sc.Compile(script_file_path); } catch (Exception ex) { throw new Exception("Error when trying to compile " + script_file_path.FullPath + ". The message returned was " + ex.Message); } si = new ScriptInfo(); si.ScriptFile = script_file_path; si.Interface = (IMohidTask)sc.FindScriptInterface("IMohidTask", ass); scripts.Add(si); return si.Interface; } }
protected IMohidSim LoadUserInterface(CmdArgs args) { try { FileName interfaceName; data.sim.PreProcessing = OnPreProcessing; if (args.HasParameter("script")) interfaceName = new FileName(args.Parameters["script"]); else return null; if (interfaceName.Extension.ToLower() == "dll") //it's a library { if (!args.HasParameter("class")) return null; string class_name = args.Parameter("class"); Assembly ass = Assembly.LoadFrom(interfaceName.FullPath); data.userInterface = (IMohidSim)Activator.CreateInstance(ass.GetType("Mohid." + class_name)); return data.userInterface; } else //it's a script { ScriptCompiler sc = new ScriptCompiler(); Assembly ass = sc.Compile(interfaceName); data.userInterface = (IMohidSim)sc.FindScriptInterface("IMohidSim", ass); return data.userInterface; } } catch (Exception ex) { throw new Exception("MohidRunEngine.LoadUserInterface", ex); } }