LoadFile() public method

public LoadFile ( String strFileName ) : ScriptObject
strFileName String
return ScriptObject
示例#1
0
 static void Main(string[] args)
 {
     Script script = new Script();
     Console.WriteLine("开始执行,当前版本:" + Script.Version);
     script.LoadLibrary();
     script.PushAssembly(typeof(Program).Assembly);
     if (Directory.Exists(CurrentDirectory + "/Library"))
     {
         string[] files = Directory.GetFiles(CurrentDirectory + "/Library", "*.dll", SearchOption.AllDirectories);
         foreach (var file in files)
         {
             try {
                 script.PushAssembly(Assembly.LoadFile(file));
                 Console.WriteLine("导入文件[" + file + "]成功");
             } catch (System.Exception ex) {
                 Console.WriteLine("导入文件[" + file + "]失败 " + ex.ToString());
             }
         }
     }
     if (Directory.Exists(CurrentDirectory + "/Program")) {
         try {
             script.PushAssembly(CompilerFile(CurrentDirectory + "/Program"));
         } catch (System.Exception ex) {
             Console.WriteLine("编译文件失败 " + ex.ToString());
         }
     }
     if (args.Length >= 1) {
         try {
             Stopwatch watch = Stopwatch.StartNew();
             if (!script.HasValue("searchpath"))
                 script.SetObject("searchpath", Path.GetDirectoryName(args[0]));
             Console.WriteLine("返回值为:" + script.LoadFile(args[0]));
             Console.WriteLine("运行时间:" + watch.ElapsedMilliseconds + " ms");
         } catch (System.Exception ex) {
             Console.WriteLine(script.GetStackInfo());
             Console.WriteLine(ex.ToString());
         }
         Console.ReadKey();
     } else {
         while (true)
         {
             try {
                 string str = Console.ReadLine();
                 if (str == "exit")  {
                     break;
                 } else if (str == "clear") {
                     Console.Clear();
                 } else if (str == "version") {
                     Console.WriteLine(Script.Version);
                 } else {
                     script.LoadString(str);
                 }
             } catch (System.Exception ex) {
                 Console.WriteLine(script.GetStackInfo());
                 Console.WriteLine(ex.ToString());
             }
         }
     }
 }
示例#2
0
        static void Main(string[] args) {
            script = new Script();
            Console.WriteLine("the current version : " + Script.Version);
            script.LoadLibrary();
            script.PushAssembly(typeof(Program).GetTypeInfo().Assembly);
#if !SCORPIO_NET_CORE
            string CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
#else
            string CurrentDirectory = "";
#endif
            LoadLibrary(Path.Combine(CurrentDirectory, "dll"));
            LoadFiles(Path.Combine(CurrentDirectory, "cs"));
            if (args.Length >= 1) {
                try {
                    string file = Path.GetFullPath(args[0]);
                    string path = Path.GetDirectoryName(file);
                    LoadLibrary(Path.Combine(path, "dll"));
                    LoadFiles(Path.Combine(path, "cs"));
                    Stopwatch watch = Stopwatch.StartNew();
                    script.PushSearchPath(CurrentDirectory);
                    script.PushSearchPath(path);
                    script.SetObject("__PATH__", path);
                    LibraryIO.Load(script);
                    Console.WriteLine("=============================");
                    ScriptObject value = script.LoadFile(file);
                    Console.WriteLine("=============================");
                    Console.WriteLine("return value : " + value);
                    Console.WriteLine("the execution time : " + watch.ElapsedMilliseconds + " ms");
                } catch (System.Exception ex) {
                    Console.WriteLine(script.GetStackInfo());
                    Console.WriteLine(ex.ToString());
                }
            } else {
                while (true) {
                    try {
                        string str = Console.ReadLine();
                        if (str == "exit")  { 
                            break;
                        } else if (str == "clear") {
                            Console.Clear();
                        } else if (str == "version") {
                            Console.WriteLine(Script.Version);
                        } else {
                            script.LoadString(str);
                        }
                    } catch (System.Exception ex) {
                        Console.WriteLine(script.GetStackInfo());
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
        }