コード例 #1
0
        public static IMethod ParseMethod(string valueStr, ref string methodName)
        {
            //Self.test_ns::AgentActionTest::Action2(0)
            if (string.IsNullOrEmpty(valueStr) || (valueStr[0] == '\"' && valueStr[1] == '\"'))
            {
                return(null);
            }

            string agentIntanceName = null;
            string agentClassName   = null;
            int    pBeginP          = ParseMethodNames(valueStr, ref agentIntanceName, ref agentClassName, ref methodName);

            uint agentClassId = Utils.MakeVariableId(agentClassName);
            uint methodId     = Utils.MakeVariableId(methodName);

            AgentMeta meta = AgentMeta.GetMeta(agentClassId);

            Debug.Check(meta != null);

            if (meta != null)
            {
                IMethod method = meta.GetMethod(methodId);

                if (method == null)
                {
                    Debug.Check(false, string.Format("Method of {0}::{1} is not registered!\n", agentClassName, methodName));
                }
                else
                {
                    method = (IMethod)(method.Clone());

                    string paramsStr = valueStr.Substring(pBeginP);
                    Debug.Check(paramsStr[0] == '(');

                    List <string> paramsTokens = new List <string>();
                    int           len          = paramsStr.Length;
                    Debug.Check(paramsStr[len - 1] == ')');

                    string text = paramsStr.Substring(1, len - 2);
                    paramsTokens = ParseForParams(text);

                    method.Load(agentIntanceName, paramsTokens.ToArray());
                }

                return(method);
            }

            return(null);
        }
コード例 #2
0
        private static bool load_xml(byte[] pBuffer)
        {
            try
            {
                Debug.Check(pBuffer != null);
                string xml = System.Text.Encoding.UTF8.GetString(pBuffer);

                SecurityParser xmlDoc = new SecurityParser();
                xmlDoc.LoadXml(xml);

                SecurityElement rootNode = xmlDoc.ToXml();

                if (rootNode.Children == null || rootNode.Tag != "agents" && rootNode.Children.Count != 1)
                {
                    return(false);
                }

                string versionStr = rootNode.Attribute("version");
                Debug.Check(!string.IsNullOrEmpty(versionStr));

                string signatureStr = rootNode.Attribute("signature");
                checkSignature(signatureStr);

                foreach (SecurityElement bbNode in rootNode.Children)
                {
                    if (bbNode.Tag == "agent" && bbNode.Children != null)
                    {
                        string    agentType = bbNode.Attribute("type").Replace("::", ".");
                        uint      classId   = Utils.MakeVariableId(agentType);
                        AgentMeta meta      = AgentMeta.GetMeta(classId);
                        if (meta == null)
                        {
                            meta = new AgentMeta();
                            _agentMetas[classId] = meta;
                        }

                        foreach (SecurityElement propertiesNode in bbNode.Children)
                        {
                            if (propertiesNode.Tag == "properties" && propertiesNode.Children != null)
                            {
                                foreach (SecurityElement propertyNode in propertiesNode.Children)
                                {
                                    if (propertyNode.Tag == "property")
                                    {
                                        string memberStr = propertyNode.Attribute("member");
                                        bool   bIsMember = (!string.IsNullOrEmpty(memberStr) && memberStr == "true");

                                        if (!bIsMember)
                                        {
                                            string propName  = propertyNode.Attribute("name");
                                            string propType  = propertyNode.Attribute("type").Replace("::", ".");
                                            string valueStr  = propertyNode.Attribute("defaultvalue");
                                            string isStatic  = propertyNode.Attribute("static");
                                            bool   bIsStatic = (!string.IsNullOrEmpty(isStatic) && isStatic == "true");

                                            registerCustomizedProperty(meta, propName, propType, valueStr, bIsStatic);
                                        }
                                    }
                                }
                            }
                        } //end of for propertiesNode
                    }
                }         //end of for bbNode

                return(true);
            }
            catch (Exception e)
            {
                Debug.Check(false, e.Message);
            }

            Debug.Check(false);
            return(false);
        }
コード例 #3
0
        public static IInstanceMember ParseProperty(string value)
        {
            try
            {
                if (string.IsNullOrEmpty(value))
                {
                    return(null);
                }

                List <string> tokens   = StringUtils.SplitTokens(value);
                string        typeName = "";

                if (tokens[0] == "const")
                {
                    // const Int32 0
                    Debug.Check(tokens.Count == 3);

                    const int kConstLength = 5;
                    string    strRemaining = value.Substring(kConstLength + 1);
                    int       p            = StringUtils.FirstToken(strRemaining, ' ', ref typeName);

                    typeName = typeName.Replace("::", ".");

                    string strVale = strRemaining.Substring(p + 1);

                    // const
                    return(AgentMeta.CreateInstanceConst(typeName, strVale));
                }
                else
                {
                    string propStr      = "";
                    string indexPropStr = "";

                    if (tokens[0] == "static")
                    {
                        // static float Self.AgentNodeTest::s_float_type_0
                        // static float Self.AgentNodeTest::s_float_type_0[int Self.AgentNodeTest::par_int_type_2]
                        Debug.Check(tokens.Count == 3 || tokens.Count == 4);

                        typeName = tokens[1];
                        propStr  = tokens[2];
                        if (tokens.Count == 4) // array index
                        {
                            indexPropStr = tokens[3];
                        }
                    }
                    else
                    {
                        // float Self.AgentNodeTest::par_float_type_1
                        // float Self.AgentNodeTest::par_float_type_1[int Self.AgentNodeTest::par_int_type_2]
                        Debug.Check(tokens.Count == 2 || tokens.Count == 3);

                        typeName = tokens[0];
                        propStr  = tokens[1];
                        if (tokens.Count == 3) // array index
                        {
                            indexPropStr = tokens[2];
                        }
                    }

                    string          arrayItem   = "";
                    IInstanceMember indexMember = null;
                    if (!string.IsNullOrEmpty(indexPropStr))
                    {
                        arrayItem   = "[]";
                        indexMember = ParseProperty <int>(indexPropStr);
                    }

                    typeName = typeName.Replace("::", ".");
                    propStr  = propStr.Replace("::", ".");

                    string[] props = propStr.Split('.');
                    Debug.Check(props.Length >= 3);

                    string instantceName = props[0];
                    string propName      = props[props.Length - 1];
                    string className     = props[1];

                    for (int i = 2; i < props.Length - 1; ++i)
                    {
                        className += "." + props[i];
                    }

                    uint      classId = Utils.MakeVariableId(className);
                    AgentMeta meta    = AgentMeta.GetMeta(classId);
                    Debug.Check(meta != null, "please add the exported 'AgentProperties.cs' and 'customizedtypes.cs' into the project!");

                    uint propId = Utils.MakeVariableId(propName + arrayItem);

                    // property
                    IProperty p = meta.GetProperty(propId);
                    if (p != null)
                    {
                        return(p.CreateInstance(instantceName, indexMember));
                    }

                    // local var
                    return(AgentMeta.CreateInstanceProperty(typeName, instantceName, indexMember, propId));
                }
            }
            catch (System.Exception e)
            {
                Debug.Check(false, e.Message);
            }

            return(null);
        }
コード例 #4
0
        private static bool load_agent(int version, BsonDeserizer d)
        {
            try
            {
                d.OpenDocument();

                string agentType = d.ReadString().Replace("::", ".");
                string pBaseName = d.ReadString();
                Debug.Check(!string.IsNullOrEmpty(pBaseName));

                uint      classId = Utils.MakeVariableId(agentType);
                AgentMeta meta    = AgentMeta.GetMeta(classId);
                if (meta == null)
                {
                    meta = new AgentMeta();
                    _agentMetas[classId] = meta;
                }

                BsonDeserizer.BsonTypes type = d.ReadType();

                while (type != BsonDeserizer.BsonTypes.BT_None)
                {
                    if (type == BsonDeserizer.BsonTypes.BT_PropertiesElement)
                    {
                        d.OpenDocument();
                        type = d.ReadType();

                        while (type != BsonDeserizer.BsonTypes.BT_None)
                        {
                            if (type == BsonDeserizer.BsonTypes.BT_PropertyElement)
                            {
                                d.OpenDocument();

                                string propName = d.ReadString();
                                string propType = d.ReadString();

                                string memberStr = d.ReadString();
                                bool   bIsMember = (!string.IsNullOrEmpty(memberStr) && memberStr == "true");

                                string isStatic  = d.ReadString();
                                bool   bIsStatic = (!string.IsNullOrEmpty(isStatic) && isStatic == "true");

                                string valueStr        = null;
                                string agentTypeMember = null;

                                if (!bIsMember)
                                {
                                    valueStr = d.ReadString();
                                }
                                else
                                {
                                    agentTypeMember = d.ReadString();
                                }

                                if (!bIsMember)
                                {
                                    registerCustomizedProperty(meta, propName, propType, valueStr, bIsStatic);
                                }

                                d.CloseDocument(true);
                            }
                            else
                            {
                                Debug.Check(false);
                            }

                            type = d.ReadType();
                        }//end of while

                        d.CloseDocument(false);
                    }
                    else if (type == BsonDeserizer.BsonTypes.BT_MethodsElement)
                    {
                        load_methods(d, agentType, type);
                    }
                    else
                    {
                        Debug.Check(type == BsonDeserizer.BsonTypes.BT_None);
                    }

                    type = d.ReadType();
                }

                d.CloseDocument(false);
                return(true);
            }
            catch (Exception ex)
            {
                Debug.Check(false, ex.Message);
            }

            return(false);
        }