/// <summary> /// 根据类型获取成员信息集合 /// </summary> /// <param name="type">类型</param> /// <returns>成员信息集合</returns> private static MemberIndex[] getMembers(Type type) { MemberIndex[] members; if (!memberCache.TryGetValue(type, out members)) { MemberIndexGroup group = MemberIndexGroup.Get(type); memberCache[type] = members = ArrayExtension.concat(group.PublicFields.getArray(value => new MemberIndex(value)), group.NonPublicFields.getArray(value => new MemberIndex(value)), group.PublicProperties.getArray(value => new MemberIndex(value)), group.NonPublicProperties.getArray(value => new MemberIndex(value))); } return(members); }
/// <summary> /// 安装下一个类型 /// </summary> protected unsafe override void nextCreate() { if (Type.Type.IsClass && !Type.Type.IsAbstract) { LeftArray <TcpMethod> methodArray = new LeftArray <TcpMethod>(Metadata.MethodIndex.GetMethods <AutoCSer.Net.TcpStreamServer.MethodAttribute>(Type, Attribute.MemberFilters, false, Attribute.IsAttribute, Attribute.IsBaseTypeAttribute) .getFind(value => !value.Method.IsGenericMethod) .getArray(value => new TcpMethod { Method = value, MethodType = Type, ServiceAttribute = Attribute })); foreach (MemberIndexInfo member in MemberIndexGroup.Get <AutoCSer.Net.TcpStreamServer.MethodAttribute>(Type, Attribute.MemberFilters, false, Attribute.IsAttribute, Attribute.IsBaseTypeAttribute)) { if (member.IsField) { FieldInfo field = (FieldInfo)member.Member; TcpMethod getMethod = new TcpMethod { Method = new Metadata.MethodIndex(field, true), MemberIndex = member, MethodType = Type, ServiceAttribute = Attribute }; if (!getMethod.Attribute.IsOnlyGetMember) { getMethod.SetMethod = new TcpMethod { Method = new MethodIndex(field, false), MemberIndex = member, MethodType = Type, ServiceAttribute = Attribute }; } methodArray.Add(getMethod); if (getMethod.SetMethod != null) { methodArray.Add(getMethod.SetMethod); } } else if (member.CanGet) { PropertyInfo property = (PropertyInfo)member.Member; TcpMethod getMethod = new TcpMethod { Method = new MethodIndex(property, true), MemberIndex = member, MethodType = Type, ServiceAttribute = Attribute }; if (member.CanSet && !getMethod.Attribute.IsOnlyGetMember) { getMethod.SetMethod = new TcpMethod { Method = new MethodIndex(property, false), MemberIndex = member, MethodType = Type, ServiceAttribute = Attribute }; } methodArray.Add(getMethod); if (getMethod.SetMethod != null) { methodArray.Add(getMethod.SetMethod); } } } MethodIndexs = methodArray.ToArray(); MethodIndexs = TcpMethod.CheckIdentity(MethodIndexs, getRememberIdentityName(Attribute.GenericType ?? Type), method => method.Method.MethodKeyFullName); if (MethodIndexs == null) { return; } int methodIndex = 0; IsVerifyMethod = false; ParameterBuilder parameterBuilder = new ParameterBuilder { IsSimpleSerialize = Attribute.IsSimpleSerialize }; foreach (TcpMethod method in MethodIndexs) { method.MethodIndex = methodIndex++; if (!method.IsNullMethod) { if (IsVerifyMethod) { method.Attribute.IsVerifyMethod = false; } else if (method.IsVerifyMethod) { IsVerifyMethod = true; } parameterBuilder.Add(method); } } ParameterTypes = parameterBuilder.Get(); //TcpMethod[] methodIndexs = MethodIndexs.getFindArray(value => !value.IsNullMethod); if (ServiceAttribute.IsSegmentation) { IsClientCode = false; create(IsServerCode = true); CSharpTypeDefinition definition = new CSharpTypeDefinition(Type, IsClientCode = true, false, Type.Type.Namespace + ".TcpStreamClient"); _code_.Length = 0; _code_.Add(definition.Start); create(IsServerCode = false); _code_.Add(definition.End); string fileName = AutoParameter.ProjectPath + "{" + AutoParameter.DefaultNamespace + "}.TcpInternalStreamServer." + ServerName + ".Client.cs"; string clientCode = Coder.WarningCode + _code_.ToString() + Coder.FileEndCode; if (Coder.WriteFile(fileName, clientCode)) { if (ServiceAttribute.ClientSegmentationCopyPath != null) { string copyFileName = ServiceAttribute.ClientSegmentationCopyPath + "{" + AutoParameter.DefaultNamespace + "}.TcpInternalStreamServer." + ServerName + ".Client.cs"; if (Coder.WriteFile(copyFileName, clientCode)) { Messages.Message(copyFileName + " 被修改"); } } Messages.Message(fileName + " 被修改"); } } else { create(IsServerCode = IsClientCode = true); } } }
/// <summary> /// 获取数据库成员信息集合 /// </summary> /// <param name="type">数据库绑定类型</param> /// <param name="database">数据库配置</param> /// <returns>数据库成员信息集合</returns> internal static KeyValue <MemberIndexInfo, MemberAttribute>[] GetMemberIndexs <attributeType>(Type type, attributeType database) where attributeType : Metadata.MemberFilterAttribute { return(GetMembers(MemberIndexGroup.Get(type).Find <MemberAttribute>(database))); }
/// <summary> /// 安装下一个类型 /// </summary> protected unsafe override void nextCreate() { if (Type.Type.IsClass && !Type.Type.IsAbstract) { LeftArray <TcpMethod> methodArray = new LeftArray <TcpMethod>(Metadata.MethodIndex.GetMethods <AutoCSer.Net.TcpServer.MethodAttribute>(Type, Attribute.GetMemberFilters, false, Attribute.IsAttribute, Attribute.IsBaseTypeAttribute) .getFind(value => !value.Method.IsGenericMethod) .getArray(value => new TcpMethod { Method = value, MethodType = Type, ServiceAttribute = Attribute })); foreach (MemberIndexInfo member in MemberIndexGroup.Get <AutoCSer.Net.TcpServer.MethodAttribute>(Type, Attribute.GetMemberFilters, false, Attribute.IsAttribute, Attribute.IsBaseTypeAttribute)) { if (member.IsField) { FieldInfo field = (FieldInfo)member.Member; TcpMethod getMethod = new TcpMethod { Method = new Metadata.MethodIndex(field, true), MemberIndex = member, MethodType = Type, ServiceAttribute = Attribute }; if (!getMethod.Attribute.IsOnlyGetMember) { getMethod.SetMethod = new TcpMethod { Method = new MethodIndex(field, false), MemberIndex = member, MethodType = Type, ServiceAttribute = Attribute }; } methodArray.Add(getMethod); if (getMethod.SetMethod != null) { methodArray.Add(getMethod.SetMethod); } } else if (member.CanGet) { PropertyInfo property = (PropertyInfo)member.Member; TcpMethod getMethod = new TcpMethod { Method = new MethodIndex(property, true), MemberIndex = member, MethodType = Type, ServiceAttribute = Attribute }; if (member.CanSet && !getMethod.Attribute.IsOnlyGetMember) { getMethod.SetMethod = new TcpMethod { Method = new MethodIndex(property, false), MemberIndex = member, MethodType = Type, ServiceAttribute = Attribute }; } methodArray.Add(getMethod); if (getMethod.SetMethod != null) { methodArray.Add(getMethod.SetMethod); } } } MethodIndexs = methodArray.ToArray(); MethodIndexs = TcpMethod.CheckIdentity(MethodIndexs, Attribute.CommandIdentityEnmuType, getRememberIdentityName(Attribute.CommandIdentityEnmuType == null ? Attribute.GenericType ?? Type : null), method => method.Method.MethodKeyFullName); if (MethodIndexs == null) { return; } int methodIndex = CallQueueCount = 0; IsVerifyMethod = false; IsCallQueueLink = ServiceAttribute.GetRemoteExpressionServerTask == Net.TcpServer.ServerTaskType.QueueLink; if (ServiceAttribute.GetRemoteExpressionServerTask == Net.TcpServer.ServerTaskType.Queue || ServiceAttribute.GetRemoteExpressionServerTask == Net.TcpServer.ServerTaskType.QueueLink) { CallQueueCount = (int)ServiceAttribute.GetRemoteExpressionCallQueueIndex + 1; } ParameterBuilder parameterBuilder = new ParameterBuilder { IsSimpleSerialize = Attribute.IsSimpleSerialize }; QueueTypeBuilder queueTypeBuilder = new QueueTypeBuilder(); foreach (TcpMethod method in MethodIndexs) { method.MethodIndex = methodIndex++; if (!method.IsNullMethod) { if (IsVerifyMethod) { method.Attribute.IsVerifyMethod = false; } else if (method.IsVerifyMethod) { IsVerifyMethod = true; IsSynchronousVerifyMethod = method.Attribute.ServerTaskType == AutoCSer.Net.TcpServer.ServerTaskType.Synchronous && !method.IsAsynchronousCallback; //method.Attribute.ServerTaskType = Net.TcpServer.ServerTaskType.Synchronous; } parameterBuilder.Add(method); queueTypeBuilder.Add(method); IsCallQueueLink |= method.Attribute.ServerTaskType == Net.TcpServer.ServerTaskType.QueueLink; if (method.Attribute.ServerTaskType == Net.TcpServer.ServerTaskType.Queue || method.Attribute.ServerTaskType == Net.TcpServer.ServerTaskType.QueueLink) { CallQueueCount = Math.Max((int)method.Attribute.GetServerQueueIndex + 1, CallQueueCount); } MaxTimeoutSeconds = Math.Max(MaxTimeoutSeconds, method.Attribute.GetClientTimeoutSeconds); //if (method.IsAsynchronousCallback && method.Attribute.ServerTaskType != Net.TcpServer.ServerTaskType.Synchronous) //{ // Messages.Message("异步函数警告" + method.MemberFullName); //} } } ParameterTypes = parameterBuilder.Get(); ServerCallQueueTypes = queueTypeBuilder.Get(); //TcpMethod[] methodIndexs = MethodIndexs.getFindArray(value => !value.IsNullMethod); if (ServiceAttribute.GetIsSegmentation) { IsClientCode = false; create(IsServerCode = true); CSharpTypeDefinition definition = new CSharpTypeDefinition(Type, IsClientCode = true, false, Type.Type.Namespace + ".TcpClient"); _code_.Length = 0; _code_.Add(definition.Start); create(IsServerCode = false); _code_.Add(definition.End); string fileName = AutoParameter.ProjectPath + "{" + AutoParameter.DefaultNamespace + "}.TcpInternalServer." + ServerName + ".Client.cs"; string clientCode = Coder.WarningCode + _code_.ToString() + Coder.FileEndCode; if (Coder.WriteFile(fileName, clientCode)) { if (ServiceAttribute.ClientSegmentationCopyPath != null) { string copyFileName = ServiceAttribute.ClientSegmentationCopyPath + "{" + AutoParameter.DefaultNamespace + "}.TcpInternalServer." + ServerName + ".Client.cs"; if (Coder.WriteFile(copyFileName, clientCode)) { Messages.Message(copyFileName + " 被修改"); } } Messages.Message(fileName + " 被修改"); } } else { create(IsServerCode = IsClientCode = true); } } }