コード例 #1
0
        public static MethodDef parseMethodString(List<Nodes.Node.ErrorCheck> result, DefaultObject node, AgentType agentType, MethodType methodType, string str)
        {
            try {
                if (agentType != null) {
                    int pos = str.IndexOf('(');

                    if (pos < 0)
                    { return null; }

                    string ownerName = agentType.ToString();
                    int pointIndex = str.IndexOf('.');

                    if (pointIndex > -1 && pointIndex < pos) {
                        ownerName = str.Substring(0, pointIndex);
                        Nodes.Behavior behavior = node.Behavior as Nodes.Behavior;

                        if (ownerName != VariableDef.kSelf && !Plugin.IsInstanceName(ownerName, behavior))
                        {
                            throw new Exception("The instance does not exist.");
                        }

                        str = str.Substring(pointIndex + 1, str.Length - pointIndex - 1);
                        agentType = Plugin.GetInstanceAgentType(ownerName, behavior, agentType);
                        //if (agentType == node.Behavior.AgentType)
                        //    ownerName = VariableDef.kSelf;
                        pos = str.IndexOf('(');
                    }

                    IList<MethodDef> actions = agentType.GetMethods(methodType);
                    string actionName = str.Substring(0, pos);
                    foreach(MethodDef actionTypeIt in actions) {
                        if (actionTypeIt.Name == actionName
#if BEHAVIAC_NAMESPACE_FIX
                            || actionTypeIt.Name.EndsWith(actionName)
#endif
                           ) {
                            MethodDef method = new MethodDef(actionTypeIt);
                            method.Owner = ownerName;

                            List<string> paras = parseParams(str.Substring(pos + 1, str.Length - pos - 2));
                            //Debug.Check((paras.Count == actionTypeIt.Params.Count));

                            //if (paras.Count == actionTypeIt.Params.Count)
                            {
                                for (int i = 0; i < paras.Count; ++i) {
                                    if (i >= method.Params.Count) {
                                        break;
                                    }

                                    string param = paras[i];
                                    MethodDef.Param par = method.Params[i];
                                    bool bOk = parseParam(result, node, method, par, param);

                                    if (!bOk) {
                                        throw new Exception(string.Format(Resources.ExceptionDesignerAttributeIllegalFloatValue, str));
                                    }
                                }
                            }

                            return method;
                        }
                    }
                }

            } catch (Exception) {
                //System.Windows.Forms.MessageBox.Show(str, Resources.LoadError, System.Windows.Forms.MessageBoxButtons.OK);
                if (result != null)
                {
                    Nodes.Node n = node as Nodes.Node;
                    string label = "";
                    if (n == null)
                    {
                        Attachments.Attachment a = node as Attachments.Attachment;
                        if (a != null)
                        {
                            n = a.Node;
                            label = a.Label;
                        }
                    }
                    else
                    {
                        label = n.Label;
                    }

                    Nodes.Node.ErrorCheck error = new Nodes.Node.ErrorCheck(n, node.Id, label, Nodes.ErrorCheckLevel.Error, str);
                    result.Add(error);
                }
            }

            return null;
        }
コード例 #2
0
        public static MethodDef parseMethodString(List <Nodes.Node.ErrorCheck> result, DefaultObject node, AgentType agentType, MethodType methodType, string str)
        {
            try {
                if (agentType != null)
                {
                    int pos = str.IndexOf('(');

                    if (pos < 0)
                    {
                        return(null);
                    }

                    string ownerName  = agentType.ToString();
                    int    pointIndex = str.IndexOf('.');

                    if (pointIndex > -1 && pointIndex < pos)
                    {
                        ownerName = str.Substring(0, pointIndex);

                        if (ownerName != VariableDef.kSelf && !Plugin.IsInstanceName(ownerName))
                        {
                            throw new Exception("The instance does not exist.");
                        }

                        str       = str.Substring(pointIndex + 1, str.Length - pointIndex - 1);
                        agentType = Plugin.GetInstanceAgentType(ownerName, agentType);
                        //if (agentType == node.Behavior.AgentType)
                        //    ownerName = VariableDef.kSelf;
                        pos = str.IndexOf('(');
                    }

                    IList <MethodDef> actions    = agentType.GetMethods(methodType);
                    string            actionName = str.Substring(0, pos);
                    foreach (MethodDef actionTypeIt in actions)
                    {
                        if (actionTypeIt.Name == actionName
#if BEHAVIAC_NAMESPACE_FIX
                            || actionTypeIt.Name.EndsWith(actionName)
#endif
                            )
                        {
                            MethodDef method = new MethodDef(actionTypeIt);
                            method.Owner = ownerName;

                            List <string> paras = parseParams(str.Substring(pos + 1, str.Length - pos - 2));
                            //Debug.Check((paras.Count == actionTypeIt.Params.Count));

                            //if (paras.Count == actionTypeIt.Params.Count)
                            {
                                for (int i = 0; i < paras.Count; ++i)
                                {
                                    if (i >= method.Params.Count)
                                    {
                                        break;
                                    }

                                    string          param = paras[i];
                                    MethodDef.Param par   = method.Params[i];
                                    bool            bOk   = parseParam(result, node, method, par, param);

                                    if (!bOk)
                                    {
                                        throw new Exception(string.Format(Resources.ExceptionDesignerAttributeIllegalFloatValue, str));
                                    }
                                }
                            }

                            return(method);
                        }
                    }
                }
            } catch (Exception) {
                //System.Windows.Forms.MessageBox.Show(str, Resources.LoadError, System.Windows.Forms.MessageBoxButtons.OK);
                if (result != null)
                {
                    Nodes.Node n     = node as Nodes.Node;
                    string     label = "";
                    if (n == null)
                    {
                        Attachments.Attachment a = node as Attachments.Attachment;
                        if (a != null)
                        {
                            n     = a.Node;
                            label = a.Label;
                        }
                    }
                    else
                    {
                        label = n.Label;
                    }

                    Nodes.Node.ErrorCheck error = new Nodes.Node.ErrorCheck(n, node.Id, label, Nodes.ErrorCheckLevel.Error, str);
                    result.Add(error);
                }
            }

            return(null);
        }