Exemple #1
0
        /// <summary>
        /// 获取配置信息
        /// </summary>
        /// <param name="serviceName">TCP调用服务名称</param>
        /// <param name="type">TCP服务器类型</param>
        /// <returns>TCP调用服务器端配置信息</returns>
        public static tcpServer GetConfig(string serviceName, Type type = null)
        {
            tcpServer attribute = fastCSharp.config.pub.Default.LoadConfig(type != null ? type.customAttribute <tcpServer>(false, true) ?? new tcpServer() : new tcpServer(), serviceName);

            if (attribute.Service == null)
            {
                attribute.Service = serviceName;
            }
            return(attribute);
        }
Exemple #2
0
            /// <summary>
            /// 安装完成处理
            /// </summary>
            protected override void onCreated()
            {
                if (methodIndexs.Count != 0)
                {
                    IsAllType = true;
                    foreach (list <methodIndex> methods in methodIndexs.group(value => value.TypeAttribute.ServiceName).Values)
                    {
                        MethodIndexs     = methods.ToArray();
                        type             = MethodIndexs[0].MethodType;
                        Attribute        = MethodIndexs[0].TypeAttribute;
                        ServiceAttribute = MethodIndexs[0].ServiceAttribute;
                        _code_.Empty();
                        create(false);
                        fastCSharp.setup.cSharp.coder.Add(@"
namespace " + AutoParameter.DefaultNamespace + "." + serverPart + @"
{
" + _partCodes_["SERVER"] + @"
}");
                        string clientCode = @"
namespace " + AutoParameter.DefaultNamespace + "." + clientPart + @"
{
" + _partCodes_["CLIENT"] + @"
}";
                        if (ServiceAttribute.IsSegmentation)
                        {
                            stringBuilder clientCallCode = clientCallCodes[Attribute.ServiceName];
                            clientCallCode.Add(clientCode);
                            string fileName = AutoParameter.ProjectPath + AutoParameter.DefaultNamespace + ".tcpCall." + Attribute.ServiceName + ".client.cs";
                            clientCode = fastCSharp.setup.cSharp.coder.WarningCode + clientCallCode.ToString();
                            if (fastCSharp.setup.cSharp.coder.WriteFile(fileName, clientCode))
                            {
                                if (ServiceAttribute.ClientSegmentationCopyPath != null)
                                {
                                    string copyFileName = ServiceAttribute.ClientSegmentationCopyPath + AutoParameter.DefaultNamespace + ".tcpCall." + Attribute.ServiceName + ".client.cs";
                                    if (!fastCSharp.setup.cSharp.coder.WriteFile(copyFileName, clientCode))
                                    {
                                        fastCSharp.setup.error.Add(copyFileName + " 写入失败");
                                    }
                                }
                                fastCSharp.setup.error.Message(fileName + " 被修改");
                            }
                        }
                        else
                        {
                            fastCSharp.setup.cSharp.coder.Add(clientCode);
                        }
                    }
                }
            }
Exemple #3
0
            /// <summary>
            /// 安装下一个类型
            /// </summary>
            protected override void NextCreate()
            {
                if (!serviceAttributes.TryGetValue(Attribute.ServiceName, out ServiceAttribute))
                {
                    serviceAttributes.Add(Attribute.ServiceName, ServiceAttribute = tcpServer.GetConfig(Attribute.ServiceName));
                }
                if (Attribute.VerifyType != null)
                {
                    ServiceAttribute.VerifyType = Attribute.VerifyType;
                }
                int methodIndex = methodIndexs.Count;

                MethodIndexs = methodInfo.GetMethods <tcpCall>(type, Attribute.filter, false, Attribute.IsAttribute, Attribute.IsBaseTypeAttribute, Attribute.IsInheritAttribute)
                               .getArray(value => new methodIndex
                {
                    Method                     = value,
                    MethodIndex                = methodIndex++,
                    MethodType                 = type,
                    ServiceAttribute           = ServiceAttribute,
                    TypeAttribute              = Attribute,
                    IsTypeGenericParameterName = type.Type.IsGenericType
                });
                methodIndexs.Add(MethodIndexs);
                if (ServiceAttribute.IsSegmentation)
                {
                    stringBuilder clientCallCode;
                    if (!clientCallCodes.TryGetValue(Attribute.ServiceName, out clientCallCode))
                    {
                        clientCallCodes.Add(Attribute.ServiceName, clientCallCode = new stringBuilder());
                    }
                    definition definition = new definition(type, true, false);
                    _code_.Empty();
                    create(false);
                    fastCSharp.setup.cSharp.coder.Add(GetType(), CodeType.Type, definition.Start + _partCodes_["SERVERCALL"] + definition.End);
                    clientCallCode.Add(definition.Start + _partCodes_["CLIENTCALL"] + definition.End);
                }
                else
                {
                    create(true);
                }
            }
Exemple #4
0
 /// <summary>
 /// 获取TCP调用泛型函数集合
 /// </summary>
 /// <param name="type">目标类型</param>
 /// <returns>TCP调用泛型函数集合</returns>
 public static Dictionary <genericMethod, MethodInfo> GetGenericMethods(Type type)
 {
     if (type != null)
     {
         tcpServer tcpServer = type.customAttribute <tcpServer>(false, cSharp.Default.IsInheritAttribute);
         if (tcpServer != null && tcpServer.IsSetup)
         {
             Dictionary <genericMethod, MethodInfo> values = new Dictionary <genericMethod, MethodInfo>();
             methodInfo[] methods = methodInfo.GetMethods <tcpServer>(type, tcpServer.filter, false, tcpServer.IsAttribute, tcpServer.IsBaseTypeAttribute, tcpServer.IsInheritAttribute);
             if (type.IsGenericType)
             {
                 methodInfo[] definitionMethods = methodInfo.GetMethods <tcpServer>(type.GetGenericTypeDefinition(), tcpServer.filter, false, tcpServer.IsAttribute, tcpServer.IsBaseTypeAttribute, tcpServer.IsInheritAttribute);
                 int          index             = 0;
                 foreach (methodInfo method in methods)
                 {
                     if (method.Method.IsGenericMethod)
                     {
                         values.Add(new genericMethod(definitionMethods[index].Method), method.Method);
                     }
                     ++index;
                 }
             }
             else
             {
                 foreach (methodInfo method in methods)
                 {
                     if (method.Method.IsGenericMethod)
                     {
                         values.Add(new genericMethod(method.Method), method.Method);
                     }
                 }
             }
             return(values);
         }
     }
     return(null);
 }