コード例 #1
0
ファイル: CSharper.cs プロジェクト: W8023Y2014/AutoCSer
            /// <summary>
            /// 生成类定义字符串
            /// </summary>
            /// <returns>类定义字符串</returns>
            public override string ToString()
            {
                typeDefinition = new TemplateGenerator.CSharpTypeDefinition(Type, true, true);
                (coder = new Coder(Parameter, Type, Auto.Language)).SkinEnd(coder.GetNode(Auto.GetFileName(Type)));
                codeBuilder = new StringArray();
                if (!Auto.IsDotNet2)
                {
                    codeBuilder.Append(@"
#if DOTNET2
#else");
                }
                codeBuilder.Append(@"
", typeDefinition.Start, @"
        /// <summary>
        /// 生成代码
        /// </summary>
        /// <param name=""isOut"">是否输出代码</param>
        protected override void create(bool _isOut_)
        {
            if (outStart(AutoCSer.CodeGenerator.CodeLanguage.", Auto.Language.ToString(), @", _isOut_))
            {
                ");
                switch (Auto.Language)
                {
                case CodeLanguage.JavaScript:
                case CodeLanguage.TypeScript:
                    return(javaScript());

                default: return(cSharp());
                }
            }
コード例 #2
0
ファイル: CSharper.cs プロジェクト: W8023Y2014/AutoCSer
            private string end()
            {
                codeBuilder.Append(@"
                if (_isOut_) outEnd();
            }
        }", typeDefinition.End);
                if (!Auto.IsDotNet2)
                {
                    codeBuilder.Append(@"
#endif");
                }
                return(codeBuilder.ToString());
            }
コード例 #3
0
ファイル: TcpStaticServer.cs プロジェクト: AutoCSer/AutoCSer
            /// <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);
                        }
                    }
                }
            }