public virtual Task StartAsync(CancellationToken cancellationToken)
 {
     mApiServer = new HttpApiServer();
     mApiServer.Debug();
     mApiServer.Options.WebSocketMaxRPS = 100;
     mApiServer.Register(typeof(Program).Assembly);
     mApiServer.Register(typeof(_Admin).Assembly);
     mApiServer.Open();
     return(Task.CompletedTask);
 }
 private void InitService()
 {
     ServiceDescriptor[] items = new ServiceDescriptor[mSettingHandler.Services.Count];
     mSettingHandler.Services.CopyTo(items, 0);
     foreach (var item in items)
     {
         mHttpControllerServices.Insert(0, item);
     }
     foreach (Assembly item in mSettingHandler.Assemblies)
     {
         Type[] types = item.GetTypes();
         foreach (Type type in types)
         {
             ControllerAttribute ca = type.GetCustomAttribute <ControllerAttribute>(false);
             if (ca != null)
             {
                 if (ca.SingleInstance)
                 {
                     mHttpControllerServices.AddSingleton(type);
                 }
                 else
                 {
                     mHttpControllerServices.AddScoped(type);
                 }
             }
         }
     }
     mHttpControllerServices.AddSingleton(mHttpServer);
     mHttpControllerServiceProvider = mHttpControllerServices.BuildServiceProvider();
     if (mSettingHandler.Assemblies != null)
     {
         mHttpServer.Register(mSettingHandler.Assemblies);
     }
 }
        public virtual Task StartAsync(CancellationToken cancellationToken)
        {
            mApiServer = new HttpApiServer();
            mApiServer.Options.Port = 9090;
            mApiServer.Options.Filters.Add(new GlobalAuthorizeHandler());
            mApiServer.Options.Filters.Add(new GlobalExceptionHandler());
            mApiServer.Options.UrlIgnoreCase = true;
            mApiServer.Options.LogLevel      = LogType.Warring;
            mApiServer.Options.LogToConsole  = true;

            // TODO:
            //   配置HTTPS访问
            //options.SSL = true;
            //options.CertificateFile = "";
            //options.CertificatePassword = "";

            mApiServer.Options.BufferPoolMaxMemory = 500;
            mApiServer.Options.MaxConnections      = 100000;
            mApiServer.Options.Statistical         = false;
            mApiServer.Options.PrivateBufferPool   = true;
            mApiServer.Options.SetDebug();

            var assemblyCollection = new Assembly[] { typeof(Program).Assembly };

            mApiServer.Register(assemblyCollection);
            mApiServer.Open();

            return(Task.CompletedTask);
        }
Example #4
0
        public async virtual Task StartAsync(CancellationToken cancellationToken)
        {
            plaintextResult         = new StringBytes(_helloWorldPayload);
            mApiServer              = new HttpApiServer();
            mApiServer.Options.Port = 8080;
            mApiServer.Options.BufferPoolMaxMemory = 500;
            mApiServer.Options.MaxConnections      = 100000;
            mApiServer.Options.Statistical         = false;
            mApiServer.Options.UrlIgnoreCase       = false;
            mApiServer.Options.LogLevel            = BeetleX.EventArgs.LogType.Error;
            mApiServer.Options.LogToConsole        = true;
            mApiServer.Options.PrivateBufferPool   = true;
            mApiServer.Register(typeof(Program).Assembly);
            HeaderTypeFactory.SERVAR_HEADER_BYTES = Encoding.ASCII.GetBytes("Server: TFB\r\n");
            mApiServer.HttpConnected += (o, e) =>
            {
                e.Session["DB"] = new RawDb(new ConcurrentRandom(), Npgsql.NpgsqlFactory.Instance);
            };
            mApiServer.Open();
            RawDb._connectionString = "Server=tfb-database;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=256;NoResetOnClose=true;Enlist=false;Max Auto Prepare=4;Multiplexing=true;Write Coalescing Delay Us=500;Write Coalescing Buffer Threshold Bytes=1000";
            //RawDb._connectionString = "Server=192.168.2.19;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=256;NoResetOnClose=true;Enlist=false;Max Auto Prepare=3";
            System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
            var response = await client.GetAsync("http://localhost:8080/json");

            mApiServer.BaseServer.Log(LogType.Info, null, $"Get josn {response.StatusCode}");
            response = await client.GetAsync("http://localhost:8080/plaintext");

            mApiServer.BaseServer.Log(LogType.Info, null, $"Get plaintext {response.StatusCode}");
        }
Example #5
0
        public async virtual Task StartAsync(CancellationToken cancellationToken)
        {
            plaintextResult         = new StringBytes(_helloWorldPayload);
            mApiServer              = new HttpApiServer();
            mApiServer.Options.Port = 8080;
            mApiServer.Options.BufferPoolMaxMemory = 500;
            mApiServer.Options.MaxConnections      = 100000;
            mApiServer.Options.Statistical         = false;
            mApiServer.Options.UrlIgnoreCase       = false;
            mApiServer.Options.LogLevel            = BeetleX.EventArgs.LogType.Error;
            mApiServer.Options.LogToConsole        = true;
            mApiServer.Options.PrivateBufferPool   = true;
            mApiServer.Register(typeof(Program).Assembly);
            mApiServer.HttpConnected += (o, e) => {
                e.Session["DB"] = new RawDb(new ConcurrentRandom(), Npgsql.NpgsqlFactory.Instance);
            };
            mApiServer.Open();
            System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
            var response = await client.GetAsync("http://localhost:8080/json");

            mApiServer.BaseServer.Log(LogType.Info, null, $"Get josn {response.StatusCode}");
            response = await client.GetAsync("http://localhost:8080/plaintext");

            mApiServer.BaseServer.Log(LogType.Info, null, $"Get plaintext {response.StatusCode}");
        }
Example #6
0
 public async virtual Task StartAsync(CancellationToken cancellationToken)
 {
     plaintextResult         = new StringBytes(_helloWorldPayload);
     mApiServer              = new HttpApiServer();
     mApiServer.Options.Port = 8080;
     mApiServer.Options.BufferPoolMaxMemory = 500;
     mApiServer.Options.MaxConnections      = 100000;
     mApiServer.Options.Statistical         = false;
     mApiServer.Options.LogLevel            = BeetleX.EventArgs.LogType.Error;
     mApiServer.Options.LogToConsole        = true;
     mApiServer.Register(typeof(Program).Assembly);
     HeaderTypeFactory.SERVAR_HEADER_BYTES = Encoding.ASCII.GetBytes("Server: TFB\r\n");
     mApiServer.HttpConnected += (o, e) =>
     {
         e.Session["DB"] = new RawDb(new ConcurrentRandom(), Npgsql.NpgsqlFactory.Instance);
     };
     mApiServer.Started += (o, e) =>
     {
         mComplete.TrySetResult(new object());
     };
     mApiServer.Open();
     RawDb._connectionString = "Server=tfb-database;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=256;NoResetOnClose=true;Enlist=false;Max Auto Prepare=4;Multiplexing=true;Write Coalescing Delay Us=500;Write Coalescing Buffer Threshold Bytes=1000";
     //RawDb._connectionString = "Server=192.168.2.19;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=256;NoResetOnClose=true;Enlist=false;Max Auto Prepare=3";
     await mComplete.Task;
 }
Example #7
0
        static void Main(string[] args)
        {
            mApiServer = new HttpApiServer();
            mApiServer.Register(typeof(Program).Assembly);
            mApiServer.Open();

            Console.Write(mApiServer.BaseServer);
            Console.Read();
        }
Example #8
0
        public virtual Task StartAsync(CancellationToken cancellationToken)
        {
            mApiServer = new BeetleX.FastHttpApi.HttpApiServer();

            mApiServer.Options.ServerTag = "Unknow server";
            mApiServer.Options.LogLevel  = BeetleX.EventArgs.LogType.Warring;
            mApiServer.Register(typeof(Home).Assembly);
            mApiServer.Open();
            return(Task.CompletedTask);
        }
Example #9
0
            public virtual Task StartAsync(CancellationToken cancellationToken)
            {
                mApiServer = new HttpApiServer();
                mApiServer.Register(typeof(Program).Assembly);
                mApiServer.Options.Debug = true;
                mApiServer.Open();

                mApiServer.Log(EventArgs.LogType.Info, $"Web api benchmark started[{typeof(Program).Assembly.GetName().Version}]");
                return(Task.CompletedTask);
            }
Example #10
0
        public static void InitHttp()
        {
            HttpApiServer http = new HttpApiServer();

            http.Register(typeof(HttpCommon).Assembly);
            http.Options.Port        = Convert.ToInt32(ConfigReader.GetSecetion("HttpPort"));
            http.Options.CrossDomain = new OptionsAttribute {
                AllowOrigin = "*", AllowMethods = "*"
            };
            http.Open();
        }
Example #11
0
 static void Main(string[] args)
 {
     mApiServer = new HttpApiServer();
     mApiServer.Options.LogToConsole = true;
     mApiServer.Options.LogLevel     = BeetleX.EventArgs.LogType.Debug;
     mApiServer.Options.SetDebug();
     mApiServer.Register(typeof(Program).Assembly);
     mApiServer.Open();
     Console.Write(mApiServer.BaseServer);
     Console.WriteLine(Environment.ProcessorCount);
     Console.Read();
 }
Example #12
0
 public virtual Task StartAsync(CancellationToken cancellationToken)
 {
     BeetleX.Buffers.BufferPool.BUFFER_SIZE   = 1024 * 2;
     BeetleX.Buffers.BufferPool.POOL_MAX_SIZE = 1024 * 1024 * 2;
     TcpBanchmarks.Service.Default.Load();
     mApiServer = new HttpApiServer();
     mApiServer.Register(typeof(Program).Assembly);
     mApiServer.Options.Debug = true;
     mApiServer.Open();
     mApiServer.Log(BeetleX.EventArgs.LogType.Info, $"Tcp benchmark started[{typeof(Program).Assembly.GetName().Version}]");
     return(Task.CompletedTask);
 }
Example #13
0
 static void Main(string[] args)
 {
     mApiServer = new HttpApiServer();
     mApiServer.Register(typeof(Program).Assembly);//加载程序集中所有控制器信息和静态资源信息
     mApiServer.Options.Port         = 9090;
     mApiServer.Options.LogLevel     = BeetleX.EventArgs.LogType.Warring;
     mApiServer.Options.LogToConsole = true;
     mApiServer.Debug();//只有在Debug模式下生产,把静态资源加载目录指向项目的views目录
     mApiServer.Open();
     Console.Write(mApiServer.BaseServer);
     Console.Read();
 }
Example #14
0
        public virtual Task StartAsync(CancellationToken cancellationToken)
        {
            mApiServer = new HttpApiServer();
            DBModules.DBHelper.Default.GetSequence("System");
            ES.ESHelper.Init(DBModules.DBHelper.Default.Setting.ElasticSearch.Value);
            mApiServer.Debug();
            mApiServer.Register(typeof(Program).Assembly);
            mApiServer.Open();

            ES.ESHelper.SyncData(mApiServer);
            JWTHelper.Init();
            return(Task.CompletedTask);
        }
Example #15
0
        static void Main(string[] args)
        {
            UnitWork.Instance.Register((services) =>
            {
                services.AddScoped <Forward.Core.Forward>();

                services.AddSingleton <MaillService>();
                services.AddSingleton <OrderService>();

                services.AddSingleton(typeof(IConfig), (serviceProvider) =>
                {
                    var instance = new Config();
                    instance.TryAdd <MaillService>("maill");
                    return(instance);
                });
            });
            UnitWork.Instance.Builder();

            var subscribe = new SubscribeService();

            subscribe.AddService <MaillService, OrderService>((response) =>
            {
                if (response is bool checkResponse)
                {
                    if (checkResponse)
                    {
                        return(new OrderModel
                        {
                            Title = "Subscribe and Create Order",
                            PayMoney = 1,
                            CreateTime = DateTime.Now
                        });
                    }
                }

                return(null);
            });

            DiagnosticListener.AllListeners.Subscribe(subscribe);

            var mApiServer = new HttpApiServer();

            mApiServer.ActionFactory.ControllerInstance += (o, e) =>
            {
                e.Controller = UnitWork.Instance.ServiceProvider.GetRequiredService(e.Type);
            };
            mApiServer.Register(Assembly.Load("Forward.Core"));
            mApiServer.Open();

            Console.ReadLine();
        }
Example #16
0
 static void Main(string[] args)
 {
     mApiServer = new HttpApiServer();
     mApiServer.ServerConfig.WriteLog      = true;
     mApiServer.ServerConfig.LogToConsole  = true;
     mApiServer.ServerConfig.Port          = 8007;
     mApiServer.ServerConfig.LogLevel      = BeetleX.EventArgs.LogType.Warring;
     mApiServer.ServerConfig.UrlIgnoreCase = true;
     mApiServer.Register(typeof(Program).Assembly);
     mApiServer.Open();
     Console.Write(mApiServer.BaseServer);
     Console.WriteLine(Environment.ProcessorCount);
     Console.Read();
 }
Example #17
0
        static void Main(string[] args)
        {
            HttpApiServer server = new HttpApiServer();

            server.AddEFCoreDB <NorthwindEFCoreSqlite.NorthwindContext>();
            server.Options.Port         = 80;
            server.Options.LogToConsole = true;
            server.Options.LogLevel     = EventArgs.LogType.Info;
            server.Options.SetDebug();
            server.Register(typeof(Program).Assembly);
            server.AddExts("woff");
            server.Open();
            Console.Read();
        }
Example #18
0
 public virtual Task StartAsync(CancellationToken cancellationToken)
 {
     mApiServer = new HttpApiServer();
     mApiServer.Register(typeof(Program).Assembly);
     mApiServer.ServerConfig.Port           = 8080;
     mApiServer.ServerConfig.MaxConnections = 100000;
     mApiServer.ServerConfig.UrlIgnoreCase  = false;
     mApiServer.ServerConfig.LogLevel       = BeetleX.EventArgs.LogType.Warring;
     mApiServer.ServerConfig.LogToConsole   = true;
     mApiServer.Open();
     Console.WriteLine("BeetleX FastHttpApi server");
     Console.WriteLine($"ServerGC:{System.Runtime.GCSettings.IsServerGC}");
     Console.Write(mApiServer.BaseServer);
     return(Task.CompletedTask);
 }
Example #19
0
 internal ConsoleInterface(string location, int port)
 {
     AntiRainApiServer = new HttpApiServer();
     AntiRainApiServer.Options.Host         = location;
     AntiRainApiServer.Options.Port         = port;
     AntiRainApiServer.Options.LogLevel     = LogType.Off;
     AntiRainApiServer.Options.LogToConsole = false;
     AntiRainApiServer.Options.Debug        = false;
     AntiRainApiServer.Options.CrossDomain  = new OptionsAttribute
     {
         AllowOrigin = "*"
     };
     AntiRainApiServer.Register(Assembly.GetExecutingAssembly());
     AntiRainApiServer.Open();
     Log.Debug("AntiRain初始化", $"AntiRain API服务正在运行[{location}:{port}]");
 }
Example #20
0
 public virtual Task StartAsync(CancellationToken cancellationToken)
 {
     plaintextResult         = new StringBytes(_helloWorldPayload);
     mApiServer              = new HttpApiServer();
     mApiServer.Options.Port = 8080;
     mApiServer.Options.BufferPoolMaxMemory = 500;
     mApiServer.Options.MaxConnections      = 100000;
     mApiServer.Options.Statistical         = false;
     mApiServer.Options.UrlIgnoreCase       = false;
     mApiServer.Options.LogLevel            = BeetleX.EventArgs.LogType.Error;
     mApiServer.Options.LogToConsole        = true;
     mApiServer.Options.PrivateBufferPool   = true;
     mApiServer.Register(typeof(Program).Assembly);
     mApiServer.Open();
     return(Task.CompletedTask);
 }
 public virtual Task StartAsync(CancellationToken cancellationToken)
 {
     mApiServer = new HttpApiServer();
     mApiServer.Register(typeof(Program).Assembly);
     mApiServer.Options.Port = 8080;
     mApiServer.Options.BufferPoolMaxMemory = 500;
     mApiServer.Options.MaxConnections      = 100000;
     mApiServer.Options.Statistical         = false;
     mApiServer.Options.UrlIgnoreCase       = false;
     mApiServer.Options.LogLevel            = BeetleX.EventArgs.LogType.Off;
     mApiServer.Options.LogToConsole        = true;
     mApiServer.Options.IOQueueEnabled      = true;
     mApiServer.Open();
     Console.WriteLine("BeetleX FastHttpApi server");
     Console.WriteLine($"ServerGC:{System.Runtime.GCSettings.IsServerGC}");
     Console.Write(mApiServer.BaseServer);
     return(Task.CompletedTask);
 }