Beispiel #1
0
        public static void Main(string[] args)
        {
            try
            {
                var consoleOptions = new ConsoleOptions();
                if (!Parser.Default.ParseArguments(args, consoleOptions))
                {
                    throw new Exception("Invalid options specified");
                }
                var script = File.ReadAllText(consoleOptions.Script);
                var dir = Path.GetDirectoryName(consoleOptions.Script);
                var ax = new AxInterpreter(consoleOptions.Debug);

                if (consoleOptions.Debug) Console.WriteLine("axScript {0}", Assembly.GetExecutingAssembly().GetName().Version);
                if (consoleOptions.Timing)
                {
                    long elapsedTotal = 0;
                    var times = consoleOptions.Time;
                    while (times > 0)
                    {
                        var s = Stopwatch.StartNew();
                        ax.Run(script, dir);
                        s.Stop();
                        Console.ForegroundColor = ConsoleColor.Magenta;
                        Console.WriteLine("Elapsed MS: {0}", s.ElapsedMilliseconds);
                        Console.ForegroundColor = ConsoleColor.White;
                        elapsedTotal += s.ElapsedMilliseconds;
                        times--;
                    }
                    Console.ForegroundColor = ConsoleColor.Magenta;
                    Console.WriteLine("Average Elapsed MS: {0}", elapsedTotal/consoleOptions.Time);
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.ReadLine();
                }
                else
                {
                    ax = new AxInterpreter(consoleOptions.Debug);
                    ax.Run(script, dir);
                }
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                while (ex.InnerException != null) ex = ex.InnerException;
                Console.WriteLine("\n\n\nERROR RUNNING SCRIPT:\n\t{0}", ex.Message);

                throw ex;
            }
        }
Beispiel #2
0
        internal static void Load(AxInterpreter i, string p)
        {
            if (!p.EndsWith(".dll"))
            {
                p = p + ".dll";
            }

            if (i.Modules.Contains(p)) return;
            if (i.Debug)
            {
                Console.WriteLine("Loading Module: \"{0}\"", p);
            }
            i.Modules.Add(p);
            var fp = Path.GetFullPath(p);
            var a = Assembly.LoadFile(fp);
            foreach (var t in a.GetTypes())
            {
                foreach (var m in t.GetMethods())
                {
                    foreach (var attr in m.GetCustomAttributes(true))
                    {
                        var axFunctionMarker = attr as ExportAx;
                        if (axFunctionMarker != null)
                        {
                            if (i.Debug)
                            {
                                Console.Write("  Importing Function: '{0}'", axFunctionMarker.Name);
                                Console.CursorLeft = 50;
                                Console.WriteLine(axFunctionMarker.Description);
                            }
                            i.RegisterFunction(axFunctionMarker.Name, new NetFunction(m));
                        }
                        var axHookMarker = attr as HookAx;
                        if (axHookMarker == null) continue;
                        if (i.Debug)
                        {
                            Console.Write("  Importing Hook Tag: '{0}'", axHookMarker.Tag);
                            Console.CursorLeft = 50;
                            Console.WriteLine(axHookMarker.Description);
                        }
                        i.RegisterHook(axHookMarker.Tag, new NetFunction(m));
                    }
                }

                foreach (var prop in t.GetProperties())
                {
                    foreach (var axFunctionMarker in prop.GetCustomAttributes(true).OfType<ExportAx>())
                    {
                        if (i.Debug)
                        {
                            Console.Write("  Importing Property [ReadOnly]: '{0}'", axFunctionMarker.Name);
                            Console.CursorLeft = 50;
                            Console.WriteLine(axFunctionMarker.Description);
                        }
                        i.RegisterFunction(axFunctionMarker.Name, new NetFunction(prop.GetGetMethod()));
                    }
                }

                foreach (var field in t.GetFields())
                {
                    foreach (var axFunctionMarker in field.GetCustomAttributes(true).OfType<ExportAx>())
                    {
                        if (i.Debug)
                        {
                            Console.Write("  Importing Field: '{0}'", axFunctionMarker.Name);
                            Console.CursorLeft = 50;
                            Console.WriteLine(axFunctionMarker.Description);
                        }
                        i.Variables.Add(axFunctionMarker.Name, field.GetValue(null));
                    }
                }
            }
        }
Beispiel #3
0
 public static void InitExitHandler(AxInterpreter ax, AxFunction func)
 {
     ax.ScriptError += exception => func.Call<Boolean>(ax, new object[] {EXIT_CODE_ERROR, exception});
     ax.ScriptEnd += exception => func.Call<Boolean>(ax, new object[] { EXIT_CODE_CLEAN, exception });
 }