예제 #1
0
        public static Dictionary <string, double> CalculateCommissions(string formula, int typeOfSale, string orderDate, double totalListPrice, double salePrice, double ytdSale, double totalEquipmentPrice, double totalToolingPrice, bool isXpert40orXactMachine)
        {
            var calculationEngine = new JintEngine();

            var functionCall = GetFunctionCall(typeOfSale, orderDate, totalListPrice, salePrice, ytdSale, totalEquipmentPrice, totalToolingPrice, isXpert40orXactMachine);

            Console.WriteLine(functionCall);

            calculationEngine.SetDebugMode(true).Run(formula);
            return((calculationEngine.Run(functionCall) as JsObject).ToDictionary(x => x.Key, x => x.Value.ToNumber()));
        }
예제 #2
0
        static void Main(string[] args)
        {
            JsGlobal   dummy;
            JintEngine eng  = new JintEngine();
            JsArray    root = null;


            root = new JsArray();
            eng.GlobalScope["PersistentRoot"] = root;


            eng.SetDebugMode(true);
            eng.SetFunction("log"
                            , new Jint.Delegates.Func <JsInstance, JsInstance>((JsInstance obj) =>
            {
                Console.WriteLine(obj == null?"NULL":obj.Value == null?"NULL 2":obj.Value.ToString());
                return(JsUndefined.Instance);
            }));


//            ((JsFunction)eng.GlobalScope["log"]).Execute(eng.Visitor, null, new JsInstance[] { new JsUndefined() });

            //   Console.WriteLine("\r\n" + eng.Run(File.ReadAllText(@"Scripts\func_jsonifier.js")));
            Console.WriteLine("\r\n" + eng.Run(File.ReadAllText(@"Scripts\test.js")));
            while (true)
            {
                Console.Write("] ");
                var l = Console.ReadLine();
                if (l.Length == 0)
                {
                    break;
                }
                var res = eng.Run(l);
                Console.WriteLine(res == null ? "<.NET NULL>" : res.ToString());
            }
            Console.WriteLine("Saving...");
            //            Console.ReadLine();
            //    root.Modify();
            //   s.Close();
            //    Console.Write("Enter to close");
            //  Console.ReadLine();
        }
예제 #3
0
 static public JintEngine Create()
 {
     if (jintEngine != null)
     {
         return(jintEngine);
     }
     jintEngine = new JintEngine()
                  .SetFunction("sleep", new Action <object>(Sleep))
                  .SetFunction("alert", new Action <object>(Alert))
                  .SetFunction("log", new Action <object>(logger.Info))
                  .SetFunction("error", new Action <object>(logger.Fatal))
                  .SetFunction("watchStart", new Jint.Delegates.Action(WatchStart))
                  .SetFunction("watchStop", new Action <string>(WatchStop))
                  .SetFunction("qq", new Jint.Delegates.Func <string>(qq))
                  .SetFunction("name", new Jint.Delegates.Func <string>(name))
                  .SetFunction("prompt", new Jint.Delegates.Func <string, string>(Prompt));
     jintEngine.DisableSecurity();
     jintEngine.SetDebugMode(true);
     return(jintEngine);
 }
예제 #4
0
파일: Program.cs 프로젝트: nate-yocom/jint
        static void Main(string[] args)
        {
            string line;
            var jint = new JintEngine();

            jint.SetFunction("print", new Action<object>(s => { Console.ForegroundColor = ConsoleColor.Blue; Console.Write(s); Console.ResetColor(); }));
            jint.SetFunction("import", new Action<string>(s => { Assembly.LoadWithPartialName(s); }));
            jint.Step =
                        (sender, information) =>
                        {
                            // Console.WriteLine("Step: {0} => {1}", information.CurrentStatement.Source, information.CurrentStatement.Source.Code);
                            return true;
                        };

            jint.SetDebugMode(true);
            jint.DisableSecurity();

            while (true) {
                Console.Write("jint > ");

                StringBuilder script = new StringBuilder();

                while (String.Empty != (line = Console.ReadLine())) {
                    if (line.Trim() == "exit") {
                        return;
                    }

                    if (line.Trim() == "reset") {
                        jint = new JintEngine();
                        break;
                    }

                    if (line.Trim() == "help" || line.Trim() == "?") {
                        Console.WriteLine(@"Jint Shell");
                        Console.WriteLine(@"");
                        Console.WriteLine(@"exit                - Quits the application");
                        Console.WriteLine(@"import(assembly)    - assembly: String containing the partial name of a .NET assembly to load");
                        Console.WriteLine(@"reset               - Initialize the current script");
                        Console.WriteLine(@"print(output)       - Prints the specified output to the console");
                        Console.WriteLine(@"");
                        break;
                    }

                    script.AppendLine(line);
                }

                Console.SetError(new StringWriter(new StringBuilder()));

                try
                {
                    jint.Run(script.ToString());
                }
                catch (Exception e) {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(e.Message);
                    Console.ResetColor();
                }

                Console.WriteLine();
            }
        }