private void GetCellMethods(EntityDef entity, ArrayList methods) { Dictionary <ushort, EntityDefMethod> dictionary = new Dictionary <ushort, EntityDefMethod>(); Dictionary <string, EntityDefMethod> dictionary2 = new Dictionary <string, EntityDefMethod>(); if (methods != null) { ushort num = 0; foreach (SecurityElement element in methods) { if (((element.Children != null) && (element.Children.Count != 0)) && ((element.Children[0] as SecurityElement).Tag == "Exposed")) { EntityDefMethod method = new EntityDefMethod { FuncName = element.Tag, FuncID = num, ArgsType = new List <VObject>() }; for (int i = 1; i < element.Children.Count; i++) { SecurityElement element2 = element.Children[i] as SecurityElement; method.ArgsType.Add(TypeMapping.GetVObject(element2.Text.Trim())); } dictionary.Add(method.FuncID, method); if (!dictionary2.ContainsKey(method.FuncName)) { dictionary2.Add(method.FuncName, method); } } num = (ushort)(num + 1); } } entity.CellMethodsByID = dictionary; entity.CellMethodsByName = dictionary2; }
private void GetHmfClientMethods(EntityDef etyDef, List <object> methods) { Dictionary <ushort, EntityDefMethod> methodByIDList = new Dictionary <ushort, EntityDefMethod>(); Dictionary <string, EntityDefMethod> methodByNameList = new Dictionary <string, EntityDefMethod>(); if (methods != null) { ushort index = 0;//方法索引 for (int i = 0; i < methods.Count; i++) { EntityDefMethod m = new EntityDefMethod(); Dictionary <object, object> fun = (Dictionary <object, object>)methods[i]; KeyValuePair <object, object> kv = fun.First(); m.FuncName = (string)kv.Key; m.FuncID = index; m.ArgsType = new List <VObject>(); if (kv.Value != null) { foreach (var args in (List <object>)kv.Value) { List <object> funargs = (List <object>)args; m.ArgsType.Add(TypeMapping.GetVObject(((string)funargs[1]).Trim()));//To do: Trim()优化 } } methodByIDList.Add(m.FuncID, m); if (!methodByNameList.ContainsKey(m.FuncName)) { methodByNameList.Add(m.FuncName, m); } index++; } } etyDef.ClientMethodsByID = methodByIDList; etyDef.ClientMethodsByName = methodByNameList; }
private void GetHmfClientMethods(EntityDef etyDef, List <object> methods) { Dictionary <ushort, EntityDefMethod> dictionary = new Dictionary <ushort, EntityDefMethod>(); Dictionary <string, EntityDefMethod> dictionary2 = new Dictionary <string, EntityDefMethod>(); if (methods != null) { ushort num = 0; for (int i = 0; i < methods.Count; i++) { EntityDefMethod method = new EntityDefMethod(); KeyValuePair <object, object> pair = ((Dictionary <object, object>)methods[i]).First <KeyValuePair <object, object> >(); method.FuncName = (string)pair.Key; method.FuncID = num; method.ArgsType = new List <VObject>(); if (pair.Value != null) { foreach (object obj2 in (List <object>)pair.Value) { List <object> list = (List <object>)obj2; method.ArgsType.Add(TypeMapping.GetVObject(((string)list[1]).Trim())); } } dictionary.Add(method.FuncID, method); if (!dictionary2.ContainsKey(method.FuncName)) { dictionary2.Add(method.FuncName, method); } num = (ushort)(num + 1); } } etyDef.ClientMethodsByID = dictionary; etyDef.ClientMethodsByName = dictionary2; }
private void GetClientMethods(EntityDef entity, ArrayList methods) { Dictionary <ushort, EntityDefMethod> dictionary = new Dictionary <ushort, EntityDefMethod>(); Dictionary <string, EntityDefMethod> dictionary2 = new Dictionary <string, EntityDefMethod>(); if (methods != null) { ushort num = 0; foreach (SecurityElement element in methods) { EntityDefMethod method = new EntityDefMethod { FuncName = element.Tag, FuncID = num, ArgsType = new List <VObject>() }; if (element.Children != null) { foreach (SecurityElement element2 in element.Children) { method.ArgsType.Add(TypeMapping.GetVObject(element2.Text.Trim())); } } dictionary.Add(method.FuncID, method); if (!dictionary2.ContainsKey(method.FuncName)) { dictionary2.Add(method.FuncName, method); } num = (ushort)(num + 1); } } entity.ClientMethodsByID = dictionary; entity.ClientMethodsByName = dictionary2; }
/// <summary> /// 将远程方法调用编码为二进制数组。 /// </summary> /// <param name="args">参数列表</param> /// <returns>编码后的二进制数组</returns> public Byte[] Encode(params Object[] args) { EntityDef ety = CurrentEntity;//DefParser.Instance.GetEntityByName(EntityName); if (ety == null) { throw new DefineParseException(String.Format("Encode error: CurrentEntity is null.")); } EntityDefMethod method = svrMethod; FuncID = method.FuncID; if (method.ArgsType.Count != args.Length) { throw new DefineParseException(String.Format("Encode error: The number of parameters is not match. func: {0}, require num: {1}, current num: {2}.", FuncID, method.ArgsType.Count, args.Length)); } //屏蔽类型检查,报错就报吧 //for (int i = 0; i < method.ArgsType.Count; i++) //{ // if (!args[i].GetType().IsAssignableFrom(method.ArgsType[i].VValueType)) // throw new DefineParseException(String.Format("Encode error: Parameters type is not match '{0}' in entity '{1}' of index '{2}'.", FuncID, ety.Name, i)); //} if (toCell) { Push(VUInt16.Instance.Encode(MSGIDType.BASEAPP_CLIENT_RPC2CELL_VIA_BASE)); Push(VUInt16.Instance.Encode(FuncID)); for (int j = 0; j < args.Length; j++) { Push(method.ArgsType[j].Encode(args[j])); } Byte[] cellRst = new Byte[m_unLen]; Buffer.BlockCopy(m_szBuff, 0, cellRst, 0, m_unLen); EndPluto(cellRst); return(cellRst); } Push(VUInt16.Instance.Encode(MSGIDType.BASEAPP_CLIENT_RPCALL)); // 指定 pluto 类型为 rpc Push(VUInt16.Instance.Encode(FuncID)); // 指定 调用的 func 标识 for (int i = 0; i < args.Length; i++) { Push(method.ArgsType[i].Encode(args[i])); // 增加参数 } Byte[] result = new Byte[m_unLen]; Buffer.BlockCopy(m_szBuff, 0, result, 0, m_unLen); EndPluto(result); return(result); }
public EntityDefMethod TryGetCellMethod(ushort id, EntityDef entity) { EntityDefMethod method = null; if (entity != null) { entity.CellMethodsByID.TryGetValue(id, out method); if (method == null) { return(this.TryGetCellMethod(id, entity.Parent)); } } return(method); }
public EntityDefMethod TryGetCellMethod(string name, EntityDef entity) { EntityDefMethod method = null; if (entity != null) { entity.CellMethodsByName.TryGetValue(name, out method); if (method == null) { return(this.TryGetCellMethod(name, entity.Parent)); } } return(method); }
private void GetCellMethods(EntityDef entity, ArrayList methods) { var methodByIDList = new Dictionary <ushort, EntityDefMethod>(); var methodByNameList = new Dictionary <string, EntityDefMethod>(); if (methods != null) { ushort index = 0; //方法索引 foreach (SecurityElement element in methods) { //判断方法参数是否为空,或者第一个Tag是否标记为公开方法 if (element.Children != null && element.Children.Count != 0 && (element.Children[0] as SecurityElement).Tag == EL_EXPOSED) { var m = new EntityDefMethod(); m.FuncName = element.Tag; m.FuncID = index; m.ArgsType = new List <VObject>(); for (var i = 1; i < element.Children.Count; i++) //跳过第一个Tag字段 { var args = element.Children[i] as SecurityElement; m.ArgsType.Add(TypeMapping.GetVObject(args.Text.Trim())); //To do: Trim()优化 } //if (!methodByIDList.ContainsKey(index)) methodByIDList.Add(m.FuncID, m); if (!methodByNameList.ContainsKey(m.FuncName)) { methodByNameList.Add(m.FuncName, m); } } index++; } } //entity.BaseMethodsByID = methodByIDList; //entity.BaseMethodsByName = methodByNameList; entity.CellMethodsByID = methodByIDList; entity.CellMethodsByName = methodByNameList; //return methodByIDList; }
private void GetHmfBaseMethods(EntityDef etyDef, List <object> methods) { Dictionary <ushort, EntityDefMethod> methodByIDList = new Dictionary <ushort, EntityDefMethod>(); Dictionary <string, EntityDefMethod> methodByNameList = new Dictionary <string, EntityDefMethod>(); if (methods != null) { ushort index = 0;//方法索引 for (int i = 0; i < methods.Count; i++) { //判断方法参数是否为空,或者第一个Tag是否标记为公开方法 Dictionary <object, object> fun = (Dictionary <object, object>)methods[i]; KeyValuePair <object, object> kv = fun.First(); List <object> v = (List <object>)kv.Value; if (v != null && v.Count != 0 && (string)((List <object>)v[0])[0] == EL_EXPOSED) { EntityDefMethod m = new EntityDefMethod(); m.FuncName = (string)kv.Key; m.FuncID = index; m.ArgsType = new List <VObject>(); for (int j = 1; j < v.Count; j++)//跳过第一个Tag字段 { List <object> args = (List <object>)v[j]; m.ArgsType.Add(TypeMapping.GetVObject(((string)args[1]).Trim()));//To do: Trim()优化 } //if (!methodByIDList.ContainsKey(index)) methodByIDList.Add(m.FuncID, m); if (!methodByNameList.ContainsKey(m.FuncName)) { methodByNameList.Add(m.FuncName, m); } } index++; } } etyDef.BaseMethodsByID = methodByIDList; etyDef.BaseMethodsByName = methodByNameList; }
private void GetClientMethods(EntityDef entity, ArrayList methods) { var methodByIDList = new Dictionary <ushort, EntityDefMethod>(); var methodByNameList = new Dictionary <string, EntityDefMethod>(); if (methods != null) { ushort index = 0; //方法索引 foreach (SecurityElement element in methods) { //if (element.NodeType == XmlNodeType.Comment) // continue; var m = new EntityDefMethod(); m.FuncName = element.Tag; m.FuncID = index; m.ArgsType = new List <VObject>(); if (element.Children != null) { foreach (SecurityElement args in element.Children) { // if (args != null && args.NodeType == XmlNodeType.Element) m.ArgsType.Add(TypeMapping.GetVObject(args.Text.Trim())); //To do: Trim()优化 } } //if (!methodList.ContainsKey(index)) methodByIDList.Add(m.FuncID, m); if (!methodByNameList.ContainsKey(m.FuncName)) { methodByNameList.Add(m.FuncName, m); } index++; } } entity.ClientMethodsByID = methodByIDList; entity.ClientMethodsByName = methodByNameList; //return methodList; }
/// <summary> /// 将远程调用的方法解码为RpcCall调用。 /// </summary> /// <param name="data">远程调用方法的二进制数组</param> /// <param name="unLen">数据偏移量</param> protected override void DoDecode(byte[] data, ref int unLen) { FuncID = (ushort)VUInt16.Instance.Decode(data, ref unLen); if (CurrentEntity == null) { throw new DefineParseException(String.Format("Decode error: Current Entity is not set.")); } EntityDefMethod method = CurrentEntity.TryGetClientMethod(FuncID); if (method == null) { throw new DefineParseException(String.Format("Decode error: Can not find function '{0}' in entity '{1}'.", FuncID, CurrentEntity.Name)); } FuncName = method.FuncName; Arguments = new Object[method.ArgsType.Count]; for (int i = 0; i < method.ArgsType.Count; i++) { Arguments[i] = method.ArgsType[i].Decode(data, ref unLen); } //if (FuncName != "GetServerTimeResp") // LoggerHelper.Debug("Client call RPC_" + FuncName); }
private void GetHmfCellMethods(EntityDef etyDef, List <object> methods) { Dictionary <ushort, EntityDefMethod> dictionary = new Dictionary <ushort, EntityDefMethod>(); Dictionary <string, EntityDefMethod> dictionary2 = new Dictionary <string, EntityDefMethod>(); if (methods != null) { ushort num = 0; for (int i = 0; i < methods.Count; i++) { KeyValuePair <object, object> pair = ((Dictionary <object, object>)methods[i]).First <KeyValuePair <object, object> >(); List <object> list = (List <object>)pair.Value; if (((list != null) && (list.Count != 0)) && (((string)((List <object>)list[0])[0]) == "Exposed")) { EntityDefMethod method = new EntityDefMethod { FuncName = (string)pair.Key, FuncID = num, ArgsType = new List <VObject>() }; for (int j = 1; j < list.Count; j++) { List <object> list2 = (List <object>)list[j]; method.ArgsType.Add(TypeMapping.GetVObject(((string)list2[1]).Trim())); } dictionary.Add(method.FuncID, method); if (!dictionary2.ContainsKey(method.FuncName)) { dictionary2.Add(method.FuncName, method); } } num = (ushort)(num + 1); } } etyDef.CellMethodsByID = dictionary; etyDef.CellMethodsByName = dictionary2; }
private void GetHmfCellMethods(EntityDef etyDef, List<object> methods) { Dictionary<ushort, EntityDefMethod> methodByIDList = new Dictionary<ushort, EntityDefMethod>(); Dictionary<string, EntityDefMethod> methodByNameList = new Dictionary<string, EntityDefMethod>(); if (methods != null) { ushort index = 0;//方法索引 for(int i = 0; i < methods.Count; i++) { //判断方法参数是否为空,或者第一个Tag是否标记为公开方法 Dictionary<object, object> fun = (Dictionary<object, object>)methods[i]; KeyValuePair<object, object> kv = fun.First(); List<object> v = (List<object>)kv.Value; if (v != null && v.Count != 0 && (string)((List<object>)v[0])[0] == EL_EXPOSED) { EntityDefMethod m = new EntityDefMethod(); m.FuncName = (string)kv.Key; m.FuncID = index; m.ArgsType = new List<VObject>(); for (int j = 1; j < v.Count; j++)//跳过第一个Tag字段 { List<object> args = (List<object>)v[j]; m.ArgsType.Add(TypeMapping.GetVObject(((string)args[1]).Trim()));//To do: Trim()优化 } methodByIDList.Add(m.FuncID, m); if (!methodByNameList.ContainsKey(m.FuncName)) methodByNameList.Add(m.FuncName, m); } index++; } } etyDef.CellMethodsByID = methodByIDList; etyDef.CellMethodsByName = methodByNameList; }
private void GetHmfClientMethods(EntityDef etyDef, List<object> methods) { Dictionary<ushort, EntityDefMethod> methodByIDList = new Dictionary<ushort, EntityDefMethod>(); Dictionary<string, EntityDefMethod> methodByNameList = new Dictionary<string, EntityDefMethod>(); if (methods != null) { ushort index = 0;//方法索引 for (int i = 0; i < methods.Count; i++) { EntityDefMethod m = new EntityDefMethod(); Dictionary<object, object> fun = (Dictionary<object, object>)methods[i]; KeyValuePair<object, object> kv = fun.First(); m.FuncName = (string)kv.Key; m.FuncID = index; m.ArgsType = new List<VObject>(); if (kv.Value != null) { foreach (var args in (List<object>)kv.Value) { List<object> funargs = (List<object>)args; m.ArgsType.Add(TypeMapping.GetVObject(((string)funargs[1]).Trim()));//To do: Trim()优化 } } methodByIDList.Add(m.FuncID, m); if (!methodByNameList.ContainsKey(m.FuncName)) methodByNameList.Add(m.FuncName, m); index++; } } etyDef.ClientMethodsByID = methodByIDList; etyDef.ClientMethodsByName = methodByNameList; }
private void GetCellMethods(EntityDef entity, ArrayList methods) { Dictionary<ushort, EntityDefMethod> methodByIDList = new Dictionary<ushort, EntityDefMethod>(); Dictionary<string, EntityDefMethod> methodByNameList = new Dictionary<string, EntityDefMethod>(); if (methods != null) { ushort index = 0;//方法索引 foreach (SecurityElement element in methods) { //判断方法参数是否为空,或者第一个Tag是否标记为公开方法 if (element.Children != null && element.Children.Count != 0 && (element.Children[0] as SecurityElement).Tag == EL_EXPOSED) { EntityDefMethod m = new EntityDefMethod(); m.FuncName = element.Tag; m.FuncID = index; m.ArgsType = new List<VObject>(); for (int i = 1; i < element.Children.Count; i++)//跳过第一个Tag字段 { SecurityElement args = element.Children[i] as SecurityElement; m.ArgsType.Add(TypeMapping.GetVObject(args.Text.Trim()));//To do: Trim()优化 } //if (!methodByIDList.ContainsKey(index)) methodByIDList.Add(m.FuncID, m); if (!methodByNameList.ContainsKey(m.FuncName)) methodByNameList.Add(m.FuncName, m); } index++; } } //entity.BaseMethodsByID = methodByIDList; //entity.BaseMethodsByName = methodByNameList; entity.CellMethodsByID = methodByIDList; entity.CellMethodsByName = methodByNameList; //return methodByIDList; }
private void GetClientMethods(EntityDef entity, ArrayList methods) { Dictionary<ushort, EntityDefMethod> methodByIDList = new Dictionary<ushort, EntityDefMethod>(); Dictionary<string, EntityDefMethod> methodByNameList = new Dictionary<string, EntityDefMethod>(); if (methods != null) { ushort index = 0;//方法索引 foreach (SecurityElement element in methods) { //if (element.NodeType == XmlNodeType.Comment) // continue; EntityDefMethod m = new EntityDefMethod(); m.FuncName = element.Tag; m.FuncID = index; m.ArgsType = new List<VObject>(); if (element.Children != null) { foreach (SecurityElement args in element.Children) { // if (args != null && args.NodeType == XmlNodeType.Element) m.ArgsType.Add(TypeMapping.GetVObject(args.Text.Trim()));//To do: Trim()优化 } } //if (!methodList.ContainsKey(index)) methodByIDList.Add(m.FuncID, m); if (!methodByNameList.ContainsKey(m.FuncName)) methodByNameList.Add(m.FuncName, m); index++; } } entity.ClientMethodsByID = methodByIDList; entity.ClientMethodsByName = methodByNameList; //return methodList; }