Beispiel #1
0
 /// <summary>
 /// 绑定引用到Action
 /// </summary>
 /// <param name="arg">参数绑定定义对象</param>
 /// <param name="act">待绑定Action</param>
 /// <param name="actType">待绑定Action的具体类型</param>
 /// <returns>是否绑定成功</returns>
 private bool BindRefValueToAction(ActionArg arg, IAction act, Type actType)
 {
     try
     {
         //从已执行队列中发现参数来源Action
         IAction resAction = FindAction(arg.RefActionId);
         if (resAction == null)
         {
             if ((act as ActionBase).Id != arg.RefActionId)
             {
                 LogError(string.Format(errRefActionLost2, act.Name, arg.Name));
                 return(false);
             }
             else
             {
                 resAction = act;
             }
         }
         //获取源Action的BingdingAttribute 元数据                                                        Filename         QualityChecker
         BindingAttribute resBindingAtt = ArgBindingHelper.GetBingdingAttribute(arg.RefName, resAction);
         if (resBindingAtt == null)
         {
             LogError(string.Format(errBindingAttributeLost4, act.Name, arg.Name, resAction.Name, arg.RefName));
             return(false);
         }
         //获取目标Action的BingdingAttribute                                                                 Filename    SpecialRegionChecker
         BindingAttribute desBindingAtt = ArgBindingHelper.GetBingdingAttribute(arg.Name, act);
         if (desBindingAtt == null)
         {
             LogError(string.Format(errBindingAttributeLost4, act.Name, arg.Name, act.Name, arg.Name));
             return(false);
         }
         //绑定参数语义类型是否兼容,泛型关系暂未做处理
         if (!resBindingAtt.SemanticType.Equals(desBindingAtt.SemanticType))
         {
             LogError(string.Format(errArgTypeNotMatch4, act.Name, arg.Name, resAction.Name, arg.RefName));
         }
         //从源Action获取绑定值                               Action1:QualityChecker.Filename
         object refValue = resAction.GetType().InvokeMember(arg.RefName, BindingFlags.GetProperty, null, resAction, null);
         //将获取到的绑定值绑定到目标Action的参数arg.Name        Action2:SpecialRegionChecker.Filename
         actType.InvokeMember(arg.Name, BindingFlags.SetProperty, null, act, new object[] { refValue });
         return(true);
     }
     catch (Exception ex)
     {
         LogError(string.Format(errBindArgFaileExceptionAtNextLog2, act.Name, arg.Name));
         LogException(ex);
         return(false);
     }
 }
Beispiel #2
0
        /// <summary>
        /// 变量绑定
        /// </summary>
        /// <param name="arg">参数绑定定义对象</param>
        /// <param name="act">待绑定Action</param>
        /// <param name="actType">待绑定Action的具体类型</param>
        /// <returns>是否绑定成功</returns>
        private bool BindVarValueToAction(ActionArg arg, IAction act, Type actType)
        {
            //变量提供者对象为空
            if (_varProvider == null)
            {
                LogError(string.Format(errVarProviderLost2, act.Name, arg.Name));
                return(false);
            }
            //获取变量
            object value = _varProvider.GetVarValue(arg.VarType, arg.RefName);

            //临时的
            if (arg.RefName.ToUpper() == "INPUTFILENAME")
            {
                LogInfo("处理:" + Path.GetFileName(value != null ? value.ToString() : string.Empty));
            }
            //将变量帮定到Action的参数Arg.Name
            return(BindValueToAction(arg.Name, value, act, actType));
        }
Beispiel #3
0
        private ActionArgCollection ParseXMLNodeToAction(XmlNode actionNode, ITask task)
        {
            int actionID = XMLNodeHelper.NodeAtt2Int(actionNode, "id", -1);

            if (actionID == -1)
            {
                throw new Exception("Action的ID定义错误[" + actionNode.OuterXml + "]");
            }
            string  assemblyUrl = null, className = null;
            IAction action = ActivatorAction(actionNode, out assemblyUrl, out className);

            if ((action as ActionBase) == null)
            {
                throw new Exception("Action[" + action.Name + "]不是继承自ActionBase");
            }
            (action as ActionBase).Id = actionID;
            if (action == null)
            {
                throw new Exception("任务定义脚本处理类[" + actionNode.OuterXml + "]不存在");
            }
            task.AddAction(action);
            List <ActionArg> actionArgs = new List <ActionArg>();

            foreach (XmlNode child in actionNode.ChildNodes)
            {
                ActionArg actionArg = ParseXMLNodeToActionArg(child, actionID);
                if (actionArg != null)
                {
                    actionArgs.Add(actionArg);
                }
            }
            ActionArgCollection actionArgCollection = new ActionArgCollection(actionID, actionArgs.ToArray());

            actionArgCollection.AssemblyUrl     = assemblyUrl;
            actionArgCollection.ClassName       = className;
            actionArgCollection.ActionAttribute = GetActionAttribute(action);
            return(actionArgCollection);
        }
Beispiel #4
0
        private ActionArg ParseXMLNodeToActionArg(XmlNode actionArgNode, int actionID)
        {
            ActionArg actionArg = new ActionArg(XMLNodeHelper.NodeAtt2String(actionArgNode, "name"));
            string    argValue  = XMLNodeHelper.NodeAtt2String(actionArgNode, "value");
            Regex     regex     = new Regex(ActionArgPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);//不区分大小写
            Match     match     = regex.Match(argValue);

            if (match.Success)
            {
                Group ArgType     = match.Groups["ArgType"];
                Group VarType     = match.Groups["VarType"];
                Group RefName     = match.Groups["RefName"];
                Group RefActionId = match.Groups["RefActionId"];
                if (ArgType.Success)
                {
                    switch (ArgType.Value.ToUpper())
                    {
                    case "REF":
                        actionArg.ArgType = enumArgType.Ref;
                        actionArg.RefName = RefName.Value;
                        break;

                    case "VAR":
                        actionArg.ArgType = enumArgType.Var;
                        break;

                    default:
                        throw new Exception("未知的ActionArg.ArgType定义[" + ArgType.Value + "]");
                    }
                }
                if (RefActionId.Success)
                {
                    actionArg.RefActionId = int.Parse(RefActionId.Value);
                    actionArg.RefName     = RefName.Value;
                }
                else if (VarType.Success)
                {
                    switch (VarType.Value.ToUpper())
                    {
                    case "ENV":
                        actionArg.VarType = enumVarType.Env;
                        actionArg.RefName = RefName.Value;
                        break;

                    case "THIS":
                        actionArg.RefActionId = actionID;
                        actionArg.RefName     = RefName.Value;
                        break;

                    default:

                        throw new Exception("未知的ActionArg.VarType定义[" + VarType.Value + "]");
                    }
                }
            }
            else
            {
                actionArg.ArgType = enumArgType.Value;
                actionArg.Value   = argValue;
            }
            return(actionArg);
        }