public Agent.CTagObjectDescriptor GetDescriptor() { if (this.m_objectDescriptor == null) { this.m_objectDescriptor = Agent.GetDescriptorByName(base.GetType().get_FullName()); } return(this.m_objectDescriptor); }
public object run(Agent parent, Agent parHolder) { if (this.m_params != null) { for (int i = 0; i < this.m_params.Length; i++) { Property paramProperty = this.m_params[i].paramProperty; if (paramProperty != null) { this.m_param_values[i] = paramProperty.GetValue(parent, parHolder); } if (this.m_params[i].paramStructMembers != null) { Type type = this.m_param_values[i].GetType(); Agent.CTagObjectDescriptor descriptorByName = Agent.GetDescriptorByName(type.get_FullName()); foreach (KeyValuePair <string, Property> current in this.m_params[i].paramStructMembers) { CMemberBase member = descriptorByName.GetMember(current.get_Key()); if (member != null) { object value = current.get_Value().GetValue(parent, parHolder); member.Set(this.m_param_values[i], value); } } } } } object result = this.method_.Invoke(parent, this.m_param_values); if (this.m_params != null) { for (int j = 0; j < this.m_params.Length; j++) { Property paramProperty2 = this.m_params[j].paramProperty; if (paramProperty2 != null) { object v = this.m_param_values[j]; paramProperty2.SetValue(parHolder, v); } if (this.m_params[j].paramStructMembers != null) { Type type2 = this.m_param_values[j].GetType(); Agent.CTagObjectDescriptor descriptorByName2 = Agent.GetDescriptorByName(type2.get_FullName()); foreach (KeyValuePair <string, Property> current2 in this.m_params[j].paramStructMembers) { CMemberBase member2 = descriptorByName2.GetMember(current2.get_Key()); if (member2 != null) { object v2 = member2.Get(this.m_param_values[j]); current2.get_Value().SetValue(parHolder, v2); } } } } } return(result); }
public object run(Agent parent, Agent parHolder) { if (this.m_params != null) { for (int i = 0; i < this.m_params.Length; i++) { Property paramProperty = this.m_params[i].paramProperty; if (paramProperty != null) { this.m_param_values[i] = paramProperty.GetValue(parent, parHolder); } if (this.m_params[i].paramStructMembers != null) { Agent.CTagObjectDescriptor descriptorByName = Agent.GetDescriptorByName(this.m_param_values[i].GetType().FullName); foreach (KeyValuePair <string, Property> pair in this.m_params[i].paramStructMembers) { CMemberBase member = descriptorByName.GetMember(pair.Key); if (member != null) { object v = pair.Value.GetValue(parent, parHolder); member.Set(this.m_param_values[i], v); } } } } } object obj3 = this.method_.Invoke(parent, this.m_param_values); if (this.m_params != null) { for (int j = 0; j < this.m_params.Length; j++) { Property property2 = this.m_params[j].paramProperty; if (property2 != null) { object obj4 = this.m_param_values[j]; property2.SetValue(parHolder, obj4); } if (this.m_params[j].paramStructMembers != null) { Agent.CTagObjectDescriptor descriptor2 = Agent.GetDescriptorByName(this.m_param_values[j].GetType().FullName); foreach (KeyValuePair <string, Property> pair2 in this.m_params[j].paramStructMembers) { CMemberBase base3 = descriptor2.GetMember(pair2.Key); if (base3 != null) { object obj5 = base3.Get(this.m_param_values[j]); pair2.Value.SetValue(parHolder, obj5); } } } } } return(obj3); }
//return true if there is a task method loaded private static void load_methods(BsonDeserizer d, string agentType, BsonDeserizer.BsonTypes type) { Agent.CTagObjectDescriptor objectDesc = Agent.GetDescriptorByName(agentType); d.OpenDocument(); type = d.ReadType(); while (type == BsonDeserizer.BsonTypes.BT_MethodElement) { d.OpenDocument(); string methodName = d.ReadString(); //string returnTypeStr = d.ReadString(); //returnTypeStr = returnTypeStr.Replace("::", "."); //string isStatic = d.ReadString(); //string eventStr = d.ReadString(); //bool bEvent = (eventStr == "true"); string agentStr = d.ReadString(); Debug.Check(!string.IsNullOrEmpty(agentStr)); CCustomMethod customeMethod = new CTaskMethod(agentType, methodName); type = d.ReadType(); while (type == BsonDeserizer.BsonTypes.BT_ParameterElement) { d.OpenDocument(); string paramName = d.ReadString(); Debug.Check(!string.IsNullOrEmpty(paramName)); string paramType = d.ReadString(); customeMethod.AddParamType(paramType); d.CloseDocument(true); type = d.ReadType(); } objectDesc.ms_methods.Add(customeMethod); d.CloseDocument(false); type = d.ReadType(); } d.CloseDocument(false); }
private static void RegisterType(Type type, bool bIsAgentType) { Attribute[] array = (Attribute[])type.GetCustomAttributes(typeof(TypeMetaInfoAttribute), false); if (!bIsAgentType || array.Length > 0) { TypeMetaInfoAttribute typeMetaInfoAttribute = (array.Length <= 0) ? null : ((TypeMetaInfoAttribute)array[0]); Agent.CTagObjectDescriptor descriptorByName = Agent.GetDescriptorByName(type.get_FullName()); if (type.get_BaseType() == typeof(Agent) || type.get_BaseType().IsSubclassOf(typeof(Agent))) { Agent.CTagObjectDescriptor descriptorByName2 = Agent.GetDescriptorByName(type.get_BaseType().get_FullName()); descriptorByName.m_parent = descriptorByName2; } descriptorByName.type = type; descriptorByName.displayName = ((typeMetaInfoAttribute != null && !string.IsNullOrEmpty(typeMetaInfoAttribute.DisplayName)) ? typeMetaInfoAttribute.DisplayName : type.get_FullName()); descriptorByName.desc = ((typeMetaInfoAttribute != null && !string.IsNullOrEmpty(typeMetaInfoAttribute.Description)) ? typeMetaInfoAttribute.Description : descriptorByName.displayName); if (Utils.IsEnumType(type)) { return; } BindingFlags bindingFlags = 62; FieldInfo[] fields = type.GetFields(bindingFlags); FieldInfo[] array2 = fields; for (int i = 0; i < array2.Length; i++) { FieldInfo fieldInfo = array2[i]; bool flag = false; MemberMetaInfoAttribute a = null; if (bIsAgentType) { Attribute[] array3 = (Attribute[])fieldInfo.GetCustomAttributes(typeof(MemberMetaInfoAttribute), false); if (array3.Length > 0) { a = (MemberMetaInfoAttribute)array3[0]; flag = true; } } else { flag = true; } if (flag) { CMemberBase cMemberBase = new CMemberBase(fieldInfo, a); for (int j = 0; j < descriptorByName.ms_members.get_Count(); j++) { if (cMemberBase.GetId() == descriptorByName.ms_members.get_Item(j).GetId()) { CMemberBase cMemberBase2 = descriptorByName.ms_members.get_Item(j); break; } } descriptorByName.ms_members.Add(cMemberBase); if ((Utils.IsCustomClassType(fieldInfo.get_FieldType()) || Utils.IsEnumType(fieldInfo.get_FieldType())) && !Agent.IsTypeRegisterd(fieldInfo.get_FieldType().get_FullName())) { Workspace.RegisterType(fieldInfo.get_FieldType(), false); } } } if (bIsAgentType) { MethodInfo[] methods = type.GetMethods(bindingFlags); MethodInfo[] array4 = methods; for (int k = 0; k < array4.Length; k++) { MethodInfo methodInfo = array4[k]; Attribute[] array5 = (Attribute[])methodInfo.GetCustomAttributes(typeof(MethodMetaInfoAttribute), false); if (array5.Length > 0) { MethodMetaInfoAttribute a2 = (MethodMetaInfoAttribute)array5[0]; CMethodBase cMethodBase = new CMethodBase(methodInfo, a2, null); descriptorByName.ms_methods.Add(cMethodBase); ParameterInfo[] parameters = methodInfo.GetParameters(); ParameterInfo[] array6 = parameters; for (int l = 0; l < array6.Length; l++) { ParameterInfo parameterInfo = array6[l]; if ((Utils.IsCustomClassType(parameterInfo.get_ParameterType()) || Utils.IsEnumType(parameterInfo.get_ParameterType())) && !Agent.IsTypeRegisterd(parameterInfo.get_ParameterType().get_FullName())) { Workspace.RegisterType(parameterInfo.get_ParameterType(), false); } } if ((Utils.IsCustomClassType(methodInfo.get_ReturnType()) || Utils.IsEnumType(methodInfo.get_ReturnType())) && !Agent.IsTypeRegisterd(methodInfo.get_ReturnType().get_FullName())) { Workspace.RegisterType(methodInfo.get_ReturnType(), false); } } } Type[] nestedTypes = type.GetNestedTypes(bindingFlags); Type[] array7 = nestedTypes; for (int m = 0; m < array7.Length; m++) { Type type2 = array7[m]; Attribute[] array8 = (Attribute[])type2.GetCustomAttributes(typeof(EventMetaInfoAttribute), false); if (array8.Length > 0) { EventMetaInfoAttribute a3 = (EventMetaInfoAttribute)array8[0]; MethodInfo method = type2.GetMethod("Invoke"); CNamedEvent cNamedEvent = new CNamedEvent(method, a3, type2.get_Name()); descriptorByName.ms_methods.Add(cNamedEvent); } } } } }
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); }