示例#1
0
            /// <summary>
            /// 下一个函数处理
            /// </summary>
            /// <param name="methodIndex"></param>
            private void next(methodIndex methodIndex)
            {
                fastCSharp.code.cSharp.tcpMethod attribute = methodIndex.Attribute;
                server server = defaultServer;

                server.type serverType  = defaultType;
                string      serviceName = attribute.ServiceName;

                if (serviceName == null)
                {
                    serviceName = Attribute.ServiceName;
                }
                if (serviceName != defaultServiceName)
                {
                    if (serviceName == null)
                    {
                        serverType = null;
                    }
                    else
                    {
                        hashString nameKey = serviceName;
                        if (!servers.TryGetValue(nameKey, out server))
                        {
                            servers.Add(nameKey, server = new server());
                            server.TcpServer.Service    = serviceName;
                        }
                        if (!serverTypes.TryGetValue(nameKey, out serverType))
                        {
                            server.Types.Add(serverType = new server.type {
                                Type = type
                            });
                            serverTypes.Add(nameKey, serverType);
                        }
                    }
                }
                if (serverType != null)
                {
                    server.IsMethod = true;
                    methodIndex.ServiceAttribute = server.TcpServer;
                    //methodIndex.MethodIndex = server.MethodIndex++;
                    methodIndex.ParameterIndex = parameterIndex++;
                    serverType.Methods.Add(methodIndex);
                }
            }
示例#2
0
            /// <summary>
            /// 安装下一个类型
            /// </summary>
            protected unsafe override void nextCreate()
            {
                Attribute = fastCSharp.config.pub.LoadConfig(Attribute, Attribute.ServiceName);
                subArray <methodIndex> methodArray = code.methodInfo.GetMethods <fastCSharp.code.cSharp.tcpMethod>(type, Attribute.MemberFilter, false, Attribute.IsAttribute, Attribute.IsBaseTypeAttribute, Attribute.IsInheritAttribute)
                                                     .getArray(value => new methodIndex
                {
                    Method           = value,
                    MethodType       = type,
                    ServiceAttribute = Attribute
                }).toSubArray();

                foreach (memberIndex member in code.memberIndexGroup.Get <fastCSharp.code.cSharp.tcpMethod>(type, Attribute.MemberFilter, false, Attribute.IsAttribute, Attribute.IsBaseTypeAttribute, Attribute.IsInheritAttribute))
                {
                    if (member.IsField)
                    {
                        FieldInfo   field     = (FieldInfo)member.Member;
                        methodIndex getMethod = new methodIndex
                        {
                            Method           = new methodInfo(field, true),
                            MemberIndex      = member,
                            MethodType       = type,
                            ServiceAttribute = Attribute
                        };
                        if (!getMethod.Attribute.IsOnlyGetMember)
                        {
                            getMethod.SetMethod = new methodIndex {
                                Method = new methodInfo(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;
                        methodIndex  getMethod = new methodIndex
                        {
                            Method           = new methodInfo(property, true),
                            MemberIndex      = member,
                            MethodType       = type,
                            ServiceAttribute = Attribute
                        };
                        if (member.CanSet && !getMethod.Attribute.IsOnlyGetMember)
                        {
                            getMethod.SetMethod = new methodIndex {
                                Method = new methodInfo(property, false), MemberIndex = member, MethodType = type, ServiceAttribute = Attribute
                            };
                        }
                        methodArray.Add(getMethod);
                        if (getMethod.SetMethod != null)
                        {
                            methodArray.Add(getMethod.SetMethod);
                        }
                    }
                }
                MethodIndexs = methodArray.ToArray();
                if (Attribute.IsIdentityCommand)
                {
                    MethodIndexs = methodIndex.CheckIdentity(MethodIndexs, Attribute.IsRememberIdentityCommand ? getRememberIdentityName() : nullRememberIdentityName, method => method.Method.MethodKeyFullName);
                    if (MethodIndexs == null)
                    {
                        return;
                    }
                    MaxCommandLength = sizeof(int) * 5 + sizeof(fastCSharp.net.tcp.commandServer.streamIdentity);
                }
                else
                {
                    MaxCommandLength = MethodIndexs.maxKey(value => (value.Method.MethodKeyFullName.Length + 3) & (int.MaxValue - 3), sizeof(int)) + sizeof(int) * 4 + sizeof(fastCSharp.net.tcp.commandServer.streamIdentity);
                }
                int index = 0;

                foreach (methodIndex method in MethodIndexs)
                {
                    method.MethodIndex = method.ParameterIndex = index++;
                }
                methodIndex[] methodIndexs = MethodIndexs.getFindArray(value => !value.IsNullMethod);
                if (ServiceAttribute.IsHttpClient && !methodIndex.CheckHttpMethodName(methodIndexs))
                {
                    return;
                }
                IsVerifyMethod = methodIndexs.any(value => value.IsVerifyMethod);
                subArray <int> groupIds = methodIndexs.distinct(value => value.Attribute.GroupId);

                groupIds.Remove(0);
                MethodGroups = groupIds.GetArray(value => new methodGroup {
                    GroupId = value
                });
                IsRemember = false;
                if (ServiceAttribute.IsSegmentation)
                {
                    IsClientCode        = false;
                    create(IsServerCode = true);
                    definition.cSharp definition = new definition.cSharp(type, IsClientCode = true, false, type.Type.Namespace + ".tcpClient");
                    _code_.Empty();
                    _code_.Add(definition.Start);
                    create(IsServerCode = false);
                    _code_.Add(definition.End);
                    string fileName   = AutoParameter.ProjectPath + "{" + AutoParameter.DefaultNamespace + "}.tcpServer." + Attribute.ServiceName + ".client.cs";
                    string clientCode = fastCSharp.code.coder.WarningCode + _code_.ToString() + fastCSharp.code.coder.FileEndCode;
                    if (fastCSharp.code.coder.WriteFile(fileName, clientCode))
                    {
                        if (ServiceAttribute.ClientSegmentationCopyPath != null)
                        {
                            string copyFileName = ServiceAttribute.ClientSegmentationCopyPath + "{" + AutoParameter.DefaultNamespace + "}.tcpServer." + Attribute.ServiceName + ".client.cs";
                            if (!fastCSharp.code.coder.WriteFile(copyFileName, clientCode))
                            {
                                fastCSharp.code.error.Add(copyFileName + " 写入失败");
                            }
                        }
                        fastCSharp.code.error.Message(fileName + " 被修改");
                    }
                }
                else
                {
                    create(IsServerCode = IsClientCode = true);
                }
                if (Attribute.IsIdentityCommand && Attribute.IsRememberIdentityCommand)
                {
                    IsRemember = true;
                    _code_.Empty();
                    create(IsServerCode = IsClientCode = false);
                    coder.AddRemember(@"
namespace " + AutoParameter.DefaultNamespace + @".tcpRemember
{
" + _partCodes_["REMEMBER"] + @"
}");
                }
            }
示例#3
0
 /// <summary>
 /// 安装下一个类型
 /// </summary>
 protected override void nextCreate()
 {
     if (Attribute.IsAbstract || type.Type.IsSealed || !type.Type.IsAbstract)
     {
         defaultServiceName = Attribute.ServiceName;
         defaultServer      = null;
         defaultType        = null;
         if (defaultServiceName != null)
         {
             hashString nameKey = defaultServiceName;
             if (!servers.TryGetValue(nameKey, out defaultServer))
             {
                 servers.Add(nameKey, defaultServer = new server());
             }
             defaultServer.TcpServer.Service     = defaultServiceName;
             defaultServer.Types.Add(defaultType = new server.type {
                 Type = type, Attribute = Attribute
             });
             if (Attribute.IsServer)
             {
                 defaultServer.AttributeType = type;
                 defaultServer.TcpServer.CopyFrom(Attribute);
             }
         }
         foreach (methodInfo method in code.methodInfo.GetMethods <fastCSharp.code.cSharp.tcpMethod>(type, Attribute.MemberFilter, false, Attribute.IsAttribute, Attribute.IsBaseTypeAttribute, Attribute.IsInheritAttribute))
         {
             next(new methodIndex
             {
                 Method     = method,
                 MethodType = type,
                 IsTypeGenericParameterName = type.Type.IsGenericType
             });
         }
         if (!type.Type.IsGenericType)
         {
             foreach (memberIndex member in code.memberIndexGroup.GetStatic <fastCSharp.code.cSharp.tcpMethod>(type, Attribute.MemberFilter, false, Attribute.IsAttribute, Attribute.IsBaseTypeAttribute, Attribute.IsInheritAttribute))
             {
                 if (member.IsField)
                 {
                     FieldInfo   field     = (FieldInfo)member.Member;
                     methodIndex getMethod = new methodIndex
                     {
                         Method      = new methodInfo(field, true),
                         MemberIndex = member,
                         MethodType  = type
                     };
                     if (!getMethod.Attribute.IsOnlyGetMember)
                     {
                         getMethod.SetMethod = new methodIndex {
                             Method = new methodInfo(field, false), MemberIndex = member, MethodType = type
                         };
                     }
                     next(getMethod);
                     if (getMethod.SetMethod != null)
                     {
                         next(getMethod.SetMethod);
                     }
                 }
                 else if (member.CanGet)
                 {
                     PropertyInfo property  = (PropertyInfo)member.Member;
                     methodIndex  getMethod = new methodIndex
                     {
                         Method      = new methodInfo(property, true),
                         MemberIndex = member,
                         MethodType  = type
                     };
                     if (member.CanSet && !getMethod.Attribute.IsOnlyGetMember)
                     {
                         getMethod.SetMethod = new methodIndex {
                             Method = new methodInfo(property, false), MemberIndex = member, MethodType = type
                         };
                     }
                     next(getMethod);
                     if (getMethod.SetMethod != null)
                     {
                         next(getMethod.SetMethod);
                     }
                 }
             }
         }
         serverTypes.Clear();
     }
 }
示例#4
0
                /// <summary>
                /// 检测方法序号
                /// </summary>
                /// <param name="methodIndexs">方法集合</param>
                /// <param name="rememberIdentityCommand">命令序号记忆数据</param>
                /// <param name="getMethodKeyName">获取命令名称的委托</param>
                /// <param name="nullMethod">空方法索引信息</param>
                /// <returns>方法集合,失败返回null</returns>
                public static methodIndex[] CheckIdentity(methodIndex[] methodIndexs, staticDictionary <string, int> rememberIdentityCommand, Func <methodIndex, string> getMethodKeyName)
                {
                    if (!rememberIdentityCommand.IsEmpty())
                    {
                        foreach (methodIndex method in methodIndexs)
                        {
                            if (method.Attribute.CommandIentity == int.MaxValue)
                            {
                                int identity = rememberIdentityCommand.Get(getMethodKeyName(method), int.MaxValue);
                                if (identity != int.MaxValue)
                                {
                                    method.Attribute.CommandIentity = identity;
                                }
                            }
                        }
                    }
                    methodIndex[] setMethodIndexs = methodIndexs.getFindArray(value => value.Attribute.CommandIentity != int.MaxValue);
                    int           count           = 0;

                    foreach (methodIndex method in setMethodIndexs)
                    {
                        int identity = method.Attribute.CommandIentity;
                        if (identity != int.MaxValue && identity > count)
                        {
                            count = identity;
                        }
                    }
                    if (++count < methodIndexs.Length)
                    {
                        count = methodIndexs.Length;
                    }
                    methodIndex[] sortMethodIndexs = new methodIndex[count];
                    foreach (methodIndex method in setMethodIndexs)
                    {
                        int identity = method.Attribute.CommandIentity;
                        if (sortMethodIndexs[identity] == null)
                        {
                            sortMethodIndexs[identity] = method;
                        }
                        else
                        {
                            error.Add(method.MethodType.FullName + " 命令序号重复 " + method.MemberFullName + "[" + identity.toString() + "]" + sortMethodIndexs[identity].MemberFullName);
                            return(null);
                        }
                    }
                    count = 0;
                    foreach (methodIndex 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);
                    //methodIndexs = methodIndexs.getSort(value => value.Attribute.CommandIentity);
                    //for (int index = 0; index != methodIndexs.Length; ++index)
                    //{
                    //    methodIndex method = methodIndexs[index];
                    //    int identity = method.Attribute.CommandIentity;
                    //    while (identity != index)
                    //    {
                    //        if (identity == int.MaxValue)
                    //        {
                    //            methodIndexs[index] = method;
                    //            method.CopyTypeAttribute.CommandIentity = identity = index;
                    //        }
                    //        else if (identity < methodIndexs.Length)
                    //        {
                    //            methodIndex moveMethod = methodIndexs[identity];
                    //            int moveIdentity = moveMethod.Attribute.CommandIentity;
                    //            if (moveIdentity == identity)
                    //            {
                    //                error.Add(method.MethodType.FullName + " 命令序号重复 " + method.Method.Method.Name + "[" + identity.toString() + "]" + moveMethod.Method.Method.Name);
                    //                return null;
                    //            }
                    //            methodIndexs[identity] = method;
                    //            identity = moveIdentity;
                    //            method = moveMethod;
                    //        }
                    //        else
                    //        {
                    //            error.Add(method.MethodType.FullName + " 命令序号错误 " + method.Method.Method.Name + "[" + identity.toString() + "] >= " + methodIndexs.Length.toString());
                    //            return null;
                    //        }
                    //    }
                    //}
                    //return methodIndexs;
                }