public ServerCounter.ServerStatus GetServerInfo()
 {
     if (ServerCounter != null)
     {
         return(ServerCounter.Next());
     }
     return(new ServerCounter.ServerStatus());
 }
Exemple #2
0
        public void Open()
        {
            NetConfig config = new NetConfig();

            config.Host                = ServerConfig.Host;
            config.Port                = ServerConfig.Port;
            config.CertificateFile     = ServerConfig.CertificateFile;
            config.CertificatePassword = ServerConfig.CertificatePassword;
            config.BufferSize          = ServerConfig.BufferSize;
            config.LogLevel            = ServerConfig.LogLevel;
            config.Combined            = ServerConfig.PacketCombined;
            config.SessionTimeOut      = ServerConfig.SessionTimeOut;
            config.UseIPv6             = ServerConfig.UseIPv6;
            config.BufferPoolMaxMemory = ServerConfig.BufferPoolMaxMemory;
            if (!string.IsNullOrEmpty(config.CertificateFile))
            {
                config.SSL = true;
            }
            config.LittleEndian = false;
            AppDomain.CurrentDomain.AssemblyResolve += ResolveHandler;
            HttpPacket hp = new HttpPacket(this, this);

            mServer = SocketFactory.CreateTcpServer(config, this, hp);
            Name    = "BeetleX Http Server";
            if (mAssemblies != null)
            {
                foreach (System.Reflection.Assembly assembly in mAssemblies)
                {
                    mResourceCenter.LoadManifestResource(assembly);
                }
            }
            mResourceCenter.LoadManifestResource(typeof(HttpApiServer).Assembly);
            mResourceCenter.Path  = ServerConfig.StaticResourcePath;
            mResourceCenter.Debug = ServerConfig.Debug;
            mResourceCenter.Load();
            ModuleManage.Load();
            StartTime = DateTime.Now;
            mServer.Open();
            mServerCounter            = new ServerCounter(this);
            mUrlRewrite.UrlIgnoreCase = ServerConfig.UrlIgnoreCase;
            mUrlRewrite.AddRegion(this.ServerConfig.Routes);
            HeaderTypeFactory.Find(HeaderTypeFactory.HOST);
            AppDomain.CurrentDomain.UnhandledException += (s, e) =>
            {
                using (System.IO.StreamWriter writer = new StreamWriter("__UnhandledException.txt"))
                {
                    Exception error = e.ExceptionObject as Exception;
                    writer.WriteLine(DateTime.Now);
                    if (error != null)
                    {
                        writer.WriteLine(error.Message);
                        writer.WriteLine(error.StackTrace);
                        if (error.InnerException != null)
                        {
                            writer.WriteLine(error.InnerException.Message);
                            writer.WriteLine(error.InnerException.StackTrace);
                        }
                    }
                    else
                    {
                        writer.WriteLine("Unhandled Exception:" + e.ExceptionObject.ToString());
                    }
                    writer.Flush();
                }
            };
            mServer.Log(LogType.Info, null, $"BeetleX FastHttpApi start@[v:{typeof(HttpApiServer).Assembly.GetName().Version}]");
        }
Exemple #3
0
        public void Open()
        {
            var date = GMTDate.Default.DATE;
            var ct   = ContentTypes.TEXT_UTF8;
            var a    = HeaderTypeFactory.Find("Content-Length");

            AppDomain.CurrentDomain.AssemblyResolve += ResolveHandler;
            HttpPacket hp         = new HttpPacket(this, this);
            var        gtmdate    = GMTDate.Default;
            string     serverInfo = $"Server: BeetleX[{typeof(BeetleX.BXException).Assembly.GetName().Version}]/FastHttpApi[{typeof(HttpApiServer).Assembly.GetName().Version}]\r\n";

            HeaderTypeFactory.SERVAR_HEADER_BYTES = Encoding.ASCII.GetBytes(serverInfo);
            mServer = SocketFactory.CreateTcpServer(this, hp)
                      .Setting(o =>
            {
                o.SyncAccept = Options.SyncAccept;
                // o.IOQueues = Options.IOQueues;
                o.DefaultListen.Host = Options.Host;
                // o.IOQueueEnabled = Options.IOQueueEnabled;
                o.DefaultListen.Port    = Options.Port;
                o.BufferSize            = Options.BufferSize;
                o.LogLevel              = Options.LogLevel;
                o.Combined              = Options.PacketCombined;
                o.SessionTimeOut        = Options.SessionTimeOut;
                o.UseIPv6               = Options.UseIPv6;
                o.BufferPoolMaxMemory   = Options.BufferPoolMaxMemory;
                o.LittleEndian          = false;
                o.Statistical           = Options.Statistical;
                o.BufferPoolGroups      = Options.BufferPoolGroups;
                o.BufferPoolSize        = Options.BufferPoolSize;
                o.PrivateBufferPool     = Options.PrivateBufferPool;
                o.PrivateBufferPoolSize = Options.MaxBodyLength;
                o.MaxWaitMessages       = Options.MaxWaitQueue;
            });
            if (Options.IOQueueEnabled)
            {
                mRequestIOQueues = new DispatchCenter <IOQueueProcessArgs>(OnIOQueueProcess, Options.IOQueues);
            }
            if (Options.SSL)
            {
                mServer.Setting(o =>
                {
                    o.AddListenSSL(Options.CertificateFile, Options.CertificatePassword, o.DefaultListen.Host, Options.SSLPort);
                });
            }
            Name = "BeetleX Http Server";
            if (mAssemblies != null)
            {
                foreach (System.Reflection.Assembly assembly in mAssemblies)
                {
                    mResourceCenter.LoadManifestResource(assembly);
                }
            }
            mResourceCenter.LoadManifestResource(typeof(HttpApiServer).Assembly);
            mResourceCenter.Path  = Options.StaticResourcePath;
            mResourceCenter.Debug = Options.Debug;
            mResourceCenter.Load();
            ModuleManager.Load();
            if (Options.ManageApiEnabled)
            {
                ServerController serverStatusController = new ServerController();
                mActionFactory.Register(serverStatusController);
            }
            StartTime = DateTime.Now;
            mServer.Open();
            mServerCounter            = new ServerCounter(this);
            mUrlRewrite.UrlIgnoreCase = Options.UrlIgnoreCase;
            mUrlRewrite.Load();
            //mUrlRewrite.AddRegion(this.Options.Routes);
            HeaderTypeFactory.Find(HeaderTypeFactory.HOST);
            AppDomain.CurrentDomain.UnhandledException += (s, e) =>
            {
                using (System.IO.StreamWriter writer = new StreamWriter("__UnhandledException.txt"))
                {
                    Exception error = e.ExceptionObject as Exception;
                    writer.WriteLine(DateTime.Now);
                    if (error != null)
                    {
                        writer.WriteLine(error.Message);
                        writer.WriteLine(error.StackTrace);
                        if (error.InnerException != null)
                        {
                            writer.WriteLine(error.InnerException.Message);
                            writer.WriteLine(error.InnerException.StackTrace);
                        }
                    }
                    else
                    {
                        writer.WriteLine("Unhandled Exception:" + e.ExceptionObject.ToString());
                    }
                    writer.Flush();
                }
            };

            mServer.Log(LogType.Info, null, $"BeetleX FastHttpApi [IOQueue:{Options.IOQueueEnabled}|Threads:{Options.IOQueues}] [V:{typeof(HttpApiServer).Assembly.GetName().Version}]");
            OnOptionLoad(new EventOptionsReloadArgs {
                HttpApiServer = this, HttpOptions = this.Options
            });
            OnStrated(new EventHttpServerStartedArgs {
                HttpApiServer = this
            });
        }
        public void Open()
        {
            AppDomain.CurrentDomain.AssemblyResolve += ResolveHandler;
            HttpPacket hp = new HttpPacket(this, this);

            mServer = SocketFactory.CreateTcpServer(this, hp)
                      .Setting(o =>
            {
                o.DefaultListen.Host  = Options.Host;
                o.IOQueueEnabled      = Options.IOQueueEnabled;
                o.DefaultListen.Port  = Options.Port;
                o.BufferSize          = Options.BufferSize;
                o.LogLevel            = Options.LogLevel;
                o.Combined            = Options.PacketCombined;
                o.SessionTimeOut      = Options.SessionTimeOut;
                o.UseIPv6             = Options.UseIPv6;
                o.BufferPoolMaxMemory = Options.BufferPoolMaxMemory;
                o.LittleEndian        = false;
                o.Statistical         = Options.Statistical;
            });
            if (Options.SSL)
            {
                mServer.Setting(o =>
                {
                    o.AddListenSSL(Options.CertificateFile, Options.CertificatePassword, o.DefaultListen.Host, Options.SSLPort);
                });
            }
            Name = "BeetleX Http Server";
            if (mAssemblies != null)
            {
                foreach (System.Reflection.Assembly assembly in mAssemblies)
                {
                    mResourceCenter.LoadManifestResource(assembly);
                }
            }
            mResourceCenter.LoadManifestResource(typeof(HttpApiServer).Assembly);
            mResourceCenter.Path  = Options.StaticResourcePath;
            mResourceCenter.Debug = Options.Debug;
            mResourceCenter.Load();
            ModuleManager.Load();
            if (Options.ManageApiEnabled)
            {
                ServerController serverStatusController = new ServerController();
                mActionFactory.Register(serverStatusController);
            }
            StartTime = DateTime.Now;
            mServer.Open();
            mServerCounter            = new ServerCounter(this);
            mUrlRewrite.UrlIgnoreCase = Options.UrlIgnoreCase;
            mUrlRewrite.AddRegion(this.Options.Routes);
            HeaderTypeFactory.Find(HeaderTypeFactory.HOST);
            AppDomain.CurrentDomain.UnhandledException += (s, e) =>
            {
                using (System.IO.StreamWriter writer = new StreamWriter("__UnhandledException.txt"))
                {
                    Exception error = e.ExceptionObject as Exception;
                    writer.WriteLine(DateTime.Now);
                    if (error != null)
                    {
                        writer.WriteLine(error.Message);
                        writer.WriteLine(error.StackTrace);
                        if (error.InnerException != null)
                        {
                            writer.WriteLine(error.InnerException.Message);
                            writer.WriteLine(error.InnerException.StackTrace);
                        }
                    }
                    else
                    {
                        writer.WriteLine("Unhandled Exception:" + e.ExceptionObject.ToString());
                    }
                    writer.Flush();
                }
            };
            mServer.Log(LogType.Info, null, $"BeetleX FastHttpApi start@[v:{typeof(HttpApiServer).Assembly.GetName().Version}]");
            OnOptionLoad(new EventOptionsReloadArgs {
                HttpApiServer = this, HttpOptions = this.Options
            });
            OnStrated(new EventHttpServerStartedArgs {
                HttpApiServer = this
            });
        }
        public void Open()
        {
            NetConfig config = new NetConfig();

            config.Host                = ServerConfig.Host;
            config.Port                = ServerConfig.Port;
            config.CertificateFile     = ServerConfig.CertificateFile;
            config.CertificatePassword = ServerConfig.CertificatePassword;
            config.BufferSize          = ServerConfig.BufferSize;
            config.LogLevel            = ServerConfig.LogLevel;
            if (!string.IsNullOrEmpty(config.CertificateFile))
            {
                config.SSL = true;
            }
            config.LittleEndian = false;
            HttpPacket hp = new HttpPacket(this.ServerConfig, this);

            mServer = SocketFactory.CreateTcpServer(config, this, hp);
            Name    = "FastHttpApi Http Server";
            if (mAssemblies != null)
            {
                foreach (System.Reflection.Assembly assembly in mAssemblies)
                {
                    mResourceCenter.LoadManifestResource(assembly);
                }
            }
            mResourceCenter.LoadManifestResource(typeof(HttpApiServer).Assembly);
            mResourceCenter.Path  = ServerConfig.StaticResourcePath;
            mResourceCenter.Debug = ServerConfig.Debug;
            mResourceCenter.Load();
            StartTime = DateTime.Now;
            mServer.Open();
            mServerCounter = new ServerCounter(this);
            HeaderTypeFactory.Find(HeaderTypeFactory.HOST);
            AppDomain.CurrentDomain.UnhandledException += (s, e) =>
            {
                using (System.IO.StreamWriter writer = new StreamWriter("__UnhandledException.txt"))
                {
                    Exception error = e.ExceptionObject as Exception;
                    writer.WriteLine(DateTime.Now);
                    if (error != null)
                    {
                        writer.WriteLine(error.Message);
                        writer.WriteLine(error.StackTrace);
                        if (error.InnerException != null)
                        {
                            writer.WriteLine(error.InnerException.Message);
                            writer.WriteLine(error.InnerException.StackTrace);
                        }
                    }
                    else
                    {
                        writer.WriteLine("Unhandled Exception:" + e.ExceptionObject.ToString());
                    }
                    writer.Flush();
                }
            };
            if (EnableLog(LogType.Info))
            {
                mServer.Log(LogType.Info, null, "FastHttpApi Server started!");
            }
        }