/// <summary>
        /// 通用的执行脚本的方法
        /// </summary>
        /// <typeparam name="TResult">返回值类型</typeparam>
        /// <typeparam name="TArg">参数类型</typeparam>
        /// <param name="operateCode">操作码</param>
        /// <param name="triggerScript">触发器脚本</param>
        /// <param name="executeMethod">执行方法名</param>
        /// <param name="arg">参数</param>
        /// <returns></returns>
        private TResult CommonExecute <TResult, TArg>(string operateCode, string triggerScript, string executeMethod, TArg arg)
        {
            //校验脚本正确性
            if (string.IsNullOrEmpty(triggerScript))
            {
                throw new ArgumentNullException("triggerScript", "triggerScript not fount");
            }

            var triggerScriptInCache = TriggerScriptCache.GetSet(triggerScript, () =>
            {
                string scriptText = $"{GetCompleteScript(triggerScript)} return new TriggerScript_Class().{executeMethod};";

                var script = CSharpScript.Create <TResult>(scriptText,
                                                           ScriptOptions.Default
                                                           .AddReferences(GeneralRefrences),
                                                           globalsType: typeof(TArg)
                                                           );

                script.Compile();

                return(script);
            });

            var result = triggerScriptInCache.RunAsync(globals: arg).Result.ReturnValue;

            return(result);
        }
        /// <summary>
        /// 更新对象
        /// </summary>
        /// <param name="triggerScript"></param>
        public new ResultModel Update(TriggerScript triggerScript)
        {
            TriggerScript myfield = GetById(triggerScript.Id);

            if (myfield != null)
            {
                //编码不允许修改
                //脚本类型不允许修改

                //如果脚本有改动,则清空脚本缓存
                if (!myfield.Script.Equals(triggerScript.Script))
                {
                    TriggerScriptCache.ClearCache(triggerScript.Script);
                }

                myfield.Script        = triggerScript.Script;
                myfield.FailurePolicy = triggerScript.FailurePolicy;

                myfield.Name        = triggerScript.Name;
                myfield.Group       = triggerScript.Group;
                myfield.SortNumber  = triggerScript.SortNumber;
                myfield.Description = triggerScript.Description;
                myfield.ModifyBy    = -1;
                myfield.ModifyTime  = DateTime.Now;
            }
            base.Update(myfield);
            return(ResultModel.Success());
        }
示例#3
0
        /// <summary>
        /// 更新对象
        /// </summary>
        /// <param name="interfaceAggregation"></param>
        public new ResultModel Update(InterfaceAggregation interfaceAggregation)
        {
            InterfaceAggregation myEntity = GetById(interfaceAggregation.Id);

            if (myEntity != null)
            {
                if (interfaceAggregation.InterfaceType != (int)InterfaceType.TriggerScriptDataSource)
                {
                    var interfaceField  = interfaceFieldService.GetById(interfaceAggregation.FieldListId);
                    var searchCondition = searchConditionService.GetById(interfaceAggregation.SearchConditionId);

                    myEntity.FieldListId   = interfaceAggregation.FieldListId;
                    myEntity.FieldListName = interfaceField.Name;

                    myEntity.SearchConditionId   = interfaceAggregation.SearchConditionId;
                    myEntity.SearchConditionName = searchCondition.Name;
                }

                myEntity.InterfaceType = interfaceAggregation.InterfaceType;

                //如果脚本有改动,则清空脚本缓存
                if (myEntity.Script != null && !myEntity.Script.Equals(interfaceAggregation.Script))
                {
                    TriggerScriptCache.ClearCache(interfaceAggregation.Script);
                }
                myEntity.Script = interfaceAggregation.Script;

                //编码不允许修改
                myEntity.Name        = interfaceAggregation.Name;
                myEntity.Group       = interfaceAggregation.Group;
                myEntity.SortNumber  = interfaceAggregation.SortNumber;
                myEntity.Description = interfaceAggregation.Description;
                myEntity.ModifyBy    = -1;
                myEntity.ModifyTime  = DateTime.Now;
            }
            base.Update(myEntity);
            return(ResultModel.Success());
        }