Beispiel #1
0
        public bool DynamicExpressoCompiled(Parameter parameter)
        {
            DynamicExpresso.Interpreter interpreter = new DynamicExpresso.Interpreter();

            Func <int, int> @delegate = interpreter.ParseAsDelegate <Func <int, int> >(EXPRESSION, "n");

            List <int> results = new List <int>(parameter.Numbers.Length);

            foreach (int number in parameter.Numbers)
            {
                int result = @delegate.Invoke(number);

                results.Add(result);
            }

            return(Assert(results, parameter.Sum));
        }
Beispiel #2
0
        public async Task Execute(IJobExecutionContext context)
        {
            try
            {
                //ILoggerRepository repository = LogManager.CreateRepository("TestJob");
                //XmlConfigurator.Configure(repository, new FileInfo("log4net.config"));
                //ILog log = LogManager.GetLogger(repository.Name, "TestJob");
                var methodName = System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.FullName;
                logger.Info("InfoInfoInfoInfoInfoInfoInfoInfoInfoInfoInfoInfoInfo");
                logger.Warn("WarnWarnWarnWarnWarnWarnWarnWarnWarnWarnWarnWarnWarnWarnWarn");
                logger.Error("ErrorErrorErrorErrorErrorErrorErrorErrorErrorErrorErrorErrorError");
                logger.Debug("DebugDebugDebugDebugDebugDebugDebugDebugDebugDebugDebug");
                //log.LogInformation("aaaaaaaaaaaaaaaaa");
                //log.LogWarning("bbbbbbbbbbbbbbbbbbbbb");
                //log.LogError("cccccccccccccccccccccccccc");
                //log.LogDebug("dddddddddddddddddd");
                var jobData     = context.JobDetail.JobDataMap; //获取Job中的参数
                var triggerData = context.Trigger.JobDataMap;   //获取Trigger中的参数
                                                                //  var data = context.MergedJobDataMap;//获取Job和Trigger中合并的参数
                var value1 = jobData.GetString("key1");
                var value2 = jobData.GetString("key2");         //
                var flag   = jobData.GetInt("flag");
                // var value3 = data.GetString("key2");

                await Task.Run(() =>
                {
//                    ==============================(Install - Package DynamicExpresso.Core)======================================

//var whereExpression = $"m.{queryField}==\"{queryValue}\"";

//                string whereExpression = "customer.Age > 18 && customer.Gender == 'F'";

//                var interpreter = new Interpreter();
//                Func<Customer, bool> dynamicWhere = interpreter.ParseAsDelegate<Func<Customer, bool>>(whereExpression, "customer");

//                Assert.AreEqual(1, customers.Where(dynamicWhere).Count());

//=====================================================================================================
//string whereExpression = "customer.Age > 18 && customer.Gender == 'F'";

//var interpreter = new Interpreter();
//Expression<Func<Customer, bool>> expression = interpreter.ParseAsExpression<Func<Customer, bool>>(whereExpression, "customer");

                    var code        = "i<100&&s.Contains(\"测试\")";
                    var interpreter = new DynamicExpresso.Interpreter();
                    var result      = interpreter.ParseAsDelegate <Func <int, string, bool> >(code, "i", "s");
                    //var result = interpreter.ParseAsExpression<Func<int, string, bool>>(code, "i", "s").Compile();
                    for (int i = 0; i < 102; i++)
                    {
                        var v = result(i, "我在测试" + i);//2213ms
                        logger.Warn(v);
                        //Console.WriteLine(v);
                    }
                    for (var i = 0; i < 10; i++)
                    {
                        logger.Info($"参数作业:{flag}");
                    }
                    //context.Scheduler.UnscheduleJob(context.Trigger.Key);// 移除触发器
                    //context.Scheduler.DeleteJob(context.JobDetail.Key);// 删除任务

                    //context.Scheduler.Shutdown();
                    //Thread.Sleep(5000);
                });
            }
            catch (Exception e)
            {
                await context.Scheduler.Shutdown();

                logger.Error(e.ToString());
            }
        }