Example #1
0
        public ITask XmlNodeToTasks(XmlNode taskNode, out ArgAutoBingdingEnvironment argAutoBingdingEnvironment)
        {
            argAutoBingdingEnvironment = null;
            if (taskNode.Name.ToUpper() != "TASK" || taskNode.ChildNodes.Count == 0)
            {
                return(null);
            }
            Task task = new Task();

            task.Name = XMLNodeHelper.NodeAtt2String(taskNode, "name");
            task.IsCanIntercurrent = XMLNodeHelper.NodeAtt2Bool(taskNode, "isCanIntercurrent", task.IsCanIntercurrent);
            List <ActionArgCollection> ActionArgCollections = new List <ActionArgCollection>();

            foreach (XmlNode child in taskNode.ChildNodes)
            {
                if (child.NodeType == XmlNodeType.Comment)
                {
                    continue;
                }
                if (child.Name.ToUpper() == "ACTION")
                {
                    ActionArgCollection actionArgCollection = ParseXMLNodeToAction(child, task);
                    if (actionArgCollection != null)
                    {
                        ActionArgCollections.Add(actionArgCollection);
                    }
                }
            }
            argAutoBingdingEnvironment = new ArgAutoBingdingEnvironment(ActionArgCollections.ToArray());
            return(task);
        }
Example #2
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);
        }
Example #3
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);
        }
Example #4
0
        private IAction ActivatorAction(XmlNode actionNode, out string assemblyFilename, out string className)
        {
            assemblyFilename = null;
            className        = null;
            string classString = XMLNodeHelper.NodeAtt2String(actionNode, "class");

            if (string.IsNullOrEmpty(classString))
            {
                throw new Exception("Action未定义处理类[" + actionNode.OuterXml + "]");
            }
            string[] dllImports = classString.Split(',');
            string   dllName    = "";

            //string actionActivator = "";
            if (dllImports == null || dllImports.Length < 2)
            {
                className = classString;
            }
            else
            {
                dllName   = dllImports[0];
                className = dllImports[1];
            }
            object action = null;

            try
            {
                Assembly assembly = null;
                //string assemblyFilename = "";
                if (_assembliesFindDirs == null || _assembliesFindDirs.Length == 0)
                {
                    assemblyFilename = dllName;
                }
                else
                {
                    foreach (string assemblieDir in _assembliesFindDirs)
                    {
                        assemblyFilename = Path.Combine(assemblieDir, dllName);
                        if (File.Exists(assemblyFilename))
                        {
                            break;
                        }
                    }
                }
                assembly = Assembly.LoadFrom(assemblyFilename);
                Type actionType = assembly.GetType(className, false);
                if (actionType == null)
                {
                    throw new Exception("未能从提供的dll[" + assemblyFilename + "]中找到定义的处理类" + className);
                }
                action = Activator.CreateInstance(actionType);
                if (actionType.GetInterface("AgileMap.Bricks.ModelBuilder.IAction") == null)
                {
                    throw new Exception("任务定义脚本处理类[" + className + "]不存在,或没有实现IAction");
                }
            }
            catch
            {
                throw;
            }
            return(action as IAction);
        }