public static void AddPropertyInstance(string agentType, Property pPropertyInstance) { AgentProperties bb = AgentProperties.Get(agentType); Debug.Check(bb != null); bb.AddPropertyInstance(pPropertyInstance); }
public static Property GetProperty(string agentType, uint variableId) { AgentProperties bb = AgentProperties.Get(agentType); Debug.Check(bb != null); Property pProperty = bb.GetProperty(variableId); return(pProperty); }
public static Property AddLocal(string agentType, string typeName, string variableName, string valueStr) { AgentProperties bb = AgentProperties.Get(agentType); //if agent type has no property and custom property if (bb == null) { bb = new AgentProperties(agentType); agent_type_blackboards[agentType] = bb; } Property pProperty = bb.AddLocal(typeName, variableName, valueStr); return(pProperty); }
public static Property AddLocal(string agentType, string typeName, string variableName, string valueStr) { AgentProperties bb = AgentProperties.Get(agentType); //if agent type has no property and custom property if (bb == null) { bb = new AgentProperties(agentType); agent_type_blackboards[agentType] = bb; } Property pProperty = bb.AddLocal(typeName, variableName, valueStr); return pProperty; }
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)); AgentProperties bb = new AgentProperties(agentType); agent_type_blackboards[agentType] = bb; 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 variableName = d.ReadString(); string typeName = d.ReadString(); string memberStr = d.ReadString(); bool bIsMember = false; if (!string.IsNullOrEmpty(memberStr) && memberStr == "true") { bIsMember = true; } string isStatic = d.ReadString(); bool bIsStatic = false; if (!string.IsNullOrEmpty(isStatic) && isStatic == "true") { bIsStatic = true; } string valueStr = null; //string agentTypeMember = agentType; string agentTypeMember = null; if (!bIsMember) { valueStr = d.ReadString(); } else { agentTypeMember = d.ReadString().Replace("::", "."); } d.CloseDocument(true); bb.AddProperty(typeName, bIsStatic, variableName, valueStr, agentTypeMember); } 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; }
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)); foreach(SecurityElement bbNode in rootNode.Children) { if (bbNode.Tag == "agent" && bbNode.Children != null) { string agentType = bbNode.Attribute("type").Replace("::", "."); AgentProperties bb = new AgentProperties(agentType); agent_type_blackboards[agentType] = bb; foreach(SecurityElement propertiesNode in bbNode.Children) { if (propertiesNode.Tag == "properties" && propertiesNode.Children != null) { foreach(SecurityElement propertyNode in propertiesNode.Children) { if (propertyNode.Tag == "property") { string name = propertyNode.Attribute("name"); string type = propertyNode.Attribute("type").Replace("::", "."); string memberStr = propertyNode.Attribute("member"); bool bIsMember = false; if (!string.IsNullOrEmpty(memberStr) && memberStr == "true") { bIsMember = true; } string isStatic = propertyNode.Attribute("static"); bool bIsStatic = false; if (!string.IsNullOrEmpty(isStatic) && isStatic == "true") { bIsStatic = true; } //string agentTypeMember = agentType; string agentTypeMember = null; string valueStr = null; if (!bIsMember) { valueStr = propertyNode.Attribute("defaultvalue"); } else { agentTypeMember = propertyNode.Attribute("agent").Replace("::", "."); } bb.AddProperty(type, bIsStatic, name, valueStr, agentTypeMember); } } } else if (propertiesNode.Tag == "methods" && propertiesNode.Children != null) { Agent.CTagObjectDescriptor objectDesc = Agent.GetDescriptorByName(agentType); foreach(SecurityElement methodNode in propertiesNode.Children) { if (methodNode.Tag == "method") { //string eventStr = methodNode.Attribute("isevent"); //bool bEvent = (eventStr == "true"); //string taskStr = methodNode.Attribute("istask"); //bool bTask = (taskStr == "true"); //skip those other custom method string methodName = methodNode.Attribute("name"); //string type = methodNode.Attribute("returntype").Replace("::", "."); //string isStatic = methodNode.Attribute("static"); //string agentTypeStr = methodNode.Attribute("agent").Replace("::", "."); CCustomMethod customeMethod = new CTaskMethod(agentType, methodName); if (methodNode.Children != null) { foreach(SecurityElement paramNode in methodNode.Children) { if (paramNode.Tag == "parameter") { string paramName = paramNode.Attribute("name"); Debug.Check(!string.IsNullOrEmpty(paramName)); string paramType = paramNode.Attribute("type"); //string paramFullName = string.Format("{0}::{1}", paramType, paramName); customeMethod.AddParamType(paramType); } } } objectDesc.ms_methods.Add(customeMethod); } }//end of for methodNode }//end of methods }//end of for propertiesNode } }//end of for bbNode return true; } catch (Exception e) { Debug.Check(false, e.Message); } Debug.Check(false); return false; }
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)); AgentProperties bb = new AgentProperties(agentType); agent_type_blackboards[agentType] = bb; 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 variableName = d.ReadString(); string typeName = d.ReadString(); string memberStr = d.ReadString(); bool bIsMember = false; if (!string.IsNullOrEmpty(memberStr) && memberStr == "true") { bIsMember = true; } string isStatic = d.ReadString(); bool bIsStatic = false; if (!string.IsNullOrEmpty(isStatic) && isStatic == "true") { bIsStatic = true; } string valueStr = null; //string agentTypeMember = agentType; string agentTypeMember = null; if (!bIsMember) { valueStr = d.ReadString(); } else { agentTypeMember = d.ReadString(); } d.CloseDocument(true); bb.AddProperty(typeName, bIsStatic, variableName, valueStr, agentTypeMember); } 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); }
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.Tag != "agents" && (rootNode.Children == null || rootNode.Children.Count != 1)) { return(false); } string versionStr = rootNode.Attribute("version"); Debug.Check(!string.IsNullOrEmpty(versionStr)); foreach (SecurityElement bbNode in rootNode.Children) { if (bbNode.Tag == "agent" && bbNode.Children != null) { string agentType = bbNode.Attribute("type").Replace("::", "."); AgentProperties bb = new AgentProperties(agentType); agent_type_blackboards[agentType] = bb; foreach (SecurityElement propertiesNode in bbNode.Children) { if (propertiesNode.Tag == "properties" && propertiesNode.Children != null) { foreach (SecurityElement propertyNode in propertiesNode.Children) { if (propertyNode.Tag == "property") { string name = propertyNode.Attribute("name"); string type = propertyNode.Attribute("type").Replace("::", "."); string memberStr = propertyNode.Attribute("member"); bool bIsMember = false; if (!string.IsNullOrEmpty(memberStr) && memberStr == "true") { bIsMember = true; } string isStatic = propertyNode.Attribute("static"); bool bIsStatic = false; if (!string.IsNullOrEmpty(isStatic) && isStatic == "true") { bIsStatic = true; } //string agentTypeMember = agentType; string agentTypeMember = null; string valueStr = null; if (!bIsMember) { valueStr = propertyNode.Attribute("defaultvalue"); } else { agentTypeMember = propertyNode.Attribute("agent").Replace("::", "."); } bb.AddProperty(type, bIsStatic, name, valueStr, agentTypeMember); } } } else if (propertiesNode.Tag == "methods" && propertiesNode.Children != null) { Agent.CTagObjectDescriptor objectDesc = Agent.GetDescriptorByName(agentType); foreach (SecurityElement methodNode in propertiesNode.Children) { if (methodNode.Tag == "method") { //string eventStr = methodNode.Attribute("isevent"); //bool bEvent = (eventStr == "true"); //string taskStr = methodNode.Attribute("istask"); //bool bTask = (taskStr == "true"); //skip those other custom method string methodName = methodNode.Attribute("name"); //string type = methodNode.Attribute("returntype").Replace("::", "."); //string isStatic = methodNode.Attribute("static"); //string agentTypeStr = methodNode.Attribute("agent").Replace("::", "."); CCustomMethod customeMethod = new CTaskMethod(agentType, methodName); if (methodNode.Children != null) { foreach (SecurityElement paramNode in methodNode.Children) { if (paramNode.Tag == "parameter") { string paramName = paramNode.Attribute("name"); Debug.Check(!string.IsNullOrEmpty(paramName)); string paramType = paramNode.Attribute("type"); //string paramFullName = string.Format("{0}::{1}", paramType, paramName); customeMethod.AddParamType(paramType); } } } objectDesc.ms_methods.Add(customeMethod); } } //end of for methodNode } //end of methods } //end of for propertiesNode } } //end of for bbNode return(true); } catch (Exception e) { Debug.Check(false, e.Message); } Debug.Check(false); return(false); }