/// <summary>
            /// 下一个函数处理
            /// </summary>
            /// <param name="methodIndex"></param>
            private void next(TcpMethod methodIndex)
            {
                AutoCSer.Net.TcpStaticSimpleServer.MethodAttribute attribute = methodIndex.Attribute;
                Server     server      = defaultServer;
                ServerType serverType  = defaultType;
                string     serviceName = attribute.GetServerName;

                if (serviceName == null)
                {
                    serviceName = Attribute.ServerName;
                }
                if (serviceName != defaultServerName)
                {
                    if (serviceName == null)
                    {
                        serverType = null;
                    }
                    else
                    {
                        HashString nameKey = serviceName;
                        if (!servers.TryGetValue(nameKey, out server))
                        {
                            servers.Add(nameKey, server = new Server());
                            server.Attribute.Name       = serviceName;
                        }
                        if (!serverTypes.TryGetValue(nameKey, out serverType))
                        {
                            server.Types.Add(serverType = new ServerType {
                                Type = Type
                            });
                            serverTypes.Add(nameKey, serverType);
                        }
                    }
                }
                if (serverType != null)
                {
                    server.IsMethod = true;
                    methodIndex.ServiceAttribute = server.Attribute;
                    //methodIndex.MethodIndex = server.MethodIndex++;
                    //methodIndex.ParameterIndex = parameterIndex++;
                    serverType.Methods.Add(methodIndex);
                }
            }
 /// <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>
            protected unsafe override void onCreated()
            {
                StringArray           clientCallCode = new StringArray();
                LeftArray <TcpMethod> methods        = new LeftArray <TcpMethod>();

                TcpMethod[]      methodIndexs;
                ParameterBuilder parameterBuilder = new ParameterBuilder();
                int staticMethodIndex             = 0;

                foreach (Server server in servers.Values)
                {
                    if (server.IsMethod)
                    {
                        IsAllType = false;
                        TcpServerAttributeType = server.AttributeType == null || server.AttributeType.Type == null ? null : server.AttributeType.FullName;
                        ServiceAttribute       = server.Attribute;
                        foreach (ServerType serverType in server.Types)
                        {
                            methods.Add(serverType.Methods);
                        }
                        methodIndexs   = methods.ToArray();
                        methods.Length = 0;
                        methodIndexs   = TcpMethod.CheckIdentity(methodIndexs, getRememberIdentityName(), method => method.Method.MethodKeyFullName);
                        if (methodIndexs == null)
                        {
                            return;
                        }
                        int index = 0;
                        IsVerifyMethod = IsCallQueue = false;
                        parameterBuilder.Clear(ServiceAttribute.IsSimpleSerialize);
                        foreach (TcpMethod method in methodIndexs)
                        {
                            method.MethodIndex       = index++;
                            method.StaticMethodIndex = ++staticMethodIndex;
                            if (!method.IsNullMethod)
                            {
                                if (IsVerifyMethod)
                                {
                                    method.Attribute.IsVerifyMethod = false;
                                }
                                else if (method.IsVerifyMethod)
                                {
                                    IsVerifyMethod = true;
                                    if (method.MethodType == server.AttributeType && server.IsTimeVerify)
                                    {
                                        TimeVerifyMethod = method;
                                    }
                                }
                                parameterBuilder.Add(method);

                                IsCallQueue |= method.Attribute.ServerTaskType == Net.TcpServer.ServerTaskType.Queue;
                            }
                        }
                        ParameterTypes = parameterBuilder.Get();
                        foreach (ServerType serverType in server.Types)
                        {
                            if (serverType.Methods.Length != 0)
                            {
                                Type = serverType.Type;
                                //TimeVerifyType = Type == server.AttributeType && server.IsTimeVerify ? Type : ExtensionType.Null;
                                Attribute    = serverType.Attribute ?? server.Attribute;
                                MethodIndexs = serverType.Methods.ToArray();
                                CSharpTypeDefinition definition = new CSharpTypeDefinition(Type, true, false);
                                _code_.Length = 0;
                                create(false);
                                Coder.Add(definition.Start + _partCodes_["SERVERCALL"] + definition.End);
                                if (ServiceAttribute.IsSegmentation)
                                {
                                    clientCallCode.Add(definition.Start + _partCodes_["CLIENTCALL"] + definition.End);
                                }
                                else
                                {
                                    Coder.Add(definition.Start + _partCodes_["CLIENTCALL"] + definition.End);
                                }
                            }
                        }
                        Type           = server.AttributeType;
                        Attribute      = server.Attribute;
                        IsAllType      = true;
                        MethodIndexs   = methodIndexs;
                        methods.Length = 0;
                        _code_.Length  = 0;
                        create(false);
                        Coder.Add(@"
namespace " + AutoParameter.DefaultNamespace + "." + serverPart + @"
{
" + _partCodes_["SERVER"] + @"
}");
                        string clientCode = @"
namespace " + AutoParameter.DefaultNamespace + "." + SimpleClientPart + @"
{
" + _partCodes_["CLIENT"] + @"
}";
                        if (ServiceAttribute.IsSegmentation)
                        {
                            clientCallCode.Add(clientCode);
                            string fileName = AutoParameter.ProjectPath + "{" + AutoParameter.DefaultNamespace + "}.TcpStaticSimpleServer." + ServiceAttribute.ServerName + ".Client.cs";
                            clientCode = Coder.WarningCode + clientCallCode.ToString() + Coder.FileEndCode;
                            if (Coder.WriteFile(fileName, clientCode))
                            {
                                if (ServiceAttribute.ClientSegmentationCopyPath != null)
                                {
                                    string copyFileName = ServiceAttribute.ClientSegmentationCopyPath + "{" + AutoParameter.DefaultNamespace + "}.TcpStaticSimpleServer." + ServiceAttribute.ServerName + ".Client.cs";
                                    if (Coder.WriteFile(copyFileName, clientCode))
                                    {
                                        Messages.Message(copyFileName + " 被修改");
                                    }
                                }
                                Messages.Message(fileName + " 被修改");
                            }
                            clientCallCode.Length = 0;
                        }
                        else
                        {
                            Coder.Add(clientCode);
                        }
                    }
                }
            }
 /// <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();
     }
 }
示例#5
0
            /// <summary>
            /// 安装完成处理
            /// </summary>
            protected unsafe override void onCreated()
            {
                foreach (ClientCode code in clientCodes.Values)
                {
                    Server server;
                    if (servers.TryGetValue(code.Attribute.ServerName, out server))
                    {
                        if (server.Attribute.GetIsSegmentation)
                        {
                            server.ClientCodes.Add(code.SegmentationCode);
                        }
                        else
                        {
                            Coder.Add(code.Code);
                        }
                    }
                }
                if (clientCodes.Count != 0)
                {
                    clientCodes = DictionaryCreator.CreateOnly <Type, ClientCode>();
                }

                StringArray           clientCallCode = new StringArray();
                LeftArray <TcpMethod> methods        = new LeftArray <TcpMethod>(0);

                TcpMethod[]      methodIndexs;
                ParameterBuilder parameterBuilder = new ParameterBuilder();
                int staticMethodIndex             = 0;

                foreach (Server server in servers.Values)
                {
                    if (server.IsMethod || server.RemoteLinkTypes.Length != 0 || server.ClientCodes.Length != 0)
                    {
                        Attribute = server.Attribute;
                        TcpServerAttributeType = server.AttributeType == null || server.AttributeType.Type == null ? null : server.AttributeType.FullName;

                        Part = PartType.RemoteLink;
                        foreach (RemoteLinkType remoteLinkType in server.RemoteLinkTypes)
                        {
                            if (remoteLinkType.IsRemoteLink)
                            {
                                Type = remoteLinkType.Type;
                                CurrentRemoteLinkType         = remoteLinkType;
                                remoteLinkType.IsRemoteMember = remoteLinkType.RemoteMethods.Length != 0 && RemoteMemberTypes.Add(Type);
                                CSharpTypeDefinition definition = new CSharpTypeDefinition(Type, true, false);
                                _code_.Length = 0;
                                create(false);
                                Coder.Add(definition.Start + _partCodes_["SERVERREMOTE"] + definition.End);
                                if (ServiceAttribute.GetIsSegmentation)
                                {
                                    clientCallCode.Add(definition.Start + _partCodes_["CLIENTREMOTE"] + definition.End);
                                }
                                else
                                {
                                    Coder.Add(definition.Start + _partCodes_["CLIENTREMOTE"] + definition.End);
                                }
                            }
                        }
                        string clientCode = null;
                        if (server.IsMethod)
                        {
                            Part = PartType.CallType;
                            foreach (ServerType serverType in server.Types)
                            {
                                methods.Add(serverType.Methods);
                            }
                            methodIndexs   = methods.ToArray();
                            methods.Length = 0;
                            methodIndexs   = TcpMethod.CheckIdentity(methodIndexs, null, getRememberIdentityName(), method => method.Method.MethodKeyFullName);
                            if (methodIndexs == null)
                            {
                                return;
                            }
                            int index = 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.Clear(ServiceAttribute.IsSimpleSerialize);
                            QueueTypeBuilder queueTypeBuilder = new QueueTypeBuilder();
                            foreach (TcpMethod method in methodIndexs)
                            {
                                method.MethodIndex       = index++;
                                method.StaticMethodIndex = ++staticMethodIndex;
                                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;
                                        if (method.MethodType == server.AttributeType && server.IsTimeVerify)
                                        {
                                            TimeVerifyMethod = method;
                                        }
                                        //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();
                            foreach (ServerType serverType in server.Types)
                            {
                                if (serverType.Methods.Array.Length != 0)
                                {
                                    Type = serverType.Type;
                                    //TimeVerifyType = Type == server.AttributeType && server.IsTimeVerify ? Type : ExtensionType.Null;
                                    Attribute    = serverType.Attribute ?? server.Attribute;
                                    MethodIndexs = serverType.Methods.Array.ToArray();
                                    CSharpTypeDefinition definition = new CSharpTypeDefinition(Type, true, false);
                                    _code_.Length = 0;
                                    create(false);
                                    Coder.Add(definition.Start + _partCodes_["SERVERCALL"] + definition.End);
                                    if (ServiceAttribute.GetIsSegmentation)
                                    {
                                        clientCallCode.Add(definition.Start + _partCodes_["CLIENTCALL"] + definition.End);
                                    }
                                    else
                                    {
                                        Coder.Add(definition.Start + _partCodes_["CLIENTCALL"] + definition.End);
                                    }
                                }
                            }

                            Part           = PartType.ServerType;
                            Type           = server.AttributeType;
                            Attribute      = server.Attribute;
                            MethodIndexs   = methodIndexs;
                            methods.Length = 0;
                            _code_.Length  = 0;
                            create(false);
                            Coder.Add(@"
namespace " + AutoParameter.DefaultNamespace + "." + serverPart + @"
{
" + _partCodes_["SERVER"] + @"
}");
                            clientCode = @"
namespace " + AutoParameter.DefaultNamespace + "." + ClientPart + @"
{
" + _partCodes_["CLIENT"] + @"
}";
                        }
                        if (ServiceAttribute.GetIsSegmentation)
                        {
                            if (clientCode != null)
                            {
                                clientCallCode.Add(clientCode);
                            }
                            clientCallCode.Append(ref server.ClientCodes);
                            string fileName = AutoParameter.ProjectPath + "{" + AutoParameter.DefaultNamespace + "}.TcpStaticServer." + ServiceAttribute.ServerName + ".Client.cs";
                            clientCode = Coder.WarningCode + clientCallCode.ToString() + Coder.FileEndCode;
                            if (Coder.WriteFile(fileName, clientCode))
                            {
                                if (ServiceAttribute.ClientSegmentationCopyPath != null)
                                {
                                    string copyFileName = ServiceAttribute.ClientSegmentationCopyPath + "{" + AutoParameter.DefaultNamespace + "}.TcpStaticServer." + ServiceAttribute.ServerName + ".Client.cs";
                                    if (Coder.WriteFile(copyFileName, clientCode))
                                    {
                                        Messages.Message(copyFileName + " 被修改");
                                    }
                                }
                                Messages.Message(fileName + " 被修改");
                            }
                            clientCallCode.Length = 0;
                        }
                        else if (clientCode != null)
                        {
                            Coder.Add(clientCode);
                        }
                    }
                }
            }
示例#6
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();
                }
            }
示例#7
0
 /// <summary>
 /// 添加方法索引信息
 /// </summary>
 /// <param name="method">方法索引信息</param>
 public void Add(TcpMethod method)
 {
     MethodParameter[] inputParameters = method.MethodParameters, outputParameters = method.Method.OutputParameters;
     if (method.IsJsonSerialize)
     {
         MethodParameterTypeNames inputParameterTypeNames = new MethodParameterTypeNames(inputParameters, method.Attribute.IsInputSerializeReferenceMember, method.Attribute.IsInputSerializeBox);
         MethodParameterTypeNames outputParameterTypeNames = method.MethodIsReturn ? new MethodParameterTypeNames(outputParameters, method.MethodReturnType, method.Attribute.IsOutputSerializeReferenceMember, method.Attribute.IsOutputSerializeBox) : new MethodParameterTypeNames(outputParameters, method.Attribute.IsOutputSerializeReferenceMember, method.Attribute.IsOutputSerializeBox);
         MethodParameterTypeNames historyInputJsonParameterIndex = default(MethodParameterTypeNames), historyOutputJsonParameterIndex = default(MethodParameterTypeNames);
         if (inputParameterTypeNames.IsParameter)
         {
             if (!JsonParameterIndexs.TryGetValue(inputParameterTypeNames, out historyInputJsonParameterIndex))
             {
                 inputParameterTypeNames.Copy(++ParameterIndex);
                 JsonParameterIndexs.Add(inputParameterTypeNames, historyInputJsonParameterIndex = inputParameterTypeNames);
             }
             method.InputParameterIndex = historyInputJsonParameterIndex.Index;
         }
         if (outputParameterTypeNames.IsParameter)
         {
             if (!JsonParameterIndexs.TryGetValue(outputParameterTypeNames, out historyOutputJsonParameterIndex))
             {
                 outputParameterTypeNames.Copy(++ParameterIndex);
                 JsonParameterIndexs.Add(outputParameterTypeNames, historyOutputJsonParameterIndex = outputParameterTypeNames);
             }
             method.OutputParameterIndex = historyOutputJsonParameterIndex.Index;
         }
         method.InputParameters  = MethodParameterPair.Get(inputParameters, historyInputJsonParameterIndex);
         method.OutputParameters = MethodParameterPair.Get(outputParameters, historyOutputJsonParameterIndex);
     }
     else
     {
         MethodParameterTypes inputParameterTypes = new MethodParameterTypes(inputParameters, method.Attribute.IsInputSerializeReferenceMember, method.Attribute.IsInputSerializeBox);
         MethodParameterTypes outputParameterTypes = method.MethodIsReturn ? new MethodParameterTypes(outputParameters, method.MethodReturnType, method.Attribute.IsOutputSerializeReferenceMember, method.Attribute.IsOutputSerializeBox) : new MethodParameterTypes(outputParameters, method.Attribute.IsOutputSerializeReferenceMember, method.Attribute.IsOutputSerializeBox);
         MethodParameterTypes historyInputParameterIndex = default(MethodParameterTypes), historyOutputParameterIndex = default(MethodParameterTypes);
         if (inputParameterTypes.IsParameter)
         {
             if (!ParameterIndexs.TryGetValue(inputParameterTypes, out historyInputParameterIndex))
             {
                 inputParameterTypes.Copy(++ParameterIndex);
                 ParameterIndexs.Add(inputParameterTypes, historyInputParameterIndex = inputParameterTypes);
             }
             method.InputParameterIndex = historyInputParameterIndex.Index;
             if (IsSimpleSerialize)
             {
                 method.IsSimpleSerializeInputParamter = historyInputParameterIndex.IsSimpleSerialize;
             }
         }
         if (outputParameterTypes.IsParameter)
         {
             if (!ParameterIndexs.TryGetValue(outputParameterTypes, out historyOutputParameterIndex))
             {
                 outputParameterTypes.Copy(++ParameterIndex);
                 ParameterIndexs.Add(outputParameterTypes, historyOutputParameterIndex = outputParameterTypes);
             }
             method.OutputParameterIndex = historyOutputParameterIndex.Index;
             if (IsSimpleSerialize)
             {
                 method.IsSimpleSerializeOutputParamter = historyOutputParameterIndex.IsSimpleSerialize;
             }
         }
         method.InputParameters  = MethodParameterPair.Get(inputParameters, historyInputParameterIndex);
         method.OutputParameters = MethodParameterPair.Get(outputParameters, historyOutputParameterIndex);
     }
     MethodParameterPair.SetInputParameter(method.OutputParameters, method.InputParameters);
 }
示例#8
0
                /// <summary>
                /// 检测方法序号
                /// </summary>
                /// <param name="methodIndexs">方法集合</param>
                /// <param name="rememberIdentityCommand">命令序号记忆数据</param>
                /// <param name="getMethodKeyName">获取命令名称的委托</param>
                /// <returns>方法集合,失败返回null</returns>
                public static TcpMethod[] CheckIdentity(TcpMethod[] methodIndexs, Dictionary <HashString, int> rememberIdentityCommand, Func <TcpMethod, string> getMethodKeyName)
                {
                    int maxIdentity = methodIndexs.Length - 1;
                    Dictionary <int, TcpMethod> identitys = DictionaryCreator.CreateInt <TcpMethod>();

                    foreach (TcpMethod method in methodIndexs)
                    {
                        int identity = method.Attribute.CommandIdentity;
                        if (identity >= 0)
                        {
                            TcpMethod identityMethod;
                            if (identitys.TryGetValue(identity, out identityMethod))
                            {
                                Messages.Add(method.MethodType.FullName + " 命令序号重复 " + method.MemberFullName + " [" + identity.toString() + "] " + identityMethod.MemberFullName);
                                return(null);
                            }
                            identitys.Add(identity, method);
                            if (identity > maxIdentity)
                            {
                                maxIdentity = identity;
                            }
                        }
                    }
                    if (rememberIdentityCommand.Count != 0)
                    {
                        foreach (TcpMethod method in methodIndexs)
                        {
                            int identity = method.Attribute.CommandIdentity;
                            if (identity < 0 && rememberIdentityCommand.TryGetValue(getMethodKeyName(method), out identity))
                            {
                                identitys.Add(method.Attribute.CommandIdentity = identity, method);
                                if (identity > maxIdentity)
                                {
                                    maxIdentity = identity;
                                }
                            }
                        }
                    }
                    TcpMethod[] sortMethodIndexs = new TcpMethod[maxIdentity + 1];
                    foreach (KeyValuePair <int, TcpMethod> methods in identitys)
                    {
                        sortMethodIndexs[methods.Key] = methods.Value;
                    }
                    maxIdentity = 0;
                    foreach (TcpMethod method in methodIndexs)
                    {
                        if (method.Attribute.CommandIdentity < 0)
                        {
                            while (sortMethodIndexs[maxIdentity] != null)
                            {
                                ++maxIdentity;
                            }
                            sortMethodIndexs[method.Attribute.CommandIdentity = maxIdentity] = method;
                            ++maxIdentity;
                        }
                    }
                    while (maxIdentity != sortMethodIndexs.Length)
                    {
                        if (sortMethodIndexs[maxIdentity] == null)
                        {
                            sortMethodIndexs[maxIdentity] = nullMethod;
                        }
                        ++maxIdentity;
                    }
                    return(sortMethodIndexs);
                    //if (rememberIdentityCommand.Count != 0)
                    //{
                    //    foreach (TcpMethod method in methodIndexs)
                    //    {
                    //        if (method.Attribute.CommandIentity == int.MaxValue)
                    //        {
                    //            int identity;
                    //            if (rememberIdentityCommand.TryGetValue(getMethodKeyName(method), out identity)) method.Attribute.CommandIentity = identity;
                    //        }
                    //    }
                    //}
                    //TcpMethod[] setMethodIndexs = methodIndexs.getFindArray(value => value.Attribute.CommandIentity != int.MaxValue);
                    //int count = 0;
                    //foreach (TcpMethod method in setMethodIndexs)
                    //{
                    //    int identity = method.Attribute.CommandIentity;
                    //    if (identity != int.MaxValue && identity > count) count = identity;
                    //}
                    //if (++count < methodIndexs.Length) count = methodIndexs.Length;
                    //TcpMethod[] sortMethodIndexs = new TcpMethod[count];
                    //foreach (TcpMethod method in setMethodIndexs)
                    //{
                    //    int identity = method.Attribute.CommandIentity;
                    //    if (sortMethodIndexs[identity] == null) sortMethodIndexs[identity] = method;
                    //    else
                    //    {
                    //        Messages.Add(method.MethodType.FullName + " 命令序号重复 " + method.MemberFullName + "[" + identity.toString() + "]" + sortMethodIndexs[identity].MemberFullName);
                    //        return null;
                    //    }
                    //}
                    //count = 0;
                    //foreach (TcpMethod method in methodIndexs.getFind(value => value.Attribute.CommandIentity == int.MaxValue))
                    //{
                    //    while (sortMethodIndexs[count] != null) ++count;
                    //    (sortMethodIndexs[count] = method).Attribute.CommandIentity = count;
                    //    ++count;
                    //}
                    //while (count != sortMethodIndexs.Length)
                    //{
                    //    if (sortMethodIndexs[count] == null) sortMethodIndexs[count] = nullMethod;
                    //    ++count;
                    //}
                    //return sortMethodIndexs;
                }
示例#9
0
            /// <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);
                    }
                }
            }