/// <summary> /// 输出类定义开始段代码 /// </summary> /// <param name="language">代码生成语言</param> /// <param name="isOutDefinition">是否输出类定义</param> /// <returns>类定义</returns> protected bool outStart(CodeLanguage language, bool isOutDefinition) { _definition_ = null; _language_ = language; if (isOutDefinition) { _code_.Length = 0; if (Coder.Add(GetType(), Type.Type)) { switch (_language_) { case CodeLanguage.JavaScript: case CodeLanguage.TypeScript: _definition_ = new JavaScriptTypeDefinition(Type); break; default: _definition_ = new CSharpTypeDefinition(Type, true, false); break; } _code_.Add(_definition_.Start); return(true); } return(false); } return(true); }
/// <summary> /// 安装完成处理 /// </summary> protected override void onCreated() { int methodIndex = methods.Length; ViewMethods = new WebView.Generator { AutoParameter = AutoParameter }.GetTypeAttributes() .getFind(value => typeof(AutoCSer.WebView.View <>).isAssignableFromGenericDefinition(value.Key) ? (value.Value == null || value.Value.IsAjax) : (value.Value != null && value.Value.IsAjax)) .GetArray(value => new ViewMethod { MethodIndex = methodIndex++, WebViewMethodType = value.Key, Attribute = value.Value ?? AutoCSer.WebView.View.DefaultAttribute, CallName = new WebView.Generator.ViewType { Type = value.Key, Attribute = value.Value ?? AutoCSer.WebView.View.DefaultAttribute, DefaultNamespace = AutoParameter.DefaultNamespace + ".", IgnoreCase = AutoParameter.WebConfig.IgnoreCase }.CallName, IsAwaitMethod = WebView.Generator.AjaxAwaitMethodTypes.Contains(value.Key) }); if (methodIndex != 0) { LeftArray <KeyValuePair <string, int> > names = (Methods = methods.ToArray()).getArray(value => value.CallName) .concat(ViewMethods.getArray(value => value.CallName)) .groupCount(value => value) .getFind(value => value.Value != 1); if (names.Length == 0) { IsPubError = false; ParameterBuilder parameterBuilder = new ParameterBuilder(); foreach (AjaxMethod method in Methods) { if (!IsPubError) { IsPubError = method.CallName == AutoCSer.WebView.AjaxBase.PubErrorCallName; } parameterBuilder.Add(method); } ParameterTypes = parameterBuilder.Get(); MethodCount = Methods.Length + ViewMethods.Length + (IsPubError ? 0 : 1); _code_.Length = 0; create(false); Coder.Add("namespace " + AutoParameter.DefaultNamespace + @" { " + _code_.ToString() + @" }"); typeScript.OnCreated(); } else { Messages.Add(@"AJAX调用名称冲突: " + names.JoinString(@" ", value => value.Key + "[" + value.Value.toString() + "]")); } } }
///// <summary> ///// 异步等待关键字 ///// </summary> //public string Await //{ // get { return "await"; } //} /// <summary> /// 输出类定义结束段代码 /// </summary> protected void outEnd() { _code_.Add(_definition_.End); switch (_language_) { case CodeLanguage.JavaScript: case CodeLanguage.TypeScript: break; default: Coder.Add(_code_.ToString(), _language_); return; } }
/// <summary> /// 安装完成处理 /// </summary> protected override void onCreated() { if (methods.Length != 0) { CallMethods = Methods = methods.ToArray(); int methodIndex = 0; ParameterBuilder parameterBuilder = new ParameterBuilder(); foreach (CallMethod method in Methods) { method.MethodIndex = methodIndex++; parameterBuilder.Add(method); } ParameterTypes = parameterBuilder.Get(); _code_.Length = 0; create(false); Coder.Add("namespace " + AutoParameter.DefaultNamespace + @" { " + _code_.ToString() + @" }"); } }
/// <summary> /// 安装下一个类型 /// </summary> protected override void nextCreate() { Type modelType; AutoCSer.Sql.ModelAttribute modelAttribute = Type.Type.customAttribute <AutoCSer.Sql.ModelAttribute>(out modelType); if (modelAttribute != null) { AutoCSer.Net.TcpStaticServer.ServerAttribute serverAttribute = AutoCSer.Metadata.TypeAttribute.GetAttribute <AutoCSer.Net.TcpStaticServer.ServerAttribute>(Type, false); if (serverAttribute != null && serverAttribute.ServerName != null && !serverAttribute.IsRemoteLinkType && serverAttribute.IsRemoteLink && (RemoteLinkType = TcpStaticServer.Generator.GetRemoteLinkType(Type)) != null) { LeftArray <TcpStaticServer.Generator.RemoteMethod> remoteMethods = new LeftArray <TcpStaticServer.Generator.RemoteMethod>(0); foreach (MethodIndex method in MethodIndex.GetMethods <AutoCSer.Net.TcpStaticServer.MethodAttribute>(Type, serverAttribute.GetMemberFilters, false, serverAttribute.IsAttribute, serverAttribute.IsBaseTypeAttribute)) { if (!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 == RemoteLinkType.ParameterType) { remoteMethods.Add(new TcpStaticServer.Generator.RemoteMethod { Type = Type, Method = method, MethodParameters = parameters, Attribute = remoteAttribute }); } } } } LeftArray <SqlModel.Generator.LogMember> logMembers = new LeftArray <SqlModel.Generator.LogMember>(0); foreach (MemberIndex member in MemberIndex.GetMembers(modelType, modelAttribute.MemberFilters)) { if (!member.IsIgnore) { AutoCSer.Sql.MemberAttribute attribute = member.GetAttribute <AutoCSer.Sql.MemberAttribute>(false); if (modelAttribute.LogServerName != null) { AutoCSer.Sql.LogAttribute logAttribute = member.GetAttribute <AutoCSer.Sql.LogAttribute>(false); if (logAttribute != null) { SqlModel.Generator.LogMember logMember = new SqlModel.Generator.LogMember { Member = member, Attribute = logAttribute, MemberAttribute = attribute }; if (modelAttribute.LogServerName != null && logMember.IsProxy) { logMembers.Add(logMember); foreach (TcpStaticServer.Generator.RemoteMethod remoteMethod in remoteMethods) { if (remoteMethod.Attribute.MemberName == member.MemberName) { remoteMethod.Member = member; break; } } } } } } } RemoteMethods = remoteMethods.GetFindArray(value => value.Member != null); LogMembers = logMembers.Length != 0 && (modelAttribute.CacheType != AutoCSer.Sql.Cache.Whole.Event.Type.Unknown && modelAttribute.CacheType != AutoCSer.Sql.Cache.Whole.Event.Type.CreateMemberKey) ? logMembers.ToArray() : EmptyArray <SqlModel.Generator.LogMember> .Array; if ((LogMembers.Length | RemoteMethods.Length) != 0) { //create(true); IsRemoteMember = RemoteMethods.Length != 0 && TcpStaticServer.Generator.RemoteMemberTypes.Add(Type); CSharpTypeDefinition definition = new CSharpTypeDefinition(Type, true, false); _code_.Length = 0; create(false); Coder.Add(definition.Start + _partCodes_["SERVER"] + definition.End); TcpStaticServer.Generator.AddClientCode(new TcpStaticServer.Generator.ClientCode { Type = Type, Attribute = serverAttribute, Code = definition.Start + _partCodes_["CLIENT"] + definition.End, SegmentationCode = definition.Start + _partCodes_["CLIENTCALL"] + definition.End }); } } } }
/// <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 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); } } } }