public static string MakeClientCppClassDeclareCodePure(TreeNode node) { RPC.RPCClassAttribute ca = node.Tag as RPC.RPCClassAttribute; if (ca == null) { return(""); } string strOut = BeginCppNamespaceDeclare(ca.RPCType.Namespace); strOut += "struct H_" + ca.RPCType.Name + ";" + EndLine; strOut += EndCppNamespaceDeclare(ca.RPCType.Namespace); return(strOut); }
public static string MakeClientCppClassCode(TreeNode node) { RPC.RPCClassAttribute ca = node.Tag as RPC.RPCClassAttribute; if (ca == null) { return(""); } string strOut = "";//= BeginCppNamespaceDeclare(ca.RPCType.Namespace); string strClassName = CSharp2CppType(ca.RPCType.Namespace) + "::H_" + ca.RPCType.Name; strOut += TabStr + strClassName + "* " + strClassName + "::smInstance(){ static " + strClassName + " gInst; return &gInst;}" + EndLine; foreach (TreeNode childNode in node.Nodes) { MethodDesc ma = childNode.Tag as MethodDesc; if (ma != null) { strOut += MakeCppCallCode(ma, strClassName); } System.Reflection.PropertyInfo pi = childNode.Tag as System.Reflection.PropertyInfo; if (pi != null) { if (pi.Name == "Item") { strOut += MakeCppIndexObjectCode(pi, System.Convert.ToInt32(childNode.Name), strClassName); } else { strOut += MakeCppChildObjectCode(pi, System.Convert.ToInt32(childNode.Name), strClassName); } } } strOut += "";//EndCppNamespaceDeclare(ca.RPCType.Namespace); return(strOut); }
public static string MakeIndexerExecuterCode(System.Reflection.PropertyInfo pi, TreeNode node, bool bIsClient) { string fullname = ""; int LimitLevel = 0; if (bIsClient) { fullname = node.Name; } else { RPC.RPCClassAttribute ClassAttr = node.Tag as RPC.RPCClassAttribute; fullname = ClassAttr.RPCType.FullName; object[] propAttrs = pi.GetCustomAttributes(typeof(RPC.RPCIndexObjectAttribute), false); if (propAttrs != null && propAttrs.Length == 1) { RPC.RPCIndexObjectAttribute propAtt = propAttrs[0] as RPC.RPCIndexObjectAttribute; if (propAtt != null) { LimitLevel = propAtt.LimitLevel; } } } string strOut = ""; strOut += "[RPC.RPCIndexExecuterTypeAttribute(" + RPC.RPCEntrance.GetIndexerHashCode(pi, fullname) + ",\"" + pi.Name + "\",typeof(HIndex_" + RPC.RPCEntrance.GetIndexerHashCode(pi, fullname) + "))]" + EndLine; strOut += "public class HIndex_" + RPC.RPCEntrance.GetIndexerHashCode(pi, fullname) + ": RPC.RPCIndexerExecuter" + EndLine; strOut += "{" + EndLine; strOut += TabStr + "public override int LimitLevel" + EndLine; strOut += TabStr + "{" + EndLine; strOut += TabStr + TabStr + "get { return " + LimitLevel + "; }" + EndLine; strOut += TabStr + "}" + EndLine; strOut += TabStr + "public override RPC.RPCObject Execute(RPC.RPCObject obj,RPC.PackageProxy pkg)" + EndLine; strOut += TabStr + "{" + EndLine; strOut += TabStr + TabStr + fullname + " host = obj as " + fullname + ";" + EndLine; strOut += TabStr + TabStr + "if (host == null) return null;" + EndLine; string strCall = ""; System.Reflection.ParameterInfo[] parameters = pi.GetIndexParameters(); for (int i = 0; i < parameters.Length; i++) { bool isNew = false; Type baseType = parameters[i].ParameterType; while (!isNew) { baseType = baseType.BaseType; if (baseType == null) { break; } if (baseType.Name == "IAutoSaveAndLoad") { isNew = true; break; } } if (isNew) { strOut += TabStr + TabStr + parameters[i].ParameterType.FullName + " " + parameters[i].Name + " = new " + parameters[i].ParameterType.FullName + "();" + EndLine; strOut += TabStr + TabStr + "pkg.Read( " + parameters[i].Name + ");" + EndLine; } else { strOut += TabStr + TabStr + parameters[i].ParameterType.FullName + " " + parameters[i].Name + ";" + EndLine; strOut += TabStr + TabStr + "pkg.Read(out " + parameters[i].Name + ");" + EndLine; } if (i == parameters.Length - 1) { strCall += parameters[i].Name; } else { strCall += parameters[i].Name + ","; } } strOut += TabStr + TabStr + "return host[" + strCall + "];" + EndLine; strOut += TabStr + "}" + EndLine; strOut += "}" + EndLine; return(strOut); }
public static string MakeClientClassCode(TreeNode node, bool bIsClient, out string strClientOut) { object obj = node.Tag; strClientOut = ""; if (obj == null) { return(""); } string[] full = obj.ToString().Split('.'); string strOut = ""; if (full.Length <= 0) { return(""); } do { if (!bIsClient) { RPC.RPCClassAttribute attr = obj as RPC.RPCClassAttribute; full = attr.RPCType.ToString().Split('.'); } if (full.Length == 1) { strOut += "public class H_" + full[0] + EndLine; strOut += "{" + EndLine; strOut += TabStr + "public static " + "H_" + full[0] + " smInstance = new H_" + full[0] + "();" + EndLine; break; } else if (full.Length > 2) { string[] objNew = new string[2]; string strNameSpace = ""; for (int i = 0; i < full.Length - 1; i++) { strNameSpace += full[i]; if (i < full.Length - 2) { strNameSpace += '.'; } } objNew[0] = strNameSpace; objNew[1] = full[full.Length - 1]; full = objNew; } strOut += "namespace " + full[0] + "{" + EndLine; strOut += "public class H_" + full[1] + EndLine; strOut += "{" + EndLine; strOut += TabStr + "public static " + full[0] + ".H_" + full[1] + " smInstance = new " + full[0] + ".H_" + full[1] + "();" + EndLine; } while (false); strClientOut += strOut; foreach (TreeNode childNode in node.Nodes) { MethodDesc ma = childNode.Tag as MethodDesc; if (ma != null) { string code = MakeCallCode(ma); strOut += code; if (!bIsClient) { if (ma.rpcAttr.LimitLevel < 400) { strClientOut += code; } } } System.Reflection.PropertyInfo pi = childNode.Tag as System.Reflection.PropertyInfo; if (pi != null) { if (pi.Name == "Item") { string strIndex = MakeIndexObjectCode(pi, System.Convert.ToInt32(childNode.Name)); strOut += strIndex; strClientOut += strIndex; } else { string strChild = MakeChildObjectCode(pi, System.Convert.ToInt32(childNode.Name)); strOut += strChild; strClientOut += strChild; } } } strOut += "}" + EndLine; strOut += "}" + EndLine; strClientOut += "}" + EndLine; strClientOut += "}" + EndLine; return(strOut); }
private void LoadMoudleForServ(string moduleName) { System.Reflection.Assembly assembly; assembly = System.Reflection.Assembly.LoadFrom(moduleName); Type[] types = assembly.GetTypes(); foreach (Type t in types) { object[] attrs = t.GetCustomAttributes(typeof(RPC.RPCClassAttribute), false); if (attrs != null && attrs.Length == 1) { RPC.RPCClassAttribute att = attrs[0] as RPC.RPCClassAttribute; if (att == null) { continue; } TreeNode cNode = this.treeView1.Nodes.Add(t.FullName); cNode.Tag = att; cNode.Name = t.FullName; System.Reflection.PropertyInfo[] props = t.GetProperties(); foreach (System.Reflection.PropertyInfo p in props) { if (p.Name == "Item") { object[] propAttrs = p.GetCustomAttributes(typeof(RPC.RPCIndexObjectAttribute), false); if (propAttrs != null && propAttrs.Length == 1) { RPC.RPCIndexObjectAttribute propAtt = propAttrs[0] as RPC.RPCIndexObjectAttribute; if (propAtt == null) { continue; } TreeNode coNode = cNode.Nodes.Add("(I:" + propAtt.ChildIndex.ToString() + ")" + p.Name); coNode.Tag = p; coNode.Name = propAtt.ChildIndex.ToString(); } } else { object[] propAttrs = p.GetCustomAttributes(typeof(RPC.RPCChildObjectAttribute), false); if (propAttrs != null && propAttrs.Length == 1) { RPC.RPCChildObjectAttribute propAtt = propAttrs[0] as RPC.RPCChildObjectAttribute; if (propAtt == null) { continue; } TreeNode coNode = cNode.Nodes.Add("(P:" + propAtt.ChildIndex.ToString() + ")" + p.Name); coNode.Tag = p; coNode.Name = propAtt.ChildIndex.ToString(); } } } { System.Reflection.MethodInfo[] methords = t.GetMethods(); Byte indexOfMethod = 0; foreach (System.Reflection.MethodInfo m in methords) { object[] mtdAttrs = m.GetCustomAttributes(typeof(RPC.RPCMethodAttribute), false); if (mtdAttrs != null && mtdAttrs.Length == 1) { RPC.RPCMethodAttribute propAtt = mtdAttrs[0] as RPC.RPCMethodAttribute; MethodDesc desc = new MethodDesc(); desc.mi = m; desc.rpcAttr = propAtt; desc.hostType = t; desc.MethodIndex = indexOfMethod; indexOfMethod++; desc.HashcodeOfMethod = RPC.RPCEntrance.GetMethodHashCode(m, t.FullName); TreeNode cmNode = cNode.Nodes.Add(m.Name); cmNode.Tag = desc; } } } } } }