public JsonResult AddCondition(ListenerPolicyViewModel model)
        {
            return(ExecuteFunctionRun(() =>
            {
                ActionResult result = new ActionResult();
                result = ParseParam(model.SchemaCode);
                if (!result.Success)
                {
                    return Json(result, JsonRequestBehavior.AllowGet);
                }

                if (string.IsNullOrWhiteSpace(model.ConditionValue))
                {
                    result.Success = false;
                    //值必填
                    result.Message = "ListenerPolicy.Msg3";
                    return Json(result, JsonRequestBehavior.AllowGet);
                }
                string text = "[{0}] [{1}] [{2}] [{3}]";
                string[] values = { model.Filter, model.Field, model.Operator, model.ConditionValue };
                string val = string.Format("[{0}][Item][Name]{1}[/Name][Operator]{2}[/Operator][Value]{3}[/Value][/Item][/{0}]", model.Filter, model.Field, model.Operator, model.ConditionValue);
                result.Success = true;
                result.Extend = new
                {
                    Text = text,
                    Values = values,
                    Val = val
                };
                return Json(result, JsonRequestBehavior.AllowGet);
            }));
        }
 public JsonResult GetListenerPolicy(string schemaCode, string ownSchemaCode)
 {
     return(ExecuteFunctionRun(() =>
     {
         ActionResult result = new ActionResult();
         result = ParseParam(schemaCode);
         string matcher = string.Empty;
         if (!result.Success)
         {
             return Json(result, JsonRequestBehavior.AllowGet);
         }
         List <Item> policyTypes = InitPolicyTypes();
         List <Item> filterMethods = InitFilterMethods();
         List <Item> filters = InitFilters();
         List <Item> fields = InitFields();
         List <Item> operators = InitOperators();
         List <Item> conditions = GetFilter(ListenerPolicy.Filter, out matcher);
         ListenerPolicyViewModel model = new ListenerPolicyViewModel()
         {
             IntervalSecond = ListenerPolicy.IntervalSecond.ToString(),
             Filter = matcher,
             Field = fields.FirstOrDefault().Value.ToString(),
             Operator = operators.FirstOrDefault().Value.ToString(),
             SchemaCode = schemaCode,
             FilterMethod = ListenerPolicy.FilterMethod ?? filterMethods.FirstOrDefault().Value,
             PolicyType = ListenerPolicy.PolicyType.ToString(),
             Conditions = conditions.Select(s => s.Value).ToList()
         };
         result.Extend = new
         {
             PolicyTypes = policyTypes,
             FilterMethods = filterMethods,
             Filters = filters,
             Fields = fields,
             Conditions = conditions,
             Operators = operators,
             ListenerPolicy = model,
             IsLocked = BizWorkflowPackageLockByID(this.SchemaCode, ownSchemaCode)
         };
         return Json(result, JsonRequestBehavior.AllowGet);
     }));
 }
        public JsonResult SaveListenerPolicy(ListenerPolicyViewModel model)
        {
            return(ExecuteFunctionRun(() =>
            {
                ActionResult result = new ActionResult();
                result = ParseParam(model.SchemaCode);
                if (!result.Success)
                {
                    return Json(result, JsonRequestBehavior.AllowGet);
                }
                BizListenerPolicyType policyType = (BizListenerPolicyType)Enum.Parse(typeof(BizListenerPolicyType), model.PolicyType);
                // 检查输入
                if ((policyType == BizListenerPolicyType.Batch || policyType == BizListenerPolicyType.EventDrivenAndBatch) &&
                    string.IsNullOrEmpty(model.Filter))
                {
                    //请输入过滤条件
                    result.Success = false;
                    result.Message = "ListenerPolicy.Msg4";
                    return Json(result, JsonRequestBehavior.AllowGet);
                }

                string conditions = model.Conditions == null ? "" : this.Filter(model.Conditions);
                //result.Extend = conditions;
                //return Json(result, JsonRequestBehavior.AllowGet);
                try
                {
                    if (model.Conditions != null && model.Conditions.Count > 0)
                    {
                        OThinker.Data.Convertor.XmlToObject(typeof(H3.BizBus.Filter.Filter), conditions);
                    }
                }
                catch
                {
                    //输入的过滤器格式错误
                    result.Success = false;
                    result.Message = "ListenerPolicy.Msg5";
                    return Json(result, JsonRequestBehavior.AllowGet);
                }
                // 验证输入是否正确
                int interval = 0;
                if (!int.TryParse(model.IntervalSecond, out interval))
                {
                    //时间间隔必须是正整数
                    result.Success = false;
                    result.Message = "ListenerPolicy.Msg6";
                    return Json(result, JsonRequestBehavior.AllowGet);
                }
                if (interval < H3.DataModel.Declaration.Filter_MinIntervalSecond)
                {
                    //时间间隔设置过于密集,会造成服务器资源消耗太大
                    result.Success = false;
                    result.Message = "ListenerPolicy.Msg7";
                    return Json(result, JsonRequestBehavior.AllowGet);
                }

                BizListenerPolicy ListenerPolicy = new BizListenerPolicy();

                ListenerPolicy.PolicyType = policyType;
                ListenerPolicy.IntervalSecond = int.Parse(model.IntervalSecond);
                ListenerPolicy.FilterMethod = model.FilterMethod;
                if (!string.IsNullOrEmpty(conditions))
                {
                    ListenerPolicy.Filter = (H3.BizBus.Filter.Filter)OThinker.Data.Convertor.XmlToObject(typeof(H3.BizBus.Filter.Filter), conditions);
                }

                if (!this.Engine.BizObjectManager.SetListenerPolicy(this.SchemaCode, ListenerPolicy))
                {
                    result.Success = false;
                    //保存失败(可能原因:1数据模型未发布;2数据模型被删除)
                    result.Message = "ListenerPolicy.Msg8";
                    return Json(result, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    this.Engine.BizObjectManager.UpdateDraftSchema(this.Schema);
                    result.Success = true;
                    result.Message = "";
                    return Json(result, JsonRequestBehavior.AllowGet);
                }
            }));
        }