Ejemplo n.º 1
0
            /// <summary>
            /// 注册TCP服务端
            /// </summary>
            /// <param name="attribute">TCP服务配置</param>
            /// <returns>是否注册成功</returns>
            public registerState Register(fastCSharp.code.cSharp.tcpServer attribute)
            {
                registerResult result = new registerResult {
                    State = registerState.NoClient
                };

#if NotFastCSharpCode
                fastCSharp.log.Error.Throw(fastCSharp.log.exceptionType.NotFastCSharpCode);
#else
                Monitor.Enter(clientLock);
                try
                {
                    result = registerClient.register(clientId, new service {
                        Host = new host {
                            Host = attribute.RegisterHost, Port = attribute.RegisterPort
                        }, IsCheck = attribute.IsRegisterCheckHost, Name = attribute.ServiceName, IsSingle = attribute.IsSingleRegister, IsPerp = attribute.IsPerpleRegister
                    }).Value;
                }
                catch (Exception error)
                {
                    fastCSharp.log.Error.Add(error, null, false);
                }
                finally { Monitor.Exit(clientLock); }
                if (result.State == registerState.Success)
                {
                    attribute.RegisterHost = result.Service.Host.Host;
                    attribute.RegisterPort = result.Service.Host.Port;
                }
#endif
                return(result.State);
            }
Ejemplo n.º 2
0
        public form()
        {
            InitializeComponent();

            context = SynchronizationContext.Current;

            tcpServer                    = fastCSharp.code.cSharp.tcpServer.GetConfig("tcpPerformance", typeof(fastCSharp.demo.tcpPerformanceServer.performanceServer));
            ipTextBox.Text               = tcpServer.Host;
            portTextBox.Text             = tcpServer.Port.toString();
            asynchronousCheckBox.Checked = tcpServer.IsServerAsynchronousReceive;

            serverTarget           = new performanceServer();
            serverTarget.OnStop   += onStop;
            serverTarget.OnClient += onClient;

            startButton_Click(null, null);
#if NotFastCSharpCode
            fastCSharp.log.Error.Throw(fastCSharp.log.exceptionType.NotFastCSharpCode);
#else
            if (performanceServer.IsStart && fastCSharp.config.pub.Default.IsDebug)
            {
#if DEBUG
                string clientFileName = (@"..\..\..\tcpPerformanceClient\bin\Debug\fastCSharp.demo.tcpPerformanceClient.exe").pathSeparator();
#else
                string clientFileName = (@"..\..\..\tcpPerformanceClient\bin\Release\fastCSharp.demo.tcpPerformanceClient.exe").pathSeparator();
#endif
                fastCSharp.diagnostics.process.StartNew(clientFileName, "1");
            }
#endif
        }
 /// <summary>
 /// portServer TCP调用服务端
 /// </summary>
 /// <param name="attribute">TCP调用服务器端配置信息</param>
 /// <param name="verify">TCP验证实例</param>
 /// <param name="value">TCP服务目标对象</param>
 public tcpServer(fastCSharp.code.cSharp.tcpServer attribute = null, fastCSharp.code.cSharp.tcpBase.ITcpVerify verify = null, fastCSharp.demo.udpPortServer.portServer value = null)
     : base(attribute ?? fastCSharp.code.cSharp.tcpServer.GetConfig("portServer", typeof(fastCSharp.demo.udpPortServer.portServer)), verify)
 {
     _value_ = value ?? new fastCSharp.demo.udpPortServer.portServer();
     setCommands(1);
     identityOnCommands[0 + 128].Set(0 + 128, 256);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 创建TCP客户端
 /// </summary>
 /// <param name="socket">TCP套接字</param>
 /// <param name="attribute">配置信息</param>
 /// <param name="connectAsync"></param>
 /// <returns></returns>
 internal static bool Create(ref Socket socket, fastCSharp.code.cSharp.tcpServer attribute, SocketAsyncEventArgs connectAsync)
 {
     try
     {
         if (attribute.IpAddress == IPAddress.Any)
         {
             if (!isAnyIpAddress)
             {
                 log.Error.Add("客户端TCP连接失败(" + attribute.ServiceName + "[" + attribute.TcpRegisterName + "] " + attribute.Host + ":" + attribute.Port.toString() + ")", null, false);
             }
             isAnyIpAddress = true;
         }
         else
         {
             isAnyIpAddress = false;
             connectAsync.RemoteEndPoint = new IPEndPoint(attribute.IpAddress, attribute.Port);
             connectAsync.SocketError    = SocketError.Success;
             socket = new Socket(attribute.IpAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
             if (socket.ConnectAsync(connectAsync))
             {
                 return(true);
             }
         }
     }
     catch (Exception error)
     {
         log.Error.Add(error, "客户端TCP连接失败(" + attribute.ServiceName + "[" + attribute.TcpRegisterName + "] " + attribute.IpAddress.ToString() + ":" + attribute.Port.toString() + ")", false);
         if (socket != null)
         {
             fastCSharp.threading.disposeTimer.Default.addSocketClose(socket);
         }
     }
     return(false);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 启动负载均衡测试服务
        /// </summary>
        protected override void start()
        {
#if NotFastCSharpCode
            fastCSharp.log.Error.Throw(fastCSharp.log.exceptionType.NotFastCSharpCode);
#else
            if (attribute == null)
            {
                attribute = fastCSharp.emit.memberCopyer <fastCSharp.code.cSharp.tcpServer> .MemberwiseClone(serverAttribute);
            }
            dispose();
            try
            {
                attribute.Port = serverAttribute.Port + Port + (fastCSharp.random.Default.NextUShort() & 1023);
                if ((loadBalancingServer = new server.tcpServer(attribute)).StartLoadBalancing(loadBalancingServerAttribute, null, output))
                {
                    output("负载均衡测试服务已启动");
                    return;
                }
            }
            catch (Exception error)
            {
                output(error);
            }
            loadBalancingServer = null;
            output("负载均衡测试服务启动失败");
            fastCSharp.threading.timerTask.Default.Add(start, date.NowSecond.AddSeconds(1));
#endif
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 创建TCP客户端
        /// </summary>
        /// <param name="attribute">配置信息</param>
        /// <returns>TCP客户端,失败返回null</returns>
        internal static Socket Create(fastCSharp.code.cSharp.tcpServer attribute)
        {
            Socket socket = null;

            try
            {
                if (attribute.IpAddress == IPAddress.Any)
                {
                    if (!isAnyIpAddress)
                    {
                        log.Error.Add("客户端TCP连接失败(" + attribute.ServiceName + "[" + attribute.TcpRegisterName + "] " + attribute.Host + ":" + attribute.Port.toString() + ")", null, false);
                    }
                    isAnyIpAddress = true;
                    return(null);
                }
                isAnyIpAddress = false;
                socket         = new Socket(attribute.IpAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                socket.Connect(attribute.IpAddress, attribute.Port);
                return(socket);
            }
            catch (Exception error)
            {
                log.Error.Add(error, "客户端TCP连接失败(" + attribute.ServiceName + "[" + attribute.TcpRegisterName + "] " + attribute.IpAddress.ToString() + ":" + attribute.Port.toString() + ")", false);
                if (socket != null)
                {
                    fastCSharp.threading.disposeTimer.Default.addSocketClose(socket);
                }
            }
            return(null);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// UPD服务端
 /// </summary>
 /// <param name="tcpServer">TCP服务调用配置</param>
 public udpServer(fastCSharp.code.cSharp.tcpServer tcpServer)
 {
     socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
     socket.Bind(new IPEndPoint(IPAddress.Parse(tcpServer.Host), tcpServer.Port));
     ports.OnRemovedLock += remove;
     fastCSharp.threading.threadPool.TinyPool.Start(receive);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// loadBalancingTest TCP调用服务端
 /// </summary>
 /// <param name="attribute">TCP调用服务器端配置信息</param>
 /// <param name="verify">TCP验证实例</param>
 /// <param name="value">TCP服务目标对象</param>
 public tcpServer(fastCSharp.code.cSharp.tcpServer attribute = null, fastCSharp.code.cSharp.tcpBase.ITcpVerify verify = null, fastCSharp.demo.loadBalancingTcpCommand.server value = null)
     : base(attribute ?? fastCSharp.code.cSharp.tcpServer.GetConfig("loadBalancingTest", typeof(fastCSharp.demo.loadBalancingTcpCommand.server)), verify)
 {
     _value_ = value ?? new fastCSharp.demo.loadBalancingTcpCommand.server();
     setCommands(2);
     identityOnCommands[0 + 128].Set(0 + 128);
     identityOnCommands[1 + 128].Set(1 + 128);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// TCP调用服务端
 /// </summary>
 /// <param name="attribute">配置信息</param>
 /// <param name="isStart">是否启动客户端</param>
 public client(fastCSharp.code.cSharp.tcpServer attribute, bool isStart)
 {
     this.attribute = attribute;
     if (isStart)
     {
         start();
     }
 }
 /// <summary>
 /// tcpPerformance TCP调用服务端
 /// </summary>
 /// <param name="attribute">TCP调用服务器端配置信息</param>
 /// <param name="verify">TCP验证实例</param>
 /// <param name="value">TCP服务目标对象</param>
 public tcpServer(fastCSharp.code.cSharp.tcpServer attribute = null, fastCSharp.code.cSharp.tcpBase.ITcpVerify verify = null, fastCSharp.demo.tcpPerformanceServer.performanceServer value = null)
     : base(attribute ?? fastCSharp.code.cSharp.tcpServer.GetConfig("tcpPerformance", typeof(fastCSharp.demo.tcpPerformanceServer.performanceServer)), verify)
 {
     _value_ = value ?? new fastCSharp.demo.tcpPerformanceServer.performanceServer();
     setCommands(2);
     identityOnCommands[0 + 128].Set(0 + 128);
     identityOnCommands[1 + 128].Set(1 + 128);
     _value_.SetCommandServer(this);
 }
Ejemplo n.º 11
0
 /// <summary>
 ///
 /// </summary>
 static memoryDatabase()
 {
     tcpServer      = fastCSharp.code.cSharp.tcpServer.GetConfig("memoryDatabasePhysical", typeof(fastCSharp.memoryDatabase.physicalServer));
     tcpServer.Host = "127.0.0.1";
     tcpServer.Port = 12345;
     //tcpServer.MergeStreamSize = 128;
     //tcpServer.ShareMemorySize = 128;
     //tcpServer.IsOnlyShareMemoryClient = true;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// UDP穿透端口服务客户端
 /// </summary>
 /// <param name="tcpServer">TCP服务调用配置</param>
 /// <param name="timeoutSeconds">超时秒数</param>
 public portClient(fastCSharp.code.cSharp.tcpServer tcpServer, int timeoutSeconds)
 {
     udpServerIp = new IPEndPoint(IPAddress.Parse(tcpServer.Host), tcpServer.Port);
     client      = new portServer.tcpClient(tcpServer, null);
     if (timeoutSeconds <= 0)
     {
         timeoutSeconds = udpServer.TimeoutSeconds;
     }
     timeoutTicks = new TimeSpan(0, 0, timeoutSeconds).Ticks;
 }
 /// <summary>
 ///  TCP调用服务端
 /// </summary>
 /// <param name="attribute">TCP调用服务器端配置信息</param>
 /// <param name="verify">TCP验证实例</param>
 /// <param name="value">TCP服务目标对象</param>
 public tcpServer(fastCSharp.code.cSharp.tcpServer attribute = null, fastCSharp.code.cSharp.tcpBase.ITcpVerify verify = null, fastCSharp.demo.chatServer.server value = null)
     : base(attribute ?? fastCSharp.code.cSharp.tcpServer.GetConfig("", typeof(fastCSharp.demo.chatServer.server)), verify)
 {
     _value_ = value ?? new fastCSharp.demo.chatServer.server();
     setCommands(5);
     identityOnCommands[0 + 128].Set(0 + 128);
     identityOnCommands[1 + 128].Set(1 + 128, 0);
     identityOnCommands[2 + 128].Set(2 + 128, 0);
     identityOnCommands[3 + 128].Set(3 + 128);
     identityOnCommands[4 + 128].Set(4 + 128, 0);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// 获取TcpCall客户端虚拟配置
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 internal static tcpServer GetTcpCallConfig(Type type)
 {
     fastCSharp.code.cSharp.tcpCall tcpCall = fastCSharp.code.typeAttribute.GetAttribute <fastCSharp.code.cSharp.tcpCall>(type, false, true);
     if (tcpCall == null)
     {
         return(null);
     }
     fastCSharp.code.cSharp.tcpServer attribute = tcpCall.Copy <fastCSharp.code.cSharp.tcpServer, fastCSharp.code.cSharp.tcpBase>();
     attribute             = fastCSharp.config.pub.LoadConfig(attribute, attribute.Service = tcpCall.ServiceName);
     attribute.TcpRegister = null;
     attribute.IsServer    = true;
     return(attribute);
 }
Ejemplo n.º 15
0
 /// <summary>
 /// 获取TCP服务端口信息
 /// </summary>
 /// <param name="commandClient">TCP调用客户端</param>
 /// <returns>是否更新</returns>
 internal bool GetHost(commandClient commandClient)
 {
     fastCSharp.code.cSharp.tcpServer attribute = commandClient.Attribute;
     if (attribute != null)
     {
         //commandClient.TcpRegisterServicesVersion = Version;
         if (Hosts.Length == 0)
         {
             attribute.Port = 0;
             if (errorServiceName != attribute.ServiceName)
             {
                 fastCSharp.log.Error.Add(attribute.ServiceName + "[" + attribute.TcpRegisterName + "] 未找到注册服务信息", new System.Diagnostics.StackFrame(), false);
             }
             errorServiceName = attribute.ServiceName;
         }
         else
         {
             if (errorServiceName == attribute.ServiceName)
             {
                 errorServiceName = null;
             }
             host host;
             int  index = hostIndex;
             if (index < Hosts.Length)
             {
                 ++hostIndex;
                 host = Hosts[index];
             }
             else
             {
                 hostIndex = 1;
                 host      = Hosts[0];
             }
             if (attribute.IsFixedClientHost)
             {
                 if (attribute.Port != host.Port)
                 {
                     attribute.Port = host.Port;
                 }
             }
             else if (attribute.Host != host.Host || attribute.Port != host.Port)
             {
                 attribute.Host = host.Host;
                 attribute.Port = host.Port;
             }
         }
         return(true);
     }
     return(false);
 }
Ejemplo n.º 16
0
            /// <summary>
            /// 获取TCP服务端口信息
            /// </summary>
            /// <param name="commandClient">TCP调用客户端</param>
            /// <returns>TCP服务端口信息是否更新</returns>
            internal bool GetHost(commandClient commandClient)
            {
                services services = commandClient.TcpRegisterServices;

                if (services == null)
                {
                    fastCSharp.code.cSharp.tcpServer attribute = commandClient.Attribute;
                    attribute.Port = 0;
                    return(false);
                }
                Monitor.Enter(servicesLock);
                bool isHost = services.GetHost(commandClient);

                Monitor.Exit(servicesLock);
                return(isHost);
            }
Ejemplo n.º 17
0
        /// <summary>
        /// TCP调用服务端
        /// </summary>
        /// <param name="attribute">配置信息</param>
        protected server(fastCSharp.code.cSharp.tcpServer attribute)
        {
            if (attribute == null)
            {
                log.Error.Throw(log.exceptionType.Null);
            }
            if (attribute.TcpRegisterName != null)
            {
                tcpRegisterClient = fastCSharp.net.tcp.tcpRegister.client.Get(attribute.TcpRegisterName);
                if (tcpRegisterClient == null)
                {
                    log.Error.Throw("TCP注册服务 " + attribute.TcpRegisterName + " 链接失败", null, false);
                }
                if (attribute.RegisterHost == null)
                {
                    attribute.RegisterHost = attribute.Host;
                }
                if (attribute.RegisterPort == 0)
                {
                    attribute.RegisterPort = attribute.Port;
                }
                fastCSharp.net.tcp.tcpRegister.registerState state = tcpRegisterClient.Register(attribute);
                if (state != fastCSharp.net.tcp.tcpRegister.registerState.Success)
                {
                    log.Error.Throw("TCP服务注册 " + attribute.ServiceName + " 失败 " + state.ToString(), null, false);
                }
                if (attribute.Port == 0)
                {
                    attribute.Port = attribute.RegisterPort;
                }
                log.Default.Add(attribute.ServiceName + " 注册 " + attribute.Host + ":" + attribute.Port.toString() + " => " + attribute.RegisterHost + ":" + attribute.RegisterPort.toString(), new System.Diagnostics.StackFrame(), false);
            }
            if (!attribute.IsServer)
            {
                log.Default.Add("配置未指明的TCP服务端 " + attribute.ServiceName, null, false);
            }
            this.attribute = attribute;
            if ((maxClientCount = attribute.MaxClientCount) <= 0)
            {
                maxClientCount = int.MaxValue;
            }
#if MONO
            //if (attribute.AcceptQueueSize > 30) attribute.AcceptQueueSize = 30;
            //else if (attribute.AcceptQueueSize < 4) attribute.AcceptQueueSize = 4;
#endif
        }
Ejemplo n.º 18
0
            /// <summary>
            /// 删除注册TCP服务端
            /// </summary>
            /// <param name="attribute">TCP服务配置</param>
            public void RemoveRegister(fastCSharp.code.cSharp.tcpServer attribute)
            {
#if NotFastCSharpCode
                fastCSharp.log.Error.Throw(fastCSharp.log.exceptionType.NotFastCSharpCode);
#else
                Monitor.Enter(clientLock);
                try
                {
                    registerClient.removeRegister(clientId, attribute.ServiceName);
                }
                catch (Exception error)
                {
                    fastCSharp.log.Error.Add(error, null, false);
                }
                finally { Monitor.Exit(clientLock); }
#endif
            }
Ejemplo n.º 19
0
 /// <summary>
 /// TCP调用服务端
 /// </summary>
 /// <param name="attribute">配置信息</param>
 protected server(fastCSharp.code.cSharp.tcpServer attribute)
 {
     if (attribute == null) log.Error.Throw(log.exceptionType.Null);
     if (attribute.TcpRegisterName != null)
     {
         tcpRegisterClient = fastCSharp.net.tcp.tcpRegister.client.Get(attribute.TcpRegisterName);
         if (tcpRegisterClient == null) log.Error.Throw("TCP注册服务 " + attribute.TcpRegisterName + " 链接失败", true, false);
         fastCSharp.net.tcp.tcpRegister.registerState state = tcpRegisterClient.Register(attribute);
         if (state != fastCSharp.net.tcp.tcpRegister.registerState.Success) log.Error.Throw("TCP服务注册 " + attribute.ServiceName + " 失败 " + state.ToString(), true, false);
         log.Default.Add(attribute.ServiceName + " 注册 " + attribute.Host + ":" + attribute.Port.toString(), false, false);
     }
     if (!attribute.IsServer) log.Default.Add("配置未指明的TCP服务端 " + attribute.ServiceName, true, false);
     this.attribute = attribute;
 }
Ejemplo n.º 20
0
        /// <summary>
        /// 释放资源
        /// </summary>
        public void Dispose()
        {
            if (Interlocked.Increment(ref isDisposed) == 1)
            {
                save();
                forwardHost = null;

                pub.Dispose(ref fileWatcher);

                Monitor.Enter(domainLock);
                domainSearcher domains = this.domains;
                this.domains = domainSearcher.Default;
                Monitor.Exit(domainLock);
                domains.Close();
                domains.Dispose();

                server[] servers = null;
                Monitor.Enter(hostLock);
                try
                {
                    servers = hosts.Values.getArray();
                    hosts = null;
                }
                finally
                {
                    Monitor.Exit(hostLock);
                    if (servers != null) foreach (server server in servers) server.Dispose();
                }
            }
        }
            public tcpClient(fastCSharp.code.cSharp.tcpServer attribute = null, fastCSharp.code.cSharp.tcpBase.ITcpClientVerify verify = null)
#endif
            {
                tcpCommandClient = new fastCSharp.net.tcp.commandClient <tcpClient>(attribute ?? fastCSharp.code.cSharp.tcpServer.GetConfig("tcpPerformance", typeof(fastCSharp.demo.tcpPerformanceServer.performanceServer)), 28, verify);
            }
            /// <summary>
            /// TCP调用客户端
            /// </summary>
            /// <param name="attribute">TCP调用服务器端配置信息</param>
            /// <param name="verify">TCP验证实例</param>
#if NOJIT
            public tcpClient(fastCSharp.code.cSharp.tcpServer attribute = null, fastCSharp.code.cSharp.tcpBase.ITcpClientVerify verify = null)
Ejemplo n.º 23
0
 private void removeForward()
 {
     forwardHost = null;
 }
Ejemplo n.º 24
0
 private bool setForward(host host)
 {
     if (isDisposed == 0 && host.HostToIpAddress())
     {
         fastCSharp.code.cSharp.tcpServer tcpServer = new fastCSharp.code.cSharp.tcpServer { Host = host.Host, Port = host.Port };
         if (tcpServer.IpAddress != IPAddress.Any)
         {
             forwardHost = tcpServer;
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 25
0
 /// <summary>
 /// TCP调用服务端
 /// </summary>
 /// <param name="attribute">配置信息</param>
 /// <param name="isStart">是否启动客户端</param>
 public client(fastCSharp.code.cSharp.tcpServer attribute, bool isStart)
 {
     this.attribute = attribute;
     if (isStart) start();
 }
Ejemplo n.º 26
0
 /// <summary>
 /// 性能测试
 /// </summary>
 public static void Test()
 {
     typeof(fastCSharp.config.pub).GetProperty("IsDebug", BindingFlags.Instance | BindingFlags.Public).SetValue(fastCSharp.config.pub.Default, true, null);
     fastCSharp.code.cSharp.tcpServer tcpServer = fastCSharp.code.cSharp.tcpServer.GetConfig("memoryDatabasePhysical", typeof(fastCSharp.memoryDatabase.physicalServer));
     tcpServer.Host = "127.0.0.1";
     tcpServer.Port = 12345;
     //tcpServer.SendBufferSize = 128 << 10;
     //tcpServer.ShareMemorySize = 128;
     //tcpServer.IsOnlyShareMemoryClient = true;
     using (fastCSharp.memoryDatabase.physicalServer.tcpServer server = new fastCSharp.memoryDatabase.physicalServer.tcpServer(tcpServer))
     {
         if (server.Start())
         {
             using (fastCSharp.memoryDatabase.physicalServer.tcpClient client = new fastCSharp.memoryDatabase.physicalServer.tcpClient(tcpServer))
             {
                 Console.WriteLine("开始加载数据...");
                 Stopwatch time = new Stopwatch();
                 time.Start();
                 using (table = new memoryDatabaseModelTable <identity> .remote(client, cache = new identityArray <identity>()))
                 {
                     cache.WaitLoad();
                     time.Stop();
                     if (table.IsDisposed)
                     {
                         Console.WriteLine("数据加载失败");
                     }
                     else
                     {
                         Console.WriteLine("数据加载完成[" + cache.Count.toString() + "] " + time.ElapsedMilliseconds.toString() + "ms");
                         Stopwatch allTime = new Stopwatch();
                         using (fastCSharp.threading.task task = new threading.task(threadCount, true, fastCSharp.threading.threadPool.TinyPool))
                         {
                             allTime.Start();
                             for (int loop = 1; loop <= 10; ++loop)//循环测试10次
                             {
                                 int length = 0;
                                 time.Restart();
                                 if (isCallback)
                                 {
                                     fastCSharp.threading.waitCount waitCount = new threading.waitCount(threadCount);
                                     for (int threadIndex = 0; threadIndex != threadCount; ++threadIndex)
                                     {
                                         new insertCallback(waitCount, countPerLoop / threadCount).Insert();
                                     }
                                     waitCount.Wait();
                                 }
                                 else
                                 {
                                     if (threadCount == 1)
                                     {
                                         identity.task();
                                     }
                                     else
                                     {
                                         for (int threadIndex = 0; threadIndex != threadCount; ++threadIndex)
                                         {
                                             task.Add(identity.task);
                                         }
                                         task.WaitFree();
                                     }
                                 }
                                 table.Flush(false);
                                 time.Stop();
                                 Console.WriteLine(((loop * countPerLoop) / 10000).toString() + "W[" + length.toString() + "] Thread[" + threadCount.toString() + "] Callback[" + isCallback.ToString() + "] " + time.ElapsedMilliseconds.toString() + "ms");
                             }
                             allTime.Stop();
                         }
                         Console.WriteLine(cache.Count.toString() + " " + allTime.ElapsedMilliseconds.toString() + "ms");
                         Console.WriteLine("测试完毕.");
                         GC.Collect();
                     }
                 }
             }
         }
         else
         {
             Console.WriteLine("数据库服务端启动失败.");
         }
     }
     Console.ReadKey();
 }
Ejemplo n.º 27
0
            /// <summary>
            /// 安装完成处理
            /// </summary>
            protected unsafe override void onCreated()
            {
                stringBuilder      clientCallCode = new stringBuilder();
                list <methodIndex> methods        = new list <methodIndex>();

                methodIndex[] methodIndexs;
                foreach (server server in servers.Values)
                {
                    if (server.IsMethod)
                    {
                        IsAllType = false;
                        TcpServerAttributeType = server.AttributeType == null || server.AttributeType.Type == null ? null : server.AttributeType.FullName;
                        ServiceAttribute       = fastCSharp.config.pub.LoadConfig(server.TcpServer, server.TcpServer.ServiceName);
                        foreach (server.type serverType in server.Types)
                        {
                            methods.Add(serverType.Methods);
                        }
                        methodIndexs = methods.ToArray();
                        methods.Empty();
                        if (ServiceAttribute.IsIdentityCommand)
                        {
                            methodIndexs = methodIndex.CheckIdentity(methodIndexs, ServiceAttribute.IsRememberIdentityCommand ? getRememberIdentityName() : nullRememberIdentityName, method => method.Method.MethodKeyFullName);
                            if (methodIndexs == null)
                            {
                                return;
                            }
                        }
                        int index = 0;
                        foreach (methodIndex method in methodIndexs)
                        {
                            method.MethodIndex = index++;
                        }
                        foreach (server.type serverType in server.Types)
                        {
                            if (serverType.Methods.Count != 0)
                            {
                                type         = serverType.Type;
                                IsTimeVerify = type == server.AttributeType && server.IsTimeVerify;
                                Attribute    = serverType.Attribute ?? new code.cSharp.tcpCall();
                                MethodIndexs = serverType.Methods.ToArray();
                                definition.cSharp definition = new definition.cSharp(type, true, false);
                                _code_.Empty();
                                create(false);
                                fastCSharp.code.coder.Add(definition.Start + _partCodes_["SERVERCALL"] + definition.End);
                                if (ServiceAttribute.IsSegmentation)
                                {
                                    clientCallCode.Add(definition.Start + _partCodes_["CLIENTCALL"] + definition.End);
                                }
                                else
                                {
                                    fastCSharp.code.coder.Add(definition.Start + _partCodes_["CLIENTCALL"] + definition.End);
                                }
                            }
                        }
                        IsAllType    = true;
                        MethodIndexs = methodIndexs;
                        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
                        });
                        MaxCommandLength = (ServiceAttribute.IsIdentityCommand ? sizeof(int) : methodIndexs.maxKey(value => (value.Method.MethodKeyFullName.Length + 3) & (int.MaxValue - 3), sizeof(int))) + sizeof(int) * 4 + sizeof(fastCSharp.net.tcp.commandServer.streamIdentity);
                        _code_.Empty();
                        create(false);
                        fastCSharp.code.coder.Add(@"
namespace " + AutoParameter.DefaultNamespace + "." + serverPart + @"
{
" + _partCodes_["SERVER"] + @"
}");
                        string clientCode = @"
namespace " + AutoParameter.DefaultNamespace + "." + clientPart + @"
{
" + _partCodes_["CLIENT"] + @"
}";
                        if (ServiceAttribute.IsIdentityCommand && ServiceAttribute.IsRememberIdentityCommand)
                        {
                            coder.AddRemember(@"
namespace " + AutoParameter.DefaultNamespace + @".tcpRemember
{
" + _partCodes_["REMEMBER"] + @"
}");
                        }
                        if (ServiceAttribute.IsSegmentation)
                        {
                            clientCallCode.Add(clientCode);
                            string fileName = AutoParameter.ProjectPath + "{" + AutoParameter.DefaultNamespace + "}.tcpCall." + ServiceAttribute.ServiceName + ".client.cs";
                            clientCode = fastCSharp.code.coder.WarningCode + clientCallCode.ToString() + fastCSharp.code.coder.FileEndCode;
                            if (fastCSharp.code.coder.WriteFile(fileName, clientCode))
                            {
                                if (ServiceAttribute.ClientSegmentationCopyPath != null)
                                {
                                    string copyFileName = ServiceAttribute.ClientSegmentationCopyPath + "{" + AutoParameter.DefaultNamespace + "}.tcpCall." + ServiceAttribute.ServiceName + ".client.cs";
                                    if (!fastCSharp.code.coder.WriteFile(copyFileName, clientCode))
                                    {
                                        fastCSharp.code.error.Add(copyFileName + " 写入失败");
                                    }
                                }
                                fastCSharp.code.error.Message(fileName + " 被修改");
                            }
                            clientCallCode.Empty();
                        }
                        else
                        {
                            fastCSharp.code.coder.Add(clientCode);
                        }
                    }
                }
            }
Ejemplo n.º 28
0
            public tcpClient(fastCSharp.code.cSharp.tcpServer attribute = null, fastCSharp.code.cSharp.tcpBase.ITcpClientVerify verify = null)
#endif
            {
                tcpCommandClient = new fastCSharp.net.tcp.commandClient <tcpClient>(attribute ?? fastCSharp.code.cSharp.tcpServer.GetConfig("loadBalancingTest", typeof(fastCSharp.demo.loadBalancingTcpCommand.server)), 28, verify);
            }