Beispiel #1
0
        public static ServerCreater CreatetRPC(this ServerCreater serverCreater, int port)
        {
            var server = new RPCServer(port);

            serverCreater.SetServer(server);
            return(serverCreater);
        }
Beispiel #2
0
        public static ServerCreater CreateWebSocket(this ServerCreater serverCreater, int port)
        {
            var server = new WebSocketServer(port);

            serverCreater.SetServer(server);
            return(serverCreater);
        }
Beispiel #3
0
 public DynamicApiMiddleware(RequestDelegate next, ServerCreater serverCreater, IServiceProvider serviceProvider)
 {
     _next            = next;
     _serverCreater   = serverCreater;
     _serviceProvider = serviceProvider;
     //_serverCreater.CreateApi();
 }
Beispiel #4
0
        public static ServerCreater CreatetApi(this ServerCreater serverCreater)
        {
            var server = new ApiServer();

            serverCreater.SetServer(server);
            return(serverCreater);
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            var server = new ServerCreater().CreatetRPC(805);

            server.CheckSign();
            server.SetSessionManage(new SessionManage());
            //server.Register<ITestService, TestService>();
            server.RegisterAll(typeof(TestService));
            server.Start();
            Console.ReadLine();
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            var server = new ServerCreater().CreatetApi();

            server.CheckSign();
            server.SetSessionManage(new SessionManage());
            //server.Register<ITestService, TestService>();
            server.RegisterAll(typeof(TestService));
            var listener = new ServerListener();

            listener.Start("http://localhost:809/");
            Console.ReadLine();
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            //1.启动consol
            //2.启动CRL.Ocelot,配置见configuration.json
            var server = new ServerCreater().CreateApi();

            server.Register <ITestService, TestService>();
            var listener = new ServerListener();

            listener.Start("http://localhost:809/");//启用apiService1
            #region 注册服务
            var consulClient = new CRL.Core.ConsulClient.Consul("http://localhost:8500");
            consulClient.UseOcelotGatewayDiscover("http://localhost:3400"); //使用网关服务发现
            var info = new CRL.Core.ConsulClient.ServiceRegistrationInfo
            {
                Address = "localhost",
                Name    = "apiService1",
                ID      = "apiService1",
                Port    = 809,
                Tags    = new[] { "v1" }
            };
            consulClient.DeregisterService(info.ID);
            var a = consulClient.RegisterService(info);//注册apiService1
            #endregion

            #region 发现调用服务
            var clientConnect = new ApiClientConnect("");
            clientConnect.UseOcelotApiGatewayDiscover("http://localhost:3400", "apiService1");//服务发现

            var clientConnect2 = new ApiClientConnect("");
            clientConnect2.UseOcelotApiGateway("http://localhost:3400");//直接使用网关
            #endregion
label1:

            var service1 = clientConnect.GetClient <ITestService>();
            var msg = service1.Login();
            Console.WriteLine("服务发现调用成功:" + msg);

            var service2 = clientConnect2.GetClient <ITestService>("serviceTest");//传入网关调用前辍
            msg = service2.Login();
            Console.WriteLine("服务网关调用成功:" + msg);

            Console.ReadLine();

            goto label1;
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            var server = new ServerCreater().CreateApi();

            server.CheckSign();
            server.UseJWTUseAuthorization(tokenCheck);
            server.SetSessionManage(new SessionManage());
            //server.Register<ITestService, TestService>();
            server.RegisterAll(System.Reflection.Assembly.GetAssembly(typeof(TestService)));
            var listener = new ServerListener();

            listener.Start("http://localhost:809/");
label1:
            //PollyTest().Wait();
            Console.ReadLine();
            goto label1;
        }
    public MainServer() //Main Thread
    {
        Console.WriteLine("MainServer started.");
        Thread.CurrentThread.Name = "mainServer";

        ServerCreater serverCreater = new ServerCreater();

        serverCreater.First2ServerCreater(); //at start we run two subserver thread
        Thread.Sleep(100);
        while (true)
        {
            Thread.Sleep(100);                                              //100+100=200ms
            RandomGenerator rand1 = new RandomGenerator();
            ServerLoads.mainAmount = ServerLoads.mainAmount - rand1.number; //responds randomly
            if (ServerLoads.mainAmount < 0)
            {
                ServerLoads.mainAmount = 0; //server load cannot be negative
            }

            Thread.Sleep(200);
            RandomGenerator rand2 = new RandomGenerator();
            ServerLoads.mainAmount = ServerLoads.mainAmount - rand2.number; //responds randomly
            if (ServerLoads.mainAmount < 0)
            {
                ServerLoads.mainAmount = 0; //server load cannot be negative
            }

            Thread.Sleep(100); //200+200+100=500ms
            //Generate random(1-100) number in every 500ms
            RandomGenerator100 rand100 = new RandomGenerator100();
            ServerLoads.mainAmount = ServerLoads.mainAmount + rand100.number;
            if (ServerLoads.mainAmount > capacity)
            {
                ServerLoads.mainAmount = capacity; //server cannot take more load than its capacity
            }

            Thread.Sleep(100);                                              //100+100=200ms
            RandomGenerator rand3 = new RandomGenerator();
            ServerLoads.mainAmount = ServerLoads.mainAmount - rand3.number; //responds randomly
            if (ServerLoads.mainAmount < 0)
            {
                ServerLoads.mainAmount = 0; //server load cannot be negative
            }
        }
    }
    public MainServer() //Main Thread
    {
        Console.WriteLine("MainServer started.");
        Thread.CurrentThread.Name = "mainServer";

        ServerCreater serverCreater = new ServerCreater();

        serverCreater.First2ServerCreater();
        Thread.Sleep(100);
        while (true)
        {
            Thread.Sleep(100); //100+100=200ms
            RandomGenerator rand1 = new RandomGenerator();
            ServerLoads.mainAmount = ServerLoads.mainAmount - rand1.number;
            if (ServerLoads.mainAmount < 0)
            {
                ServerLoads.mainAmount = 0;
            }

            Thread.Sleep(200);
            RandomGenerator rand2 = new RandomGenerator();
            ServerLoads.mainAmount = ServerLoads.mainAmount - rand2.number;
            if (ServerLoads.mainAmount < 0)
            {
                ServerLoads.mainAmount = 0;
            }

            Thread.Sleep(100); //200+200+100=500ms
            //Generate random(1-100) number in every 500ms
            RandomGenerator100 rand100 = new RandomGenerator100();
            ServerLoads.mainAmount = ServerLoads.mainAmount + rand100.number;
            if (ServerLoads.mainAmount > capacity)
            {
                ServerLoads.mainAmount = capacity;
            }

            Thread.Sleep(100); //100+100=200ms
            RandomGenerator rand3 = new RandomGenerator();
            ServerLoads.mainAmount = ServerLoads.mainAmount - rand3.number;
            if (ServerLoads.mainAmount < 0)
            {
                ServerLoads.mainAmount = 0;
            }
        }
    }
Beispiel #11
0
        static void Main(string[] args)
        {
            var server = new ServerCreater().CreateWebSocket(8015);

            server.CheckSign();
            server.SetSessionManage(new SessionManage());
            //server.Register<ITestService, TestService>();
            server.RegisterAll(System.Reflection.Assembly.GetAssembly(typeof(TestService)));
            server.Start();
            new CRL.Core.ThreadWork().Start("send", () =>
            {
                var socket = server.GetServer() as CRL.WebSocket.WebSocketServer;
                socket.SendMessage("hubro", new socketMsg()
                {
                    name = DateTime.Now.ToString()
                }, out string error);
                Console.WriteLine("send msg");
                return(true);
            }, 10);
            Console.ReadLine();
        }