Пример #1
0
 /// <summary>
 /// 安装下一个类型
 /// </summary>
 protected override void nextCreate()
 {
     if ((Attribute.IsAbstract || Type.Type.IsSealed || !Type.Type.IsAbstract) && !Type.Type.IsInterface)
     {
         defaultServerName = Attribute.ServerName;
         defaultServer     = null;
         defaultType       = null;
         if (defaultServerName != null)
         {
             HashString nameKey = defaultServerName;
             if (!servers.TryGetValue(nameKey, out defaultServer))
             {
                 servers.Add(nameKey, defaultServer = new Server());
             }
             defaultServer.Attribute.Name        = defaultServerName;
             defaultServer.Types.Add(defaultType = new ServerType {
                 Type = Type, Attribute = Attribute
             });
             if (Attribute.IsServer)
             {
                 defaultServer.AttributeType = Type;
                 defaultServer.Attribute.CopyFrom(Attribute);
             }
         }
         foreach (MethodIndex method in MethodIndex.GetMethods <AutoCSer.Net.TcpStaticSimpleServer.MethodAttribute>(Type, Attribute.MemberFilters, false, Attribute.IsAttribute, Attribute.IsBaseTypeAttribute))
         {
             next(new TcpMethod {
                 Method = method, MethodType = Type
             });
         }
         if (!Type.Type.IsGenericType)
         {
             foreach (MemberIndexInfo member in StaticMemberIndexGroup.Get <AutoCSer.Net.TcpStaticSimpleServer.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
                     };
                     if (!getMethod.Attribute.IsOnlyGetMember)
                     {
                         getMethod.SetMethod = new TcpMethod {
                             Method = new Metadata.MethodIndex(field, false), MemberIndex = member, MethodType = Type
                         };
                     }
                     next(getMethod);
                     if (getMethod.SetMethod != null)
                     {
                         next(getMethod.SetMethod);
                     }
                 }
                 else if (member.CanGet)
                 {
                     PropertyInfo property  = (PropertyInfo)member.Member;
                     TcpMethod    getMethod = new TcpMethod
                     {
                         Method      = new Metadata.MethodIndex(property, true),
                         MemberIndex = member,
                         MethodType  = Type
                     };
                     if (member.CanSet && !getMethod.Attribute.IsOnlyGetMember)
                     {
                         getMethod.SetMethod = new TcpMethod {
                             Method = new Metadata.MethodIndex(property, false), MemberIndex = member, MethodType = Type
                         };
                     }
                     next(getMethod);
                     if (getMethod.SetMethod != null)
                     {
                         next(getMethod.SetMethod);
                     }
                 }
             }
         }
         serverTypes.Clear();
     }
 }
Пример #2
0
            /// <summary>
            /// 安装下一个类型
            /// </summary>
            protected override void nextCreate()
            {
                if ((Attribute.IsAbstract || Type.Type.IsSealed || !Type.Type.IsAbstract) && !Type.Type.IsInterface)
                {
                    defaultServerName = Attribute.ServerName;
                    defaultServer     = null;
                    defaultType       = null;
                    if (defaultServerName != null)
                    {
                        HashString nameKey = defaultServerName;
                        if (!servers.TryGetValue(nameKey, out defaultServer))
                        {
                            servers.Add(nameKey, defaultServer = new Server());
                        }
                        defaultServer.Attribute.Name        = defaultServerName;
                        defaultServer.Types.Add(defaultType = new ServerType {
                            Type = Type, Attribute = Attribute
                        });
                        if (Attribute.IsServer)
                        {
                            defaultServer.AttributeType = Type;
                            defaultServer.Attribute.CopyFrom(Attribute);
                        }
                    }
                    RemoteLinkType remoteLinkType = null;
                    if (Attribute.ServerName != null)
                    {
                        if (Attribute.IsRemoteLinkType)
                        {
                            remoteLinkType = new RemoteLinkType {
                                Type = Type, ParameterType = Type
                            }
                        }
                        ;
                        else if (Attribute.IsRemoteLink)
                        {
                            remoteLinkType = GetRemoteLinkType(Type);
                        }
                    }
                    LeftArray <RemoteMethod> remoteMethods = new LeftArray <RemoteMethod>(0);
                    foreach (MethodIndex method in MethodIndex.GetMethods <AutoCSer.Net.TcpStaticServer.MethodAttribute>(Type, Attribute.GetMemberFilters, false, Attribute.IsAttribute, Attribute.IsBaseTypeAttribute))
                    {
                        next(new TcpMethod {
                            Method = method, MethodType = Type
                        });
                        if (remoteLinkType != null && !method.Method.IsGenericMethodDefinition)
                        {
                            AutoCSer.Net.TcpStaticServer.RemoteMemberAttribute remoteAttribute = method.GetSetupAttribute <AutoCSer.Net.TcpStaticServer.RemoteMemberAttribute>(false);
                            if (remoteAttribute != null && remoteAttribute.IsClientRemoteMember)
                            {
                                MethodParameter[] parameters = method.Parameters;
                                if (parameters.Length >= 1 && parameters[0].ParameterType.Type == remoteLinkType.ParameterType)
                                {
                                    remoteMethods.Add(new RemoteMethod {
                                        Type = Type, Method = method, MethodParameters = parameters, Attribute = remoteAttribute
                                    });
                                }
                            }
                        }
                    }
                    if (remoteLinkType != null)
                    {
                        remoteLinkType.RemoteMethods = remoteMethods.ToArray();

                        LeftArray <RemoteMember> remoteMembers = new LeftArray <RemoteMember>(0);
                        foreach (MemberIndex member in MemberIndex.GetMembers <AutoCSer.Net.TcpStaticServer.RemoteMemberAttribute>(Type, AutoCSer.Metadata.MemberFilters.NonPublicInstanceProperty, true, false))
                        {
                            if (member.CanGet)
                            {
                                AutoCSer.Net.TcpStaticServer.RemoteMemberAttribute remoteAttribute = member.GetSetupAttribute <AutoCSer.Net.TcpStaticServer.RemoteMemberAttribute>(false);
                                if (remoteAttribute != null)
                                {
                                    if (member.IsField || ((PropertyInfo)member.Member).GetIndexParameters().Length == 0)
                                    {
                                        remoteMembers.Add(new RemoteMember {
                                            Member = member, Attribute = remoteAttribute
                                        });
                                    }
                                }
                            }
                        }
                        foreach (MethodIndex member in MethodIndex.GetMethods <AutoCSer.Net.TcpStaticServer.RemoteMemberAttribute>(Type, AutoCSer.Metadata.MemberFilters.NonPublicInstance, false, true, false))
                        {
                            if (!member.Method.IsGenericMethodDefinition)
                            {
                                AutoCSer.Net.TcpStaticServer.RemoteMemberAttribute remoteAttribute = member.GetSetupAttribute <AutoCSer.Net.TcpStaticServer.RemoteMemberAttribute>(false);
                                if (remoteAttribute != null)
                                {
                                    remoteMembers.Add(new RemoteMember {
                                        Method = member, Attribute = remoteAttribute
                                    });
                                }
                            }
                        }
                        remoteLinkType.RemoteMembers = remoteMembers.ToArray();

                        RemoteLinkBuilder cacheBuilder = new RemoteLinkBuilder();
                        foreach (MemberIndex member in MemberIndex.GetMembers <AutoCSer.Net.TcpStaticServer.RemoteLinkAttribute>(Type, AutoCSer.Metadata.MemberFilters.NonPublicInstance, true, false))
                        {
                            cacheBuilder.Push(member);
                        }
                        remoteLinkType.RemoteLinks = cacheBuilder.Caches.ToArray();

                        if (remoteLinkType.IsRemoteLink)
                        {
                            defaultServer.RemoteLinkTypes.Add(remoteLinkType);
                        }
                    }
                    if (!Type.Type.IsGenericType)
                    {
                        foreach (MemberIndexInfo member in StaticMemberIndexGroup.Get <AutoCSer.Net.TcpStaticServer.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
                                };
                                if (!getMethod.Attribute.IsOnlyGetMember)
                                {
                                    getMethod.SetMethod = new TcpMethod {
                                        Method = new Metadata.MethodIndex(field, false), MemberIndex = member, MethodType = Type
                                    };
                                }
                                next(getMethod);
                                if (getMethod.SetMethod != null)
                                {
                                    next(getMethod.SetMethod);
                                }
                            }
                            else if (member.CanGet)
                            {
                                PropertyInfo property  = (PropertyInfo)member.Member;
                                TcpMethod    getMethod = new TcpMethod
                                {
                                    Method      = new Metadata.MethodIndex(property, true),
                                    MemberIndex = member,
                                    MethodType  = Type
                                };
                                if (member.CanSet && !getMethod.Attribute.IsOnlyGetMember)
                                {
                                    getMethod.SetMethod = new TcpMethod {
                                        Method = new Metadata.MethodIndex(property, false), MemberIndex = member, MethodType = Type
                                    };
                                }
                                next(getMethod);
                                if (getMethod.SetMethod != null)
                                {
                                    next(getMethod.SetMethod);
                                }
                            }
                        }
                    }
                    serverTypes.Empty();
                }
            }